-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added hpa update predicate to reconcile a scaledobject only if hpa spec,label or annotation is changed #5282
Added hpa update predicate to reconcile a scaledobject only if hpa spec,label or annotation is changed #5282
Conversation
Thank you for your contribution! 🙏 We will review your PR as soon as possible. While you are waiting, make sure to:
Learn more about: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add check for annotations here as well:
Lines 154 to 183 in a2c21ec
func (r *ScaledObjectReconciler) updateHPAIfNeeded(ctx context.Context, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject, foundHpa *autoscalingv2.HorizontalPodAutoscaler, gvkr *kedav1alpha1.GroupVersionKindResource) error { | |
hpa, err := r.newHPAForScaledObject(ctx, logger, scaledObject, gvkr) | |
if err != nil { | |
logger.Error(err, "Failed to create new HPA resource", "HPA.Namespace", scaledObject.Namespace, "HPA.Name", getHPAName(scaledObject)) | |
return err | |
} | |
// DeepDerivative ignores extra entries in arrays which makes removing the last trigger not update things, so trigger and update any time the metrics count is different. | |
if len(hpa.Spec.Metrics) != len(foundHpa.Spec.Metrics) || !equality.Semantic.DeepDerivative(hpa.Spec, foundHpa.Spec) { | |
logger.V(1).Info("Found difference in the HPA spec accordint to ScaledObject", "currentHPA", foundHpa.Spec, "newHPA", hpa.Spec) | |
if err = r.Client.Update(ctx, hpa); err != nil { | |
foundHpa.Spec = hpa.Spec | |
logger.Error(err, "Failed to update HPA", "HPA.Namespace", foundHpa.Namespace, "HPA.Name", foundHpa.Name) | |
return err | |
} | |
logger.Info("Updated HPA according to ScaledObject", "HPA.Namespace", foundHpa.Namespace, "HPA.Name", foundHpa.Name) | |
} | |
if !equality.Semantic.DeepDerivative(hpa.ObjectMeta.Labels, foundHpa.ObjectMeta.Labels) { | |
logger.V(1).Info("Found difference in the HPA labels accordint to ScaledObject", "currentHPA", foundHpa.ObjectMeta.Labels, "newHPA", hpa.ObjectMeta.Labels) | |
if err = r.Client.Update(ctx, hpa); err != nil { | |
foundHpa.ObjectMeta.Labels = hpa.ObjectMeta.Labels | |
logger.Error(err, "Failed to update HPA", "HPA.Namespace", foundHpa.Namespace, "HPA.Name", foundHpa.Name) | |
return err | |
} | |
logger.Info("Updated HPA according to ScaledObject", "HPA.Namespace", foundHpa.Namespace, "HPA.Name", foundHpa.Name) | |
} | |
return nil |
I am thinking that as scaledobject controller is not adding any new annotation to the HPA and HPA controller might add some annotation to it, so it should be fine to remove predicate.AnnotationChangedPredicate{} and leave this piece of code as it is. We are now on autoscaling/v2 where currently no annotation is being added by hpa controller but i saw in autoscaling/v1 that the current metrics were part of the annotations and they kept changing. |
…ec,label or ownerRefernce is changed Signed-off-by: deefreak <deepakgts2@gmail.com>
…ec,label or annotation is changed Signed-off-by: deefreak <deepakgts2@gmail.com>
…ec,label or annotation is changed Signed-off-by: deefreak <deepakgts2@gmail.com>
…ec or label is changed Signed-off-by: deefreak <deepakgts2@gmail.com>
c1011c6
to
00193f8
Compare
We are propagating the ScaledObject labels/annotations so I'd say that we have to keep the predicate: Lines 134 to 139 in a2c21ec
|
Sorry, my bad , missed this. Also, confirmed that currently hpa controller is not adding any annotations to the hpa object. So, it should be fine to add the annotation changed predicate . I will also then make changes to the
to add check for annotations as well. |
yes please |
…ec,label or annotation is changed Signed-off-by: deefreak <deepakgts2@gmail.com>
@zroubalik I have done all the commented changes. Have added unit tests to test the HPASpecChangedPredicate as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, I wonder whether we can test that updates to status don't trigger a reconcile loop?
/run-e2e |
As there will be no change in scaledobjects, it will be really hard to test through a unit test. I mean there will be nothing to compare for before and after reconcile. Although i have compared it on a cluster with more than 100+ scaledobjects and there were no reconcilations for hpa status updates(.status.currentMetrics) after applying this fix. |
yeah, agree |
I added the check for annotations as similar to the labels. when I was testing, the hpa created through scaledobject has no annotations, thus annotation was nil and therefore adding an annotation to the hpa was not reconciling again. So, we should add this condition, verified that this is working @zroubalik @JorTurFer what do you think? |
Good catch, please do that! |
…ec,label or annotation is changed Signed-off-by: deefreak <deepakgts2@gmail.com>
Done and added tests for label and annotation changes as well. |
…ec,label or annotation is changed Signed-off-by: deefreak <deepakgts2@gmail.com>
…ect-reconciles-by-HPA-status-updates
…s-by-HPA-status-updates' into redundant-scaledobject-reconciles-by-HPA-status-updates
/run-e2e |
@zroubalik I see this run-e2e is failing . Any idea how to fix this? |
/run-e2e |
I think that it was an unrelated issue |
Given checks have passed, can it be approved now? |
…ec,label or annotation is changed (kedacore#5282) Signed-off-by: deefreak <deepakgts2@gmail.com> Signed-off-by: anton.lysina <alysina@gmail.com>
This change fixes #5281 .
We have verified that scaledobject reconcilation is triggered only when hpa spec/label changes or hpa is deleted.
I raise this PR to get early feedback and automated tests will be added soon.