Skip to content

Commit

Permalink
fix pod network handling with a host network
Browse files Browse the repository at this point in the history
the function `GetDefaultNamespaceMode` for pods checks if we are sharing each namespace
and if not, returns the default which in the case of a network is slirp.

add a switch case for explicitly checking if the pod's network mode is host
and if so, return specgen.Host for the container

resolves containers#13763

Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
Signed-off-by: cdoern <cdoern@redhat.com>
  • Loading branch information
cdoern authored and cdoern committed Jun 2, 2022
1 parent bdaac4b commit 6dbbd61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/specgen/generate/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func GetDefaultNamespaceMode(nsType string, cfg *config.Config, pod *libpod.Pod)
podMode = true
case nsType == "net" && pod.SharesNet():
podMode = true
case nsType == "net" && pod.NetworkMode() == "host":
toReturn.NSMode = specgen.Host
return toReturn, nil
case nsType == "cgroup" && pod.SharesCgroup():
podMode = true
}
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/pod_infra_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ var _ = Describe("Podman pod create", func() {
session = podmanTest.Podman([]string{"run", fedoraMinimal, "curl", "-f", "localhost"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())

session = podmanTest.Podman([]string{"pod", "create", "--network", "host"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"run", "-dt", "--pod", session.OutputToString(), ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"inspect", "--format", "'{{.NetworkSettings.SandboxKey}}'", session.OutputToString()})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).Should(ContainSubstring("''")) // no network path... host
})

It("podman pod correctly sets up IPCNS", func() {
Expand Down

0 comments on commit 6dbbd61

Please sign in to comment.