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: Add subnet mask behind IP address to match Docker API #12328

Merged
merged 1 commit into from
Nov 23, 2021
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
15 changes: 12 additions & 3 deletions pkg/api/handlers/compat/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package compat

import (
"encoding/json"
"fmt"
"net"
"net/http"

Expand Down Expand Up @@ -69,12 +70,20 @@ func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, network nettyp
return nil, err
}
if netData, ok := data.NetworkSettings.Networks[network.Name]; ok {
ipv4Address := ""
if netData.IPAddress != "" {
ipv4Address = fmt.Sprintf("%s/%d", netData.IPAddress, netData.IPPrefixLen)
}
ipv6Address := ""
if netData.GlobalIPv6Address != "" {
ipv6Address = fmt.Sprintf("%s/%d", netData.GlobalIPv6Address, netData.GlobalIPv6PrefixLen)
}
containerEndpoint := types.EndpointResource{
Name: netData.NetworkID,
Name: con.Name(),
EndpointID: netData.EndpointID,
MacAddress: netData.MacAddress,
IPv4Address: netData.IPAddress,
IPv6Address: netData.GlobalIPv6Address,
IPv4Address: ipv4Address,
IPv6Address: ipv6Address,
}
containerEndpoints[con.ID()] = containerEndpoint
}
Expand Down
27 changes: 27 additions & 0 deletions test/apiv2/35-networks.at
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,31 @@ t DELETE libpod/networks/macvlan1 200 \
.[0].Name~macvlan1 \
.[0].Err=null

#
# test networks with containers
#
podman pull $IMAGE &>/dev/null

# Ensure clean slate
podman rm -a -f &>/dev/null

# create a network
podman network create --subnet 10.10.253.0/24 --gateway 10.10.253.1 network5
t GET libpod/networks/json?filters='{"name":["network5"]}' 200 \
.[0].id~[0-9a-f]\\{64\\}
nid=$(jq -r '.[0].id' <<<"$output")
# create a pod on a network
CNAME=mynettest
podman run --network network5 --name $CNAME --ip 10.10.253.2 --mac-address 0a:01:73:78:43:18 -td $IMAGE top
t GET libpod/containers/json?all=true 200 \
.[0].Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.[0].Id' <<<"$output")
# compat api inspect network
t GET networks/$nid 200 .Name="network5" \
.Containers[\"$cid\"].Name=$CNAME \
.Containers[\"$cid\"].MacAddress=0a:01:73:78:43:18 \
.Containers[\"$cid\"].IPv4Address=10.10.253.2/24
# clean the network
podman network rm -f network5

# vim: filetype=sh