diff --git a/pkg/controller/podautoscaler/horizontal.go b/pkg/controller/podautoscaler/horizontal.go index a814a6c8069..282d54462ce 100644 --- a/pkg/controller/podautoscaler/horizontal.go +++ b/pkg/controller/podautoscaler/horizontal.go @@ -836,7 +836,7 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare // computeReplicasForMetrics may return both non-zero metricDesiredReplicas and an error. // That means some metrics still work and HPA should perform scaling based on them. if err != nil && metricDesiredReplicas == -1 { - a.setCurrentReplicasInStatus(hpa, currentReplicas) + a.setCurrentReplicasAndMetricsInStatus(hpa, currentReplicas, metricStatuses) if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil { utilruntime.HandleError(err) } @@ -879,7 +879,7 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare if err != nil { a.eventRecorder.Eventf(hpa, v1.EventTypeWarning, "FailedRescale", "New size: %d; reason: %s; error: %v", desiredReplicas, rescaleReason, err.Error()) setCondition(hpa, autoscalingv2.AbleToScale, v1.ConditionFalse, "FailedUpdateScale", "the HPA controller was unable to update the target scale: %v", err) - a.setCurrentReplicasInStatus(hpa, currentReplicas) + a.setCurrentReplicasAndMetricsInStatus(hpa, currentReplicas, metricStatuses) if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil { utilruntime.HandleError(err) } @@ -1357,9 +1357,9 @@ func (a *HorizontalController) scaleForResourceMappings(ctx context.Context, nam return nil, schema.GroupResource{}, firstErr } -// setCurrentReplicasInStatus sets the current replica count in the status of the HPA. -func (a *HorizontalController) setCurrentReplicasInStatus(hpa *autoscalingv2.HorizontalPodAutoscaler, currentReplicas int32) { - a.setStatus(hpa, currentReplicas, hpa.Status.DesiredReplicas, hpa.Status.CurrentMetrics, false) +// setCurrentReplicasAndMetricsInStatus sets the current replica count and metrics in the status of the HPA. +func (a *HorizontalController) setCurrentReplicasAndMetricsInStatus(hpa *autoscalingv2.HorizontalPodAutoscaler, currentReplicas int32, metricStatuses []autoscalingv2.MetricStatus) { + a.setStatus(hpa, currentReplicas, hpa.Status.DesiredReplicas, metricStatuses, false) } // setStatus recreates the status of the given HPA, updating the current and