Skip to content

Commit

Permalink
Merge pull request #9109 from mheon/issue6618
Browse files Browse the repository at this point in the history
Fix #6618
  • Loading branch information
openshift-merge-robot authored Jan 27, 2021
2 parents c3b3984 + 02ec529 commit 2102e26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 5 additions & 3 deletions libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
if c.state.NetNS == nil {
// We still want to make dummy configurations for each CNI net
// the container joined.
if len(networks) > 0 && !isDefault {
if len(networks) > 0 {
settings.Networks = make(map[string]*define.InspectAdditionalNetwork, len(networks))
for _, net := range networks {
cniNet := new(define.InspectAdditionalNetwork)
Expand All @@ -998,7 +998,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 Expand Up @@ -1028,7 +1028,9 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
settings.Networks[name] = addedNet
}

return settings, nil
if !isDefault {
return settings, nil
}
}

// If not joining networks, we should have at most 1 result
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,27 @@ var _ = Describe("Podman inspect", func() {
Expect(inspect.OutputToString()).To(Equal(`"{"80/tcp":[{"HostIp":"","HostPort":"8080"}]}"`))
})

It("Verify container inspect has default network", func() {
SkipIfRootless("Requires root CNI networking")
ctrName := "testctr"
session := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())

inspect := podmanTest.InspectContainer(ctrName)
Expect(len(inspect)).To(Equal(1))
Expect(len(inspect[0].NetworkSettings.Networks)).To(Equal(1))
})

It("Verify stopped container still has default network in inspect", func() {
SkipIfRootless("Requires root CNI networking")
ctrName := "testctr"
session := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(BeZero())

inspect := podmanTest.InspectContainer(ctrName)
Expect(len(inspect)).To(Equal(1))
Expect(len(inspect[0].NetworkSettings.Networks)).To(Equal(1))
})
})

0 comments on commit 2102e26

Please sign in to comment.