summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--libpod/kube.go9
-rw-r--r--libpod/networking_linux.go2
-rw-r--r--libpod/networking_slirp4netns.go14
-rw-r--r--test/e2e/generate_kube_test.go23
-rw-r--r--test/system/500-networking.bats70
6 files changed, 87 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index 1c6d4ba3d..b94a6d237 100644
--- a/Makefile
+++ b/Makefile
@@ -425,8 +425,8 @@ pkg/api/swagger.yaml: .gopathok
make -C pkg/api
$(MANPAGES): %: %.md .install.md2man docdir
- @sed -e 's/\((podman.*\.md)\)//' -e 's/\[\(podman.*\)\]/\1/' \
- -e 's;<\(/\)\?\(a[^>]*\|sup\)>;;g' $< | \
+ @sed -e 's/\((podman[^)]*\.md)\)//g' -e 's/\[\(podman[^]]*\)\]/\1/g' \
+ -e 's;<\(/\)\?\(a\|a\s\+[^>]*\|sup\)>;;g' $< | \
$(GOMD2MAN) -in /dev/stdin -out $(subst source/markdown,build/man,$@)
.PHONY: docdir
diff --git a/libpod/kube.go b/libpod/kube.go
index 11ccaeadc..adcfe92c9 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "fmt"
"math/rand"
"os"
"strconv"
@@ -539,11 +540,17 @@ func libpodMountsToKubeVolumeMounts(c *Container) ([]v1.VolumeMount, []v1.Volume
namedVolumes, mounts := c.sortUserVolumes(c.config.Spec)
vms := make([]v1.VolumeMount, 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)
if err != nil {
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)
vos = append(vos, vo)
}
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 6e2c2880f..cfed5a1f2 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -577,7 +577,7 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) error {
// set up port forwarder for CNI-in-slirp4netns
netnsPath := ctr.state.NetNS.Path()
// TODO: support slirp4netns port forwarder as well
- return r.setupRootlessPortMappingViaRLK(ctr, netnsPath)
+ return r.setupRootlessPortMappingViaRLK(ctr, netnsPath, "")
}
return nil
}
diff --git a/libpod/networking_slirp4netns.go b/libpod/networking_slirp4netns.go
index 72ab3c919..c46dc6972 100644
--- a/libpod/networking_slirp4netns.go
+++ b/libpod/networking_slirp4netns.go
@@ -312,7 +312,7 @@ func (r *Runtime) setupSlirp4netns(ctr *Container) error {
if netOptions.isSlirpHostForward {
return r.setupRootlessPortMappingViaSlirp(ctr, cmd, apiSocket)
}
- return r.setupRootlessPortMappingViaRLK(ctr, netnsPath)
+ return r.setupRootlessPortMappingViaRLK(ctr, netnsPath, netOptions.cidr)
}
return nil
}
@@ -363,7 +363,7 @@ func waitForSync(syncR *os.File, cmd *exec.Cmd, logFile io.ReadSeeker, timeout t
return nil
}
-func (r *Runtime) setupRootlessPortMappingViaRLK(ctr *Container, netnsPath string) error {
+func (r *Runtime) setupRootlessPortMappingViaRLK(ctr *Container, netnsPath, slirp4CIDR string) error {
syncR, syncW, err := os.Pipe()
if err != nil {
return errors.Wrapf(err, "failed to open pipe")
@@ -391,6 +391,16 @@ func (r *Runtime) setupRootlessPortMappingViaRLK(ctr *Container, netnsPath strin
}
childIP := slirp4netnsIP
+ // set the correct childIP when a custom cidr is set
+ if slirp4CIDR != "" {
+ _, cidr, err := net.ParseCIDR(slirp4CIDR)
+ if err != nil {
+ return errors.Wrap(err, "failed to parse slirp4netns cidr")
+ }
+ // the slirp container ip is always the hundredth ip in the subnet
+ cidr.IP[len(cidr.IP)-1] = cidr.IP[len(cidr.IP)-1] + 100
+ childIP = cidr.IP.String()
+ }
outer:
for _, r := range ctr.state.NetworkStatus {
for _, i := range r.IPs {
diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go
index c3586d9b6..611e8ddac 100644
--- a/test/e2e/generate_kube_test.go
+++ b/test/e2e/generate_kube_test.go
@@ -496,6 +496,29 @@ var _ = Describe("Podman generate kube", func() {
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() {
vol := "vol-test-persistent-volume-claim"
diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
index 8da864798..21240e521 100644
--- a/test/system/500-networking.bats
+++ b/test/system/500-networking.bats
@@ -77,35 +77,47 @@ load helpers
# FIXME: randomize port, and create second random host port
myport=54321
- # Container will exit as soon as 'nc' receives input
- # We use '-n -v' to give us log messages showing an incoming connection
- # and its IP address; the purpose of that is guaranteeing that the
- # remote IP is not 127.0.0.1 (podman PR #9052).
- # We could get more parseable output by using $NCAT_REMOTE_ADDR,
- # but busybox nc doesn't support that.
- run_podman run -d --userns=keep-id -p 127.0.0.1:$myport:$myport \
- $IMAGE nc -l -n -v -p $myport
- cid="$output"
-
- # emit random string, and check it
- teststring=$(random_string 30)
- echo "$teststring" | nc 127.0.0.1 $myport
-
- run_podman logs $cid
- # Sigh. We can't check line-by-line, because 'nc' output order is
- # unreliable. We usually get the 'connect to' line before the random
- # string, but sometimes we get it after. So, just do substring checks.
- is "$output" ".*listening on \[::\]:$myport .*" "nc -v shows right port"
-
- # This is the truly important check: make sure the remote IP is
- # in the 10.X range, not 127.X.
- is "$output" \
- ".*connect to \[::ffff:10\..*\]:$myport from \[::ffff:10\..*\]:.*" \
- "nc -v shows remote IP address in 10.X space (not 127.0.0.1)"
- is "$output" ".*${teststring}.*" "test string received on container"
-
- # Clean up
- run_podman rm $cid
+ for cidr in "" "$(random_rfc1918_subnet).0/24"; do
+ myport=$(( myport + 1 ))
+ if [[ -z $cidr ]]; then
+ # regex to match that we are in 10.X subnet
+ match="10\..*"
+ else
+ # Issue #9828 make sure a custom slir4netns cidr also works
+ network_arg="--network slirp4netns:cidr=$cidr"
+ # slirp4netns interface ip is always .100
+ match="${cidr%.*}.100"
+ fi
+
+ # Container will exit as soon as 'nc' receives input
+ # We use '-n -v' to give us log messages showing an incoming connection
+ # and its IP address; the purpose of that is guaranteeing that the
+ # remote IP is not 127.0.0.1 (podman PR #9052).
+ # We could get more parseable output by using $NCAT_REMOTE_ADDR,
+ # but busybox nc doesn't support that.
+ run_podman run -d --userns=keep-id $network_arg -p 127.0.0.1:$myport:$myport \
+ $IMAGE nc -l -n -v -p $myport
+ cid="$output"
+
+ # emit random string, and check it
+ teststring=$(random_string 30)
+ echo "$teststring" | nc 127.0.0.1 $myport
+
+ run_podman logs $cid
+ # Sigh. We can't check line-by-line, because 'nc' output order is
+ # unreliable. We usually get the 'connect to' line before the random
+ # string, but sometimes we get it after. So, just do substring checks.
+ is "$output" ".*listening on \[::\]:$myport .*" "nc -v shows right port"
+
+ # This is the truly important check: make sure the remote IP is not 127.X.
+ is "$output" \
+ ".*connect to \[::ffff:$match*\]:$myport from \[::ffff:$match\]:.*" \
+ "nc -v shows remote IP address is not 127.0.0.1"
+ is "$output" ".*${teststring}.*" "test string received on container"
+
+ # Clean up
+ run_podman rm $cid
+ done
}
# "network create" now works rootless, with the help of a special container