@@ -57,12 +57,15 @@ var _ = Describe("kubebuilder", func() {
57
57
})
58
58
59
59
AfterEach (func () {
60
- By ("By removing restricted namespace label" )
60
+ By ("removing restricted namespace label" )
61
61
_ = kbc .RemoveNamespaceLabelToEnforceRestricted ()
62
62
63
- By ("clean up API objects created during the test " )
63
+ By ("undeploy the project " )
64
64
_ = kbc .Make ("undeploy" )
65
65
66
+ By ("uninstalling the project" )
67
+ _ = kbc .Make ("uninstall" )
68
+
66
69
By ("removing controller image and working dir" )
67
70
kbc .Destroy ()
68
71
})
@@ -88,25 +91,19 @@ var _ = Describe("kubebuilder", func() {
88
91
GenerateV4WithoutMetrics (kbc )
89
92
Run (kbc , true , false , false , false , false )
90
93
})
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
+ })
98
103
It ("should generate a runnable project with webhooks and metrics protected by network policies" , func () {
99
104
GenerateV4WithNetworkPolicies (kbc )
100
105
Run (kbc , true , false , false , true , true )
101
106
})
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
- // })
110
107
})
111
108
})
112
109
@@ -464,9 +461,15 @@ func getControllerName(kbc *utils.TestContext) string {
464
461
return nil
465
462
}
466
463
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}" )
468
467
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
+ }
470
473
}()
471
474
Eventually (verifyControllerUp , 5 * time .Minute , time .Second ).Should (Succeed ())
472
475
return controllerPodName
@@ -529,8 +532,34 @@ func getMetricsOutput(kbc *utils.TestContext) string {
529
532
g .Expect (err ).NotTo (HaveOccurred ())
530
533
g .Expect (status ).To (Equal ("Succeeded" ), fmt .Sprintf ("curl pod in %s status" , status ))
531
534
}
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
+ }()
532
551
Eventually (verifyCurlUp , 240 * time .Second , time .Second ).Should (Succeed ())
533
552
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
+
534
563
By ("validating that the metrics endpoint is serving as expected" )
535
564
getCurlLogs := func (g Gomega ) {
536
565
metricsOutput , err = kbc .Kubectl .Logs ("curl" )
@@ -569,16 +598,6 @@ func metricsShouldBeUnavailable(kbc *utils.TestContext) {
569
598
}
570
599
Eventually (verifyCurlUp , 240 * time .Second , time .Second ).Should (Succeed ())
571
600
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
-
582
601
By ("validating that the metrics endpoint is not working as expected" )
583
602
getCurlLogs := func (g Gomega ) {
584
603
metricsOutput , err := kbc .Kubectl .Logs ("curl" )
@@ -626,7 +645,7 @@ func cmdOptsToCreateCurlPod(kbc *utils.TestContext, token string) []string {
626
645
627
646
func removeCurlPod (kbc * utils.TestContext ) {
628
647
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" )
630
649
Expect (err ).NotTo (HaveOccurred ())
631
650
}
632
651
0 commit comments