Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cluster-autoscaler/core/scaleup/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ func (o *ScaleUpOrchestrator) ComputeExpansionOption(
}

option.SimilarNodeGroups = o.ComputeSimilarNodeGroups(nodeGroup, nodeInfos, schedulablePodGroups, now)
if option.SimilarNodeGroups != nil {
// if similar node groups are found, log about them
similarNodeGroupIds := make([]string, 0)
for _, sng := range option.SimilarNodeGroups {
similarNodeGroupIds = append(similarNodeGroupIds, sng.Id())
}
klog.V(5).Infof("Found %d similar node groups: %v", len(option.SimilarNodeGroups), similarNodeGroupIds)
} else if o.autoscalingContext.BalanceSimilarNodeGroups {
// if no similar node groups are found and the flag is enabled, log about it
klog.V(5).Info("No similar node groups found")
}

estimateStart := time.Now()
expansionEstimator := o.estimatorBuilder(
Expand Down
12 changes: 12 additions & 0 deletions cluster-autoscaler/processors/nodegroupset/compare_nodegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ limitations under the License.
package nodegroupset

import (
"fmt"
"math"

apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
"k8s.io/autoscaler/cluster-autoscaler/utils/scheduler"
klog "k8s.io/klog/v2"
)

// BasicIgnoredLabels define a set of basic labels that should be ignored when comparing the similarity
Expand Down Expand Up @@ -122,34 +124,44 @@ func IsCloudProviderNodeInfoSimilar(

for kind, qtyList := range capacity {
if len(qtyList) != 2 {
dissimilarNodesLog(n1.Node().Name, n2.Node().Name, fmt.Sprintf("missing capacity %q", kind))
return false
}
switch kind {
case apiv1.ResourceMemory:
if !resourceListWithinTolerance(qtyList, ratioOpts.MaxCapacityMemoryDifferenceRatio) {
dissimilarNodesLog(n1.Node().Name, n2.Node().Name, "memory not within tolerance")
return false
}
default:
// For other capacity types we require exact match.
// If this is ever changed, enforcing MaxCoresTotal limits
// as it is now may no longer work.
if qtyList[0].Cmp(qtyList[1]) != 0 {
dissimilarNodesLog(n1.Node().Name, n2.Node().Name, fmt.Sprintf("capacity resource %q does not match", kind))
return false
}
}
}

// For allocatable and free we allow resource quantities to be within a few % of each other
if !resourceMapsWithinTolerance(allocatable, ratioOpts.MaxAllocatableDifferenceRatio) {
dissimilarNodesLog(n1.Node().Name, n2.Node().Name, "allocatable resources not within tolerance")
return false
}
if !resourceMapsWithinTolerance(free, ratioOpts.MaxFreeDifferenceRatio) {
dissimilarNodesLog(n1.Node().Name, n2.Node().Name, "free resources not within tolerance")
return false
}

if !compareLabels(nodes, ignoredLabels) {
dissimilarNodesLog(n1.Node().Name, n2.Node().Name, "labels do not match")
return false
}

return true
}

func dissimilarNodesLog(node1, node2, message string) {
klog.V(5).Infof("nodes %q and %q are not similar, %s", node1, node2, message)
}
Loading