From c49f7d0441d0066a9face9cef11f07775d323907 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 2 May 2018 16:19:15 -0700 Subject: [PATCH] cli: expand drain info for node status --- CHANGELOG.md | 5 +++++ command/node_status.go | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 062fd2d7770..ea823a82a88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.8.4 (Unreleased) + +IMPROVEMENTS: + * cli: Add node drain details to node status + ## 0.8.3 (April 27, 2018) BUG FIXES: diff --git a/command/node_status.go b/command/node_status.go index 226c054fcd0..69f99acc0df 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "sort" + "strconv" "strings" "time" @@ -299,6 +300,26 @@ func nodeDrivers(n *api.Node) []string { return drivers } +func nodeDrainString(n *api.Node) string { + if n.DrainStrategy != nil { + b := new(strings.Builder) + b.WriteString("true") + + if n.DrainStrategy.ForceDeadline.IsZero() { + b.WriteString("; no deadline") + } else { + fmt.Fprintf(b, "; %s deadline", formatTime(n.DrainStrategy.ForceDeadline)) + } + + if n.DrainStrategy.IgnoreSystemJobs { + b.WriteString("; ignoring system jobs") + } + return b.String() + } + + return strconv.FormatBool(n.Drain) +} + func (c *NodeStatusCommand) formatNode(client *api.Client, node *api.Node) int { // Format the header output basic := []string{ @@ -306,7 +327,7 @@ func (c *NodeStatusCommand) formatNode(client *api.Client, node *api.Node) int { fmt.Sprintf("Name|%s", node.Name), fmt.Sprintf("Class|%s", node.NodeClass), fmt.Sprintf("DC|%s", node.Datacenter), - fmt.Sprintf("Drain|%v", node.Drain), + fmt.Sprintf("Drain|%v", nodeDrainString(node)), fmt.Sprintf("Eligibility|%s", node.SchedulingEligibility), fmt.Sprintf("Status|%s", node.Status), }