mirror of https://github.com/containers/podman.git
Merge pull request #19042 from dgibson/bug17922
pasta: Create /etc/hosts entries for pods using pasta networking
This commit is contained in:
commit
acaaf3de41
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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" {
|
||||
|
|
Loading…
Reference in New Issue