As of now promoting (or demoting) a node that has its role
left unchanged will always print a successful message.
This PR fixes the issue by matching the behavior on swarmkit's
swarmctl command and printing a message when desired role is
the current role of the node.
As a result this also avoids calling update when it is not
necessary.
Signed-off-by: Alexandre Beslic <alexandre.beslic@gmail.com>
| ... | ... |
@@ -22,6 +22,10 @@ func newDemoteCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 22 | 22 |
|
| 23 | 23 |
func runDemote(dockerCli *client.DockerCli, nodes []string) error {
|
| 24 | 24 |
demote := func(node *swarm.Node) error {
|
| 25 |
+ if node.Spec.Role == swarm.NodeRoleWorker {
|
|
| 26 |
+ fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID) |
|
| 27 |
+ return errNoRoleChange |
|
| 28 |
+ } |
|
| 25 | 29 |
node.Spec.Role = swarm.NodeRoleWorker |
| 26 | 30 |
return nil |
| 27 | 31 |
} |
| ... | ... |
@@ -22,6 +22,10 @@ func newPromoteCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 22 | 22 |
|
| 23 | 23 |
func runPromote(dockerCli *client.DockerCli, nodes []string) error {
|
| 24 | 24 |
promote := func(node *swarm.Node) error {
|
| 25 |
+ if node.Spec.Role == swarm.NodeRoleManager {
|
|
| 26 |
+ fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID) |
|
| 27 |
+ return errNoRoleChange |
|
| 28 |
+ } |
|
| 25 | 29 |
node.Spec.Role = swarm.NodeRoleManager |
| 26 | 30 |
return nil |
| 27 | 31 |
} |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package node |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
|
| 6 | 7 |
"github.com/docker/docker/api/client" |
| ... | ... |
@@ -13,6 +14,10 @@ import ( |
| 13 | 13 |
"golang.org/x/net/context" |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
+var ( |
|
| 17 |
+ errNoRoleChange = errors.New("role was already set to the requested value")
|
|
| 18 |
+) |
|
| 19 |
+ |
|
| 16 | 20 |
func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
|
| 17 | 21 |
nodeOpts := newNodeOptions() |
| 18 | 22 |
|
| ... | ... |
@@ -53,6 +58,9 @@ func updateNodes(dockerCli *client.DockerCli, nodes []string, mergeNode func(nod |
| 53 | 53 |
|
| 54 | 54 |
err = mergeNode(&node) |
| 55 | 55 |
if err != nil {
|
| 56 |
+ if err == errNoRoleChange {
|
|
| 57 |
+ continue |
|
| 58 |
+ } |
|
| 56 | 59 |
return err |
| 57 | 60 |
} |
| 58 | 61 |
err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec) |