Skip to content

Commit d1f62df

Browse files
committed
add-valid-autoscaling-strategy-conditions
Signed-off-by: learner0810 <[email protected]>
1 parent d00fda3 commit d1f62df

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/controller/podautoscaler/podautoscaler_controller.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,18 @@ func (r *PodAutoscalerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
207207
}
208208

209209
if !checkValidAutoscalingStrategy(pa.Spec.ScalingStrategy) {
210-
// TODO: update status or conditions
211-
// this is unrecoverable unless user make changes.
212-
return ctrl.Result{}, nil
210+
apimeta.SetStatusCondition(&pa.Status.Conditions, metav1.Condition{
211+
Type: "AutoscalingStrategy",
212+
Status: metav1.ConditionTrue,
213+
LastTransitionTime: metav1.Now(),
214+
Reason: "AutoscalingStrategyInvalid",
215+
Message: fmt.Sprintf("autoscaling strategy %s is invalid", pa.Spec.ScalingStrategy),
216+
})
217+
return ctrl.Result{}, r.Client.Status().Update(ctx, &pa)
218+
}
219+
220+
if apimeta.RemoveStatusCondition(&pa.Status.Conditions, "AutoscalingStrategy") {
221+
return ctrl.Result{}, r.Client.Status().Update(ctx, &pa)
213222
}
214223

215224
switch pa.Spec.ScalingStrategy {
@@ -218,12 +227,6 @@ func (r *PodAutoscalerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
218227
case autoscalingv1alpha1.KPA, autoscalingv1alpha1.APA:
219228
return r.reconcileCustomPA(ctx, pa)
220229
}
221-
222-
newStatus := computeStatus(ctx, pa)
223-
if err := r.updateStatusIfNeeded(ctx, newStatus, &pa); err != nil {
224-
return ctrl.Result{}, err
225-
}
226-
227230
return ctrl.Result{}, nil
228231
}
229232

0 commit comments

Comments
 (0)