2016-09-08 13:11:39 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2023-09-09 18:27:44 -04:00
|
|
|
"context"
|
2016-09-08 13:11:39 -04:00
|
|
|
"fmt"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-12-25 16:23:35 -05:00
|
|
|
func newPromoteCommand(dockerCli command.Cli) *cobra.Command {
|
2016-09-08 13:11:39 -04:00
|
|
|
return &cobra.Command{
|
|
|
|
Use: "promote NODE [NODE...]",
|
|
|
|
Short: "Promote one or more nodes to manager in the swarm",
|
|
|
|
Args: cli.RequiresMinArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2023-09-09 18:27:44 -04:00
|
|
|
return runPromote(cmd.Context(), dockerCli, args)
|
2016-09-08 13:11:39 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-09 18:27:44 -04:00
|
|
|
func runPromote(ctx context.Context, dockerCli command.Cli, nodes []string) error {
|
2016-09-08 13:11:39 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
success := func(nodeID string) {
|
|
|
|
fmt.Fprintf(dockerCli.Out(), "Node %s promoted to a manager in the swarm.\n", nodeID)
|
|
|
|
}
|
2023-09-09 18:27:44 -04:00
|
|
|
return updateNodes(ctx, dockerCli, nodes, promote, success)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|