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

fix: [release-2.9] [ACM-14189]identify healthy managed clusters #1638

Open
wants to merge 1 commit into
base: release-2.9
Choose a base branch
from
Open
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
40 changes: 33 additions & 7 deletions tests/pkg/utils/mco_managedcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package utils
import (
"context"
"errors"
"os"

goversion "github.com/hashicorp/go-version"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -51,16 +52,41 @@ func ListManagedClusters(opt TestOptions) ([]string, error) {
for _, obj := range objs.Items {
metadata := obj.Object["metadata"].(map[string]interface{})
name := metadata["name"].(string)
labels := metadata["labels"].(map[string]interface{})
if labels != nil {
obsControllerStr := ""
if obsController, ok := labels["feature.open-cluster-management.io/addon-observability-controller"]; ok {
obsControllerStr = obsController.(string)

if os.Getenv("IS_KIND_ENV") == "true" {
// We do not have the obs add on label added in kind cluster
clusterNames = append(clusterNames, name)
continue
}

status, ok := obj.Object["status"].(map[string]interface{})
if !ok {
// No status found, skip this cluster
continue
}

conditions, ok := status["conditions"].([]interface{})
if !ok {
// No conditions found, skip this cluster
continue
}

available := false
for _, condition := range conditions {
conditionMap, ok := condition.(map[string]interface{})
if !ok {
continue
}
if obsControllerStr != "unreachable" {
clusterNames = append(clusterNames, name)
if conditionMap["type"] == "ManagedClusterConditionAvailable" && conditionMap["status"] == "True" {
available = true
break
}
}

// Only add clusters with ManagedClusterConditionAvailable status == True
if available {
clusterNames = append(clusterNames, name)
}
}

if len(clusterNames) == 0 {
Expand Down
Loading