Skip to content

Commit ba190eb

Browse files
(ci) - fix cleanup to allow tests broken for 1.33 work
1 parent 5d3e33b commit ba190eb

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

test/e2e/v4/plugin_cluster_test.go

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ var _ = Describe("kubebuilder", func() {
5757
})
5858

5959
AfterEach(func() {
60-
By("By removing restricted namespace label")
60+
By("removing restricted namespace label")
6161
_ = kbc.RemoveNamespaceLabelToEnforceRestricted()
6262

63-
By("clean up API objects created during the test")
63+
By("undeploy the project")
6464
_ = kbc.Make("undeploy")
6565

66+
By("uninstalling the project")
67+
_ = kbc.Make("uninstall")
68+
6669
By("removing controller image and working dir")
6770
kbc.Destroy()
6871
})
@@ -88,25 +91,19 @@ var _ = Describe("kubebuilder", func() {
8891
GenerateV4WithoutMetrics(kbc)
8992
Run(kbc, true, false, false, false, false)
9093
})
91-
// FIXME: This test is currently disabled because it requires to be fixed:
92-
// https://github.com/kubernetes-sigs/kubebuilder/issues/4853
93-
// It is not working for k8s 1.33
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-
// })
94+
It("should generate a runnable project with the manager running "+
95+
"as restricted and without webhooks", func() {
96+
GenerateV4WithoutWebhooks(kbc)
97+
Run(kbc, false, false, false, true, false)
98+
})
99+
It("should generate a runnable project with metrics protected by network policies", func() {
100+
GenerateV4WithNetworkPoliciesWithoutWebhooks(kbc)
101+
Run(kbc, false, false, false, true, true)
102+
})
98103
It("should generate a runnable project with webhooks and metrics protected by network policies", func() {
99104
GenerateV4WithNetworkPolicies(kbc)
100105
Run(kbc, true, false, false, true, true)
101106
})
102-
// FIXME: This test is currently disabled because it requires to be fixed:
103-
// https://github.com/kubernetes-sigs/kubebuilder/issues/4853
104-
// It is not working for k8s 1.33
105-
// It("should generate a runnable project with the manager running "+
106-
// "as restricted and without webhooks", func() {
107-
// GenerateV4WithoutWebhooks(kbc)
108-
// Run(kbc, false, false, false, true, false)
109-
// })
110107
})
111108
})
112109

@@ -464,9 +461,15 @@ func getControllerName(kbc *utils.TestContext) string {
464461
return nil
465462
}
466463
defer func() {
467-
out, err := kbc.Kubectl.CommandInNamespace("describe", "all")
464+
status, err := kbc.Kubectl.Get(
465+
true,
466+
"pods", controllerPodName, "-o", "jsonpath={.status.phase}")
468467
Expect(err).NotTo(HaveOccurred())
469-
_, _ = fmt.Fprintln(GinkgoWriter, out)
468+
if status != "Running" {
469+
out, err := kbc.Kubectl.CommandInNamespace("describe", "all")
470+
Expect(err).NotTo(HaveOccurred())
471+
_, _ = fmt.Fprintln(GinkgoWriter, out)
472+
}
470473
}()
471474
Eventually(verifyControllerUp, 5*time.Minute, time.Second).Should(Succeed())
472475
return controllerPodName
@@ -529,8 +532,34 @@ func getMetricsOutput(kbc *utils.TestContext) string {
529532
g.Expect(err).NotTo(HaveOccurred())
530533
g.Expect(status).To(Equal("Succeeded"), fmt.Sprintf("curl pod in %s status", status))
531534
}
535+
defer func() {
536+
status, errCurl := kbc.Kubectl.Get(
537+
true,
538+
"pods", "curl", "-o", "jsonpath={.status.phase}")
539+
Expect(errCurl).NotTo(HaveOccurred())
540+
if status != "Succeeded" {
541+
out, errDescribe := kbc.Kubectl.CommandInNamespace("describe", "all")
542+
Expect(errDescribe).NotTo(HaveOccurred())
543+
_, _ = fmt.Fprintln(GinkgoWriter, out)
544+
545+
out, err = kbc.Kubectl.Get(true,
546+
"pods", "curl", "-o", "jsonpath={.status.phase}", "--namespace", kbc.Kubectl.Namespace)
547+
Expect(err).NotTo(HaveOccurred())
548+
_, _ = fmt.Fprintln(GinkgoWriter, out)
549+
}
550+
}()
532551
Eventually(verifyCurlUp, 240*time.Second, time.Second).Should(Succeed())
533552

553+
By("validating that the correct ServiceAccount is being used")
554+
saName := kbc.Kubectl.ServiceAccount
555+
currentSAOutput, err := kbc.Kubectl.Get(
556+
true,
557+
"serviceaccount", saName,
558+
"-o", "jsonpath={.metadata.name}",
559+
)
560+
Expect(err).NotTo(HaveOccurred(), "Failed to fetch the service account")
561+
Expect(currentSAOutput).To(Equal(saName), "The ServiceAccount in use does not match the expected one")
562+
534563
By("validating that the metrics endpoint is serving as expected")
535564
getCurlLogs := func(g Gomega) {
536565
metricsOutput, err = kbc.Kubectl.Logs("curl")
@@ -569,16 +598,6 @@ func metricsShouldBeUnavailable(kbc *utils.TestContext) {
569598
}
570599
Eventually(verifyCurlUp, 240*time.Second, time.Second).Should(Succeed())
571600

572-
By("validating that the correct ServiceAccount is being used")
573-
saName := kbc.Kubectl.ServiceAccount
574-
currentSAOutput, err := kbc.Kubectl.Get(
575-
true,
576-
"serviceaccount", saName,
577-
"-o", "jsonpath={.metadata.name}",
578-
)
579-
Expect(err).NotTo(HaveOccurred(), "Failed to fetch the service account")
580-
Expect(currentSAOutput).To(Equal(saName), "The ServiceAccount in use does not match the expected one")
581-
582601
By("validating that the metrics endpoint is not working as expected")
583602
getCurlLogs := func(g Gomega) {
584603
metricsOutput, err := kbc.Kubectl.Logs("curl")
@@ -626,7 +645,7 @@ func cmdOptsToCreateCurlPod(kbc *utils.TestContext, token string) []string {
626645

627646
func removeCurlPod(kbc *utils.TestContext) {
628647
By("cleaning up the curl pod")
629-
_, err := kbc.Kubectl.Delete(true, "pods/curl")
648+
_, err := kbc.Kubectl.Delete(true, "pods/curl", "--grace-period=0", "--force")
630649
Expect(err).NotTo(HaveOccurred())
631650
}
632651

0 commit comments

Comments
 (0)