@@ -91,25 +91,19 @@ var _ = Describe("kubebuilder", func() {
91
91
GenerateV4WithoutMetrics (kbc )
92
92
Run (kbc , true , false , false , false , false )
93
93
})
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
+ })
101
98
It ("should generate a runnable project with webhooks and metrics protected by network policies" , func () {
102
99
GenerateV4WithNetworkPolicies (kbc )
103
100
Run (kbc , true , false , false , true , true )
104
101
})
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
+ })
113
107
})
114
108
})
115
109
@@ -151,11 +145,11 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
151
145
Expect (err ).NotTo (HaveOccurred ())
152
146
}
153
147
154
- if isToUseInstaller && ! isToUseHelmChart {
155
- By ("building the installer" )
156
- err = kbc .Make ("build-installer" , "IMG=" + kbc .ImageName )
157
- Expect (err ).NotTo (HaveOccurred ())
148
+ By ("building the installer" )
149
+ err = kbc .Make ("build-installer" , "IMG=" + kbc .ImageName )
150
+ Expect (err ).NotTo (HaveOccurred ())
158
151
152
+ if isToUseInstaller && ! isToUseHelmChart {
159
153
By ("deploying the controller-manager with the installer" )
160
154
_ , err = kbc .Kubectl .Apply (true , "-f" , "dist/install.yaml" )
161
155
Expect (err ).NotTo (HaveOccurred ())
@@ -492,10 +486,6 @@ func getMetricsOutput(kbc *utils.TestContext) string {
492
486
Expect (err ).NotTo (HaveOccurred (), "Failed to check clusterrolebinding existence" )
493
487
}
494
488
495
- token , err := serviceAccountToken (kbc )
496
- Expect (err ).NotTo (HaveOccurred ())
497
- Expect (token ).NotTo (BeEmpty ())
498
-
499
489
var metricsOutput string
500
490
By ("validating that the controller-manager service is available" )
501
491
_ , err = kbc .Kubectl .Get (
@@ -518,40 +508,80 @@ func getMetricsOutput(kbc *utils.TestContext) string {
518
508
Eventually (checkServiceEndpoint , 2 * time .Minute , time .Second ).Should (Succeed (),
519
509
"Service endpoint should be ready" )
520
510
511
+ By ("waiting briefly to ensure controller is listening on port 8443" )
512
+ time .Sleep (15 * time .Second )
513
+
514
+ token , err := serviceAccountToken (kbc )
515
+ Expect (err ).NotTo (HaveOccurred ())
516
+ Expect (token ).NotTo (BeEmpty ())
517
+ podName := fmt .Sprintf ("curl-%s" , kbc .TestSuffix )
521
518
By ("creating a curl pod to access the metrics endpoint" )
522
- cmdOpts := cmdOptsToCreateCurlPod (kbc , token )
519
+ cmdOpts := cmdOptsToCreateCurlPod (kbc , token , podName )
523
520
_ , err = kbc .Kubectl .CommandInNamespace (cmdOpts ... )
524
521
Expect (err ).NotTo (HaveOccurred ())
525
522
526
523
By ("validating that the curl pod is running as expected" )
527
524
verifyCurlUp := func (g Gomega ) {
528
- var status string
529
- status , err = kbc .Kubectl .Get (
530
- true ,
531
- "pods" , "curl" , "-o" , "jsonpath={.status.phase}" )
525
+ maxRetries := 3
526
+ var status , logs string
527
+
528
+ for i := 0 ; i < maxRetries ; i ++ {
529
+ status , err = kbc .Kubectl .Get (
530
+ true ,
531
+ "pods" , podName , "-o" , "jsonpath={.status.phase}" )
532
+ g .Expect (err ).NotTo (HaveOccurred ())
533
+
534
+ if status == "Succeeded" {
535
+ return
536
+ }
537
+
538
+ logs , _ = kbc .Kubectl .Logs (podName )
539
+
540
+ if status == "Failed" ||
541
+ strings .Contains (logs , "Failed to connect" ) ||
542
+ strings .Contains (logs , "Connection refused" ) {
543
+ By ("Outputting curl pod logs for debugging" )
544
+ _ , _ = fmt .Fprintln (GinkgoWriter , logs )
545
+
546
+ By ("Outputting manager pod logs for debugging" )
547
+ controllerPodName := getControllerName (kbc )
548
+ managerLogs , _ := kbc .Kubectl .Logs (controllerPodName )
549
+ _ , _ = fmt .Fprintln (GinkgoWriter , managerLogs )
550
+
551
+ By ("Describing all resources for debugging" )
552
+ out , errDescribe := kbc .Kubectl .CommandInNamespace ("describe" , "all" )
553
+ Expect (errDescribe ).NotTo (HaveOccurred ())
554
+ _ , _ = fmt .Fprintln (GinkgoWriter , out )
555
+
556
+ By (fmt .Sprintf ("curl pod failed with status %s. Retrying (%d/%d)..." , status , i + 1 , maxRetries ))
557
+ _ , _ = kbc .Kubectl .Delete (true , "pod" , podName , "--ignore-not-found" ,
558
+ "--grace-period=0" , "--force" )
559
+ time .Sleep (3 * time .Second )
560
+
561
+ cmdOpts = cmdOptsToCreateCurlPod (kbc , token , podName )
562
+ _ , err = kbc .Kubectl .CommandInNamespace (cmdOpts ... )
563
+ g .Expect (err ).NotTo (HaveOccurred ())
564
+
565
+ time .Sleep (5 * time .Second )
566
+ } else {
567
+ By (fmt .Sprintf ("curl pod in %s state without known failure, waiting..." , status ))
568
+ time .Sleep (5 * time .Second )
569
+ }
570
+ }
571
+ status , err = kbc .Kubectl .Get (true , "pods" , podName , "-o" , "jsonpath={.status.phase}" )
532
572
g .Expect (err ).NotTo (HaveOccurred ())
533
- g .Expect (status ).To (Equal ("Succeeded" ), fmt .Sprintf ("curl pod in %s status " , status ))
573
+ g .Expect (status ).To (Equal ("Succeeded" ), fmt .Sprintf ("curl pod in %s state after all retries " , status ))
534
574
}
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" )
575
+ Eventually (verifyCurlUp , 2 * time .Minute , time .Second ).Should (Succeed ())
546
576
547
577
By ("validating that the metrics endpoint is serving as expected" )
548
578
getCurlLogs := func (g Gomega ) {
549
- metricsOutput , err = kbc .Kubectl .Logs ("curl" )
579
+ metricsOutput , err = kbc .Kubectl .Logs (podName )
550
580
g .Expect (err ).NotTo (HaveOccurred ())
551
581
g .Expect (metricsOutput ).Should (ContainSubstring ("< HTTP/1.1 200 OK" ))
552
582
}
553
583
Eventually (getCurlLogs , 10 * time .Second , time .Second ).Should (Succeed ())
554
- removeCurlPod (kbc )
584
+ removeCurlPod (kbc , podName )
555
585
return metricsOutput
556
586
}
557
587
@@ -565,9 +595,10 @@ func metricsShouldBeUnavailable(kbc *utils.TestContext) {
565
595
token , err := serviceAccountToken (kbc )
566
596
Expect (err ).NotTo (HaveOccurred ())
567
597
Expect (token ).NotTo (BeEmpty ())
598
+ podName := fmt .Sprintf ("curl-%s" , kbc .TestSuffix )
568
599
569
600
By ("creating a curl pod to access the metrics endpoint" )
570
- cmdOpts := cmdOptsToCreateCurlPod (kbc , token )
601
+ cmdOpts := cmdOptsToCreateCurlPod (kbc , token , podName )
571
602
_ , err = kbc .Kubectl .CommandInNamespace (cmdOpts ... )
572
603
Expect (err ).NotTo (HaveOccurred ())
573
604
@@ -589,13 +620,13 @@ func metricsShouldBeUnavailable(kbc *utils.TestContext) {
589
620
g .Expect (metricsOutput ).Should (ContainSubstring ("Could not resolve host" ))
590
621
}
591
622
Eventually (getCurlLogs , 10 * time .Second , time .Second ).Should (Succeed ())
592
- removeCurlPod (kbc )
623
+ removeCurlPod (kbc , podName )
593
624
}
594
625
595
- func cmdOptsToCreateCurlPod (kbc * utils.TestContext , token string ) []string {
626
+ func cmdOptsToCreateCurlPod (kbc * utils.TestContext , token , podName string ) []string {
596
627
//nolint:lll
597
628
cmdOpts := []string {
598
- "run" , "curl" ,
629
+ "run" , podName ,
599
630
"--restart=Never" ,
600
631
"--namespace" , kbc .Kubectl .Namespace ,
601
632
"--image=curlimages/curl:latest" ,
@@ -627,9 +658,9 @@ func cmdOptsToCreateCurlPod(kbc *utils.TestContext, token string) []string {
627
658
return cmdOpts
628
659
}
629
660
630
- func removeCurlPod (kbc * utils.TestContext ) {
661
+ func removeCurlPod (kbc * utils.TestContext , podName string ) {
631
662
By ("cleaning up the curl pod" )
632
- _ , err := kbc .Kubectl .Delete (true , "pods/curl" , "--grace-period=0" , "--force" )
663
+ _ , err := kbc .Kubectl .Delete (true , fmt . Sprintf ( "pods/%s" , podName ) , "--grace-period=0" , "--force" )
633
664
Expect (err ).NotTo (HaveOccurred ())
634
665
}
635
666
0 commit comments