@@ -172,9 +172,9 @@ func (r *ScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Request
172
172
}
173
173
}
174
174
175
- // reconcile ScaledObject and set status appropriately
176
- msg , err := r .reconcileScaledObject (ctx , reqLogger , scaledObject )
177
175
conditions := scaledObject .Status .Conditions .DeepCopy ()
176
+ // reconcile ScaledObject and set status appropriately
177
+ msg , err := r .reconcileScaledObject (ctx , reqLogger , scaledObject , & conditions )
178
178
if err != nil {
179
179
reqLogger .Error (err , msg )
180
180
conditions .SetReadyCondition (metav1 .ConditionFalse , "ScaledObjectCheckFailed" , msg )
@@ -197,14 +197,13 @@ func (r *ScaledObjectReconciler) Reconcile(ctx context.Context, req ctrl.Request
197
197
}
198
198
199
199
// reconcileScaledObject implements reconciler logic for ScaledObject
200
- func (r * ScaledObjectReconciler ) reconcileScaledObject (ctx context.Context , logger logr.Logger , scaledObject * kedav1alpha1.ScaledObject ) (string , error ) {
200
+ func (r * ScaledObjectReconciler ) reconcileScaledObject (ctx context.Context , logger logr.Logger , scaledObject * kedav1alpha1.ScaledObject , conditions * kedav1alpha1. Conditions ) (string , error ) {
201
201
// Check the presence of "autoscaling.keda.sh/paused-replicas" annotation on the scaledObject (since the presence of this annotation will pause
202
202
// autoscaling no matter what number of replicas is provided), and if so, stop the scale loop and delete the HPA on the scaled object.
203
203
_ , paused := scaledObject .GetAnnotations ()[kedacontrollerutil .PausedReplicasAnnotation ]
204
204
if paused {
205
205
logger .Info ("ScaledObject is paused, so skipping the request." )
206
206
msg := kedav1alpha1 .ScaledObjectConditionPausedMessage
207
- conditions := scaledObject .Status .Conditions .DeepCopy ()
208
207
if err := r .stopScaleLoop (ctx , logger , scaledObject ); err != nil {
209
208
msg = "failed to stop the scale loop for paused ScaledObject"
210
209
conditions .SetPausedCondition (metav1 .ConditionFalse , "ScaledObjectStopScaleLoopFailed" , msg )
@@ -416,7 +415,7 @@ func (r *ScaledObjectReconciler) checkReplicaCountBoundsAreValid(scaledObject *k
416
415
417
416
// ensureHPAForScaledObjectExists ensures that in cluster exist up-to-date HPA for specified ScaledObject, returns true if a new HPA was created
418
417
func (r * ScaledObjectReconciler ) ensureHPAForScaledObjectExists (ctx context.Context , logger logr.Logger , scaledObject * kedav1alpha1.ScaledObject , gvkr * kedav1alpha1.GroupVersionKindResource ) (bool , error ) {
419
- hpaName := getHPAName (scaledObject )
418
+ hpaName := getHPANameOnEnsure (scaledObject )
420
419
foundHpa := & autoscalingv2.HorizontalPodAutoscaler {}
421
420
// Check if HPA for this ScaledObject already exists
422
421
err := r .Client .Get (ctx , types.NamespacedName {Name : hpaName , Namespace : scaledObject .Namespace }, foundHpa )
@@ -456,7 +455,7 @@ func (r *ScaledObjectReconciler) ensureHPAForScaledObjectExists(ctx context.Cont
456
455
457
456
// ensureHPAForScaledObjectIsDeleted ensures that in cluster any HPA for specified ScaledObject is deleted, returns true if no HPA exists
458
457
func (r * ScaledObjectReconciler ) ensureHPAForScaledObjectIsDeleted (ctx context.Context , logger logr.Logger , scaledObject * kedav1alpha1.ScaledObject ) (bool , error ) {
459
- hpaName := getHPAName (scaledObject )
458
+ hpaName := getHPANameOnEnsure (scaledObject )
460
459
foundHpa := & autoscalingv2.HorizontalPodAutoscaler {}
461
460
// Check if HPA for this ScaledObject already exists
462
461
err := r .Client .Get (ctx , types.NamespacedName {Name : hpaName , Namespace : scaledObject .Namespace }, foundHpa )
@@ -474,6 +473,13 @@ func (r *ScaledObjectReconciler) ensureHPAForScaledObjectIsDeleted(ctx context.C
474
473
return true , nil
475
474
}
476
475
476
+ func getHPANameOnEnsure (scaledObject * kedav1alpha1.ScaledObject ) string {
477
+ if scaledObject .Status .HpaName != "" {
478
+ return scaledObject .Status .HpaName
479
+ }
480
+ return getHPAName (scaledObject )
481
+ }
482
+
477
483
func isHpaRenamed (scaledObject * kedav1alpha1.ScaledObject , foundHpa * autoscalingv2.HorizontalPodAutoscaler ) bool {
478
484
// if HPA name defined in SO -> check if equals to the found HPA
479
485
if scaledObject .Spec .Advanced != nil && scaledObject .Spec .Advanced .HorizontalPodAutoscalerConfig != nil && scaledObject .Spec .Advanced .HorizontalPodAutoscalerConfig .Name != "" {
0 commit comments