Conversation
opts/opts.go
Outdated
| func (opts *SetOpts) String() string { | ||
| return fmt.Sprintf("%v", opts.values) | ||
| } |
There was a problem hiding this comment.
Slightly wondering if this should produce a string based on the map[string]bool or an output based on the (more human-readable) comma-separated list.
Do you know where the string-format surfaces? Also; is the stringer interface required for FlagOpts, or would this be something we could postpone (add when needed?)
cmd/dockerd/config.go
Outdated
| flags.StringVar(&conf.ExecRoot, "exec-root", conf.ExecRoot, "Root directory for execution state files") | ||
| flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address") | ||
| flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri") | ||
| flags.Var(opts.NewNamedSetOpts("feature", conf.Features), "feature", "Enable feature in the daemon") |
There was a problem hiding this comment.
Oh (haven't checked yet); also wondering now what we do with other options; if we accept a comma-separated list, or only multiple flags (i.e. --something foo=bar,bar=baz versus --something foo=bar --something bar=baz).
I THINK we may be using the latter, and because of that are using singular for the flag-names (because each flag takes a single value). For example the --storage-opt flag only takes a single option, but the equivalent in the config-file is storage-opts (plural) as it accepts multiple.
We may need to look at consistency there.
There was a problem hiding this comment.
That's already how this is implemented, right? Adding a new --feature flag which, when specified multiple times, adds entries to the (existing) features map in the configuration structure.
There was a problem hiding this comment.
Ah, you're right, I think I mis-interpreted the type itself to accepting multiple values.
But this one should use plural (features); the name here is used to correlate flags with the config (daemon.json) to detect conflicts.
Currently, this PR doesn't detect those:
echo '{"features": {"containerd-snapshotter": true}}' > /etc/docker/daemon.json
hack/make.sh binary && make install
dockerd --feature containerd-snapshotter=true --validate
configuration OKChanging this to plural;
diff --git a/cmd/dockerd/config.go b/cmd/dockerd/config.go
index 2ea669f0b1..bb6e44ac6e 100644
--- a/cmd/dockerd/config.go
+++ b/cmd/dockerd/config.go
@@ -28,7 +28,7 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
flags.StringVar(&conf.ExecRoot, "exec-root", conf.ExecRoot, "Root directory for execution state files")
flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address")
flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri")
- flags.Var(opts.NewNamedSetOpts("feature", conf.Features), "feature", "Enable feature in the daemon")
+ flags.Var(opts.NewNamedSetOpts("features", conf.Features), "feature", "Enable feature in the daemon")
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 MTU for the default "bridge" network`)Then it correctly handles the conflict;
hack/make.sh binary && make install
dockerd --feature containerd-snapshotter=true --validate
unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: features: (from flag: map[containerd-snapshotter:true], from file: map[containerd-snapshotter:true])
tianon
left a comment
There was a problem hiding this comment.
This LGTM, but I'd personally feel better about it if we could get eyes from @corhere who's semi-recently really familiar with how all our configuration intersects (🙇), because I know that bit's really complex and we've had some subtle bugs in that area.
|
Great initiative! This should simplify using the daemon in CI or other places where working with configuration files is cumbersome, or configuration may vary. Question: Will this also allow setting the things like enabling containerd image store for the docker engine? |
opts/opts.go
Outdated
|
|
||
| var _ NamedOption = &NamedSetOpts{} | ||
|
|
||
| // NewNamedMapOpts creates a reference to a new NamedMapOpts struct. |
There was a problem hiding this comment.
| // NewNamedMapOpts creates a reference to a new NamedMapOpts struct. | |
| // NewNamedSetOpts creates a reference to a new NamedSetOpts struct. |
opts/opts.go
Outdated
| } | ||
| } | ||
|
|
||
| // Name returns the name of the NamedMapOpts in the configuration. |
There was a problem hiding this comment.
| // Name returns the name of the NamedMapOpts in the configuration. | |
| // Name returns the name of the NamedSetOpts in the configuration. |
opts/opts.go
Outdated
| // NewSetOpts creates a new SetOpts with the specified set of values as a map of string to bool. | ||
| func NewSetOpts(values map[string]bool) *SetOpts { | ||
| if values == nil { | ||
| values = make(map[string]bool) | ||
| } | ||
| return &SetOpts{ | ||
| values: values, | ||
| } | ||
| } |
There was a problem hiding this comment.
Looks like this one is only used internally to help NamedSetOpts - should we combine them? (I'm trying to reduce the public API of this opts package - we could even consider making the new one un-exported in daemon/config or somewhere in internal/ or daemon/internal.
cmd/dockerd/config.go
Outdated
| flags.StringVar(&conf.ExecRoot, "exec-root", conf.ExecRoot, "Root directory for execution state files") | ||
| flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address") | ||
| flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri") | ||
| flags.Var(opts.NewNamedSetOpts("feature", conf.Features), "feature", "Enable feature in the daemon") |
There was a problem hiding this comment.
Ah, you're right, I think I mis-interpreted the type itself to accepting multiple values.
But this one should use plural (features); the name here is used to correlate flags with the config (daemon.json) to detect conflicts.
Currently, this PR doesn't detect those:
echo '{"features": {"containerd-snapshotter": true}}' > /etc/docker/daemon.json
hack/make.sh binary && make install
dockerd --feature containerd-snapshotter=true --validate
configuration OKChanging this to plural;
diff --git a/cmd/dockerd/config.go b/cmd/dockerd/config.go
index 2ea669f0b1..bb6e44ac6e 100644
--- a/cmd/dockerd/config.go
+++ b/cmd/dockerd/config.go
@@ -28,7 +28,7 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
flags.StringVar(&conf.ExecRoot, "exec-root", conf.ExecRoot, "Root directory for execution state files")
flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address")
flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri")
- flags.Var(opts.NewNamedSetOpts("feature", conf.Features), "feature", "Enable feature in the daemon")
+ flags.Var(opts.NewNamedSetOpts("features", conf.Features), "feature", "Enable feature in the daemon")
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 MTU for the default "bridge" network`)Then it correctly handles the conflict;
hack/make.sh binary && make install
dockerd --feature containerd-snapshotter=true --validate
unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: features: (from flag: map[containerd-snapshotter:true], from file: map[containerd-snapshotter:true])|
@vasylenko yes, this will allow enabling |
Signed-off-by: Derek McGowan <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
bbf7ec0 to
f13c082
Compare
|
Updated this PR:
@laurazard PTAL |
dismissing, as I made the last updates
|
TODO (but I may do so in a follow-up)
|
thaJeztah
left a comment
There was a problem hiding this comment.
"LGTM" as well
I'll do a small follow-up for the man-page, but didn't want to block this one on that.
Adds a
--featureflag to the daemon options. This allows quickly toggling features when running the daemon directly or writing daemon tests.- Description for the changelog