Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed May 12, 2023
1 parent 6dd6894 commit 060aa8c
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions test/e2e/v4/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func curlMetrics(kbc *utils.TestContext) string {
ExpectWithOffset(2, len(token)).To(BeNumerically(">", 0))

By("creating a curl pod")
By("Reading the metrics token")
cmdOpts := []string{
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, strings.TrimSpace(token)),
Expand All @@ -319,7 +320,7 @@ func curlMetrics(kbc *utils.TestContext) string {
By("validating that the metrics endpoint is serving as expected")
var metricsOutput string
getCurlLogs := func() string {
metricsOutput, err = kbc.Kubectl.Logs("curl")
metricsOutput, err = kbc.Kubectl.CommandInNamespace("logs", "curl")
ExpectWithOffset(3, err).NotTo(HaveOccurred())
return metricsOutput
}
Expand All @@ -338,36 +339,29 @@ func curlMetrics(kbc *utils.TestContext) string {
// is currently being supported in kubebuilder test infra.
// TokenRequest API returns the token in raw JWT format itself. There is no conversion required.
func ServiceAccountToken(kbc *utils.TestContext) (out string, err error) {
By("Creating the ServiceAccount token")
secretName := fmt.Sprintf("%s-token-request", kbc.Kubectl.ServiceAccount)
tokenRequestFile := filepath.Join(kbc.Dir, secretName)
err = os.WriteFile(tokenRequestFile, []byte(tokenRequestRawString), os.FileMode(0o755))
if err != nil {
return out, err
}
var rawJson string
var tokenResult string
Eventually(func() error {
// Output of this is already a valid JWT token. No need to covert this from base64 to string format
rawJson, err = kbc.Kubectl.Command(
"create",
"--raw", fmt.Sprintf(
"/api/v1/namespaces/%s/serviceaccounts/%s/token",
kbc.Kubectl.Namespace,
kbc.Kubectl.ServiceAccount,
),
"-f", tokenRequestFile,
)
cmd := exec.Command("kubectl", "create", "--raw", fmt.Sprintf(
"/api/v1/namespaces/%s/serviceaccounts/%s/token",
kbc.Kubectl.Namespace,
"brainstorming-ekco-controller-manager"),
"-f", "-")
cmd.Stdin = strings.NewReader(tokenRequestRawString)
rawJSON, err := kbc.Run(cmd)
if err != nil {
return err
}
var token tokenRequest
err = json.Unmarshal([]byte(rawJson), &token)
err = json.Unmarshal(rawJSON, &token)
if err != nil {
return err
}
out = token.Status.Token
tokenResult = token.Status.Token
return nil
}, time.Minute, time.Second).Should(Succeed())
ExpectWithOffset(2, err).NotTo(HaveOccurred())
ExpectWithOffset(2, len(tokenResult)).To(BeNumerically(">", 0))

return out, err
}

0 comments on commit 060aa8c

Please sign in to comment.