Skip to content

Commit 3ab7211

Browse files
author
Jeff Peeler
committed
fix(e2e): metrics are now served 8081
Ensure that when certificate arguments are passed, metrics are retrieved over HTTPS. Otherwise, retrieve metrics over HTTP.
1 parent 2f9f600 commit 3ab7211

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

test/e2e/metrics_e2e_test.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
package e2e
44

55
import (
6-
"fmt"
76
"testing"
87

98
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
109
log "github.com/sirupsen/logrus"
1110
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/util/net"
1212
)
1313

1414
// TestMetrics tests the metrics endpoint of the OLM pod.
@@ -26,21 +26,49 @@ func TestMetricsEndpoint(t *testing.T) {
2626
}
2727

2828
podName := podList.Items[0].GetName()
29+
log.Infof("Looking at pod %v in namespace %v", podName, operatorNamespace)
2930

30-
rawOutput, err := getMetricsFromPod(t, c, podName, operatorNamespace, 8080)
31+
rawOutput, err := getMetricsFromPod(t, c, podName, operatorNamespace, "8081")
3132
if err != nil {
3233
t.Fatalf("Metrics test failed: %v\n", err)
3334
}
3435

3536
log.Debugf("Metrics:\n%v", rawOutput)
3637
}
3738

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+
3967
rawOutput, err := client.KubernetesInterface().CoreV1().RESTClient().Get().
4068
Namespace(namespace).
4169
Resource("pods").
4270
SubResource("proxy").
43-
Name(fmt.Sprintf("%v:%v", podName, port)).
71+
Name(net.JoinSchemeNamePort(scheme, podName, port)).
4472
Suffix("metrics").
4573
Do().Raw()
4674
if err != nil {

0 commit comments

Comments
 (0)