Skip to content

Commit

Permalink
feat: scale disruption cost by the node utilization
Browse files Browse the repository at this point in the history
Signed-off-by: Cameron McAvoy <[email protected]>
  • Loading branch information
cnmcavoy committed Feb 24, 2025
1 parent 82a7d80 commit 0374e0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/controllers/disruption/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewCandidate(ctx context.Context, kubeClient client.Client, recorder events
zone: node.Labels()[corev1.LabelTopologyZone],
reschedulablePods: lo.Filter(pods, func(p *corev1.Pod, _ int) bool { return pod.IsReschedulable(p) }),
// We get the disruption cost from all pods in the candidate, not just the reschedulable pods
disruptionCost: disruptionutils.ReschedulingCost(ctx, pods) * disruptionutils.LifetimeRemaining(clk, nodePool, node.NodeClaim),
disruptionCost: disruptionutils.ReschedulingCost(ctx, pods) * disruptionutils.LifetimeRemaining(clk, nodePool, node.NodeClaim) * node.Utilization(),
}, nil
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/controllers/state/statenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ func (in *StateNode) Available() corev1.ResourceList {
return resources.Subtract(in.Allocatable(), in.PodRequests())
}

// Utilization is the ratio of requested resources to allocatable resources
func (in *StateNode) Utilization() float64 {
alloc := in.Allocatable()
requested := in.PodRequests()
utilization := 0.0
for resource, request := range requested {
allocResource := alloc[resource]
utilization += float64(request.MilliValue()) / float64(allocResource.MilliValue())
}
return utilization / float64(len(requested))
}

func (in *StateNode) DaemonSetRequests() corev1.ResourceList {
return resources.Merge(lo.Values(in.daemonSetRequests)...)
}
Expand Down

0 comments on commit 0374e0d

Please sign in to comment.