From 565d60ff150f9d12f9d32410b36667587bc9e9a0 Mon Sep 17 00:00:00 2001 From: PingWang Date: Fri, 15 Jul 2022 14:12:13 +0800 Subject: [PATCH] HandleError of updateStatusIfNeeded in func reconcileAutoscaler Signed-off-by: PingWang --- pkg/controller/podautoscaler/horizontal.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/controller/podautoscaler/horizontal.go b/pkg/controller/podautoscaler/horizontal.go index ff5e960f687..b7ef130627f 100644 --- a/pkg/controller/podautoscaler/horizontal.go +++ b/pkg/controller/podautoscaler/horizontal.go @@ -581,7 +581,9 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare if err != nil { a.eventRecorder.Event(hpa, v1.EventTypeWarning, "FailedGetScale", err.Error()) setCondition(hpa, autoscalingv2.AbleToScale, v1.ConditionFalse, "FailedGetScale", "the HPA controller was unable to get the target's current scale: %v", err) - a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa) + if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil { + utilruntime.HandleError(err) + } return fmt.Errorf("invalid API version in scale target reference: %v", err) } @@ -594,7 +596,9 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare if err != nil { a.eventRecorder.Event(hpa, v1.EventTypeWarning, "FailedGetScale", err.Error()) setCondition(hpa, autoscalingv2.AbleToScale, v1.ConditionFalse, "FailedGetScale", "the HPA controller was unable to get the target's current scale: %v", err) - a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa) + if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil { + utilruntime.HandleError(err) + } return fmt.Errorf("unable to determine resource for scale target reference: %v", err) } @@ -602,7 +606,9 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare if err != nil { a.eventRecorder.Event(hpa, v1.EventTypeWarning, "FailedGetScale", err.Error()) setCondition(hpa, autoscalingv2.AbleToScale, v1.ConditionFalse, "FailedGetScale", "the HPA controller was unable to get the target's current scale: %v", err) - a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa) + if err := a.updateStatusIfNeeded(ctx, hpaStatusOriginal, hpa); err != nil { + utilruntime.HandleError(err) + } return fmt.Errorf("failed to query scale subresource for %s: %v", reference, err) } setCondition(hpa, autoscalingv2.AbleToScale, v1.ConditionTrue, "SucceededGetScale", "the HPA controller was able to get the target's current scale")