Skip to content

Commit f038712

Browse files
committed
fix: added check for hostname to minimize bin-packing compute
Signed-off-by: MenD32 <[email protected]>
1 parent 886516c commit f038712

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

cluster-autoscaler/estimator/binpacking_estimator.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (e *BinpackingNodeEstimator) tryToScheduleOnNewNodes(
186186
// The pod can't be scheduled on the newly created node because of scheduling predicates.
187187

188188
// Check if node failed because of topology constraints.
189-
if hasTopologyConstraintError(err) {
189+
if isPodUsingHostNameTopologyKey(pod) && hasTopologyConstraintError(err) {
190190
// If the pod can't be scheduled on the last node because of topology constraints, we can stop binpacking.
191191
// The pod can't be scheduled on any new node either, because it has the same topology constraints.
192192
nodeName, err := e.clusterSnapshot.SchedulePodOnAnyNodeMatching(pod, func(nodeInfo *framework.NodeInfo) bool {
@@ -273,6 +273,22 @@ func hasTopologyConstraintError(err clustersnapshot.SchedulingError) bool {
273273
return slices.Contains(err.FailingPredicateReasons(), podtopologyspread.ErrReasonConstraintsNotMatch)
274274
}
275275

276+
// isPodUsingHostNameTopoKey returns true if the pod has any topology spread
277+
// constraint that uses the kubernetes.io/hostname topology key
278+
func isPodUsingHostNameTopologyKey(pod *apiv1.Pod) bool {
279+
if pod == nil || pod.Spec.TopologySpreadConstraints == nil {
280+
return false
281+
}
282+
283+
for _, constraint := range pod.Spec.TopologySpreadConstraints {
284+
if constraint.TopologyKey == apiv1.LabelHostname {
285+
return true
286+
}
287+
}
288+
289+
return false
290+
}
291+
276292
func observeBinpackingHeterogeneity(podsEquivalenceGroups []PodEquivalenceGroup, nodeTemplate *framework.NodeInfo) {
277293
node := nodeTemplate.Node()
278294
var instanceType, cpuCount string

cluster-autoscaler/estimator/binpacking_estimator_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func TestBinpackingEstimate(t *testing.T) {
172172
expectProcessedPods: highResourcePodGroup.Pods,
173173
},
174174
{
175-
name: "hostname topology spreading with maxSkew=2 forces 2 pods/node",
175+
name: "hostname topology spreading with maxSkew=2 allows 8 pods to schedule retroactively",
176176
millicores: 1000,
177177
memory: 5000,
178178
podsEquivalenceGroup: []PodEquivalenceGroup{makePodEquivalenceGroup(
@@ -195,8 +195,8 @@ func TestBinpackingEstimate(t *testing.T) {
195195
podsEquivalenceGroup: []PodEquivalenceGroup{makePodEquivalenceGroup(
196196
BuildTestPod(
197197
"estimatee",
198-
200,
199-
200,
198+
20,
199+
100,
200200
WithNamespace("universe"),
201201
WithLabels(map[string]string{
202202
"app": "estimatee",

0 commit comments

Comments
 (0)