Skip to content

Commit

Permalink
ignore minReplicas/maxReplicas in hpa webhook (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho authored Jan 5, 2024
1 parent b2f6a7d commit e88c7f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion api/autoscaling/v2/horizontalpodautoscaler_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ func (h *HPAWebhook) Default(ctx context.Context, obj runtime.Object) error {
return nil
}

hpa, _, err = h.hpaService.ChangeHPAFromTortoiseRecommendation(t, hpa, time.Now(), false) // we don't need to record metrics.
modifiedhpa, _, err := h.hpaService.ChangeHPAFromTortoiseRecommendation(t, hpa.DeepCopy(), time.Now(), false) // we don't need to record metrics.
if err != nil {
// Block updating HPA may be critical. Just ignore it with error logs.
log.FromContext(ctx).Error(err, "failed to get tortoise for mutating webhook of HPA", "hpa", klog.KObj(hpa), "tortoise", tortoiseName)
return nil
}
// Only overwrite metrics and ignore other fields like minReplicas and maxReplicas.
// If we want to overwrite minReplicas and maxReplicas, it'd be complicated because we have to consider the emergency mode.
hpa.Spec.Metrics = modifiedhpa.Spec.Metrics

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: sample
namespace: default
spec:
maxReplicas: 12
maxReplicas: 10 # not overwritten
metrics:
- type: ContainerResource
containerResource:
Expand All @@ -20,7 +20,7 @@ spec:
target:
type: Utilization
averageUtilization: 30
minReplicas: 3
minReplicas: 1 # not overwritten
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
Expand Down

0 comments on commit e88c7f1

Please sign in to comment.