Skip to content

Commit 48a0050

Browse files
fix: ci e2e tests
1 parent b9c3ab6 commit 48a0050

File tree

1 file changed

+58
-31
lines changed

1 file changed

+58
-31
lines changed

test/e2e/v4/plugin_cluster_test.go

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,19 @@ var _ = Describe("kubebuilder", func() {
9191
GenerateV4WithoutMetrics(kbc)
9292
Run(kbc, true, false, false, false, false)
9393
})
94-
// FIXME: This test is currently disabled because it requires to be fixed:
95-
// https://github.com/kubernetes-sigs/kubebuilder/issues/4853
96-
// It is not working for k8s 1.33
97-
// It("should generate a runnable project with metrics protected by network policies", func() {
98-
// GenerateV4WithNetworkPoliciesWithoutWebhooks(kbc)
99-
// Run(kbc, false, false, false, true, true)
100-
// })
94+
It("should generate a runnable project with metrics protected by network policies", func() {
95+
GenerateV4WithNetworkPoliciesWithoutWebhooks(kbc)
96+
Run(kbc, false, false, false, true, true)
97+
})
10198
It("should generate a runnable project with webhooks and metrics protected by network policies", func() {
10299
GenerateV4WithNetworkPolicies(kbc)
103100
Run(kbc, true, false, false, true, true)
104101
})
105-
// FIXME: This test is currently disabled because it requires to be fixed:
106-
// https://github.com/kubernetes-sigs/kubebuilder/issues/4853
107-
// It is not working for k8s 1.33
108-
// It("should generate a runnable project with the manager running "+
109-
// "as restricted and without webhooks", func() {
110-
// GenerateV4WithoutWebhooks(kbc)
111-
// Run(kbc, false, false, false, true, false)
112-
// })
102+
It("should generate a runnable project with the manager running "+
103+
"as restricted and without webhooks", func() {
104+
GenerateV4WithoutWebhooks(kbc)
105+
Run(kbc, false, false, false, true, false)
106+
})
113107
})
114108
})
115109

@@ -525,24 +519,57 @@ func getMetricsOutput(kbc *utils.TestContext) string {
525519

526520
By("validating that the curl pod is running as expected")
527521
verifyCurlUp := func(g Gomega) {
528-
var status string
529-
status, err = kbc.Kubectl.Get(
530-
true,
531-
"pods", "curl", "-o", "jsonpath={.status.phase}")
522+
maxRetries := 3
523+
var status, logs string
524+
525+
for i := 0; i < maxRetries; i++ {
526+
status, err = kbc.Kubectl.Get(
527+
true,
528+
"pods", "curl", "-o", "jsonpath={.status.phase}")
529+
g.Expect(err).NotTo(HaveOccurred())
530+
531+
if status == "Succeeded" {
532+
return
533+
}
534+
535+
logs, _ = kbc.Kubectl.Logs("curl")
536+
537+
if status == "Failed" ||
538+
strings.Contains(logs, "Failed to connect") ||
539+
strings.Contains(logs, "Connection refused") {
540+
By("Outputting curl pod logs for debugging")
541+
_, _ = fmt.Fprintln(GinkgoWriter, logs)
542+
543+
By("Outputting manager pod logs for debugging")
544+
controllerPodName := getControllerName(kbc)
545+
managerLogs, _ := kbc.Kubectl.Logs(controllerPodName)
546+
_, _ = fmt.Fprintln(GinkgoWriter, managerLogs)
547+
548+
By("Describing all resources for debugging")
549+
out, errDescribe := kbc.Kubectl.CommandInNamespace("describe", "all")
550+
Expect(errDescribe).NotTo(HaveOccurred())
551+
_, _ = fmt.Fprintln(GinkgoWriter, out)
552+
553+
By(fmt.Sprintf("curl pod failed with status %s. Retrying (%d/%d)...", status, i+1, maxRetries))
554+
_, _ = kbc.Kubectl.Delete(true, "pod", "curl", "--ignore-not-found",
555+
"--grace-period=0", "--force")
556+
time.Sleep(3 * time.Second)
557+
558+
cmdOpts = cmdOptsToCreateCurlPod(kbc, token)
559+
_, err = kbc.Kubectl.CommandInNamespace(cmdOpts...)
560+
g.Expect(err).NotTo(HaveOccurred())
561+
562+
time.Sleep(5 * time.Second)
563+
} else {
564+
By(fmt.Sprintf("curl pod in %s state without known failure, waiting...", status))
565+
time.Sleep(5 * time.Second)
566+
}
567+
}
568+
status, err = kbc.Kubectl.Get(true, "pods", "curl", "-o", "jsonpath={.status.phase}")
532569
g.Expect(err).NotTo(HaveOccurred())
533-
g.Expect(status).To(Equal("Succeeded"), fmt.Sprintf("curl pod in %s status", status))
570+
g.Expect(status).To(Equal("Succeeded"), fmt.Sprintf("curl pod in %s state after all retries", status))
534571
}
535-
Eventually(verifyCurlUp, 240*time.Second, time.Second).Should(Succeed())
536-
537-
By("validating that the correct ServiceAccount is being used")
538-
saName := kbc.Kubectl.ServiceAccount
539-
currentSAOutput, err := kbc.Kubectl.Get(
540-
true,
541-
"serviceaccount", saName,
542-
"-o", "jsonpath={.metadata.name}",
543-
)
544-
Expect(err).NotTo(HaveOccurred(), "Failed to fetch the service account")
545-
Expect(currentSAOutput).To(Equal(saName), "The ServiceAccount in use does not match the expected one")
572+
Eventually(verifyCurlUp, 2*time.Minute, time.Second).Should(Succeed())
546573

547574
By("validating that the metrics endpoint is serving as expected")
548575
getCurlLogs := func(g Gomega) {

0 commit comments

Comments
 (0)