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

compat API: allow MacAddress on container config #16745

Merged
merged 1 commit into from
Dec 5, 2022
Merged
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
13 changes: 13 additions & 0 deletions pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
NoHosts: rtc.Containers.NoHosts,
}

// sigh docker-compose sets the mac address on the container config instead on the per network endpoint config
containerMacAddress := cc.MacAddress

// network names
switch {
case len(cc.NetworkingConfig.EndpointsConfig) > 0:
Expand Down Expand Up @@ -331,6 +334,16 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
return nil, nil, fmt.Errorf("failed to parse the mac address %q", endpoint.MacAddress)
}
netOpts.StaticMAC = types.HardwareAddr(staticMac)
} else if len(containerMacAddress) > 0 {
// docker-compose only sets one mac address for the container on the container config
// If there are more than one network attached it will end up on the first one,
// which is not deterministic since we iterate a map. Not nice but this matches docker.
staticMac, err := net.ParseMAC(containerMacAddress)
if err != nil {
return nil, nil, fmt.Errorf("failed to parse the mac address %q", containerMacAddress)
}
netOpts.StaticMAC = types.HardwareAddr(staticMac)
containerMacAddress = ""
}
}

Expand Down
1 change: 1 addition & 0 deletions test/compose/ipam_set_ip/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: "3.2"
services:
test:
image: alpine
mac_address: 32:b5:b2:55:48:72
networks:
net1:
ipv4_address: 10.123.0.253
Expand Down
4 changes: 3 additions & 1 deletion test/compose/ipam_set_ip/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ if [ "$TEST_FLAVOR" = "compose_v2" ]; then
ctr_name="ipam_set_ip-test-1"
fi
podman container inspect "$ctr_name" --format '{{ .NetworkSettings.Networks.ipam_set_ip_net1.IPAddress }}'
like "$output" "10.123.0.253" "$testname : ip address is set"
is "$output" "10.123.0.253" "$testname : ip address is set"
podman container inspect "$ctr_name" --format '{{ .NetworkSettings.Networks.ipam_set_ip_net1.MacAddress }}'
is "$output" "32:b5:b2:55:48:72" "$testname : mac address is set"