Is there a way to drain a node via the REST API but disable the drain deadline similar to how the Nomad CLI works?
With the CLI no-deadline can be specified:
I have a migrate stanza configured but an unknown number of jobs on that node. I’d have to ballpark the migrate time for each job to all fit under the deadline so if I could ignore that that would help a lot.
Eyeballing the CLI doc I took a pass at similar naming in the REST version but this doesn’t seem to be documented anywhere. Got a 200 back:
Looking at the code that gets executed (https://github.com/hashicorp/nomad/blob/master/api/nodes.go#L80), in snippet form below, it seems that the API expects a duration instead of a NoDeadline boolean. Maybe try to set the Deadline field to 0 (the CLI sets the value to 0 when “noDeadline” is specified).
// Parse the duration
var d time.Duration
if force {
d = -1 * time.Second
} else if noDeadline {
d = 0
}
// DrainSpec describes a Node's drain behavior.
type DrainSpec struct {
// Deadline is the duration after StartTime when the remaining
// allocations on a draining Node should be told to stop.
Deadline time.Duration
// IgnoreSystemJobs allows systems jobs to remain on the node even though it
// has been marked for draining.
IgnoreSystemJobs bool
}
// UpdateDrain is used to update the drain strategy for a given node. If
// markEligible is true and the drain is being removed, the node will be marked
// as having its scheduling being eligible
func (n *Nodes) UpdateDrain(nodeID string, spec *DrainSpec, markEligible bool, q *WriteOptions) (*NodeDrainUpdateResponse, error) {
req := &NodeUpdateDrainRequest{
NodeID: nodeID,
DrainSpec: spec,
MarkEligible: markEligible,
}
var resp NodeDrainUpdateResponse
wm, err := n.client.write("/v1/node/"+nodeID+"/drain", req, &resp, q)
if err != nil {
return nil, err
}
resp.WriteMeta = *wm
return &resp, nil
}