Skip to content

Commit

Permalink
Fix network mode in play kube
Browse files Browse the repository at this point in the history
We need to use the config network mode when no network mode was set. To
do so we have to keep the nsmode empty, MakeContainer() will use the
correct network mode from the config when needed.

Fixes containers#12248

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Nov 12, 2021
1 parent 5f3ce25 commit 164c42b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
11 changes: 0 additions & 11 deletions pkg/specgen/generate/pod_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/rootless"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -216,15 +215,6 @@ func MapSpec(p *specgen.PodSpecGenerator) (*specgen.SpecGenerator, error) {
logrus.Debugf("No networking because the infra container is missing")
break
}
if rootless.IsRootless() {
logrus.Debugf("Pod will use slirp4netns")
if p.InfraContainerSpec.NetNS.NSMode != "host" {
p.InfraContainerSpec.NetworkOptions = p.NetworkOptions
p.InfraContainerSpec.NetNS.NSMode = specgen.NamespaceMode("slirp4netns")
}
} else {
logrus.Debugf("Pod using bridge network mode")
}
case specgen.Bridge:
p.InfraContainerSpec.NetNS.NSMode = specgen.Bridge
logrus.Debugf("Pod using bridge network mode")
Expand Down Expand Up @@ -258,7 +248,6 @@ func MapSpec(p *specgen.PodSpecGenerator) (*specgen.SpecGenerator, error) {
return nil, errors.Errorf("pods presently do not support network mode %s", p.NetNS.NSMode)
}

libpod.WithPodCgroups()
if len(p.InfraCommand) > 0 {
p.InfraContainerSpec.Entrypoint = p.InfraCommand
}
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/config/containers-netns2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[containers]

netns = "bridge"
28 changes: 28 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,34 @@ invalid kube kind
Expect(exists).To(Exit(0))
})

It("podman play kube use network mode from config", func() {
confPath, err := filepath.Abs("config/containers-netns2.conf")
Expect(err).ToNot(HaveOccurred())
os.Setenv("CONTAINERS_CONF", confPath)
defer os.Unsetenv("CONTAINERS_CONF")
if IsRemote() {
podmanTest.RestartRemoteService()
}

pod := getPod()
err = generateKubeYaml("pod", pod, kubeYaml)
Expect(err).To(BeNil())

kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))

podInspect := podmanTest.Podman([]string{"pod", "inspect", pod.Name, "--format", "{{.InfraContainerID}}"})
podInspect.WaitWithDefaultTimeout()
Expect(podInspect).To(Exit(0))
infraID := podInspect.OutputToString()

inspect := podmanTest.Podman([]string{"inspect", "--format", "{{.HostConfig.NetworkMode}}", infraID})
inspect.WaitWithDefaultTimeout()
Expect(inspect).To(Exit(0))
Expect(inspect.OutputToString()).To(Equal("bridge"))
})

It("podman play kube replace", func() {
pod := getPod()
err := generateKubeYaml("pod", pod, kubeYaml)
Expand Down

0 comments on commit 164c42b

Please sign in to comment.