From dca6d8cd65d7c3ab3879f0726fcac3c36a02f9e3 Mon Sep 17 00:00:00 2001 From: Coleen Iona Quadros Date: Mon, 11 Nov 2024 16:33:59 +0100 Subject: [PATCH 1/5] look for local cluster label Signed-off-by: Coleen Iona Quadros --- .../placementrule/placementrule_controller.go | 13 ++++++++++++- .../controllers/placementrule/predicate_func.go | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go index ce031fb5b..29afe0442 100644 --- a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go +++ b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go @@ -613,7 +613,11 @@ func updateManagedClusterList(obj client.Object) { managedClusterListMutex.Lock() defer managedClusterListMutex.Unlock() if version, ok := obj.GetLabels()["openshiftVersion"]; ok { - managedClusterList.Store(obj.GetName(), version) + if isLocalCluster(obj) { + managedClusterList.Store(localClusterName, "mimical") + } else { + managedClusterList.Store(obj.GetName(), version) + } } else { managedClusterList.Store(obj.GetName(), nonOCP) } @@ -1113,3 +1117,10 @@ func isReconcileRequired(request ctrl.Request, managedCluster string) bool { } return false } + +func isLocalCluster(obj client.Object) bool { + if val, ok := obj.GetLabels()["local-cluster"]; ok && val == "true" { + return true + } + return false +} diff --git a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go index 265be9b59..26658c08c 100644 --- a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go +++ b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go @@ -33,7 +33,7 @@ func getClusterPreds() predicate.Funcs { } //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 { + if !isLocalCluster(e.Object) { updateManagedClusterList(e.Object) } @@ -63,7 +63,7 @@ func getClusterPreds() predicate.Funcs { } //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 { + if !isLocalCluster(e.ObjectNew) { updateManagedClusterList(e.ObjectNew) } @@ -81,7 +81,7 @@ func getClusterPreds() predicate.Funcs { //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 { + if isLocalCluster(e.Object) { managedClusterList.Delete(e.Object.GetName()) } managedClusterImageRegistryMutex.Lock() From 109d14c488b43f052a7362c7609932a1e345cade Mon Sep 17 00:00:00 2001 From: Coleen Iona Quadros Date: Mon, 11 Nov 2024 16:49:22 +0100 Subject: [PATCH 2/5] look for local cluster label Signed-off-by: Coleen Iona Quadros --- .../controllers/placementrule/predicate_func.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go index 26658c08c..cab66c4ab 100644 --- a/operators/multiclusterobservability/controllers/placementrule/predicate_func.go +++ b/operators/multiclusterobservability/controllers/placementrule/predicate_func.go @@ -81,7 +81,7 @@ func getClusterPreds() predicate.Funcs { //ACM 8509: Special case for local-cluster, we deploy endpoint and metrics collector in the hub //whether hubSelfManagement is enabled or not - if isLocalCluster(e.Object) { + if !isLocalCluster(e.Object) { managedClusterList.Delete(e.Object.GetName()) } managedClusterImageRegistryMutex.Lock() From 932df51a65a0da9c04e5063d1147d1140033e95a Mon Sep 17 00:00:00 2001 From: Coleen Iona Quadros Date: Mon, 11 Nov 2024 17:11:14 +0100 Subject: [PATCH 3/5] update Signed-off-by: Coleen Iona Quadros --- .../placementrule/placementrule_controller.go | 23 +++---------------- tests/pkg/utils/mco_oba.go | 23 ------------------- 2 files changed, 3 insertions(+), 43 deletions(-) diff --git a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go index 29afe0442..a7eed0768 100644 --- a/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go +++ b/operators/multiclusterobservability/controllers/placementrule/placementrule_controller.go @@ -123,25 +123,6 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, nil } - // ACM 8509: Special case for hub/local cluster metrics collection - // We want to ensure that the local-cluster is always in the managedClusterList - // In the case when hubSelfManagement is enabled, we will delete it from the list and modify the object - // to cater to the use case of deploying in open-cluster-management-observability namespace - managedClusterList.Delete("local-cluster") - if _, ok := managedClusterList.Load("local-cluster"); !ok { - obj := &clusterv1.ManagedCluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "local-cluster", - Namespace: config.GetDefaultNamespace(), - Labels: map[string]string{ - "openshiftVersion": "mimical", - }, - }, - } - installMetricsWithoutAddon = true - updateManagedClusterList(obj) - } - if !deleteAll && !mco.Spec.ObservabilityAddonSpec.EnableMetrics { reqLogger.Info("EnableMetrics is set to false. Delete Observability addons") deleteAll = true @@ -181,7 +162,9 @@ func (r *PlacementRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, err } - if !deleteAll && installMetricsWithoutAddon { + if !installMetricsWithoutAddon { + // Delete only once + installMetricsWithoutAddon = true err = deleteObsAddon(r.Client, localClusterName) if err != nil { log.Error(err, "Failed to delete observabilityaddon") diff --git a/tests/pkg/utils/mco_oba.go b/tests/pkg/utils/mco_oba.go index 43dfbdae1..32690b72a 100644 --- a/tests/pkg/utils/mco_oba.go +++ b/tests/pkg/utils/mco_oba.go @@ -95,29 +95,6 @@ func CheckAllOBAsEnabled(opt TestOptions) error { return nil } -func CheckAllOBADisabled(opt TestOptions) error { - clusters, err := ListManagedClusters(opt) - if err != nil { - return err - } - for _, cluster := range clusters { - // skip the check for local-cluster - if cluster == "local-cluster" { - klog.V(1).Infof("Skip OBA status for managedcluster: %v", cluster) - continue - } - err = CheckOBAStatus(opt, cluster, ManagedClusterAddOnDisabledMessage) - if err != nil { - return err - } - err = CheckManagedClusterAddonsStatus(opt, cluster, ManagedClusterAddOnDisabledMessage) - if err != nil { - return err - } - } - return nil -} - func CheckAllOBAsDeleted(opt TestOptions) error { clusters, err := ListManagedClusters(opt) if err != nil { From 02cf941139e5774a41fc512d2031f80dcb61ae2d Mon Sep 17 00:00:00 2001 From: Coleen Iona Quadros Date: Tue, 12 Nov 2024 12:39:33 +0100 Subject: [PATCH 4/5] update tests Signed-off-by: Coleen Iona Quadros --- cicd-scripts/setup-e2e-tests.sh | 1 + tests/pkg/utils/mco_deploy.go | 23 ----------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/cicd-scripts/setup-e2e-tests.sh b/cicd-scripts/setup-e2e-tests.sh index 6a86b5bcd..223293473 100755 --- a/cicd-scripts/setup-e2e-tests.sh +++ b/cicd-scripts/setup-e2e-tests.sh @@ -88,6 +88,7 @@ approve_csr_joinrequest() { for clustername in ${clusternames}; do echo "approve joinrequest for ${clustername}" kubectl patch managedcluster ${clustername} --patch '{"spec":{"hubAcceptsClient":true}}' --type=merge + kubectl label managedcluster ${clustername} local-cluster=true if [[ -n ${IS_KIND_ENV} ]]; then # update vendor label for KinD env kubectl label managedcluster ${clustername} vendor- diff --git a/tests/pkg/utils/mco_deploy.go b/tests/pkg/utils/mco_deploy.go index 0a48233c0..5cac229b0 100644 --- a/tests/pkg/utils/mco_deploy.go +++ b/tests/pkg/utils/mco_deploy.go @@ -350,29 +350,6 @@ func CheckStatefulSetPodReady(opt TestOptions, stsName string) error { return nil } -func CheckDeploymentPodReady(opt TestOptions, deployName string) error { - client := NewKubeClient( - opt.HubCluster.ClusterServerURL, - opt.KubeConfig, - opt.HubCluster.KubeContext) - deploys := client.AppsV1().Deployments(MCO_NAMESPACE) - deploy, err := deploys.Get(context.TODO(), deployName, metav1.GetOptions{}) - if err != nil { - klog.V(1).Infof("Error while retrieving deployment %s: %s", deployName, err.Error()) - return err - } - - if deploy.Status.ReadyReplicas != *deploy.Spec.Replicas || - deploy.Status.UpdatedReplicas != *deploy.Spec.Replicas || - deploy.Status.AvailableReplicas != *deploy.Spec.Replicas { - err = fmt.Errorf("deployment %s should have %d but got %d ready replicas", - deployName, *deploy.Spec.Replicas, - deploy.Status.ReadyReplicas) - return err - } - return nil -} - // ModifyMCOCR modifies the MCO CR for reconciling. modify multiple parameter to save running time func ModifyMCOCR(opt TestOptions) error { clientDynamic := NewKubeClientDynamic( From 303b4077a3b63b8204ed9aedc5d240edab6bcc1d Mon Sep 17 00:00:00 2001 From: Coleen Iona Quadros Date: Tue, 12 Nov 2024 12:43:25 +0100 Subject: [PATCH 5/5] update tests Signed-off-by: Coleen Iona Quadros --- cicd-scripts/setup-e2e-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cicd-scripts/setup-e2e-tests.sh b/cicd-scripts/setup-e2e-tests.sh index 223293473..09680d186 100755 --- a/cicd-scripts/setup-e2e-tests.sh +++ b/cicd-scripts/setup-e2e-tests.sh @@ -22,7 +22,7 @@ AGENT_NS="open-cluster-management-agent" HUB_NS="open-cluster-management-hub" OBSERVABILITY_NS="open-cluster-management-observability" IMAGE_REPO="quay.io/stolostron" -export MANAGED_CLUSTER="local-cluster" # registration-operator needs this +export MANAGED_CLUSTER="hub-cluster" # registration-operator needs this SED_COMMAND=${SED}' -i-e -e'