diff --git a/cmd/dockerd/config.go b/cmd/dockerd/config.go index f142b7538c..b9d586a4ba 100644 --- a/cmd/dockerd/config.go +++ b/cmd/dockerd/config.go @@ -65,7 +65,8 @@ 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.StringVar(&conf.NodeGenericResources, "node-generic-resources", "", "user defined resources (e.g. fpga=2;gpu={UUID1,UUID2,UUID3})") + flags.Var(opts.NewListOptsRef(&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") // "--deprecated-key-path" is to allow configuration of the key used diff --git a/daemon/config/config.go b/daemon/config/config.go index a340997073..f7a0df58ed 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -171,7 +171,8 @@ type CommonConfig struct { Experimental bool `json:"experimental"` // Experimental indicates whether experimental features should be exposed or not // Exposed node Generic Resources - NodeGenericResources string `json:"node-generic-resources,omitempty"` + // e.g: ["orange=red", "orange=green", "orange=blue", "apple=3"] + NodeGenericResources []string `json:"node-generic-resources,omitempty"` // NetworkControlPlaneMTU allows to specify the control plane MTU, this will allow to optimize the network use in some components NetworkControlPlaneMTU int `json:"network-control-plane-mtu,omitempty"` diff --git a/daemon/config/opts.go b/daemon/config/opts.go index 00f32e43bb..cdf264911f 100644 --- a/daemon/config/opts.go +++ b/daemon/config/opts.go @@ -7,8 +7,8 @@ import ( ) // ParseGenericResources parses and validates the specified string as a list of GenericResource -func ParseGenericResources(value string) ([]swarm.GenericResource, error) { - if value == "" { +func ParseGenericResources(value []string) ([]swarm.GenericResource, error) { + if len(value) == 0 { return nil, nil } diff --git a/opts/opts.go b/opts/opts.go index a86d74d60a..a2cc5e33b1 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -263,6 +263,16 @@ func ValidateLabel(val string) (string, error) { return val, nil } +// ValidateSingleGenericResource validates that a single entry in the +// generic resource list is valid. +// i.e 'GPU=UID1' is valid however 'GPU:UID1' or 'UID1' isn't +func ValidateSingleGenericResource(val string) (string, error) { + if strings.Count(val, "=") < 1 { + return "", fmt.Errorf("invalid node-generic-resource format `%s` expected `name=value`", val) + } + return val, nil +} + // ParseLink parses and validates the specified string as a link format (name:alias) func ParseLink(val string) (string, string, error) { if val == "" {