Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default net info in container inspect #9092

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,13 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
return nil, err
}

// If this a container with a netns and on the default network
if c.state.NetNS != nil && isDefault {
mheon marked this conversation as resolved.
Show resolved Hide resolved
settings.Networks = make(map[string]*define.InspectAdditionalNetwork, len(networks))
cniNet := new(define.InspectAdditionalNetwork)
cniNet.NetworkID = c.runtime.netPlugin.GetDefaultNetworkName()
settings.Networks[c.runtime.netPlugin.GetDefaultNetworkName()] = cniNet
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is still unnecessary, though. All your work here is undone by the if len(networks) > 0 block below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also are going to need to modify the other use of !isDefault (L958) - the one that handles non-running containers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should talk about that ... look at the block just beneath this. it looks there is step prior where the map is setup. lets discuss in watercooler.

// We can't do more if the network is down.
if c.state.NetNS == nil {
// We still want to make dummy configurations for each CNI net
Expand All @@ -998,7 +1005,7 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
}

// If we have CNI networks - handle that here
if len(networks) > 0 && !isDefault {
if len(networks) > 0 {
if len(networks) != len(c.state.NetworkStatus) {
return nil, errors.Wrapf(define.ErrInternal, "network inspection mismatch: asked to join %d CNI network(s) %v, but have information on %d network(s)", len(networks), networks, len(c.state.NetworkStatus))
}
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,16 @@ var _ = Describe("Podman inspect", func() {
Expect(inspect.OutputToString()).To(Equal(`"{"80/tcp":[{"HostIp":"","HostPort":"8080"}]}"`))
})

It("Verify container inspect has default network", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add another test with a container that is not running.

session := podmanTest.Podman([]string{"run", "-dt", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())
cid := session.OutputToString()
inspect := podmanTest.Podman([]string{"inspect", cid})
inspect.WaitWithDefaultTimeout()
Expect(inspect.ExitCode()).To(BeZero())
data := inspect.InspectContainerToJSON()
Expect(len(data[0].NetworkSettings.Networks)).To(BeNumerically(">", 0))
})

})