Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

look for local cluster label #1667

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cicd-scripts/setup-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -613,7 +596,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)
}
Expand Down Expand Up @@ -1113,3 +1100,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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

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

Expand All @@ -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()
Expand Down
23 changes: 0 additions & 23 deletions tests/pkg/utils/mco_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 0 additions & 23 deletions tests/pkg/utils/mco_oba.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading