Skip to content

Commit

Permalink
Scale only cpu via millis
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Sep 19, 2023
1 parent 5ce026a commit 974053e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/controllers/vpa_runnable.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (v *VpaRunnable) reconcile(ctx context.Context) {
largest := maxByMemory(viable)
containers := int64(len(target.PodSpec.Containers))
// distribute a fraction of maximum capacity evenly across containers
cpuScaled := scaleQuantity(largest.Status.Allocatable.Cpu(), v.CapacityPercent/containers)
cpuScaled := scaleQuantityMilli(largest.Status.Allocatable.Cpu(), v.CapacityPercent/containers)
memScaled := scaleQuantity(largest.Status.Allocatable.Memory(), v.CapacityPercent/containers)
err = v.patchMaxRessources(ctx, patchParams{
vpa: target.Vpa,
Expand Down Expand Up @@ -167,6 +167,10 @@ func maxByMemory(nodes []corev1.Node) corev1.Node {
return maxNode
}

func scaleQuantity(q *resource.Quantity, percent int64) *resource.Quantity {
func scaleQuantityMilli(q *resource.Quantity, percent int64) *resource.Quantity {
return resource.NewMilliQuantity(q.MilliValue()*percent/scaleDivisor, q.Format)
}

func scaleQuantity(q *resource.Quantity, percent int64) *resource.Quantity {
return resource.NewQuantity(q.Value()*percent/scaleDivisor, q.Format)
}

0 comments on commit 974053e

Please sign in to comment.