|
@@ -20,6 +20,7 @@ type initOptions struct {
|
|
|
// Not a NodeAddrOption because it has no default port.
|
|
|
advertiseAddr string
|
|
|
forceNewCluster bool
|
|
|
+ availability string
|
|
|
}
|
|
|
|
|
|
func newInitCommand(dockerCli command.Cli) *cobra.Command {
|
|
@@ -41,6 +42,7 @@ func newInitCommand(dockerCli command.Cli) *cobra.Command {
|
|
|
flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: <ip|interface>[:port])")
|
|
|
flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state")
|
|
|
flags.BoolVar(&opts.autolock, flagAutolock, false, "Enable manager autolocking (requiring an unlock key to start a stopped manager)")
|
|
|
+ flags.StringVar(&opts.availability, flagAvailability, "active", "Availability of the node (active/pause/drain)")
|
|
|
addSwarmFlags(flags, &opts.swarmOptions)
|
|
|
return cmd
|
|
|
}
|
|
@@ -56,6 +58,15 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro
|
|
|
Spec: opts.swarmOptions.ToSpec(flags),
|
|
|
AutoLockManagers: opts.swarmOptions.autolock,
|
|
|
}
|
|
|
+ if flags.Changed(flagAvailability) {
|
|
|
+ availability := swarm.NodeAvailability(strings.ToLower(opts.availability))
|
|
|
+ switch availability {
|
|
|
+ case swarm.NodeAvailabilityActive, swarm.NodeAvailabilityPause, swarm.NodeAvailabilityDrain:
|
|
|
+ req.Availability = availability
|
|
|
+ default:
|
|
|
+ return fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
nodeID, err := client.SwarmInit(ctx, req)
|
|
|
if err != nil {
|