Skip to content

Commit fd010ad

Browse files
Merge pull request #12269 from Luap99/backport3.4
[v3.4] backport networking fixes
2 parents 8de9950 + 9c94530 commit fd010ad

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

cmd/podman/pods/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func create(cmd *cobra.Command, args []string) error {
116116
return fmt.Errorf("cannot specify no-hosts without an infra container")
117117
}
118118
flags := cmd.Flags()
119-
createOptions.Net, err = common.NetFlagsToNetOptions(nil, *flags, false)
119+
createOptions.Net, err = common.NetFlagsToNetOptions(nil, *flags, createOptions.Infra)
120120
if err != nil {
121121
return err
122122
}
@@ -139,7 +139,7 @@ func create(cmd *cobra.Command, args []string) error {
139139
createOptions.CpusetCpus = infraOptions.CPUSetCPUs
140140
createOptions.Pid = infraOptions.PID
141141
flags := cmd.Flags()
142-
infraOptions.Net, err = common.NetFlagsToNetOptions(nil, *flags, false)
142+
infraOptions.Net, err = common.NetFlagsToNetOptions(nil, *flags, createOptions.Infra)
143143
if err != nil {
144144
return err
145145
}

libpod/networking_slirp4netns.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ func getRootlessPortChildIP(c *Container) string {
629629
// reloadRootlessRLKPortMapping will trigger a reload for the port mappings in the rootlessport process.
630630
// This should only be called by network connect/disconnect and only as rootless.
631631
func (c *Container) reloadRootlessRLKPortMapping() error {
632+
if len(c.config.PortMappings) == 0 {
633+
return nil
634+
}
632635
childIP := getRootlessPortChildIP(c)
633636
logrus.Debugf("reloading rootless ports for container %s, childIP is %s", c.config.ID, childIP)
634637

test/e2e/config/containers-netns.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[containers]
2+
3+
netns = "host"

test/e2e/network_connect_disconnect_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
8888
dis := podmanTest.Podman([]string{"network", "disconnect", netName, "test"})
8989
dis.WaitWithDefaultTimeout()
9090
Expect(dis).Should(Exit(0))
91+
Expect(dis.ErrorToString()).Should(Equal(""))
9192

9293
inspect := podmanTest.Podman([]string{"container", "inspect", "test", "--format", "{{len .NetworkSettings.Networks}}"})
9394
inspect.WaitWithDefaultTimeout()
@@ -178,6 +179,7 @@ var _ = Describe("Podman network connect and disconnect", func() {
178179
connect := podmanTest.Podman([]string{"network", "connect", newNetName, "test"})
179180
connect.WaitWithDefaultTimeout()
180181
Expect(connect).Should(Exit(0))
182+
Expect(connect.ErrorToString()).Should(Equal(""))
181183

182184
inspect := podmanTest.Podman([]string{"container", "inspect", "test", "--format", "{{len .NetworkSettings.Networks}}"})
183185
inspect.WaitWithDefaultTimeout()

test/e2e/pod_create_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,4 +806,22 @@ ENTRYPOINT ["sleep","99999"]
806806
Expect(ok).To(BeTrue())
807807
})
808808

809+
It("podman pod create read network mode from config", func() {
810+
confPath, err := filepath.Abs("config/containers-netns.conf")
811+
Expect(err).ToNot(HaveOccurred())
812+
os.Setenv("CONTAINERS_CONF", confPath)
813+
defer os.Unsetenv("CONTAINERS_CONF")
814+
if IsRemote() {
815+
podmanTest.RestartRemoteService()
816+
}
817+
818+
pod := podmanTest.Podman([]string{"pod", "create", "--name", "test", "--infra-name", "test-infra"})
819+
pod.WaitWithDefaultTimeout()
820+
Expect(pod).Should(Exit(0))
821+
822+
inspect := podmanTest.Podman([]string{"inspect", "--format", "{{.HostConfig.NetworkMode}}", "test-infra"})
823+
inspect.WaitWithDefaultTimeout()
824+
Expect(inspect).Should(Exit(0))
825+
Expect(inspect.OutputToString()).Should(Equal("host"))
826+
})
809827
})

test/system/500-networking.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ load helpers
391391
mac="$output"
392392

393393
run_podman network disconnect $netname $cid
394+
is "$output" "" "Output should be empty (no errors)"
394395

395396
# check that we cannot curl (timeout after 3 sec)
396397
run curl --max-time 3 -s $SERVER/index.txt
@@ -399,6 +400,7 @@ load helpers
399400
fi
400401

401402
run_podman network connect $netname $cid
403+
is "$output" "" "Output should be empty (no errors)"
402404

403405
# curl should work again
404406
run curl --max-time 3 -s $SERVER/index.txt
@@ -415,8 +417,15 @@ load helpers
415417
die "MAC address did not change after podman network disconnect/connect"
416418
fi
417419

420+
# Disconnect/reconnect of a container *with no ports* should succeed quietly
421+
run_podman network disconnect $netname $background_cid
422+
is "$output" "" "disconnect of container with no open ports"
423+
run_podman network connect $netname $background_cid
424+
is "$output" "" "(re)connect of container with no open ports"
425+
418426
# connect a second network
419427
run_podman network connect $netname2 $cid
428+
is "$output" "" "Output should be empty (no errors)"
420429

421430
# curl should work
422431
run curl --max-time 3 -s $SERVER/index.txt

0 commit comments

Comments
 (0)