@@ -32,7 +32,7 @@ import (
32
32
func TestOperatorControllerMetricsExportedEndpoint (t * testing.T ) {
33
33
client := utils .FindK8sClient (t )
34
34
curlNamespace := createRandomNamespace (t , client )
35
- componentNamespace := getComponentNamespace (t , client , "app.kubernetes.io/name=operator-controller" )
35
+ componentNamespace := getComponentNamespace (t , client , operatorManagerSelector )
36
36
metricsURL := fmt .Sprintf ("https://operator-controller-service.%s.svc.cluster.local:8443/metrics" , componentNamespace )
37
37
38
38
config := NewMetricsTestConfig (
@@ -52,7 +52,7 @@ func TestOperatorControllerMetricsExportedEndpoint(t *testing.T) {
52
52
func TestCatalogdMetricsExportedEndpoint (t * testing.T ) {
53
53
client := utils .FindK8sClient (t )
54
54
curlNamespace := createRandomNamespace (t , client )
55
- componentNamespace := getComponentNamespace (t , client , "app.kubernetes.io/name=catalogd" )
55
+ componentNamespace := getComponentNamespace (t , client , catalogdManagerSelector )
56
56
metricsURL := fmt .Sprintf ("https://catalogd-service.%s.svc.cluster.local:7443/metrics" , componentNamespace )
57
57
58
58
config := NewMetricsTestConfig (
@@ -231,16 +231,20 @@ func createRandomNamespace(t *testing.T, client string) string {
231
231
}
232
232
233
233
// 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
+ }
242
245
}
243
- return namespace
246
+ t .Fatalf ("No namespace found for selectors: %v" , selectors )
247
+ return ""
244
248
}
245
249
246
250
func stdoutAndCombined (cmd * exec.Cmd ) ([]byte , []byte , error ) {
0 commit comments