@@ -23,28 +23,43 @@ func TestOperatorControllerMetricsExportedEndpoint(t *testing.T) {
23
23
token string
24
24
curlPod = "curl-metrics"
25
25
namespace = "olmv1-system"
26
+ client = ""
27
+ clients = []string {"kubectl" , "oc" }
26
28
)
27
29
30
+ t .Log ("Looking for k8s client" )
31
+ for _ , c := range clients {
32
+ err := exec .Command ("command" , "-v" , c ).Run ()
33
+ if err == nil {
34
+ client = c
35
+ break
36
+ }
37
+ }
38
+ if client == "" {
39
+ t .Skip ("k8s client not found, skipping test" )
40
+ }
41
+ t .Logf ("Using %q as k8s client" , client )
42
+
28
43
t .Log ("Creating ClusterRoleBinding for operator controller metrics" )
29
- cmd := exec .Command ("kubectl" , "create" , "clusterrolebinding" , "operator-controller-metrics-binding" ,
44
+ cmd := exec .Command (client , "create" , "clusterrolebinding" , "operator-controller-metrics-binding" ,
30
45
"--clusterrole=operator-controller-metrics-reader" ,
31
46
"--serviceaccount=" + namespace + ":operator-controller-controller-manager" )
32
47
output , err := cmd .CombinedOutput ()
33
48
require .NoError (t , err , "Error creating ClusterRoleBinding: %s" , string (output ))
34
49
35
50
defer func () {
36
51
t .Log ("Cleaning up ClusterRoleBinding" )
37
- _ = exec .Command ("kubectl" , "delete" , "clusterrolebinding" , "operator-controller-metrics-binding" , "--ignore-not-found=true" ).Run ()
52
+ _ = exec .Command (client , "delete" , "clusterrolebinding" , "operator-controller-metrics-binding" , "--ignore-not-found=true" ).Run ()
38
53
}()
39
54
40
55
t .Log ("Generating ServiceAccount token" )
41
- tokenCmd := exec .Command ("kubectl" , "create" , "token" , "operator-controller-controller-manager" , "-n" , namespace )
56
+ tokenCmd := exec .Command (client , "create" , "token" , "operator-controller-controller-manager" , "-n" , namespace )
42
57
tokenOutput , err := tokenCmd .Output ()
43
58
require .NoError (t , err , "Error creating token: %s" , string (tokenOutput ))
44
59
token = string (bytes .TrimSpace (tokenOutput ))
45
60
46
61
t .Log ("Creating curl pod to validate the metrics endpoint" )
47
- cmd = exec .Command ("kubectl" , "run" , curlPod ,
62
+ cmd = exec .Command (client , "run" , curlPod ,
48
63
"--image=curlimages/curl:7.87.0" , "-n" , namespace ,
49
64
"--restart=Never" ,
50
65
"--overrides" , `{
@@ -73,17 +88,17 @@ func TestOperatorControllerMetricsExportedEndpoint(t *testing.T) {
73
88
74
89
defer func () {
75
90
t .Log ("Cleaning up curl pod" )
76
- _ = exec .Command ("kubectl" , "delete" , "pod" , curlPod , "-n" , namespace , "--ignore-not-found=true" ).Run ()
91
+ _ = exec .Command (client , "delete" , "pod" , curlPod , "-n" , namespace , "--ignore-not-found=true" ).Run ()
77
92
}()
78
93
79
94
t .Log ("Waiting for the curl pod to be ready" )
80
- waitCmd := exec .Command ("kubectl" , "wait" , "--for=condition=Ready" , "pod" , curlPod , "-n" , namespace , "--timeout=60s" )
95
+ waitCmd := exec .Command (client , "wait" , "--for=condition=Ready" , "pod" , curlPod , "-n" , namespace , "--timeout=60s" )
81
96
waitOutput , waitErr := waitCmd .CombinedOutput ()
82
97
require .NoError (t , waitErr , "Error waiting for curl pod to be ready: %s" , string (waitOutput ))
83
98
84
99
t .Log ("Validating the metrics endpoint" )
85
100
metricsURL := "https://operator-controller-controller-manager-metrics-service." + namespace + ".svc.cluster.local:8443/metrics"
86
- curlCmd := exec .Command ("kubectl" , "exec" , curlPod , "-n" , namespace , "--" ,
101
+ curlCmd := exec .Command (client , "exec" , curlPod , "-n" , namespace , "--" ,
87
102
"curl" , "-v" , "-k" , "-H" , "Authorization: Bearer " + token , metricsURL )
88
103
output , err = curlCmd .CombinedOutput ()
89
104
require .NoError (t , err , "Error calling metrics endpoint: %s" , string (output ))
0 commit comments