From d1f62dff52500511216546f85c831b123c327ef1 Mon Sep 17 00:00:00 2001 From: learner0810 Date: Wed, 4 Jun 2025 16:31:36 +0800 Subject: [PATCH] add-valid-autoscaling-strategy-conditions Signed-off-by: learner0810 --- .../podautoscaler/podautoscaler_controller.go | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/controller/podautoscaler/podautoscaler_controller.go b/pkg/controller/podautoscaler/podautoscaler_controller.go index 57b062293..fbc00e6dc 100644 --- a/pkg/controller/podautoscaler/podautoscaler_controller.go +++ b/pkg/controller/podautoscaler/podautoscaler_controller.go @@ -207,9 +207,18 @@ func (r *PodAutoscalerReconciler) Reconcile(ctx context.Context, req ctrl.Reques } if !checkValidAutoscalingStrategy(pa.Spec.ScalingStrategy) { - // TODO: update status or conditions - // this is unrecoverable unless user make changes. - return ctrl.Result{}, nil + apimeta.SetStatusCondition(&pa.Status.Conditions, metav1.Condition{ + Type: "AutoscalingStrategy", + Status: metav1.ConditionTrue, + LastTransitionTime: metav1.Now(), + Reason: "AutoscalingStrategyInvalid", + Message: fmt.Sprintf("autoscaling strategy %s is invalid", pa.Spec.ScalingStrategy), + }) + return ctrl.Result{}, r.Client.Status().Update(ctx, &pa) + } + + if apimeta.RemoveStatusCondition(&pa.Status.Conditions, "AutoscalingStrategy") { + return ctrl.Result{}, r.Client.Status().Update(ctx, &pa) } switch pa.Spec.ScalingStrategy { @@ -218,12 +227,6 @@ func (r *PodAutoscalerReconciler) Reconcile(ctx context.Context, req ctrl.Reques case autoscalingv1alpha1.KPA, autoscalingv1alpha1.APA: return r.reconcileCustomPA(ctx, pa) } - - newStatus := computeStatus(ctx, pa) - if err := r.updateStatusIfNeeded(ctx, newStatus, &pa); err != nil { - return ctrl.Result{}, err - } - return ctrl.Result{}, nil }