summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya R <arajan@redhat.com>2022-03-31 14:46:50 +0530
committerAditya R <arajan@redhat.com>2022-03-31 15:07:22 +0530
commitdaeea48df5061d1d7a7207995fa166c2106ba3ae (patch)
treedc654d918cd0fb947670f44769a57e0faac62fed
parentc08e8c30a1069acab69bd5704c6362c7c90252d6 (diff)
downloadpodman-daeea48df5061d1d7a7207995fa166c2106ba3ae.tar.gz
podman-daeea48df5061d1d7a7207995fa166c2106ba3ae.tar.bz2
podman-daeea48df5061d1d7a7207995fa166c2106ba3ae.zip
kube: configmap volume should be reused if already exists
`podman play kube` creates a new volume for configmap, if same configmap is applied again volume can be re-used, there is no need to remove and re-create the volume again Signed-off-by: Aditya R <arajan@redhat.com>
-rw-r--r--pkg/domain/infra/abi/play.go11
-rw-r--r--test/e2e/play_kube_test.go26
2 files changed, 36 insertions, 1 deletions
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index 1423ab06e..c3f6bb17d 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -290,7 +290,16 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
if v.Type == kube.KubeVolumeTypeConfigMap && !v.Optional {
vol, err := ic.Libpod.NewVolume(ctx, libpod.WithVolumeName(v.Source))
if err != nil {
- return nil, errors.Wrapf(err, "cannot create a local volume for volume from configmap %q", v.Source)
+ if errors.Is(err, define.ErrVolumeExists) {
+ // Volume for this configmap already exists do not
+ // error out instead reuse the current volume.
+ vol, err = ic.Libpod.GetVolume(v.Source)
+ if err != nil {
+ return nil, errors.Wrapf(err, "cannot re-use local volume for volume from configmap %q", v.Source)
+ }
+ } else {
+ return nil, errors.Wrapf(err, "cannot create a local volume for volume from configmap %q", v.Source)
+ }
}
mountPoint, err := vol.MountPoint()
if err != nil || mountPoint == "" {
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 6a4083565..f16180854 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -1679,6 +1679,32 @@ var _ = Describe("Podman play kube", func() {
Expect(inspect.OutputToString()).To(ContainSubstring(`FOO=foo`))
})
+ It("podman play kube test env value from configmap and --replace should reuse the configmap volume", func() {
+ SkipIfRemote("configmap list is not supported as a param")
+ cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
+ cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
+ err := generateKubeYaml("configmap", cm, cmYamlPathname)
+ Expect(err).To(BeNil())
+
+ pod := getPod(withCtr(getCtr(withEnv("FOO", "", "configmap", "foo", "FOO", false))))
+ err = generateKubeYaml("pod", pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml, "--configmap", cmYamlPathname})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube).Should(Exit(0))
+
+ // create pod again with --replace
+ kube = podmanTest.Podman([]string{"play", "kube", "--replace", kubeYaml, "--configmap", cmYamlPathname})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube).Should(Exit(0))
+
+ inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'"})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect).Should(Exit(0))
+ Expect(inspect.OutputToString()).To(ContainSubstring(`FOO=foo`))
+ })
+
It("podman play kube test required env value from configmap with missing key", func() {
SkipIfRemote("configmap list is not supported as a param")
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")