Skip to content

Commit 9c0d57a

Browse files
committed
feat: scale disruption cost by the node utilization
Signed-off-by: Cameron McAvoy <[email protected]>
1 parent 82a7d80 commit 9c0d57a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/controllers/disruption/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func NewCandidate(ctx context.Context, kubeClient client.Client, recorder events
112112
zone: node.Labels()[corev1.LabelTopologyZone],
113113
reschedulablePods: lo.Filter(pods, func(p *corev1.Pod, _ int) bool { return pod.IsReschedulable(p) }),
114114
// We get the disruption cost from all pods in the candidate, not just the reschedulable pods
115-
disruptionCost: disruptionutils.ReschedulingCost(ctx, pods) * disruptionutils.LifetimeRemaining(clk, nodePool, node.NodeClaim),
115+
disruptionCost: disruptionutils.ReschedulingCost(ctx, pods) * disruptionutils.LifetimeRemaining(clk, nodePool, node.NodeClaim) * node.Utilization(),
116116
}, nil
117117
}
118118

pkg/controllers/state/statenode.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,21 @@ func (in *StateNode) Available() corev1.ResourceList {
365365
return resources.Subtract(in.Allocatable(), in.PodRequests())
366366
}
367367

368+
// Utilization is the ratio of requested resources to allocatable resources
369+
func (in *StateNode) Utilization() float64 {
370+
requested := in.PodRequests()
371+
if len(requested) == 0 {
372+
return 0
373+
}
374+
alloc := in.Allocatable()
375+
utilization := 0.0
376+
for resource, request := range requested {
377+
allocResource := alloc[resource]
378+
utilization += float64(request.MilliValue()) / float64(allocResource.MilliValue())
379+
}
380+
return utilization / float64(len(requested))
381+
}
382+
368383
func (in *StateNode) DaemonSetRequests() corev1.ResourceList {
369384
return resources.Merge(lo.Values(in.daemonSetRequests)...)
370385
}

0 commit comments

Comments
 (0)