Skip to content

Commit

Permalink
(rootful) docker-compose now updates network MTU
Browse files Browse the repository at this point in the history
Previously, the following network block did not update using
docker-compose:

```
networks:
  default:
    driver: bridge
    driver_opts:
      mtu: 9000
```

In the API, the network options were previously not being handled when the
network was being created. I translated the docker options into podman
options, and added the options to the network.

When doing `podman network inspect <network>`, the results now contain
`"mtu": "9000"`

Fixes: containers#14482

Signed-off-by: Jake Correnti <[email protected]>
  • Loading branch information
Jake Correnti committed Jul 5, 2022
1 parent 1ada01a commit 488eb3b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
46 changes: 40 additions & 6 deletions pkg/api/handlers/compat/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) {

func CreateNetwork(w http.ResponseWriter, r *http.Request) {
var (
networkCreate types.NetworkCreateRequest
network nettypes.Network
networkCreate types.NetworkCreateRequest
network nettypes.Network
responseWarning string
)
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
if err := json.NewDecoder(r.Body).Decode(&networkCreate); err != nil {
Expand All @@ -179,8 +180,40 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
network.Internal = networkCreate.Internal
network.IPv6Enabled = networkCreate.EnableIPv6

// FIXME use docker options and convert them to valid libpod options
// network.Options = networkCreate.Options
network.Options = make(map[string]string)

// TODO: we should consider making this constants in c/common/libnetwork/types
for opt, optVal := range networkCreate.Options {
switch opt {
case "mtu":
fallthrough
case "com.docker.network.driver.mtu":
if network.Driver == nettypes.BridgeNetworkDriver {
network.Options["mtu"] = optVal
}
case "icc":
fallthrough
case "com.docker.network.bridge.enable_icc":
// TODO: needs to be implemented
if network.Driver == nettypes.BridgeNetworkDriver {
responseWarning = "com.docker.network.bridge.enable_icc is not currently implemented"
}
case "com.docker.network.bridge.name":
if network.Driver == nettypes.BridgeNetworkDriver {
network.NetworkInterface = optVal
}
case "mode":
if network.Driver == nettypes.MacVLANNetworkDriver || network.Driver == nettypes.IPVLANNetworkDriver {
network.Options[opt] = optVal
}
case "parent":
if network.Driver == nettypes.MacVLANNetworkDriver || network.Driver == nettypes.IPVLANNetworkDriver {
network.NetworkInterface = optVal
}
default:
responseWarning = "\"" + opt + ": " + optVal + "\" is not a recognized option"
}
}

// dns is only enabled for the bridge driver
if network.Driver == nettypes.BridgeNetworkDriver {
Expand Down Expand Up @@ -242,9 +275,10 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {

body := struct {
ID string `json:"Id"`
Warning string
Warning string `json:"Warning"`
}{
ID: newNetwork.ID,
ID: newNetwork.ID,
Warning: responseWarning,
}
utils.WriteResponse(w, http.StatusCreated, body)
}
Expand Down
26 changes: 26 additions & 0 deletions test/compose/update_network_mtu/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.7'

services:
nginx:
image: alpine
ports:
- 8000:5000
networks:
- default
- macvlan_net

networks:
default:
driver: bridge
driver_opts:
com.docker.network.bridge.name: docker0
com.docker.network.driver.mtu: 9000
macvlan_net:
driver: macvlan
driver_opts:
mode: bridge
ipam:
config:
-
subnet: 192.168.20.0/24
gateway: 192.168.20.1
10 changes: 10 additions & 0 deletions test/compose/update_network_mtu/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- bash -*-

podman network inspect --format='{{ range . }} {{ .Options.mtu }} {{ end }}' update_network_mtu_default
like "$output" "9000" "$testname : network mtu is set"

podman network inspect --format='{{ range . }} {{ .NetworkInterface }} {{ end }}' update_network_mtu_default
like "$output" "docker0" "$testname: network interface is set"

podman network inspect --format='{{ range . }} {{ .Options.mode }} {{ end }}' update_network_mtu_macvlan_net
like "$output" "bridge" "$testname : network mode is set"

0 comments on commit 488eb3b

Please sign in to comment.