Skip to content

Commit

Permalink
Return slirp ip information from getHosts()
Browse files Browse the repository at this point in the history
When one container shares the network namespace with another container
or with a Pod, there should be an entry added to the /etc/hosts file
for the second container.

Fixes: containers#12003

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Feb 17, 2022
1 parent a429dcd commit f50fab5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,17 @@ func (c *Container) getHosts() string {

if depCtr != nil {
host := ""
if depCtr.config.NetMode.IsSlirp4netns() {
// When using slirp4netns, the interface gets a static IP
if slirp4netnsIP, err := GetSlirp4netnsIP(depCtr.slirp4netnsSubnet); err != nil {
logrus.Warnf("Failed to determine slirp4netnsIP: %v", err.Error())
} else {
return fmt.Sprintf("%s\t%s %s\n", slirp4netnsIP.String(), c.Hostname(), c.config.Name)
}
}
outer:
// Paul this is returning nothing, even though I know depctr is up and
// running with an IP Address in rootfull mode?
for net, status := range depCtr.getNetworkStatus() {
network, err := c.runtime.network.NetworkInspect(net)
// only add the host entry for bridge networks
Expand Down
1 change: 1 addition & 0 deletions libpod/networking_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package libpod
Expand Down
1 change: 1 addition & 0 deletions test/e2e/run_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
exec4.WaitWithDefaultTimeout()
Expect(exec4).Should(Exit(0))
Expect(exec4.OutputToString()).To(ContainSubstring("192.0.2.2 test1"))
Expect(exec4.OutputToString()).To(ContainSubstring(ctrName2))
})

It("podman run /etc/hosts contains --hostname", func() {
Expand Down

0 comments on commit f50fab5

Please sign in to comment.