mirror of
https://github.com/containers/podman.git
synced 2025-06-19 16:33:24 +08:00
Merge pull request #10136 from zhangguanzhang/generate-kube-volume
Fixes generate kube incorrect when bind-mounting "/" and "/root"
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -539,11 +540,17 @@ func libpodMountsToKubeVolumeMounts(c *Container) ([]v1.VolumeMount, []v1.Volume
|
|||||||
namedVolumes, mounts := c.sortUserVolumes(c.config.Spec)
|
namedVolumes, mounts := c.sortUserVolumes(c.config.Spec)
|
||||||
vms := make([]v1.VolumeMount, 0, len(mounts))
|
vms := make([]v1.VolumeMount, 0, len(mounts))
|
||||||
vos := make([]v1.Volume, 0, len(mounts))
|
vos := make([]v1.Volume, 0, len(mounts))
|
||||||
for _, m := range mounts {
|
|
||||||
|
var suffix string
|
||||||
|
for index, m := range mounts {
|
||||||
vm, vo, err := generateKubeVolumeMount(m)
|
vm, vo, err := generateKubeVolumeMount(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vms, vos, err
|
return vms, vos, err
|
||||||
}
|
}
|
||||||
|
// Name will be the same, so use the index as suffix
|
||||||
|
suffix = fmt.Sprintf("-%d", index)
|
||||||
|
vm.Name += suffix
|
||||||
|
vo.Name += suffix
|
||||||
vms = append(vms, vm)
|
vms = append(vms, vm)
|
||||||
vos = append(vos, vo)
|
vos = append(vos, vo)
|
||||||
}
|
}
|
||||||
|
@ -496,6 +496,29 @@ var _ = Describe("Podman generate kube", func() {
|
|||||||
Expect(inspect.OutputToString()).To(ContainSubstring(vol1))
|
Expect(inspect.OutputToString()).To(ContainSubstring(vol1))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman generate kube when bind-mounting '/' and '/root' at the same time ", func() {
|
||||||
|
// Fixes https://github.com/containers/podman/issues/9764
|
||||||
|
|
||||||
|
ctrName := "mount-root-ctr"
|
||||||
|
session1 := podmanTest.Podman([]string{"run", "-d", "--pod", "new:mount-root-conflict", "--name", ctrName,
|
||||||
|
"-v", "/:/volume1/",
|
||||||
|
"-v", "/root:/volume2/",
|
||||||
|
"alpine", "top"})
|
||||||
|
session1.WaitWithDefaultTimeout()
|
||||||
|
Expect(session1.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"generate", "kube", "mount-root-conflict"})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
pod := new(v1.Pod)
|
||||||
|
err := yaml.Unmarshal(kube.Out.Contents(), pod)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
Expect(len(pod.Spec.Volumes)).To(Equal(2))
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
It("podman generate kube with persistent volume claim", func() {
|
It("podman generate kube with persistent volume claim", func() {
|
||||||
vol := "vol-test-persistent-volume-claim"
|
vol := "vol-test-persistent-volume-claim"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user