From 6e7715d65ba892a47d355e16bf9ad87fb537a2d0 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 26 Jan 2018 13:15:36 -0800 Subject: [PATCH] Fix "--node-generic-resource" singular/plural Daemon flags that can be specified multiple times use singlar names for flags, but plural names for the configuration file. To make the daemon configuration know how to correlate the flag with the corresponding configuration option, `opt.NewNamedListOptsRef()` should be used instead of `opt.NewListOptsRef()`. Commit 6702ac590e6148cb3f606388dde93a011cb14931 attempted to fix the daemon not corresponding the flag with the configuration file option, but did so by changing the name of the flag to plural. This patch reverts that change, and uses `opt.NewNamedListOptsRef()` instead. Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/config.go | 2 +- cmd/dockerd/daemon_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/dockerd/config.go b/cmd/dockerd/config.go index c55332e183..abdac9a7fb 100644 --- a/cmd/dockerd/config.go +++ b/cmd/dockerd/config.go @@ -67,7 +67,7 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) { flags.StringVar(&conf.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on") - flags.Var(opts.NewListOptsRef(&conf.NodeGenericResources, opts.ValidateSingleGenericResource), "node-generic-resources", "Advertise user-defined resource") + flags.Var(opts.NewNamedListOptsRef("node-generic-resources", &conf.NodeGenericResources, opts.ValidateSingleGenericResource), "node-generic-resource", "Advertise user-defined resource") flags.IntVar(&conf.NetworkControlPlaneMTU, "network-control-plane-mtu", config.DefaultNetworkMtu, "Network Control plane MTU") diff --git a/cmd/dockerd/daemon_test.go b/cmd/dockerd/daemon_test.go index e5e4aa34e2..b065831871 100644 --- a/cmd/dockerd/daemon_test.go +++ b/cmd/dockerd/daemon_test.go @@ -61,6 +61,22 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) { testutil.ErrorContains(t, err, "as a flag and in the configuration file: labels") } +func TestLoadDaemonCliWithConflictingNodeGenericResources(t *testing.T) { + tempFile := fs.NewFile(t, "config", fs.WithContent(`{"node-generic-resources": ["foo=bar", "bar=baz"]}`)) + defer tempFile.Remove() + configFile := tempFile.Path() + + opts := defaultOptions(configFile) + flags := opts.flags + + assert.NoError(t, flags.Set("config-file", configFile)) + assert.NoError(t, flags.Set("node-generic-resource", "r1=bar")) + assert.NoError(t, flags.Set("node-generic-resource", "r2=baz")) + + _, err := loadDaemonCliConfig(opts) + testutil.ErrorContains(t, err, "as a flag and in the configuration file: node-generic-resources") +} + func TestLoadDaemonCliWithConflictingLabels(t *testing.T) { opts := defaultOptions("") flags := opts.flags