mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Merge pull request #13732 from flouthoc/reuse-configmap-volume
kube: `configmap` volume should be reused if already exists
This commit is contained in:
@ -290,7 +290,16 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
|
|||||||
if v.Type == kube.KubeVolumeTypeConfigMap && !v.Optional {
|
if v.Type == kube.KubeVolumeTypeConfigMap && !v.Optional {
|
||||||
vol, err := ic.Libpod.NewVolume(ctx, libpod.WithVolumeName(v.Source))
|
vol, err := ic.Libpod.NewVolume(ctx, libpod.WithVolumeName(v.Source))
|
||||||
if err != nil {
|
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()
|
mountPoint, err := vol.MountPoint()
|
||||||
if err != nil || mountPoint == "" {
|
if err != nil || mountPoint == "" {
|
||||||
|
@ -1679,6 +1679,32 @@ var _ = Describe("Podman play kube", func() {
|
|||||||
Expect(inspect.OutputToString()).To(ContainSubstring(`FOO=foo`))
|
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() {
|
It("podman play kube test required env value from configmap with missing key", func() {
|
||||||
SkipIfRemote("configmap list is not supported as a param")
|
SkipIfRemote("configmap list is not supported as a param")
|
||||||
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
|
Reference in New Issue
Block a user