Przeglądaj źródła

dockerd: "--mtu": update description, hide on Windows and warn if set

The --mtu option is only used for the default "bridge" network on Linux.
On Windows, the flag is available, but ignored. As this option has been
available for a long time, and was always silently ignored, deprecating
or removing it would be a breaking change (and perhaps it's possible to
support it in future).

This patch:

- hides the option on Windows binaries
- logs a warning if the option is set to any non-zero value other than
  the default on a Windows binary

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 lat temu
rodzic
commit
11abd0742e
2 zmienionych plików z 18 dodań i 1 usunięć
  1. 12 1
      cmd/dockerd/config.go
  2. 6 0
      daemon/config/config_windows.go

+ 12 - 1
cmd/dockerd/config.go

@@ -1,6 +1,8 @@
 package main
 
 import (
+	"runtime"
+
 	"github.com/docker/docker/daemon/config"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/registry"
@@ -28,7 +30,16 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error {
 	flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri")
 
 	flags.Var(opts.NewNamedMapMapOpts("default-network-opts", conf.DefaultNetworkOpts, nil), "default-network-opt", "Default network options")
-	flags.IntVar(&conf.Mtu, "mtu", conf.Mtu, "Set the containers network MTU")
+	flags.IntVar(&conf.Mtu, "mtu", conf.Mtu, `Set the MTU for the default "bridge" network`)
+	if runtime.GOOS == "windows" {
+		// The mtu option is not used on Windows, but it has been available since
+		// "forever" (and always silently ignored). We hide the flag for now,
+		// to discourage using it (and print a warning if it's set), but not
+		// "hard-deprecating" it, to not break users, and in case it will be
+		// supported on Windows in future.
+		flags.MarkHidden("mtu")
+	}
+
 	flags.IntVar(&conf.NetworkControlPlaneMTU, "network-control-plane-mtu", conf.NetworkControlPlaneMTU, "Network Control plane MTU")
 	flags.IntVar(&conf.NetworkDiagnosticPort, "network-diagnostic-port", 0, "TCP port number of the network diagnostic server")
 	_ = flags.MarkHidden("network-diagnostic-port")

+ 6 - 0
daemon/config/config_windows.go

@@ -1,8 +1,11 @@
 package config // import "github.com/docker/docker/daemon/config"
 
 import (
+	"context"
 	"os"
 	"path/filepath"
+
+	"github.com/containerd/containerd/log"
 )
 
 const (
@@ -45,6 +48,9 @@ func (conf *Config) IsSwarmCompatible() error {
 
 // ValidatePlatformConfig checks if any platform-specific configuration settings are invalid.
 func (conf *Config) ValidatePlatformConfig() error {
+	if conf.Mtu != 0 && conf.Mtu != DefaultNetworkMtu {
+		log.G(context.TODO()).Warn(`WARNING: MTU for the default network is not configurable on Windows, and this option will be ignored.`)
+	}
 	return nil
 }