diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-04-19 05:01:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 05:01:52 -0400 |
commit | 21ae0730344b8510a1af2045aceebaa1a7a38f4c (patch) | |
tree | 21431c4730510587ae0932501db8049e52f5cb8a | |
parent | 6ff56ab50a10e2350013c4ff1bf4b8d5d7b5aa87 (diff) | |
parent | 18d462c41bfa0d06353427d1abe2f60f0724d28d (diff) | |
download | podman-21ae0730344b8510a1af2045aceebaa1a7a38f4c.tar.gz podman-21ae0730344b8510a1af2045aceebaa1a7a38f4c.tar.bz2 podman-21ae0730344b8510a1af2045aceebaa1a7a38f4c.zip |
Merge pull request #10069 from EduardoVega/clean-mounts-9618
Ensure mount destination is clean, no trailing slash
-rw-r--r-- | pkg/specgen/generate/storage.go | 9 | ||||
-rw-r--r-- | test/e2e/play_kube_test.go | 48 |
2 files changed, 54 insertions, 3 deletions
diff --git a/pkg/specgen/generate/storage.go b/pkg/specgen/generate/storage.go index e135f4728..8066834f7 100644 --- a/pkg/specgen/generate/storage.go +++ b/pkg/specgen/generate/storage.go @@ -57,10 +57,13 @@ func finalizeMounts(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Ru } for _, m := range s.Mounts { - if _, ok := unifiedMounts[m.Destination]; ok { - return nil, nil, nil, errors.Wrapf(errDuplicateDest, "conflict in specified mounts - multiple mounts at %q", m.Destination) + // Ensure that mount dest is clean, so that it can be + // compared against named volumes and avoid duplicate mounts. + cleanDestination := filepath.Clean(m.Destination) + if _, ok := unifiedMounts[cleanDestination]; ok { + return nil, nil, nil, errors.Wrapf(errDuplicateDest, "conflict in specified mounts - multiple mounts at %q", cleanDestination) } - unifiedMounts[m.Destination] = m + unifiedMounts[cleanDestination] = m } for _, m := range commonMounts { diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 5c25c4459..f89da4c05 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -1894,6 +1894,54 @@ spec: Expect(inspect.OutputToString()).To(ContainSubstring(correct)) }) + It("podman play kube test duplicate volume destination between host path and image volumes", func() { + // Create host test directory and file + testdir := "testdir" + testfile := "testfile" + + hostPathDir := filepath.Join(tempdir, testdir) + err := os.Mkdir(hostPathDir, 0755) + Expect(err).To(BeNil()) + + hostPathDirFile := filepath.Join(hostPathDir, testfile) + f, err := os.Create(hostPathDirFile) + Expect(err).To(BeNil()) + f.Close() + + // Create container image with named volume + containerfile := fmt.Sprintf(` +FROM %s +VOLUME %s`, ALPINE, hostPathDir+"/") + + image := "podman-kube-test:podman" + podmanTest.BuildImage(containerfile, image, "false") + + // Create and play kube pod + ctr := getCtr(withVolumeMount(hostPathDir+"/", false), withImage(image)) + pod := getPod(withCtr(ctr), withVolume(getHostPathVolume("Directory", hostPathDir+"/"))) + err = generateKubeYaml("pod", pod, kubeYaml) + Expect(err).To(BeNil()) + + kube := podmanTest.Podman([]string{"play", "kube", kubeYaml}) + kube.WaitWithDefaultTimeout() + Expect(kube.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "ls", hostPathDir + "/" + testfile}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + + inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod)}) + inspect.WaitWithDefaultTimeout() + Expect(inspect.ExitCode()).To(Equal(0)) + + // If two volumes are specified and share the same destination, + // only one will be mounted. Host path volumes take precedence. + ctrJSON := inspect.InspectContainerToJSON() + Expect(len(ctrJSON[0].Mounts)).To(Equal(1)) + Expect(ctrJSON[0].Mounts[0].Type).To(Equal("bind")) + + }) + It("podman play kube test with PersistentVolumeClaim volume", func() { volumeName := "namedVolume" |