summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorEduardo Vega <edvegavalerio@gmail.com>2021-03-26 18:16:41 -0600
committerEduardo Vega <edvegavalerio@gmail.com>2021-04-09 14:01:13 -0600
commit61cb6d61dd420a000c843171b5917b5595874a67 (patch)
treeb56af885a529beb0ddf0386b090bc7cda5c93b49 /libpod
parentf143de9db6861cd8b8d6fc4e03f2826041307982 (diff)
downloadpodman-61cb6d61dd420a000c843171b5917b5595874a67.tar.gz
podman-61cb6d61dd420a000c843171b5917b5595874a67.tar.bz2
podman-61cb6d61dd420a000c843171b5917b5595874a67.zip
Add support for play/generate kube volumes
Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/kube.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/libpod/kube.go b/libpod/kube.go
index b4dd4f10a..11ccaeadc 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -16,6 +16,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
+ "k8s.io/apimachinery/pkg/api/resource"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -113,6 +114,50 @@ func (p *Pod) getInfraContainer() (*Container, error) {
return p.runtime.GetContainer(infraID)
}
+// GenerateForKube generates a v1.PersistentVolumeClaim from a libpod volume.
+func (v *Volume) GenerateForKube() *v1.PersistentVolumeClaim {
+ annotations := make(map[string]string)
+ annotations[util.VolumeDriverAnnotation] = v.Driver()
+
+ for k, v := range v.Options() {
+ switch k {
+ case "o":
+ annotations[util.VolumeMountOptsAnnotation] = v
+ case "device":
+ annotations[util.VolumeDeviceAnnotation] = v
+ case "type":
+ annotations[util.VolumeTypeAnnotation] = v
+ case "UID":
+ annotations[util.VolumeUIDAnnotation] = v
+ case "GID":
+ annotations[util.VolumeGIDAnnotation] = v
+ }
+ }
+
+ return &v1.PersistentVolumeClaim{
+ TypeMeta: v12.TypeMeta{
+ Kind: "PersistentVolumeClaim",
+ APIVersion: "v1",
+ },
+ ObjectMeta: v12.ObjectMeta{
+ Name: v.Name(),
+ Labels: v.Labels(),
+ Annotations: annotations,
+ CreationTimestamp: v12.Now(),
+ },
+ Spec: v1.PersistentVolumeClaimSpec{
+ Resources: v1.ResourceRequirements{
+ Requests: map[v1.ResourceName]resource.Quantity{
+ v1.ResourceStorage: resource.MustParse("1Gi"),
+ },
+ },
+ AccessModes: []v1.PersistentVolumeAccessMode{
+ v1.ReadWriteOnce,
+ },
+ },
+ }
+}
+
// GenerateKubeServiceFromV1Pod creates a v1 service object from a v1 pod object
func GenerateKubeServiceFromV1Pod(pod *v1.Pod, servicePorts []v1.ServicePort) v1.Service {
service := v1.Service{}