pasta: Create /etc/hosts entries for pods using pasta networking

For pods with bridged and slirp4netns networking we create /etc/hosts
entries to make it more convenient for the containers to address each
other.  We omitted to do this for pasta networking, however.  Add the
necessary code to do this.

Closes: https://github.com/containers/podman/issues/17922

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson
2023-06-29 11:02:25 +10:00
parent fca3c2ef84
commit 39624473b0
4 changed files with 36 additions and 0 deletions

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
}