diff --git a/tests/pkg/utils/mco_managedcluster.go b/tests/pkg/utils/mco_managedcluster.go index 9e96ffe4b..15c424fdc 100644 --- a/tests/pkg/utils/mco_managedcluster.go +++ b/tests/pkg/utils/mco_managedcluster.go @@ -52,16 +52,40 @@ 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 os.Getenv("IS_KIND_ENV") == "true" { // We do not have the obs add on label added in kind cluster clusterNames = append(clusterNames, name) continue } - if labels != nil { - if obsController, ok := labels["feature.open-cluster-management.io/addon-observability-controller"]; ok && obsController.(string) != "unreachable" { - clusterNames = append(clusterNames, name) + + 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 conditionMap["type"] == "ManagedClusterConditionAvailable" && conditionMap["status"] == "True" { + available = true + break + } + } + + // Only add clusters with ManagedClusterConditionAvailable status == True + if available { + clusterNames = append(clusterNames, name) } }