-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: add tests to verify metrics endpoint
- Loading branch information
1 parent
e461013
commit 4d3281f
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"os/exec" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Catalogd Metrics Workflow Validation", func() { | ||
|
||
var ( | ||
token string | ||
curlPod = "curl-metrics" | ||
namespace = "olmv1-system" | ||
) | ||
|
||
BeforeEach(func() { | ||
By("Creating ClusterRoleBinding for catalogd metrics") | ||
_, err := exec.Command("kubectl", "create", "clusterrolebinding", "catalogd-metrics-binding", | ||
"--clusterrole=catalogd-metrics-reader", | ||
"--serviceaccount="+namespace+":catalogd-controller-manager").CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
By("Generating a token for the catalogd-controller-manager ServiceAccount") | ||
out, err := exec.Command("kubectl", "create", "token", "catalogd-controller-manager", "-n", namespace).Output() | ||
Expect(err).ToNot(HaveOccurred()) | ||
token = string(bytes.TrimSpace(out)) | ||
|
||
By("Creating a curl pod to validate the metrics endpoint") | ||
curlPodManifest := ` | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: curl-metrics | ||
namespace: olmv1-system | ||
spec: | ||
serviceAccountName: catalogd-controller-manager | ||
containers: | ||
- name: curl | ||
image: curlimages/curl:7.87.0 | ||
command: | ||
- sh | ||
- -c | ||
- sleep 3600 | ||
restartPolicy: Never` | ||
cmd := exec.Command("kubectl", "apply", "-f", "-") | ||
cmd.Stdin = bytes.NewReader([]byte(curlPodManifest)) | ||
Expect(cmd.Run()).To(Succeed()) | ||
|
||
By("Waiting for the curl pod to be ready") | ||
Eventually(func() string { | ||
out, _ := exec.Command("kubectl", "get", "pod", curlPod, "-n", namespace, "-o", "jsonpath={.status.phase}").Output() | ||
return string(out) | ||
}, "60s", "5s").Should(Equal("Running")) | ||
}) | ||
|
||
It("Validates the metrics endpoint", func() { | ||
By("Calling the metrics endpoint from within the curl pod") | ||
metricsURL := "https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics" | ||
curlCmd := []string{ | ||
"exec", "-it", curlPod, "-n", namespace, "--", "curl", "-v", "-k", | ||
"-H", "Authorization: Bearer " + token, metricsURL, | ||
} | ||
cmd := exec.Command("kubectl", curlCmd...) | ||
output, err := cmd.CombinedOutput() | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(string(output)).To(ContainSubstring("200 OK")) | ||
Expect(string(output)).To(ContainSubstring("# HELP")) | ||
}) | ||
|
||
AfterEach(func() { | ||
By("Cleaning up resources") | ||
_ = exec.Command("kubectl", "delete", "pod", curlPod, "-n", namespace, "--ignore-not-found=true").Run() | ||
_ = exec.Command("kubectl", "delete", "clusterrolebinding", "catalogd-metrics-binding", "--ignore-not-found=true").Run() | ||
}) | ||
}) |