Skip to content

Commit 0374e0d

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

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,18 @@ 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+
alloc := in.Allocatable()
371+
requested := in.PodRequests()
372+
utilization := 0.0
373+
for resource, request := range requested {
374+
allocResource := alloc[resource]
375+
utilization += float64(request.MilliValue()) / float64(allocResource.MilliValue())
376+
}
377+
return utilization / float64(len(requested))
378+
}
379+
368380
func (in *StateNode) DaemonSetRequests() corev1.ResourceList {
369381
return resources.Merge(lo.Values(in.daemonSetRequests)...)
370382
}

0 commit comments

Comments
 (0)