Merge pull request #19042 from dgibson/bug17922

pasta: Create /etc/hosts entries for pods using pasta networking
This commit is contained in:
OpenShift Merge Robot 2023-06-30 05:07:50 -04:00 committed by GitHub
commit acaaf3de41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 0 deletions

View File

@ -2203,6 +2203,12 @@ func (c *Container) getHostsEntries() (etchosts.HostEntries, error) {
switch {
case c.config.NetMode.IsBridge():
entries = etchosts.GetNetworkHostEntries(c.state.NetworkStatus, names...)
case c.config.NetMode.IsPasta():
ip, err := getPastaIP(c.state)
if err != nil {
return nil, err
}
entries = etchosts.HostEntries{{IP: ip.String(), Names: names}}
case c.config.NetMode.IsSlirp4netns():
ip, err := getSlirp4netnsIP(c.slirp4netnsSubnet)
if err != nil {

View File

@ -271,3 +271,7 @@ func (c *Container) reloadRootlessRLKPortMapping() error {
func (c *Container) setupRootlessNetwork() error {
return nil
}
func getPastaIP(state *ContainerState) (net.IP, error) {
return nil, fmt.Errorf("pasta networking is Linux only")
}

View File

@ -19,6 +19,7 @@ import (
"github.com/containers/common/libnetwork/resolvconf"
"github.com/containers/common/libnetwork/slirp4netns"
"github.com/containers/common/libnetwork/types"
netUtil "github.com/containers/common/libnetwork/util"
"github.com/containers/common/pkg/netns"
"github.com/containers/common/pkg/util"
"github.com/containers/podman/v4/pkg/rootless"
@ -757,3 +758,13 @@ func (c *Container) inspectJoinedNetworkNS(networkns string) (q types.StatusBloc
})
return result, err
}
func getPastaIP(state *ContainerState) (net.IP, error) {
var ip string
err := ns.WithNetNSPath(state.NetNS, func(_ ns.NetNS) error {
// get the first ip in the netns
ip = netUtil.GetLocalIP()
return nil
})
return net.ParseIP(ip), err
}

View File

@ -235,6 +235,21 @@ function teardown() {
"Container has IPv6 global address with IPv6 disabled"
}
@test "podman networking with pasta(1) - podman puts pasta IP in /etc/hosts" {
skip_if_no_ipv4 "IPv4 not routable on the host"
pname="p$(random_string 30)"
ip="$(default_addr 4)"
run_podman pod create --net=pasta --name "${pname}"
run_podman run --pod="${pname}" "${IMAGE}" getent hosts "${pname}"
assert "$(echo ${output} | cut -f1 -d' ')" = "${ip}" "Correct /etc/hsots entry missing"
run_podman pod rm "${pname}"
run_podman rmi $(pause_image)
}
### Routes #####################################################################
@test "podman networking with pasta(1) - IPv4 default route" {