Skip to content

Commit a098899

Browse files
committed
Use semi-colon as the field separator for internal volumes-from inspect annotation
The current field separator comma of the inspect annotation conflicts with the mount options of --volumes-from as the mount options itself can be comma separated. Signed-off-by: Vikas Goel <[email protected]>
1 parent 2431fb3 commit a098899

File tree

6 files changed

+69
-5
lines changed

6 files changed

+69
-5
lines changed

libpod/container_inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (c *Container) volumesFrom() ([]string, error) {
5454
return nil, err
5555
}
5656
if ctrs, ok := ctrSpec.Annotations[define.InspectAnnotationVolumesFrom]; ok {
57-
return strings.Split(ctrs, ","), nil
57+
return strings.Split(ctrs, ";"), nil
5858
}
5959
return nil, nil
6060
}
@@ -511,7 +511,7 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
511511
hostConfig.AutoRemove = true
512512
}
513513
if ctrs, ok := ctrSpec.Annotations[define.InspectAnnotationVolumesFrom]; ok {
514-
hostConfig.VolumesFrom = strings.Split(ctrs, ",")
514+
hostConfig.VolumesFrom = strings.Split(ctrs, ";")
515515
}
516516
if ctrSpec.Annotations[define.InspectAnnotationPrivileged] == define.InspectResponseTrue {
517517
hostConfig.Privileged = true

libpod/pod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (p *Pod) VolumesFrom() []string {
278278
return nil
279279
}
280280
if ctrs, ok := infra.config.Spec.Annotations[define.InspectAnnotationVolumesFrom]; ok {
281-
return strings.Split(ctrs, ",")
281+
return strings.Split(ctrs, ";")
282282
}
283283
return nil
284284
}

pkg/specgen/generate/oci_freebsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
152152
}
153153

154154
if len(s.VolumesFrom) > 0 {
155-
configSpec.Annotations[define.InspectAnnotationVolumesFrom] = strings.Join(s.VolumesFrom, ",")
155+
configSpec.Annotations[define.InspectAnnotationVolumesFrom] = strings.Join(s.VolumesFrom, ";")
156156
}
157157

158158
if s.IsPrivileged() {

pkg/specgen/generate/oci_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
322322
}
323323

324324
if len(s.VolumesFrom) > 0 {
325-
configSpec.Annotations[define.InspectAnnotationVolumesFrom] = strings.Join(s.VolumesFrom, ",")
325+
configSpec.Annotations[define.InspectAnnotationVolumesFrom] = strings.Join(s.VolumesFrom, ";")
326326
}
327327

328328
if s.IsPrivileged() {

test/e2e/container_inspect_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package integration
22

33
import (
4+
"os"
5+
"path/filepath"
6+
47
"github.com/containers/podman/v4/libpod/define"
58
"github.com/containers/podman/v4/pkg/annotations"
69
. "github.com/containers/podman/v4/test/utils"
@@ -44,4 +47,27 @@ var _ = Describe("Podman container inspect", func() {
4447
Expect(data[0].NetworkSettings.Ports).
4548
To(Equal(map[string][]define.InspectHostPort{"80/tcp": nil, "8989/tcp": nil}))
4649
})
50+
51+
It("podman inspect shows volumes-from with mount options", func() {
52+
ctr1 := "volfctr"
53+
ctr2 := "voltctr"
54+
vol1 := filepath.Join(podmanTest.TempDir, "vol-test1")
55+
volsctr := ctr1 + ":z,ro"
56+
57+
err := os.MkdirAll(vol1, 0755)
58+
Expect(err).ToNot(HaveOccurred())
59+
60+
session := podmanTest.Podman([]string{"create", "--name", ctr1, "-v", vol1, CITEST_IMAGE})
61+
session.WaitWithDefaultTimeout()
62+
Expect(session).Should(ExitCleanly())
63+
64+
session = podmanTest.Podman([]string{"create", "--volumes-from", volsctr, "--name", ctr2, CITEST_IMAGE})
65+
session.WaitWithDefaultTimeout()
66+
Expect(session).Should(ExitCleanly())
67+
68+
data := podmanTest.InspectContainer(ctr2)
69+
Expect(data).To(HaveLen(1))
70+
Expect(data[0].HostConfig.VolumesFrom).To(Equal([]string{volsctr}))
71+
Expect(data[0].Config.Annotations[define.InspectAnnotationVolumesFrom]).To(Equal(volsctr))
72+
})
4773
})

test/e2e/generate_kube_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,44 @@ USER test1`
16991699
Expect(pod.Annotations).To(HaveKeyWithValue(define.InspectAnnotationVolumesFrom+"/"+ctr2, ctr1))
17001700
})
17011701

1702+
It("pod volumes-from annotation with semicolon as field separator", func() {
1703+
// Assert that volumes-from annotation for multiple source
1704+
// containers along with their mount options are getting
1705+
// generated with semicolon as the field separator.
1706+
1707+
srcctr1, srcctr2, tgtctr := "srcctr1", "srcctr2", "tgtctr"
1708+
frmopt1, frmopt2 := srcctr1+":ro", srcctr2+":ro"
1709+
vol1 := filepath.Join(podmanTest.TempDir, "vol-test1")
1710+
vol2 := filepath.Join(podmanTest.TempDir, "vol-test2")
1711+
1712+
err1 := os.MkdirAll(vol1, 0755)
1713+
Expect(err1).ToNot(HaveOccurred())
1714+
1715+
err2 := os.MkdirAll(vol2, 0755)
1716+
Expect(err2).ToNot(HaveOccurred())
1717+
1718+
session := podmanTest.Podman([]string{"create", "--name", srcctr1, "-v", vol1, CITEST_IMAGE})
1719+
session.WaitWithDefaultTimeout()
1720+
Expect(session).Should(ExitCleanly())
1721+
1722+
session = podmanTest.Podman([]string{"create", "--name", srcctr2, "-v", vol2, CITEST_IMAGE})
1723+
session.WaitWithDefaultTimeout()
1724+
Expect(session).Should(ExitCleanly())
1725+
1726+
session = podmanTest.Podman([]string{"create", "--volumes-from", frmopt1, "--volumes-from", frmopt2, "--name", tgtctr, CITEST_IMAGE})
1727+
session.WaitWithDefaultTimeout()
1728+
Expect(session).Should(ExitCleanly())
1729+
1730+
kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", tgtctr})
1731+
kube.WaitWithDefaultTimeout()
1732+
Expect(kube).Should(ExitCleanly())
1733+
1734+
pod := new(v1.Pod)
1735+
err3 := yaml.Unmarshal(kube.Out.Contents(), pod)
1736+
Expect(err3).ToNot(HaveOccurred())
1737+
Expect(pod.Annotations).To(HaveKeyWithValue(define.InspectAnnotationVolumesFrom+"/"+tgtctr, frmopt1+";"+frmopt2))
1738+
})
1739+
17021740
It("--podman-only on container with --rm", func() {
17031741
ctr := "ctr"
17041742

0 commit comments

Comments
 (0)