summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-04-12 12:36:20 +0200
committerGitHub <noreply@github.com>2021-04-12 12:36:20 +0200
commit9d3e31071087908207a8f7fdc84939edf3dc47c0 (patch)
tree7993a84a9b70504b2a99c88085e5e7205bc0b94b /libpod
parent3b03ff7d1ea65c31ca8c9a28e70f7dd5a43afbf0 (diff)
parent61cb6d61dd420a000c843171b5917b5595874a67 (diff)
downloadpodman-9d3e31071087908207a8f7fdc84939edf3dc47c0.tar.gz
podman-9d3e31071087908207a8f7fdc84939edf3dc47c0.tar.bz2
podman-9d3e31071087908207a8f7fdc84939edf3dc47c0.zip
Merge pull request #9935 from EduardoVega/5788-kube-volume
Add support for play/generate kube PersistentVolumeClaims and Podman volumes
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{}