From 1e1e584dc3ebf0da14d66ee987e4468937addfd0 Mon Sep 17 00:00:00 2001 From: Coleen Iona Quadros Date: Mon, 30 Sep 2024 13:49:27 +0200 Subject: [PATCH] fix concurrent map writes Signed-off-by: Coleen Iona Quadros --- .../placementrule/placementrule_controller.go | 3 -- .../placementrule/predicate_func.go | 31 ++++++------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go index 57ec4883d..062d49899 100644 --- a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go +++ b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go @@ -196,9 +196,6 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, err } } - if operatorconfig.IsMCOTerminating { - delete(managedClusterList, "local-cluster") - } if !deleteAll { if err := createAllRelatedRes( diff --git a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go index 9c2f11553..a78e8ccc7 100644 --- a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go +++ b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go @@ -9,8 +9,6 @@ import ( "reflect" "strings" - clusterv1 "open-cluster-management.io/api/cluster/v1" - "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/config" operatorconfig "github.com/stolostron/multicluster-observability-operator/operators/pkg/config" @@ -26,13 +24,6 @@ func getClusterPreds() predicate.Funcs { createFunc := func(e event.CreateEvent) bool { log.Info("CreateFunc", "managedCluster", e.Object.GetName()) - //ACM 8509: Special case for local-cluster, we do not react changes to - //local-cluster as it is expected to be always present in the managed cluster list - //whether hubSelfManagement is enabled or not - if e.Object.GetName() == "local-cluster" { - return false - } - if isAutomaticAddonInstallationDisabled(e.Object) { return false } @@ -40,6 +31,9 @@ func getClusterPreds() predicate.Funcs { if !areManagedClusterLabelsReady(e.Object) { return false } + //ACM 8509: Special case for local-cluster, we do not react changes to + //local-cluster as it is expected to be always present in the managed cluster list + //whether hubSelfManagement is enabled or not if e.Object.GetName() != localClusterName { updateManagedClusterList(e.Object) } @@ -50,10 +44,6 @@ func getClusterPreds() predicate.Funcs { updateFunc := func(e event.UpdateEvent) bool { log.Info("UpdateFunc", "managedCluster", e.ObjectNew.GetName()) - if e.ObjectNew.GetName() == "local-cluster" { - return false - } - if e.ObjectNew.GetResourceVersion() == e.ObjectOld.GetResourceVersion() { return false } @@ -72,16 +62,14 @@ func getClusterPreds() predicate.Funcs { if !areManagedClusterLabelsReady(e.ObjectNew) { return false } + //ACM 8509: Special case for local-cluster, we do not react changes to + //local-cluster as it is expected to be always present in the managed cluster list + //whether hubSelfManagement is enabled or not if e.ObjectNew.GetName() != localClusterName { updateManagedClusterList(e.ObjectNew) } } - //log the diff in managedccluster object - if !reflect.DeepEqual(e.ObjectNew.(*clusterv1.ManagedCluster), e.ObjectOld.(*clusterv1.ManagedCluster)) { - log.Info("managedcluster object New diff", "managedCluster", e.ObjectNew.GetName(), "diff", fmt.Sprintf("%+v", e.ObjectNew.(*clusterv1.ManagedCluster))) - log.Info("managedcluster object Old diff", "managedCluster", e.ObjectOld.GetName(), "diff", fmt.Sprintf("%+v", e.ObjectOld.(*clusterv1.ManagedCluster))) - } return true } @@ -89,14 +77,13 @@ func getClusterPreds() predicate.Funcs { deleteFunc := func(e event.DeleteEvent) bool { log.Info("DeleteFunc", "managedCluster", e.Object.GetName()) - if e.Object.GetName() == "local-cluster" { - return false - } - if isAutomaticAddonInstallationDisabled(e.Object) { return false } + //ACM 8509: Special case for local-cluster, we do not react changes to + //local-cluster as it is expected to be always present in the managed cluster list + //whether hubSelfManagement is enabled or not if e.Object.GetName() != localClusterName { managedClusterList.Delete(e.Object.GetName()) }