diff --git a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go index 93eebc5bd..ce031fb5b 100644 --- a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go +++ b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go @@ -62,6 +62,7 @@ var ( defaultAddonDeploymentConfig = &addonv1alpha1.AddOnDeploymentConfig{} isplacementControllerRunnning = false managedClusterList = sync.Map{} + managedClusterListMutex = &sync.RWMutex{} installMetricsWithoutAddon = false ) @@ -386,6 +387,7 @@ func createAllRelatedRes( } failedCreateManagedClusterRes := false + managedClusterListMutex.RLock() managedClusterList.Range(func(key, value interface{}) bool { managedCluster := key.(string) openshiftVersion := value.(string) @@ -444,6 +446,8 @@ func createAllRelatedRes( } } + managedClusterListMutex.RUnlock() + failedDeleteOba := false for _, cluster := range clustersToCleanup { err = deleteObsAddon(c, cluster) @@ -606,8 +610,8 @@ func areManagedClusterLabelsReady(obj client.Object) bool { } func updateManagedClusterList(obj client.Object) { - //ACM 8509: Special case for local-cluster, we deploy endpoint and metrics collector in the hub - //whether hubSelfManagement is enabled or not + managedClusterListMutex.Lock() + defer managedClusterListMutex.Unlock() if version, ok := obj.GetLabels()["openshiftVersion"]; ok { managedClusterList.Store(obj.GetName(), version) } else { diff --git a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go index 61027c878..265be9b59 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" @@ -33,6 +31,8 @@ func getClusterPreds() predicate.Funcs { if !areManagedClusterLabelsReady(e.Object) { return false } + //ACM 8509: Special case for local-cluster, we deploy endpoint and metrics collector in the hub + //whether hubSelfManagement is enabled or not if e.Object.GetName() != localClusterName { updateManagedClusterList(e.Object) } @@ -61,16 +61,13 @@ func getClusterPreds() predicate.Funcs { if !areManagedClusterLabelsReady(e.ObjectNew) { return false } + //ACM 8509: Special case for local-cluster, we deploy endpoint and metrics collector in the hub + //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 } @@ -82,6 +79,8 @@ func getClusterPreds() predicate.Funcs { return false } + //ACM 8509: Special case for local-cluster, we deploy endpoint and metrics collector in the hub + //whether hubSelfManagement is enabled or not if e.Object.GetName() != localClusterName { managedClusterList.Delete(e.Object.GetName()) }