Skip to content

Commit

Permalink
add mutex lock to update managedclusterlist
Browse files Browse the repository at this point in the history
Signed-off-by: Coleen Iona Quadros <[email protected]>
  • Loading branch information
coleenquadros committed Sep 30, 2024
1 parent 4ade8e0 commit 4ef83c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
defaultAddonDeploymentConfig = &addonv1alpha1.AddOnDeploymentConfig{}
isplacementControllerRunnning = false
managedClusterList = sync.Map{}
managedClusterListMutex = &sync.RWMutex{}
installMetricsWithoutAddon = false
)

Expand Down Expand Up @@ -386,6 +387,7 @@ func createAllRelatedRes(
}

failedCreateManagedClusterRes := false
managedClusterListMutex.RLock()
managedClusterList.Range(func(key, value interface{}) bool {
managedCluster := key.(string)
openshiftVersion := value.(string)
Expand Down Expand Up @@ -444,6 +446,8 @@ func createAllRelatedRes(
}
}

managedClusterListMutex.RUnlock()

failedDeleteOba := false
for _, cluster := range clustersToCleanup {
err = deleteObsAddon(c, cluster)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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())
}
Expand Down

0 comments on commit 4ef83c5

Please sign in to comment.