Skip to content

Commit

Permalink
Report properly whether pod shares host network
Browse files Browse the repository at this point in the history
Fixes: containers#14028

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Apr 28, 2022
1 parent 87454cf commit 7f28fd9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
9 changes: 9 additions & 0 deletions libpod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libpod/pod_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/system/200-pod.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7f28fd9

Please sign in to comment.