Skip to content

Commit

Permalink
Set network ID if available during container inspect. Fixes container…
Browse files Browse the repository at this point in the history
…s#24910

Signed-off-by: Florian Apolloner <[email protected]>
  • Loading branch information
apollo13 committed Jan 7, 2025
1 parent d3cd509 commit 6a9f795
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contrib/cirrus/setup_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ case "$TEST_FLAVOR" in
;;
compose_v2)
showrun dnf -y remove docker-compose
showrun curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
showrun curl -SL https://github.com/docker/compose/releases/download/v2.31.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
showrun chmod +x /usr/local/bin/docker-compose
;& # Continue with next item
apiv2)
Expand Down
14 changes: 12 additions & 2 deletions libpod/networking_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
if len(networks) > 0 {
settings.Networks = make(map[string]*define.InspectAdditionalNetwork, len(networks))
for net, opts := range networks {
netID := net
network, err := c.runtime.network.NetworkInspect(net)
if err == nil {
netID = network.ID
}
cniNet := new(define.InspectAdditionalNetwork)
cniNet.NetworkID = net
cniNet.NetworkID = netID
cniNet.Aliases = opts.Aliases
settings.Networks[net] = cniNet
}
Expand Down Expand Up @@ -272,9 +277,14 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
settings.Networks = make(map[string]*define.InspectAdditionalNetwork, len(networks))

for name, opts := range networks {
netID := name
network, err := c.runtime.network.NetworkInspect(name)
if err == nil {
netID = network.ID
}
result := netStatus[name]
addedNet := new(define.InspectAdditionalNetwork)
addedNet.NetworkID = name
addedNet.NetworkID = netID
addedNet.Aliases = opts.Aliases
addedNet.InspectBasicNetworkConfig = resultToBasicNetworkConfig(result)

Expand Down
1 change: 0 additions & 1 deletion test/compose/uptwice/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
app:
build: .
Expand Down
3 changes: 1 addition & 2 deletions test/compose/uptwice/tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- bash -*-

CR=$'\r'
NL=$'\n'

cp docker-compose.yml docker-compose.yml.bak
Expand All @@ -10,5 +9,5 @@ output=$(podman_compose up -d 2>&1)
# Horrible output check here but we really want to make sure that there are
# no unexpected warning/errors and the normal messages are send on stderr as
# well so we cannot check for an empty stderr.
expected="Container uptwice-app-1 Recreate${NL}Container uptwice-app-1 Recreated${NL}Container uptwice-app-1 Starting${NL}Container uptwice-app-1 Started"
expected=" Container uptwice-app-1 Recreate${NL} Container uptwice-app-1 Recreated${NL} Container uptwice-app-1 Starting${NL} Container uptwice-app-1 Started${NL}"
is "$output" "$expected" "no error output in compose up (#15580)"
8 changes: 8 additions & 0 deletions test/compose/uptwice_idempotent/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
app:
image: alpine
command: [sleep, infinity]
networks:
- net1
networks:
net1:
11 changes: 11 additions & 0 deletions test/compose/uptwice_idempotent/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- bash -*-

NL=$'\n'

output=$(podman_compose up -d 2>&1)

# Horrible output check here but we really want to make sure that there are
# no unexpected warning/errors and the normal messages are send on stderr as
# well so we cannot check for an empty stderr.
expected=" Container uptwice_idempotent-app-1 Running${NL}"
is "$output" "$expected" "no container recreation in compose up (#24950)"

0 comments on commit 6a9f795

Please sign in to comment.