summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-04-27 17:06:30 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2022-04-28 10:27:21 -0400
commit7f28fd938607df64e8844f3125838fc659753843 (patch)
tree16dba97f21bb623852762196ece971f71f67026e
parent87454cf87a36f3cab0a8a613d20011fc896b1ce4 (diff)
downloadpodman-7f28fd938607df64e8844f3125838fc659753843.tar.gz
podman-7f28fd938607df64e8844f3125838fc659753843.tar.bz2
podman-7f28fd938607df64e8844f3125838fc659753843.zip
Report properly whether pod shares host network
Fixes: https://github.com/containers/podman/issues/14028 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
-rw-r--r--libpod/pod.go9
-rw-r--r--libpod/pod_api.go2
-rw-r--r--test/system/200-pod.bats28
3 files changed, 38 insertions, 1 deletions
diff --git a/libpod/pod.go b/libpod/pod.go
index ed2d97b37..6cfe76a18 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -159,6 +159,15 @@ func (p *Pod) CPUQuota() int64 {
return 0
}
+// NetworkMode returns the Network mode given by the user ex: pod, private...
+func (p *Pod) NetworkMode() string {
+ infra, err := p.runtime.GetContainer(p.state.InfraContainerID)
+ if err != nil {
+ return ""
+ }
+ return infra.NetworkMode()
+}
+
// PidMode returns the PID mode given by the user ex: pod, private...
func (p *Pod) PidMode() string {
infra, err := p.runtime.GetContainer(p.state.InfraContainerID)
diff --git a/libpod/pod_api.go b/libpod/pod_api.go
index 48049798b..ba30d878e 100644
--- a/libpod/pod_api.go
+++ b/libpod/pod_api.go
@@ -593,7 +593,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
return nil, err
}
infraConfig = new(define.InspectPodInfraConfig)
- infraConfig.HostNetwork = !infra.config.ContainerNetworkConfig.UseImageHosts
+ infraConfig.HostNetwork = p.NetworkMode() == "host"
infraConfig.StaticIP = infra.config.ContainerNetworkConfig.StaticIP
infraConfig.NoManageResolvConf = infra.config.UseImageResolvConf
infraConfig.NoManageHosts = infra.config.UseImageHosts
diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats
index ef4bf1a6c..64f95f723 100644
--- a/test/system/200-pod.bats
+++ b/test/system/200-pod.bats
@@ -381,4 +381,32 @@ EOF
is "$output" ".*$container_3_ID.*"
}
+@test "podman pod create share net" {
+ run_podman pod create --name test
+ run_podman pod inspect test --format {{.InfraConfig.HostNetwork}}
+ is "$output" "false" "Default network sharing should be false"
+ run_podman pod rm test
+
+ run_podman pod create --name test --share ipc --network private
+ run_podman pod inspect test --format {{.InfraConfig.HostNetwork}}
+ is "$output" "false" "Private network sharing with only ipc should be false"
+ run_podman pod rm test
+
+ run_podman pod create --name test --share net --network private
+ run_podman pod inspect test --format {{.InfraConfig.HostNetwork}}
+ is "$output" "false" "Private network sharing with only net should be false"
+ run_podman pod rm test
+
+ run_podman pod create --name test --share net --network host
+ run_podman pod inspect test --format {{.InfraConfig.HostNetwork}}
+ is "$output" "true" "Host network sharing with only net should be true"
+ run_podman pod rm test
+
+ run_podman pod create --name test --share ipc --network host
+ run_podman pod inspect test --format {{.InfraConfig.HostNetwork}}
+ is "$output" "true" "Host network sharing with only ipc should be true"
+ run_podman pod rm test
+
+}
+
# vim: filetype=sh