From d1d9fd50c25c28132d50d88f287641bc58446ce8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 18 Aug 2022 12:51:23 +0200 Subject: [PATCH] daemon: complete the "--graph" / "-g" deprecation The `-g` / `--graph` options were soft deprecated in favor of `--data-root` in 261ef1fa27c4dfefa5f686b0a4ef354a43040e58 (v17.05.0) and at the time considered to not be removed. However, with the move towards containerd snapshotters, having these options around adds additional complexity to handle fallbacks for deprecated (and hidden) flags, so completing the deprecation. With this patch: dockerd --graph=/var/lib/docker --validate Flag --graph has been deprecated, Use --data-root instead unable to configure the Docker daemon with file /etc/docker/daemon.json: merged configuration validation from file and command line flags failed: the "graph" config file option is deprecated; use "data-root" instead mkdir -p /etc/docker echo '{"graph":"/var/lib/docker"}' > /etc/docker/daemon.json dockerd --validate unable to configure the Docker daemon with file /etc/docker/daemon.json: merged configuration validation from file and command line flags failed: the "graph" config file option is deprecated; use "data-root" instead Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b58de39ca78a42e01f4e0d80c53ed11f8357be83) Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/config.go | 7 +++---- cmd/dockerd/daemon.go | 7 ------- daemon/config/config.go | 17 ++++++----------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/cmd/dockerd/config.go b/cmd/dockerd/config.go index 4e3b4f2f07..a719b8fc43 100644 --- a/cmd/dockerd/config.go +++ b/cmd/dockerd/config.go @@ -79,10 +79,9 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error { // Deprecated flags / options - // "--graph" is "soft-deprecated" in favor of "data-root". This flag was added - // before Docker 1.0, so won't be removed, only hidden, to discourage its usage. - flags.StringVarP(&conf.Root, "graph", "g", conf.Root, "Root of the Docker runtime") - _ = flags.MarkHidden("graph") + //nolint:staticcheck // TODO(thaJeztah): remove in next release. + flags.StringVarP(&conf.RootDeprecated, "graph", "g", conf.RootDeprecated, "Root of the Docker runtime") + _ = flags.MarkDeprecated("graph", "Use --data-root instead") flags.BoolVarP(&conf.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run") _ = flags.MarkDeprecated("restart", "Please use a restart policy on docker run") flags.StringVar(&conf.ClusterAdvertise, "cluster-advertise", "", "Address or interface name to advertise") diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index 8cbb29e429..991175d2b2 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -395,9 +395,6 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) { conf.Hosts = opts.Hosts conf.LogLevel = opts.LogLevel - if flags.Changed("graph") && flags.Changed("data-root") { - return nil, errors.New(`cannot specify both "--graph" and "--data-root" option`) - } if flags.Changed(FlagTLS) { conf.TLS = &opts.TLS } @@ -448,10 +445,6 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) { return nil, err } - if flags.Changed("graph") { - logrus.Warnf(`The "-g / --graph" flag is deprecated. Please use "--data-root" instead`) - } - // Check if duplicate label-keys with different values are found newLabels, err := config.GetConflictFreeLabels(conf.Labels) if err != nil { diff --git a/daemon/config/config.go b/daemon/config/config.go index 0afcbd4437..3e17ed53a9 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -157,7 +157,7 @@ type CommonConfig struct { NetworkDiagnosticPort int `json:"network-diagnostic-port,omitempty"` Pidfile string `json:"pidfile,omitempty"` RawLogs bool `json:"raw-logs,omitempty"` - RootDeprecated string `json:"graph,omitempty"` + RootDeprecated string `json:"graph,omitempty"` // Deprecated: use Root instead. TODO(thaJeztah): remove in next release. Root string `json:"data-root,omitempty"` ExecRoot string `json:"exec-root,omitempty"` SocketGroup string `json:"group,omitempty"` @@ -479,16 +479,6 @@ func getConflictFreeConfiguration(configFile string, flags *pflag.FlagSet) (*Con return nil, err } - if config.RootDeprecated != "" { - logrus.Warn(`The "graph" config file option is deprecated. Please use "data-root" instead.`) - - if config.Root != "" { - return nil, errors.New(`cannot specify both "graph" and "data-root" config file options`) - } - - config.Root = config.RootDeprecated - } - return &config, nil } @@ -579,6 +569,11 @@ func findConfigurationConflicts(config map[string]interface{}, flags *pflag.Flag // such as config.DNS, config.Labels, config.DNSSearch, // as well as config.MaxConcurrentDownloads, config.MaxConcurrentUploads and config.MaxDownloadAttempts. func Validate(config *Config) error { + //nolint:staticcheck // TODO(thaJeztah): remove in next release. + if config.RootDeprecated != "" { + return errors.New(`the "graph" config file option is deprecated; use "data-root" instead`) + } + // validate log-level if config.LogLevel != "" { if _, err := logrus.ParseLevel(config.LogLevel); err != nil {