Skip to content

Commit 24b375c

Browse files
committed
modify ScaleUp policy to allow scale up more than 100%
1 parent 805134b commit 24b375c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

internal/controller/prescale_controller.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,19 @@ func (r *PrescaleReconciler) executePrescale(ctx context.Context, req ctrl.Reque
394394

395395
// Prescale HPA Spec Metrics CPU AverageUtilization to prescaleSpecCpuUtilization
396396
hpa.Spec.Metrics[originalSpecCpuUtilizationIndex].Resource.Target.AverageUtilization = &prescaleSpecCpuUtilization
397-
if originalScaleUpStabilizationWindowSeconds != nil {
398-
zero := int32(0)
399-
hpa.Spec.Behavior.ScaleUp.StabilizationWindowSeconds = &zero
400-
}
397+
398+
// Add ScaleUp policy that will allow to scale up to the percent
399+
// TODO: add check if policy already exists before adding and add to OrphanedScaleUpPolicies
400+
hpa.Spec.Behavior.ScaleUp.Policies = append(hpa.Spec.Behavior.ScaleUp.Policies, autoscalingv2.HPAScalingPolicy{
401+
Type: autoscalingv2.PercentScalingPolicy,
402+
Value: percent,
403+
PeriodSeconds: 5,
404+
})
405+
zero := int32(0)
406+
hpa.Spec.Behavior.ScaleUp.StabilizationWindowSeconds = &zero
407+
maxPolicy := autoscalingv2.MaxChangePolicySelect
408+
hpa.Spec.Behavior.ScaleUp.SelectPolicy = &maxPolicy
409+
401410
if err := r.Update(ctx, hpa); err != nil {
402411
log.Error(err, "failed to update hpa for prescale")
403412
r.Recorder.Event(prescaler, corev1.EventTypeWarning, "FailedUpdateHPA", err.Error())
@@ -482,6 +491,15 @@ func (r *PrescaleReconciler) revertHPA(ctx context.Context, req ctrl.Request, pr
482491
if scheduleResult.originalScaleUpStabilizationWindowSeconds != nil {
483492
hpa.Spec.Behavior.ScaleUp.StabilizationWindowSeconds = scheduleResult.originalScaleUpStabilizationWindowSeconds
484493
}
494+
495+
// Remove ScaleUp policy we added for prescale by searching for the policy with PeriodSeconds = 5 and percent = scheduleResult.bestMissedSchedule.Percent
496+
for i, policy := range hpa.Spec.Behavior.ScaleUp.Policies {
497+
if policy.PeriodSeconds == 5 && policy.Value == scheduleResult.bestMissedSchedule.Percent {
498+
hpa.Spec.Behavior.ScaleUp.Policies = append(hpa.Spec.Behavior.ScaleUp.Policies[:i], hpa.Spec.Behavior.ScaleUp.Policies[i+1:]...)
499+
break
500+
}
501+
}
502+
485503
if err := r.Update(ctx, hpa); err != nil {
486504
log.Error(err, "failed to update hpa for revert")
487505
r.Recorder.Event(prescaler, corev1.EventTypeWarning, "FailedUpdateHPA", err.Error())

0 commit comments

Comments
 (0)