From 88d57ca70cf691e3f4d2ae1bc66681186768752d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=BD=AC?= Date: Thu, 17 Mar 2022 17:51:28 +0800 Subject: [PATCH] Fix returns unmatched error when updating hpa object failed (#2677) Signed-off-by: shitaibin Co-authored-by: Zbynek Roubalik --- CHANGELOG.md | 1 + controllers/keda/hpa.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6c2c599879..c6f36cd2e8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ - **General:** Improve e2e tests reliability ([#2580](https://github.com/kedacore/keda/issues/2580)) - **General:** Syncronize HPA annotations from ScaledObject ([#2659](https://github.com/kedacore/keda/pull/2659)) - **General:** Improve e2e tests to always cleanup resources in cluster ([#2584](https://github.com/kedacore/keda/issues/2584)) +- **General:** Fix mismatched errors for updating HPA ([#2719](https://github.com/kedacore/keda/issues/2719)) - **Memory Scaler** Adding e2e test for the memory scaler ([#2220](https://github.com/kedacore/keda/issues/2220)) ## v.2.6.1 diff --git a/controllers/keda/hpa.go b/controllers/keda/hpa.go index f5b1551164e..f2eb65c9828 100644 --- a/controllers/keda/hpa.go +++ b/controllers/keda/hpa.go @@ -131,7 +131,7 @@ func (r *ScaledObjectReconciler) updateHPAIfNeeded(ctx context.Context, logger l // 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 r.Client.Update(ctx, hpa) != nil { + 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 @@ -144,7 +144,7 @@ func (r *ScaledObjectReconciler) updateHPAIfNeeded(ctx context.Context, logger l 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 r.Client.Update(ctx, hpa) != nil { + 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