Skip to content

Commit

Permalink
play kube respect hostNetwork
Browse files Browse the repository at this point in the history
We need to use the host network when it is set in the config and
--network was not used.

This regression was added in 3e9af20.

Fixes #14015

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Apr 27, 2022
1 parent 053b096 commit 70a2c00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
22 changes: 12 additions & 10 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,20 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
return nil, err
}

ns, networks, netOpts, err := specgen.ParseNetworkFlag(options.Networks)
if err != nil {
return nil, err
}
if len(options.Networks) > 0 {
ns, networks, netOpts, err := specgen.ParseNetworkFlag(options.Networks)
if err != nil {
return nil, err
}

if (ns.IsBridge() && len(networks) == 0) || ns.IsHost() {
return nil, errors.Errorf("invalid value passed to --network: bridge or host networking must be configured in YAML")
}
if (ns.IsBridge() && len(networks) == 0) || ns.IsHost() {
return nil, errors.Errorf("invalid value passed to --network: bridge or host networking must be configured in YAML")
}

podOpt.Net.Network = ns
podOpt.Net.Networks = networks
podOpt.Net.NetworkOptions = netOpts
podOpt.Net.Network = ns
podOpt.Net.Networks = networks
podOpt.Net.NetworkOptions = netOpts
}

// FIXME This is very hard to support properly with a good ux
if len(options.StaticIPs) > *ipIndex {
Expand Down
17 changes: 12 additions & 5 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2779,11 +2779,7 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
})

It("podman play kube test with HostNetwork", func() {
if !strings.Contains(podmanTest.OCIRuntime, "crun") {
Skip("Test only works on crun")
}

pod := getPod(withHostNetwork())
pod := getPod(withHostNetwork(), withCtr(getCtr(withCmd([]string{"readlink", "/proc/self/ns/net"}), withArg(nil))))
err := generateKubeYaml("pod", pod, kubeYaml)
Expect(err).To(BeNil())

Expand All @@ -2795,6 +2791,17 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(inspect.OutputToString()).To(Equal("true"))

ns := SystemExec("readlink", []string{"/proc/self/ns/net"})
ns.WaitWithDefaultTimeout()
Expect(ns).Should(Exit(0))
netns := ns.OutputToString()
Expect(netns).ToNot(BeEmpty())

logs := podmanTest.Podman([]string{"logs", getCtrNameInPod(pod)})
logs.WaitWithDefaultTimeout()
Expect(logs).Should(Exit(0))
Expect(logs.OutputToString()).To(Equal(netns))
})

It("podman play kube persistentVolumeClaim", func() {
Expand Down

0 comments on commit 70a2c00

Please sign in to comment.