From 1e32f015c46923027f3f4a10d43bbaf661a03011 Mon Sep 17 00:00:00 2001 From: Saswata Mukherjee Date: Wed, 11 Dec 2024 14:09:50 +0000 Subject: [PATCH] Add annotation predicate, update in mco mode Signed-off-by: Saswata Mukherjee --- .../controllers/placementrule/obsaddon.go | 15 +++++++++++++++ .../placementrule/placementrule_controller.go | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/operators/multiclusterobservability/controllers/placementrule/obsaddon.go b/operators/multiclusterobservability/controllers/placementrule/obsaddon.go index 98d231486..2b5a1d299 100644 --- a/operators/multiclusterobservability/controllers/placementrule/obsaddon.go +++ b/operators/multiclusterobservability/controllers/placementrule/obsaddon.go @@ -111,6 +111,21 @@ func createObsAddon(mco *mcov1beta2.MultiClusterObservability, c client.Client, return err } + // Check if existing addon was created by MCO + if found.Annotations != nil && found.Annotations["observability.open-cluster-management.io/addon-source"] == "mco" { + // Only update if specs are different + if found.Spec != ec.Spec { + found.Spec = ec.Spec + err = c.Update(context.TODO(), found) + if err != nil { + log.Error(err, "Failed to update observabilityaddon cr") + return err + } + log.Info("observabilityaddon updated", "namespace", namespace) + return nil + } + } + log.Info("observabilityaddon already existed/unchanged", "namespace", namespace) return nil } diff --git a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go index 62440db99..70a840489 100644 --- a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go +++ b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go @@ -655,7 +655,9 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { !reflect.DeepEqual(e.ObjectNew.(*mcov1beta1.ObservabilityAddon).Status.Conditions, e.ObjectOld.(*mcov1beta1.ObservabilityAddon).Status.Conditions) && !reflect.DeepEqual(e.ObjectNew.(*mcov1beta1.ObservabilityAddon).Spec, - e.ObjectOld.(*mcov1beta1.ObservabilityAddon).Spec) { + e.ObjectOld.(*mcov1beta1.ObservabilityAddon).Spec) && + !reflect.DeepEqual(e.ObjectNew.(*mcov1beta1.ObservabilityAddon).Annotations, + e.ObjectOld.(*mcov1beta1.ObservabilityAddon).Annotations) { return true } return false