From 269149a9fddefe68fdcfb19a96072d65da2086ff Mon Sep 17 00:00:00 2001 From: Ygal Blum Date: Wed, 24 Jan 2024 09:59:35 +0200 Subject: [PATCH] Kube Play - allow creating image based volumes Add volume.podman.io/image annotation to allow setting the source image Signed-off-by: Ygal Blum --- docs/source/markdown/podman-kube-play.1.md.in | 1 + pkg/domain/infra/abi/play.go | 2 ++ pkg/util/kube.go | 2 ++ test/e2e/play_kube_test.go | 30 +++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/docs/source/markdown/podman-kube-play.1.md.in b/docs/source/markdown/podman-kube-play.1.md.in index a2c07a459c..90b7c89e61 100644 --- a/docs/source/markdown/podman-kube-play.1.md.in +++ b/docs/source/markdown/podman-kube-play.1.md.in @@ -61,6 +61,7 @@ A Kubernetes PersistentVolumeClaim represents a Podman named volume. Only the Pe - volume.podman.io/gid - volume.podman.io/mount-options - volume.podman.io/import-source +- volume.podman.io/image Use `volume.podman.io/import-source` to import the contents of the tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) specified in the annotation's value into the created Podman volume diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 610648d892..6fd38312a1 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -1147,6 +1147,8 @@ func (ic *ContainerEngine) playKubePVC(ctx context.Context, mountLabel string, p opts["o"] = v case util.VolumeImportSourceAnnotation: importFrom = v + case util.VolumeImageAnnotation: + opts["image"] = v } } volOptions = append(volOptions, libpod.WithVolumeOptions(opts)) diff --git a/pkg/util/kube.go b/pkg/util/kube.go index 1a70ed0518..7159fa7460 100644 --- a/pkg/util/kube.go +++ b/pkg/util/kube.go @@ -15,4 +15,6 @@ const ( VolumeMountOptsAnnotation = "volume.podman.io/mount-options" // Kube annotation for podman volume import source. VolumeImportSourceAnnotation = "volume.podman.io/import-source" + // Kube annotation for podman volume image. + VolumeImageAnnotation = "volume.podman.io/image" ) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index f4c1a739bd..359bd4dc6a 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -4062,6 +4062,36 @@ o: {{ .Options.o }}`}) Expect(files[0].Name()).To(Equal(fileName)) }) + It("persistentVolumeClaim - image based", func() { + volName := "myVolWithStorage" + imageName := "quay.io/libpod/alpine_nginx:latest" + pvc := getPVC(withPVCName(volName), + withPVCAnnotations(util.VolumeDriverAnnotation, "image"), + withPVCAnnotations(util.VolumeImageAnnotation, imageName), + ) + err = generateKubeYaml("persistentVolumeClaim", pvc, kubeYaml) + Expect(err).ToNot(HaveOccurred()) + + kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube).Should(ExitCleanly()) + + inspect := podmanTest.Podman([]string{"inspect", volName, "--format", ` +{ + "Name": "{{ .Name }}", + "Driver": "{{ .Driver }}", + "Image": "{{ .Options.image }}" +}`}) + inspect.WaitWithDefaultTimeout() + Expect(inspect).Should(ExitCleanly()) + mp := make(map[string]string) + err = json.Unmarshal([]byte(inspect.OutputToString()), &mp) + Expect(err).ToNot(HaveOccurred()) + Expect(mp["Name"]).To(Equal(volName)) + Expect(mp["Driver"]).To(Equal("image")) + Expect(mp["Image"]).To(Equal(imageName)) + }) + // Multi doc related tests It("multi doc yaml with persistentVolumeClaim, service and deployment", func() { yamlDocs := []string{}