Skip to content

Commit

Permalink
Merge pull request #21342 from ygalblum/kube-play-pvc-image-based
Browse files Browse the repository at this point in the history
Kube Play - allow creating image based volumes
  • Loading branch information
openshift-merge-bot[bot] authored Jan 25, 2024
2 parents f3f0620 + 269149a commit a0ad2cf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/markdown/podman-kube-play.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
30 changes: 30 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit a0ad2cf

Please sign in to comment.