Handle force draining

This commit is contained in:
Alex Dadgar 2018-06-06 13:05:39 -07:00
parent 0118f68710
commit 217231347f
2 changed files with 9 additions and 7 deletions

View File

@ -304,8 +304,9 @@ func formatDrain(n *api.Node) string {
if n.DrainStrategy != nil {
b := new(strings.Builder)
b.WriteString("true")
if n.DrainStrategy.ForceDeadline.IsZero() {
if n.DrainStrategy.DrainSpec.Deadline.Nanoseconds() < 0 {
b.WriteString("; force drain")
} else if n.DrainStrategy.ForceDeadline.IsZero() {
b.WriteString("; no deadline")
} else {
fmt.Fprintf(b, "; %s deadline", formatTime(n.DrainStrategy.ForceDeadline))

View File

@ -262,16 +262,17 @@ func TestNodeStatusCommand_FormatDrain(t *testing.T) {
assert.Equal("false", formatDrain(node))
node.DrainStrategy = &api.DrainStrategy{}
assert.Equal("true; no deadline", formatDrain(node))
// formatTime special cases Unix(0, 0), so increment by 1
node.DrainStrategy.ForceDeadline = time.Unix(1, 0)
t.Logf(node.DrainStrategy.ForceDeadline.String())
node.DrainStrategy = &api.DrainStrategy{}
node.DrainStrategy.Deadline = -1 * time.Second
assert.Equal("true; force drain", formatDrain(node))
// formatTime special cases Unix(0, 0), so increment by 1
node.DrainStrategy = &api.DrainStrategy{}
node.DrainStrategy.ForceDeadline = time.Unix(1, 0).UTC()
assert.Equal("true; 1970-01-01T00:00:01Z deadline", formatDrain(node))
node.DrainStrategy.IgnoreSystemJobs = true
assert.Equal("true; 1970-01-01T00:00:01Z deadline; ignoring system jobs", formatDrain(node))
}