mirror of
https://github.com/docker/cli.git
synced 2026-01-18 08:21:31 +03:00
Allow swarm join with --availability=drain
This fix tries to address the issue raised in 24596 where it was not
possible to join as manager only (`--availability=drain`).
This fix adds a new flag `--availability` to `swarm join`.
Related documentation has been updated.
An integration test has been added.
NOTE: Additional pull request for swarmkit and engine-api will
be created separately.
This fix fixes 24596.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Upstream-commit: ab2635ead0
Component: cli
This commit is contained in:
@@ -2,12 +2,15 @@ package swarm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/net/context"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
type joinOptions struct {
|
||||
@@ -16,6 +19,7 @@ type joinOptions struct {
|
||||
// Not a NodeAddrOption because it has no default port.
|
||||
advertiseAddr string
|
||||
token string
|
||||
availability string
|
||||
}
|
||||
|
||||
func newJoinCommand(dockerCli command.Cli) *cobra.Command {
|
||||
@@ -29,7 +33,7 @@ func newJoinCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Args: cli.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.remote = args[0]
|
||||
return runJoin(dockerCli, opts)
|
||||
return runJoin(dockerCli, cmd.Flags(), opts)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -37,10 +41,11 @@ func newJoinCommand(dockerCli command.Cli) *cobra.Command {
|
||||
flags.Var(&opts.listenAddr, flagListenAddr, "Listen address (format: <ip|interface>[:port])")
|
||||
flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: <ip|interface>[:port])")
|
||||
flags.StringVar(&opts.token, flagToken, "", "Token for entry into the swarm")
|
||||
flags.StringVar(&opts.availability, flagAvailability, "active", "Availability of the node (active/pause/drain)")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runJoin(dockerCli command.Cli, opts joinOptions) error {
|
||||
func runJoin(dockerCli command.Cli, flags *pflag.FlagSet, opts joinOptions) error {
|
||||
client := dockerCli.Client()
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -50,6 +55,16 @@ func runJoin(dockerCli command.Cli, opts joinOptions) error {
|
||||
AdvertiseAddr: opts.advertiseAddr,
|
||||
RemoteAddrs: []string{opts.remote},
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
err := client.SwarmJoin(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -28,6 +28,7 @@ const (
|
||||
flagSnapshotInterval = "snapshot-interval"
|
||||
flagLockKey = "lock-key"
|
||||
flagAutolock = "autolock"
|
||||
flagAvailability = "availability"
|
||||
)
|
||||
|
||||
type swarmOptions struct {
|
||||
|
||||
Reference in New Issue
Block a user