Skip to content

Commit

Permalink
cmd/dockerd: produce error when using discovery options
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jan 6, 2022
1 parent 65b92a7 commit 9f2240c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
19 changes: 8 additions & 11 deletions cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
if cli.Config, err = loadDaemonCliConfig(opts); err != nil {
return err
}
if err := checkDeprecatedOptions(cli.Config); err != nil {
return err
}

if opts.Validate {
// If config wasn't OK we wouldn't have made it this far.
Expand All @@ -89,8 +92,6 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {

configureProxyEnv(cli.Config)

warnOnDeprecatedConfigOptions(cli.Config)

if err := configureDaemonLogs(cli.Config); err != nil {
return err
}
Expand Down Expand Up @@ -465,16 +466,12 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
return conf, nil
}

func warnOnDeprecatedConfigOptions(config *config.Config) {
if config.ClusterAdvertise != "" {
logrus.Warn(`The "cluster-advertise" option is deprecated. To be removed soon.`)
}
if config.ClusterStore != "" {
logrus.Warn(`The "cluster-store" option is deprecated. To be removed soon.`)
}
if len(config.ClusterOpts) > 0 {
logrus.Warn(`The "cluster-store-opt" option is deprecated. To be removed soon.`)
func checkDeprecatedOptions(config *config.Config) error {
// Overlay networks with external k/v stores have been deprecated
if config.ClusterAdvertise != "" || len(config.ClusterOpts) > 0 || config.ClusterStore != "" {
return errors.New("Host-discovery and overlay networks with external k/v stores are deprecated. The 'cluster-advertise', 'cluster-store', and 'cluster-store-opt' options have been removed")
}
return nil
}

func initRouter(opts routerOptions) {
Expand Down
9 changes: 1 addition & 8 deletions cmd/dockerd/daemon_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,14 @@ func TestLoadDaemonConfigWithNetwork(t *testing.T) {
}

func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
content := `{
"cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"},
"log-opts": {"tag": "test"}
}`
content := `{"log-opts": {"tag": "test"}}`
tempFile := fs.NewFile(t, "config", fs.WithContent(content))
defer tempFile.Remove()

opts := defaultOptions(t, tempFile.Path())
loadedConfig, err := loadDaemonCliConfig(opts)
assert.NilError(t, err)
assert.Assert(t, loadedConfig != nil)
assert.Check(t, loadedConfig.ClusterOpts != nil)

expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
assert.Check(t, is.Equal(expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"]))
assert.Check(t, loadedConfig.LogConfig.Config != nil)
assert.Check(t, is.Equal("test", loadedConfig.LogConfig.Config["tag"]))
}
Expand Down

0 comments on commit 9f2240c

Please sign in to comment.