mirror of
https://github.com/containers/podman.git
synced 2025-07-24 07:58:04 +08:00
Merge pull request #8075 from mheon/fix_8073
Retrieve network inspect info from dependency container
This commit is contained in:
@ -823,6 +823,20 @@ func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
|
|||||||
// Produce an InspectNetworkSettings containing information on the container
|
// Produce an InspectNetworkSettings containing information on the container
|
||||||
// network.
|
// network.
|
||||||
func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, error) {
|
func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, error) {
|
||||||
|
if c.config.NetNsCtr != "" {
|
||||||
|
netNsCtr, err := c.runtime.GetContainer(c.config.NetNsCtr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Have to sync to ensure that state is populated
|
||||||
|
if err := netNsCtr.syncContainer(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
logrus.Debugf("Container %s shares network namespace, retrieving network info of container %s", c.ID(), c.config.NetNsCtr)
|
||||||
|
|
||||||
|
return netNsCtr.getContainerNetworkInfo()
|
||||||
|
}
|
||||||
|
|
||||||
settings := new(define.InspectNetworkSettings)
|
settings := new(define.InspectNetworkSettings)
|
||||||
settings.Ports = makeInspectPortBindings(c.config.PortMappings)
|
settings.Ports = makeInspectPortBindings(c.config.PortMappings)
|
||||||
|
|
||||||
|
@ -245,6 +245,24 @@ var _ = Describe("Podman pod create", func() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman container in pod with IP address shares IP address", func() {
|
||||||
|
SkipIfRootless("Rootless does not support --ip")
|
||||||
|
podName := "test"
|
||||||
|
ctrName := "testCtr"
|
||||||
|
ip := GetRandomIPAddress()
|
||||||
|
podCreate := podmanTest.Podman([]string{"pod", "create", "--ip", ip, "--name", podName})
|
||||||
|
podCreate.WaitWithDefaultTimeout()
|
||||||
|
Expect(podCreate.ExitCode()).To(Equal(0))
|
||||||
|
podCtr := podmanTest.Podman([]string{"run", "--name", ctrName, "--pod", podName, "-d", "-t", ALPINE, "top"})
|
||||||
|
podCtr.WaitWithDefaultTimeout()
|
||||||
|
Expect(podCtr.ExitCode()).To(Equal(0))
|
||||||
|
ctrInspect := podmanTest.Podman([]string{"inspect", ctrName})
|
||||||
|
ctrInspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(ctrInspect.ExitCode()).To(Equal(0))
|
||||||
|
ctrJSON := ctrInspect.InspectContainerToJSON()
|
||||||
|
Expect(ctrJSON[0].NetworkSettings.IPAddress).To(Equal(ip))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman create pod with IP address and no infra should fail", func() {
|
It("podman create pod with IP address and no infra should fail", func() {
|
||||||
name := "test"
|
name := "test"
|
||||||
ip := GetRandomIPAddress()
|
ip := GetRandomIPAddress()
|
||||||
|
Reference in New Issue
Block a user