2015-09-13 00:09:03 +00:00
|
|
|
|
package command
|
|
|
|
|
|
|
|
|
|
import (
|
2018-03-28 21:01:54 +00:00
|
|
|
|
"context"
|
2015-09-13 00:09:03 +00:00
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
2018-02-23 23:56:36 +00:00
|
|
|
|
"time"
|
2017-08-22 20:13:44 +00:00
|
|
|
|
|
2018-02-23 23:56:36 +00:00
|
|
|
|
"github.com/hashicorp/nomad/api"
|
2017-08-22 20:13:44 +00:00
|
|
|
|
"github.com/hashicorp/nomad/api/contexts"
|
2021-05-07 17:58:40 +00:00
|
|
|
|
flaghelper "github.com/hashicorp/nomad/helper/flags"
|
|
|
|
|
|
2017-08-22 20:13:44 +00:00
|
|
|
|
"github.com/posener/complete"
|
2015-09-13 00:09:03 +00:00
|
|
|
|
)
|
|
|
|
|
|
2018-02-23 23:56:36 +00:00
|
|
|
|
var (
|
|
|
|
|
// defaultDrainDuration is the default drain duration if it is not specified
|
|
|
|
|
// explicitly
|
|
|
|
|
defaultDrainDuration = 1 * time.Hour
|
|
|
|
|
)
|
|
|
|
|
|
2015-09-13 00:09:03 +00:00
|
|
|
|
type NodeDrainCommand struct {
|
2015-09-14 20:13:52 +00:00
|
|
|
|
Meta
|
2015-09-13 00:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *NodeDrainCommand) Help() string {
|
|
|
|
|
helpText := `
|
2018-02-23 23:56:36 +00:00
|
|
|
|
Usage: nomad node drain [options] <node>
|
2015-09-13 00:09:03 +00:00
|
|
|
|
|
2020-11-19 21:38:08 +00:00
|
|
|
|
Toggles node draining on a specified node. It is required that either
|
|
|
|
|
-enable or -disable is specified, but not both. The -self flag is useful to
|
|
|
|
|
drain the local node.
|
|
|
|
|
|
|
|
|
|
If ACLs are enabled, this option requires a token with the 'node:write'
|
|
|
|
|
capability.
|
2015-09-13 00:09:03 +00:00
|
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
|
General Options:
|
|
|
|
|
|
2020-11-19 16:15:23 +00:00
|
|
|
|
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
|
2015-09-14 20:13:52 +00:00
|
|
|
|
|
|
|
|
|
Node Drain Options:
|
2015-09-13 00:09:03 +00:00
|
|
|
|
|
|
|
|
|
-disable
|
|
|
|
|
Disable draining for the specified node.
|
|
|
|
|
|
|
|
|
|
-enable
|
|
|
|
|
Enable draining for the specified node.
|
2016-03-24 21:43:20 +00:00
|
|
|
|
|
2018-02-23 23:56:36 +00:00
|
|
|
|
-deadline <duration>
|
|
|
|
|
Set the deadline by which all allocations must be moved off the node.
|
|
|
|
|
Remaining allocations after the deadline are forced removed from the node.
|
|
|
|
|
If unspecified, a default deadline of one hour is applied.
|
|
|
|
|
|
2018-03-06 22:16:20 +00:00
|
|
|
|
-detach
|
|
|
|
|
Return immediately instead of entering monitor mode.
|
|
|
|
|
|
2018-05-10 02:54:05 +00:00
|
|
|
|
-monitor
|
|
|
|
|
Enter monitor mode directly without modifying the drain status.
|
|
|
|
|
|
2018-02-23 23:56:36 +00:00
|
|
|
|
-force
|
|
|
|
|
Force remove allocations off the node immediately.
|
|
|
|
|
|
|
|
|
|
-no-deadline
|
|
|
|
|
No deadline allows the allocations to drain off the node without being force
|
|
|
|
|
stopped after a certain deadline.
|
|
|
|
|
|
|
|
|
|
-ignore-system
|
|
|
|
|
Ignore system allows the drain to complete without stopping system job
|
2018-02-27 17:41:55 +00:00
|
|
|
|
allocations. By default system jobs are stopped last.
|
2018-02-23 23:56:36 +00:00
|
|
|
|
|
2018-03-08 19:06:30 +00:00
|
|
|
|
-keep-ineligible
|
|
|
|
|
Keep ineligible will maintain the node's scheduling ineligibility even if
|
|
|
|
|
the drain is being disabled. This is useful when an existing drain is being
|
|
|
|
|
cancelled but additional scheduling on the node is not desired.
|
|
|
|
|
|
2021-05-07 17:58:40 +00:00
|
|
|
|
-m
|
|
|
|
|
Message for the drain update operation. Registered in drain metadata as
|
|
|
|
|
"message" during drain enable and "cancel_message" during drain disable.
|
|
|
|
|
|
|
|
|
|
-meta <key>=<value>
|
|
|
|
|
Custom metadata to store on the drain operation, can be used multiple times.
|
|
|
|
|
|
2016-04-11 22:20:49 +00:00
|
|
|
|
-self
|
2018-02-23 23:56:36 +00:00
|
|
|
|
Set the drain status of the local node.
|
2016-04-11 22:20:49 +00:00
|
|
|
|
|
2016-03-24 21:43:20 +00:00
|
|
|
|
-yes
|
|
|
|
|
Automatic yes to prompts.
|
2015-09-13 00:09:03 +00:00
|
|
|
|
`
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *NodeDrainCommand) Synopsis() string {
|
2015-09-13 18:39:49 +00:00
|
|
|
|
return "Toggle drain mode on a given node"
|
2015-09-13 00:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 20:13:44 +00:00
|
|
|
|
func (c *NodeDrainCommand) AutocompleteFlags() complete.Flags {
|
2017-08-23 21:56:21 +00:00
|
|
|
|
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
|
|
|
|
|
complete.Flags{
|
2018-03-08 19:06:30 +00:00
|
|
|
|
"-disable": complete.PredictNothing,
|
|
|
|
|
"-enable": complete.PredictNothing,
|
|
|
|
|
"-deadline": complete.PredictAnything,
|
2018-03-06 22:16:20 +00:00
|
|
|
|
"-detach": complete.PredictNothing,
|
2018-03-08 19:06:30 +00:00
|
|
|
|
"-force": complete.PredictNothing,
|
|
|
|
|
"-no-deadline": complete.PredictNothing,
|
|
|
|
|
"-ignore-system": complete.PredictNothing,
|
|
|
|
|
"-keep-ineligible": complete.PredictNothing,
|
2021-05-07 17:58:40 +00:00
|
|
|
|
"-m": complete.PredictNothing,
|
|
|
|
|
"-meta": complete.PredictNothing,
|
2018-03-08 19:06:30 +00:00
|
|
|
|
"-self": complete.PredictNothing,
|
|
|
|
|
"-yes": complete.PredictNothing,
|
2017-08-23 21:56:21 +00:00
|
|
|
|
})
|
2017-08-22 20:13:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *NodeDrainCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
|
return complete.PredictFunc(func(a complete.Args) []string {
|
2017-08-29 21:29:32 +00:00
|
|
|
|
client, err := c.Meta.Client()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 05:17:51 +00:00
|
|
|
|
resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Nodes, nil)
|
2017-08-22 20:13:44 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
return []string{}
|
|
|
|
|
}
|
|
|
|
|
return resp.Matches[contexts.Nodes]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
|
func (c *NodeDrainCommand) Name() string { return "node-drain" }
|
|
|
|
|
|
2015-09-13 00:09:03 +00:00
|
|
|
|
func (c *NodeDrainCommand) Run(args []string) int {
|
2018-03-06 22:16:20 +00:00
|
|
|
|
var enable, disable, detach, force,
|
2018-05-07 20:14:58 +00:00
|
|
|
|
noDeadline, ignoreSystem, keepIneligible,
|
|
|
|
|
self, autoYes, monitor bool
|
2021-05-07 17:58:40 +00:00
|
|
|
|
var deadline, message string
|
|
|
|
|
var metaVars flaghelper.StringFlag
|
2015-09-13 00:09:03 +00:00
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
|
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
2015-09-13 00:09:03 +00:00
|
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
|
flags.BoolVar(&enable, "enable", false, "Enable drain mode")
|
|
|
|
|
flags.BoolVar(&disable, "disable", false, "Disable drain mode")
|
2018-02-23 23:56:36 +00:00
|
|
|
|
flags.StringVar(&deadline, "deadline", "", "Deadline after which allocations are force stopped")
|
2018-03-06 22:16:20 +00:00
|
|
|
|
flags.BoolVar(&detach, "detach", false, "")
|
2018-02-23 23:56:36 +00:00
|
|
|
|
flags.BoolVar(&force, "force", false, "Force immediate drain")
|
|
|
|
|
flags.BoolVar(&noDeadline, "no-deadline", false, "Drain node with no deadline")
|
|
|
|
|
flags.BoolVar(&ignoreSystem, "ignore-system", false, "Do not drain system job allocations from the node")
|
2018-03-08 19:06:30 +00:00
|
|
|
|
flags.BoolVar(&keepIneligible, "keep-ineligible", false, "Do not update the nodes scheduling eligibility")
|
2016-04-11 22:20:49 +00:00
|
|
|
|
flags.BoolVar(&self, "self", false, "")
|
2016-03-24 21:43:20 +00:00
|
|
|
|
flags.BoolVar(&autoYes, "yes", false, "Automatic yes to prompts.")
|
2018-05-07 20:14:58 +00:00
|
|
|
|
flags.BoolVar(&monitor, "monitor", false, "Monitor drain status.")
|
2021-05-07 17:58:40 +00:00
|
|
|
|
flags.StringVar(&message, "m", "", "Drain message")
|
|
|
|
|
flags.Var(&metaVars, "meta", "Drain metadata")
|
2015-09-13 00:09:03 +00:00
|
|
|
|
|
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 20:14:58 +00:00
|
|
|
|
// Check that enable or disable is not set with monitor
|
2018-05-10 02:54:05 +00:00
|
|
|
|
if monitor && (enable || disable) {
|
2018-05-07 20:14:58 +00:00
|
|
|
|
c.Ui.Error("The -monitor flag cannot be used with the '-enable' or '-disable' flags")
|
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 00:09:03 +00:00
|
|
|
|
// Check that we got either enable or disable, but not both.
|
2018-05-07 20:14:58 +00:00
|
|
|
|
if (enable && disable) || (!monitor && !enable && !disable) {
|
2020-01-02 22:42:27 +00:00
|
|
|
|
c.Ui.Error("Either the '-enable' or '-disable' flag must be set, unless using '-monitor'")
|
2018-04-18 16:02:11 +00:00
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
2015-09-13 00:09:03 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that we got a node ID
|
2015-09-14 20:13:52 +00:00
|
|
|
|
args = flags.Args()
|
2016-04-11 22:20:49 +00:00
|
|
|
|
if l := len(args); self && l != 0 || !self && l != 1 {
|
2018-02-23 23:56:36 +00:00
|
|
|
|
c.Ui.Error("Node ID must be specified if -self isn't being used")
|
2018-04-18 16:02:11 +00:00
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
2018-02-23 23:56:36 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate a compatible set of flags were set
|
|
|
|
|
if disable && (deadline != "" || force || noDeadline || ignoreSystem) {
|
|
|
|
|
c.Ui.Error("-disable can't be combined with flags configuring drain strategy")
|
2018-04-18 16:02:11 +00:00
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
2018-02-23 23:56:36 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
if deadline != "" && (force || noDeadline) {
|
|
|
|
|
c.Ui.Error("-deadline can't be combined with -force or -no-deadline")
|
2018-04-18 16:02:11 +00:00
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
2018-02-23 23:56:36 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
if force && noDeadline {
|
|
|
|
|
c.Ui.Error("-force and -no-deadline are mutually exclusive")
|
2018-04-18 16:02:11 +00:00
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
2015-09-13 00:09:03 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 23:56:36 +00:00
|
|
|
|
// Parse the duration
|
|
|
|
|
var d time.Duration
|
|
|
|
|
if force {
|
|
|
|
|
d = -1 * time.Second
|
|
|
|
|
} else if noDeadline {
|
|
|
|
|
d = 0
|
|
|
|
|
} else if deadline != "" {
|
|
|
|
|
dur, err := time.ParseDuration(deadline)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("Failed to parse deadline %q: %v", deadline, err))
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
if dur <= 0 {
|
|
|
|
|
c.Ui.Error("A positive drain duration must be given")
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d = dur
|
|
|
|
|
} else {
|
|
|
|
|
d = defaultDrainDuration
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 00:09:03 +00:00
|
|
|
|
// Get the HTTP client
|
2015-09-14 20:13:52 +00:00
|
|
|
|
client, err := c.Meta.Client()
|
2015-09-13 00:09:03 +00:00
|
|
|
|
if err != nil {
|
2015-09-14 20:13:52 +00:00
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
2015-09-13 00:09:03 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-11 22:20:49 +00:00
|
|
|
|
// If -self flag is set then determine the current node.
|
2017-09-26 22:26:33 +00:00
|
|
|
|
var nodeID string
|
2016-04-11 22:20:49 +00:00
|
|
|
|
if !self {
|
|
|
|
|
nodeID = args[0]
|
|
|
|
|
} else {
|
|
|
|
|
var err error
|
|
|
|
|
if nodeID, err = getLocalNodeID(client); err != nil {
|
|
|
|
|
c.Ui.Error(err.Error())
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-20 17:02:10 +00:00
|
|
|
|
// Check if node exists
|
2016-03-17 23:48:45 +00:00
|
|
|
|
if len(nodeID) == 1 {
|
2020-12-09 19:05:18 +00:00
|
|
|
|
c.Ui.Error("Identifier must contain at least two characters.")
|
2016-03-17 23:48:45 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
2016-01-21 19:53:05 +00:00
|
|
|
|
|
2018-03-11 18:52:59 +00:00
|
|
|
|
nodeID = sanitizeUUIDPrefix(nodeID)
|
2016-03-17 23:48:45 +00:00
|
|
|
|
nodes, _, err := client.Nodes().PrefixList(nodeID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error toggling drain mode: %s", err))
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
// Return error if no nodes are found
|
|
|
|
|
if len(nodes) == 0 {
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("No node(s) with prefix or id %q found", nodeID))
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
if len(nodes) > 1 {
|
2018-02-27 22:43:35 +00:00
|
|
|
|
c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s",
|
|
|
|
|
formatNodeStubList(nodes, true)))
|
2017-07-21 00:31:07 +00:00
|
|
|
|
return 1
|
2016-03-17 23:48:45 +00:00
|
|
|
|
}
|
2016-03-24 21:43:20 +00:00
|
|
|
|
|
2016-03-17 23:48:45 +00:00
|
|
|
|
// Prefix lookup matched a single node
|
2018-12-21 00:03:07 +00:00
|
|
|
|
node, meta, err := client.Nodes().Info(nodes[0].ID, nil)
|
2016-03-17 23:48:45 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error toggling drain mode: %s", err))
|
|
|
|
|
return 1
|
2015-12-20 17:02:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 17:58:40 +00:00
|
|
|
|
// If monitoring the drain start the monitor and return when done
|
2018-05-07 20:14:58 +00:00
|
|
|
|
if monitor {
|
2018-12-21 00:03:07 +00:00
|
|
|
|
if node.DrainStrategy == nil {
|
|
|
|
|
c.Ui.Warn("No drain strategy set")
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2018-05-07 20:14:58 +00:00
|
|
|
|
c.Ui.Info(fmt.Sprintf("%s: Monitoring node %q: Ctrl-C to detach monitoring", formatTime(time.Now()), node.ID))
|
2018-12-21 00:03:07 +00:00
|
|
|
|
c.monitorDrain(client, context.Background(), node, meta.LastIndex, ignoreSystem)
|
2018-05-07 20:14:58 +00:00
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 21:43:20 +00:00
|
|
|
|
// Confirm drain if the node was a prefix match.
|
|
|
|
|
if nodeID != node.ID && !autoYes {
|
|
|
|
|
verb := "enable"
|
|
|
|
|
if disable {
|
|
|
|
|
verb = "disable"
|
|
|
|
|
}
|
|
|
|
|
question := fmt.Sprintf("Are you sure you want to %s drain mode for node %q? [y/N]", verb, node.ID)
|
|
|
|
|
answer, err := c.Ui.Ask(question)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("Failed to parse answer: %v", err))
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if answer == "" || strings.ToLower(answer)[0] == 'n' {
|
|
|
|
|
// No case
|
|
|
|
|
c.Ui.Output("Canceling drain toggle")
|
|
|
|
|
return 0
|
2016-03-28 02:17:29 +00:00
|
|
|
|
} else if strings.ToLower(answer)[0] == 'y' && len(answer) > 1 {
|
2016-03-24 21:43:20 +00:00
|
|
|
|
// Non exact match yes
|
|
|
|
|
c.Ui.Output("For confirmation, an exact ‘y’ is required.")
|
|
|
|
|
return 0
|
|
|
|
|
} else if answer != "y" {
|
|
|
|
|
c.Ui.Output("No confirmation detected. For confirmation, an exact 'y' is required.")
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 23:56:36 +00:00
|
|
|
|
var spec *api.DrainSpec
|
|
|
|
|
if enable {
|
|
|
|
|
spec = &api.DrainSpec{
|
|
|
|
|
Deadline: d,
|
|
|
|
|
IgnoreSystemJobs: ignoreSystem,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 17:58:40 +00:00
|
|
|
|
// propagate drain metadata if cancelling
|
|
|
|
|
drainMeta := make(map[string]string)
|
|
|
|
|
if disable && node.LastDrain != nil && node.LastDrain.Meta != nil {
|
|
|
|
|
drainMeta = node.LastDrain.Meta
|
|
|
|
|
}
|
|
|
|
|
if message != "" {
|
|
|
|
|
if enable {
|
|
|
|
|
drainMeta["message"] = message
|
|
|
|
|
} else {
|
|
|
|
|
drainMeta["cancel_message"] = message
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, m := range metaVars {
|
|
|
|
|
if len(m) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
kv := strings.SplitN(m, "=", 2)
|
|
|
|
|
if len(kv) == 2 {
|
|
|
|
|
drainMeta[kv[0]] = kv[1]
|
|
|
|
|
} else {
|
|
|
|
|
drainMeta[kv[0]] = ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 00:09:03 +00:00
|
|
|
|
// Toggle node draining
|
2021-05-07 17:58:40 +00:00
|
|
|
|
drainResponse, err := client.Nodes().UpdateDrainOpts(node.ID,
|
|
|
|
|
&api.DrainOptions{
|
|
|
|
|
DrainSpec: spec,
|
|
|
|
|
MarkEligible: !keepIneligible,
|
|
|
|
|
Meta: drainMeta,
|
|
|
|
|
}, nil)
|
2018-03-06 22:16:20 +00:00
|
|
|
|
if err != nil {
|
2018-02-23 23:56:36 +00:00
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error updating drain specification: %s", err))
|
2015-09-13 00:09:03 +00:00
|
|
|
|
return 1
|
|
|
|
|
}
|
2018-02-27 21:54:27 +00:00
|
|
|
|
|
2018-03-30 00:05:06 +00:00
|
|
|
|
if !enable || detach {
|
|
|
|
|
if enable {
|
|
|
|
|
c.Ui.Output(fmt.Sprintf("Node %q drain strategy set", node.ID))
|
|
|
|
|
} else {
|
|
|
|
|
c.Ui.Output(fmt.Sprintf("Node %q drain strategy unset", node.ID))
|
|
|
|
|
}
|
2018-03-28 21:01:54 +00:00
|
|
|
|
}
|
2018-03-06 22:16:20 +00:00
|
|
|
|
|
|
|
|
|
if enable && !detach {
|
2018-03-30 18:07:40 +00:00
|
|
|
|
now := time.Now()
|
2018-03-30 21:20:05 +00:00
|
|
|
|
c.Ui.Info(fmt.Sprintf("%s: Ctrl-C to stop monitoring: will not cancel the node drain", formatTime(now)))
|
2018-03-30 18:07:40 +00:00
|
|
|
|
c.Ui.Output(fmt.Sprintf("%s: Node %q drain strategy set", formatTime(now), node.ID))
|
2021-05-07 17:58:40 +00:00
|
|
|
|
c.monitorDrain(client, context.Background(), node, drainResponse.LastIndex, ignoreSystem)
|
2018-03-06 22:16:20 +00:00
|
|
|
|
}
|
2015-09-13 00:09:03 +00:00
|
|
|
|
return 0
|
|
|
|
|
}
|
2018-05-07 20:14:58 +00:00
|
|
|
|
|
|
|
|
|
func (c *NodeDrainCommand) monitorDrain(client *api.Client, ctx context.Context, node *api.Node, index uint64, ignoreSystem bool) {
|
|
|
|
|
outCh := client.Nodes().MonitorDrain(ctx, node.ID, index, ignoreSystem)
|
|
|
|
|
for msg := range outCh {
|
|
|
|
|
switch msg.Level {
|
|
|
|
|
case api.MonitorMsgLevelInfo:
|
|
|
|
|
c.Ui.Info(fmt.Sprintf("%s: %s", formatTime(time.Now()), msg))
|
|
|
|
|
case api.MonitorMsgLevelWarn:
|
|
|
|
|
c.Ui.Warn(fmt.Sprintf("%s: %s", formatTime(time.Now()), msg))
|
|
|
|
|
case api.MonitorMsgLevelError:
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("%s: %s", formatTime(time.Now()), msg))
|
|
|
|
|
default:
|
|
|
|
|
c.Ui.Output(fmt.Sprintf("%s: %s", formatTime(time.Now()), msg))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|