Skip to content

Commit

Permalink
Extract function to calculate acceptable ranges for node group
Browse files Browse the repository at this point in the history
  • Loading branch information
bskiba committed Jul 24, 2024
1 parent bd40d70 commit d08f0b4
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions cluster-autoscaler/clusterstate/clusterstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,25 +555,26 @@ type AcceptableRange struct {
func (csr *ClusterStateRegistry) updateAcceptableRanges(targetSize map[string]int) {
result := make(map[string]AcceptableRange)
for _, nodeGroup := range csr.cloudProvider.NodeGroups() {
size := targetSize[nodeGroup.Id()]
readiness := csr.perNodeGroupReadiness[nodeGroup.Id()]
result[nodeGroup.Id()] = AcceptableRange{
MinNodes: size - len(readiness.LongUnregistered),
MaxNodes: size,
CurrentTarget: size,
}
result[nodeGroup.Id()] = csr.acceptableRangeForNodeGroup(targetSize[nodeGroup.Id()], nodeGroup.Id())
}
for nodeGroupName, scaleUpRequest := range csr.scaleUpRequests {
acceptableRange := result[nodeGroupName]
acceptableRange.MinNodes -= scaleUpRequest.Increase
result[nodeGroupName] = acceptableRange
csr.acceptableRanges = result
}

func (csr *ClusterStateRegistry) acceptableRangeForNodeGroup(targetSize int, nodeGroupId string) AcceptableRange {
longUnregistered := 0
if readiness, found := csr.perNodeGroupReadiness[nodeGroupId]; found {
longUnregistered = len(readiness.LongUnregistered)
}
for nodeGroupName, scaleDownRequests := range csr.scaleDownRequests {
acceptableRange := result[nodeGroupName]
acceptableRange.MaxNodes += len(scaleDownRequests)
result[nodeGroupName] = acceptableRange
ar := AcceptableRange{
MinNodes: targetSize - longUnregistered,
MaxNodes: targetSize,
CurrentTarget: targetSize,
}
csr.acceptableRanges = result
if scaleUpRequest, found := csr.scaleUpRequests[nodeGroupId]; found {
ar.MinNodes -= scaleUpRequest.Increase
}
ar.MaxNodes += len(csr.scaleDownRequests[nodeGroupId])
return ar
}

// Readiness contains readiness information about a group of nodes.
Expand Down

0 comments on commit d08f0b4

Please sign in to comment.