@@ -32,7 +32,7 @@ import (
3232func TestOperatorControllerMetricsExportedEndpoint (t * testing.T ) {
3333 client := utils .FindK8sClient (t )
3434 curlNamespace := createRandomNamespace (t , client )
35- componentNamespace := getComponentNamespace (t , client , "app.kubernetes.io/name=operator-controller" )
35+ componentNamespace := getComponentNamespace (t , client , operatorManagerSelector )
3636 metricsURL := fmt .Sprintf ("https://operator-controller-service.%s.svc.cluster.local:8443/metrics" , componentNamespace )
3737
3838 config := NewMetricsTestConfig (
@@ -52,7 +52,7 @@ func TestOperatorControllerMetricsExportedEndpoint(t *testing.T) {
5252func TestCatalogdMetricsExportedEndpoint (t * testing.T ) {
5353 client := utils .FindK8sClient (t )
5454 curlNamespace := createRandomNamespace (t , client )
55- componentNamespace := getComponentNamespace (t , client , "app.kubernetes.io/name=catalogd" )
55+ componentNamespace := getComponentNamespace (t , client , catalogdManagerSelector )
5656 metricsURL := fmt .Sprintf ("https://catalogd-service.%s.svc.cluster.local:7443/metrics" , componentNamespace )
5757
5858 config := NewMetricsTestConfig (
@@ -231,16 +231,20 @@ func createRandomNamespace(t *testing.T, client string) string {
231231}
232232
233233// getComponentNamespace returns the namespace where operator-controller or catalogd is running
234- func getComponentNamespace (t * testing.T , client , selector string ) string {
235- cmd := exec .Command (client , "get" , "pods" , "--all-namespaces" , "--selector=" + selector , "--output=jsonpath={.items[0].metadata.namespace}" )
236- output , err := cmd .CombinedOutput ()
237- require .NoError (t , err , "Error determining namespace: %s" , string (output ))
238-
239- namespace := string (bytes .TrimSpace (output ))
240- if namespace == "" {
241- t .Fatal ("No namespace found for selector " + selector )
234+ func getComponentNamespace (t * testing.T , client string , selectors []string ) string {
235+ for _ , selector := range selectors {
236+ cmd := exec .Command (client , "get" , "pods" , "--all-namespaces" , "--selector=" + selector , "--output=jsonpath={.items[0].metadata.namespace}" )
237+ output , err := cmd .CombinedOutput ()
238+ if err != nil {
239+ continue
240+ }
241+ namespace := string (bytes .TrimSpace (output ))
242+ if namespace != "" {
243+ return namespace
244+ }
242245 }
243- return namespace
246+ t .Fatalf ("No namespace found for selectors: %v" , selectors )
247+ return ""
244248}
245249
246250func stdoutAndCombined (cmd * exec.Cmd ) ([]byte , []byte , error ) {
0 commit comments