Merge pull request #25455 from abronan/improve_cli_promote_demote_output

swarm: improve cli output on node promote/demote for unchanged role
This commit is contained in:
Vincent Demeester 2016-08-06 09:12:46 +02:00 committed by GitHub
commit 8615c8b52d
3 changed files with 16 additions and 0 deletions

View file

@ -22,6 +22,10 @@ func newDemoteCommand(dockerCli *client.DockerCli) *cobra.Command {
func runDemote(dockerCli *client.DockerCli, nodes []string) error {
demote := func(node *swarm.Node) error {
if node.Spec.Role == swarm.NodeRoleWorker {
fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID)
return errNoRoleChange
}
node.Spec.Role = swarm.NodeRoleWorker
return nil
}

View file

@ -22,6 +22,10 @@ func newPromoteCommand(dockerCli *client.DockerCli) *cobra.Command {
func runPromote(dockerCli *client.DockerCli, nodes []string) error {
promote := func(node *swarm.Node) error {
if node.Spec.Role == swarm.NodeRoleManager {
fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID)
return errNoRoleChange
}
node.Spec.Role = swarm.NodeRoleManager
return nil
}

View file

@ -1,6 +1,7 @@
package node
import (
"errors"
"fmt"
"github.com/docker/docker/api/client"
@ -13,6 +14,10 @@ import (
"golang.org/x/net/context"
)
var (
errNoRoleChange = errors.New("role was already set to the requested value")
)
func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
nodeOpts := newNodeOptions()
@ -53,6 +58,9 @@ func updateNodes(dockerCli *client.DockerCli, nodes []string, mergeNode func(nod
err = mergeNode(&node)
if err != nil {
if err == errNoRoleChange {
continue
}
return err
}
err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec)