Merge pull request #43449 from thaJeztah/daemon_config_cleanup

daemon: move more consts for default configuration values to daemon/config
This commit is contained in:
Sebastiaan van Stijn 2022-04-20 17:01:19 +02:00 committed by GitHub
commit 79becebd3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 25 deletions

View file

@ -3,20 +3,14 @@ package main
import ( import (
"runtime" "runtime"
"github.com/docker/docker/daemon"
"github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/config"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/docker/plugin/executor/containerd"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
const (
// defaultShutdownTimeout is the default shutdown timeout for the daemon
defaultShutdownTimeout = 15
// defaultTrustKeyFile is the default filename for the trust key // defaultTrustKeyFile is the default filename for the trust key
defaultTrustKeyFile = "key.json" const defaultTrustKeyFile = "key.json"
)
// installCommonConfigFlags adds flags to the pflag.FlagSet to configure the daemon // installCommonConfigFlags adds flags to the pflag.FlagSet to configure the daemon
func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error { func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error {
@ -80,7 +74,7 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error {
flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull") flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull")
flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push") flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push")
flags.IntVar(&maxDownloadAttempts, "max-download-attempts", config.DefaultDownloadAttempts, "Set the max download attempts for each pull") flags.IntVar(&maxDownloadAttempts, "max-download-attempts", config.DefaultDownloadAttempts, "Set the max download attempts for each pull")
flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout") flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", config.DefaultShutdownTimeout, "Set the default shutdown timeout")
flags.IntVar(&conf.NetworkDiagnosticPort, "network-diagnostic-port", 0, "TCP port number of the network diagnostic server") flags.IntVar(&conf.NetworkDiagnosticPort, "network-diagnostic-port", 0, "TCP port number of the network diagnostic server")
_ = flags.MarkHidden("network-diagnostic-port") _ = flags.MarkHidden("network-diagnostic-port")
@ -96,8 +90,8 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error {
conf.MaxConcurrentUploads = &maxConcurrentUploads conf.MaxConcurrentUploads = &maxConcurrentUploads
conf.MaxDownloadAttempts = &maxDownloadAttempts conf.MaxDownloadAttempts = &maxDownloadAttempts
flags.StringVar(&conf.ContainerdNamespace, "containerd-namespace", daemon.ContainersNamespace, "Containerd namespace to use") flags.StringVar(&conf.ContainerdNamespace, "containerd-namespace", config.DefaultContainersNamespace, "Containerd namespace to use")
flags.StringVar(&conf.ContainerdPluginNamespace, "containerd-plugins-namespace", containerd.PluginNamespace, "Containerd namespace to use for plugins") flags.StringVar(&conf.ContainerdPluginNamespace, "containerd-plugins-namespace", config.DefaultPluginNamespace, "Containerd namespace to use for plugins")
flags.StringVar(&conf.DefaultRuntime, "default-runtime", config.StockRuntimeName, "Default OCI runtime for containers") flags.StringVar(&conf.DefaultRuntime, "default-runtime", config.StockRuntimeName, "Default OCI runtime for containers")

View file

@ -38,11 +38,18 @@ const (
DefaultNetworkMtu = 1500 DefaultNetworkMtu = 1500
// DisableNetworkBridge is the default value of the option to disable network bridge // DisableNetworkBridge is the default value of the option to disable network bridge
DisableNetworkBridge = "none" DisableNetworkBridge = "none"
// DefaultShutdownTimeout is the default shutdown timeout (in seconds) for
// the daemon for containers to stop when it is shutting down.
DefaultShutdownTimeout = 15
// DefaultInitBinary is the name of the default init binary // DefaultInitBinary is the name of the default init binary
DefaultInitBinary = "docker-init" DefaultInitBinary = "docker-init"
// DefaultRuntimeBinary is the default runtime to be used by // DefaultRuntimeBinary is the default runtime to be used by
// containerd if none is specified // containerd if none is specified
DefaultRuntimeBinary = "runc" DefaultRuntimeBinary = "runc"
// DefaultContainersNamespace is the name of the default containerd namespace used for users containers.
DefaultContainersNamespace = "moby"
// DefaultPluginNamespace is the name of the default containerd namespace used for plugins.
DefaultPluginNamespace = "plugins.moby"
// LinuxV1RuntimeName is the runtime used to specify the containerd v1 shim with the runc binary // LinuxV1RuntimeName is the runtime used to specify the containerd v1 shim with the runc binary
// Note this is different than io.containerd.runc.v1 which would be the v1 shim using the v2 shim API. // Note this is different than io.containerd.runc.v1 which would be the v1 shim using the v2 shim API.

View file

@ -5,20 +5,20 @@ import (
"net" "net"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
units "github.com/docker/go-units" units "github.com/docker/go-units"
) )
const ( const (
// DefaultIpcMode is default for container's IpcMode, if not set otherwise // DefaultIpcMode is default for container's IpcMode, if not set otherwise
DefaultIpcMode = containertypes.IPCModePrivate DefaultIpcMode = container.IPCModePrivate
// DefaultCgroupNamespaceMode is the default mode for containers cgroup namespace when using cgroups v2. // DefaultCgroupNamespaceMode is the default mode for containers cgroup namespace when using cgroups v2.
DefaultCgroupNamespaceMode = containertypes.CgroupnsModePrivate DefaultCgroupNamespaceMode = container.CgroupnsModePrivate
// DefaultCgroupV1NamespaceMode is the default mode for containers cgroup namespace when using cgroups v1. // DefaultCgroupV1NamespaceMode is the default mode for containers cgroup namespace when using cgroups v1.
DefaultCgroupV1NamespaceMode = containertypes.CgroupnsModeHost DefaultCgroupV1NamespaceMode = container.CgroupnsModeHost
// StockRuntimeName is the reserved name/alias used to represent the // StockRuntimeName is the reserved name/alias used to represent the
// OCI runtime being shipped with the docker daemon package. // OCI runtime being shipped with the docker daemon package.
@ -129,7 +129,7 @@ func (conf *Config) IsSwarmCompatible() error {
func verifyDefaultIpcMode(mode string) error { func verifyDefaultIpcMode(mode string) error {
const hint = `use "shareable" or "private"` const hint = `use "shareable" or "private"`
dm := containertypes.IpcMode(mode) dm := container.IpcMode(mode)
if !dm.Valid() { if !dm.Valid() {
return fmt.Errorf("default IPC mode setting (%v) is invalid; "+hint, dm) return fmt.Errorf("default IPC mode setting (%v) is invalid; "+hint, dm)
} }
@ -140,7 +140,7 @@ func verifyDefaultIpcMode(mode string) error {
} }
func verifyDefaultCgroupNsMode(mode string) error { func verifyDefaultCgroupNsMode(mode string) error {
cm := containertypes.CgroupnsMode(mode) cm := container.CgroupnsMode(mode)
if !cm.Valid() { if !cm.Valid() {
return fmt.Errorf(`default cgroup namespace mode (%v) is invalid; use "host" or "private"`, cm) return fmt.Errorf(`default cgroup namespace mode (%v) is invalid; use "host" or "private"`, cm)
} }

View file

@ -69,11 +69,6 @@ import (
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
) )
// ContainersNamespace is the name of the namespace used for users containers
const (
ContainersNamespace = "moby"
)
var ( var (
errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform") errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform")
) )

View file

@ -16,9 +16,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// PluginNamespace is the name used for the plugins namespace
const PluginNamespace = "plugins.moby"
// ExitHandler represents an object that is called when the exit event is received from containerd // ExitHandler represents an object that is called when the exit event is received from containerd
type ExitHandler interface { type ExitHandler interface {
HandleExitEvent(id string) error HandleExitEvent(id string) error