3
3
package e2e
4
4
5
5
import (
6
- "fmt"
7
6
"testing"
8
7
9
8
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
10
9
log "github.com/sirupsen/logrus"
11
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
+ "k8s.io/apimachinery/pkg/util/net"
12
12
)
13
13
14
14
// TestMetrics tests the metrics endpoint of the OLM pod.
@@ -26,21 +26,49 @@ func TestMetricsEndpoint(t *testing.T) {
26
26
}
27
27
28
28
podName := podList .Items [0 ].GetName ()
29
+ log .Infof ("Looking at pod %v in namespace %v" , podName , operatorNamespace )
29
30
30
- rawOutput , err := getMetricsFromPod (t , c , podName , operatorNamespace , 8080 )
31
+ rawOutput , err := getMetricsFromPod (t , c , podName , operatorNamespace , "8081" )
31
32
if err != nil {
32
33
t .Fatalf ("Metrics test failed: %v\n " , err )
33
34
}
34
35
35
36
log .Debugf ("Metrics:\n %v" , rawOutput )
36
37
}
37
38
38
- func getMetricsFromPod (t * testing.T , client operatorclient.ClientInterface , podName string , namespace string , port int ) (string , error ) {
39
+ func getMetricsFromPod (t * testing.T , client operatorclient.ClientInterface , podName string , namespace string , port string ) (string , error ) {
40
+ olmPod , err := client .KubernetesInterface ().CoreV1 ().Pods (namespace ).Get (podName , metav1.GetOptions {})
41
+ if err != nil {
42
+ return "" , err
43
+ }
44
+ if len (olmPod .Spec .Containers ) != 1 {
45
+ t .Fatalf ("Expected only 1 container in olm-operator pod, got %v" , len (olmPod .Spec .Containers ))
46
+ }
47
+
48
+ var foundCert bool
49
+ var foundKey bool
50
+ // assuming -tls-cert and -tls-key aren't used anywhere else as a parameter value
51
+ for _ , param := range olmPod .Spec .Containers [0 ].Args {
52
+ if param == "-tls-cert" {
53
+ foundCert = true
54
+ } else if param == "-tls-key" {
55
+ foundKey = true
56
+ }
57
+ }
58
+
59
+ var scheme string
60
+ if foundCert && foundKey {
61
+ scheme = "https"
62
+ } else {
63
+ scheme = "http"
64
+ }
65
+ log .Infof ("Retrieving metrics using scheme %v\n " , scheme )
66
+
39
67
rawOutput , err := client .KubernetesInterface ().CoreV1 ().RESTClient ().Get ().
40
68
Namespace (namespace ).
41
69
Resource ("pods" ).
42
70
SubResource ("proxy" ).
43
- Name (fmt . Sprintf ( "%v:%v" , podName , port )).
71
+ Name (net . JoinSchemeNamePort ( scheme , podName , port )).
44
72
Suffix ("metrics" ).
45
73
Do ().Raw ()
46
74
if err != nil {
0 commit comments