Skip to content

Commit

Permalink
scaleutils: fix least busy selector on clusters older than v1.0.0 (#508)
Browse files Browse the repository at this point in the history
This adds additional API calls when performing the least busy node
selector as a best effort to work on cluster that running Nomad
versions before v1.0.0.

v1.0.0 including API functionality which allows node resources to
be include in the stub list node object which is used when
performing least busy calculations. In version prior to this, the
information is only available within the node info object.
  • Loading branch information
jrasell authored Jul 8, 2021
1 parent 6af6abf commit bc1a8d2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sdk/helper/scaleutils/nodeselector/least_busy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ func (l *leastBusyClusterScaleInNodeSelector) Select(nodes []*api.NodeListStub,

for i, node := range nodes {

// The NodeResources object is only available within the Nomad
// api.NodeListStub from v1.0.0 onwards. Therefore in clusters running
// clients on lower versions, we need additional API calls to discover
// this information.
if node.NodeResources == nil {

nodeInfo, _, err := l.client.Nodes().Info(node.ID, nil)
if err != nil {
l.log.Error("failed to call node info for resource detail", "error", err)
return nil
}
if nodeInfo.NodeResources == nil {
l.log.Error("node object does not contain resource info", "node_id", node.ID)
return nil
}

// Update the node to include the resource object.
node.NodeResources = nodeInfo.NodeResources

if node.ReservedResources == nil && nodeInfo.ReservedResources != nil {
node.ReservedResources = nodeInfo.ReservedResources
}
}

// In the event of an API error, we are unable to ensure the selected
// nodes are the least busy. Therefore we must exit. In the future we
// could consider adding a threshold, configurable by the operator to
Expand Down

0 comments on commit bc1a8d2

Please sign in to comment.