Skip to content

Commit f13eba2

Browse files
authored
Merge pull request #421 from pdettori/fix/webhook-readiness-420
Fix: add TLS connectivity probe to webhook readiness checks
2 parents 6413ac1 + ce59ce4 commit f13eba2

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

kagenti-operator/cmd/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ func main() {
688688
setupLog.Error(err, "unable to set up ready check")
689689
os.Exit(1)
690690
}
691+
if err := mgr.AddReadyzCheck("webhook", webhookServer.StartedChecker()); err != nil {
692+
setupLog.Error(err, "unable to set up webhook ready check")
693+
os.Exit(1)
694+
}
691695

692696
setupLog.Info("starting manager")
693697
if err := mgr.Start(ctx); err != nil {

kagenti-operator/test/e2e/e2e_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ var _ = Describe("AuthBridge Injection E2E", Ordered, func() {
344344
g.Expect(output).NotTo(BeEmpty(), "webhook endpoint not yet populated")
345345
}, 2*time.Minute, 2*time.Second).Should(Succeed())
346346

347+
By("waiting for controller pod to be fully Ready")
348+
Eventually(func() error {
349+
return utils.ProbeWebhookReady(controllerNamespace)
350+
}, 2*time.Minute, 2*time.Second).Should(Succeed())
351+
347352
By("creating auth bridge test namespace")
348353
cmd := exec.Command("kubectl", "create", "ns", authBridgeTestNamespace)
349354
_, err := utils.Run(cmd)
@@ -696,6 +701,11 @@ var _ = Describe("AgentCard E2E", Ordered, func() {
696701
g.Expect(output).NotTo(BeEmpty(), "webhook endpoint not yet populated")
697702
}, 2*time.Minute, 2*time.Second).Should(Succeed())
698703

704+
By("waiting for controller pod to be fully Ready")
705+
Eventually(func() error {
706+
return utils.ProbeWebhookReady(controllerNamespace)
707+
}, 2*time.Minute, 2*time.Second).Should(Succeed())
708+
699709
By("creating test namespace with labels")
700710
cmd := exec.Command("kubectl", "create", "ns", testNamespace)
701711
_, err := utils.Run(cmd)
@@ -1039,6 +1049,11 @@ rules:
10391049
g.Expect(output).NotTo(BeEmpty(), "webhook endpoint not yet populated")
10401050
}, 2*time.Minute, 2*time.Second).Should(Succeed())
10411051

1052+
By("waiting for controller pod to be fully Ready")
1053+
Eventually(func() error {
1054+
return utils.ProbeWebhookReady(controllerNamespace)
1055+
}, 2*time.Minute, 2*time.Second).Should(Succeed())
1056+
10421057
By("creating test namespace")
10431058
cmd := exec.Command("kubectl", "create", "ns", agentRuntimeTestNamespace)
10441059
_, err := utils.Run(cmd)
@@ -1513,6 +1528,11 @@ rules:
15131528
g.Expect(output).NotTo(BeEmpty(), "webhook endpoint not yet populated")
15141529
}, 2*time.Minute, 2*time.Second).Should(Succeed())
15151530

1531+
By("waiting for controller pod to be fully Ready")
1532+
Eventually(func() error {
1533+
return utils.ProbeWebhookReady(controllerNamespace)
1534+
}, 2*time.Minute, 2*time.Second).Should(Succeed())
1535+
15161536
By("setting KAGENTI_SPIRE_TRUST_DOMAIN env var")
15171537
envCmd := exec.Command("kubectl", "set", "env", "deployment/"+controllerDeployment,
15181538
"-n", controllerNamespace, "KAGENTI_SPIRE_TRUST_DOMAIN=example.org")
@@ -1974,6 +1994,11 @@ rules:
19741994
g.Expect(output).NotTo(BeEmpty(), "webhook endpoint not yet populated")
19751995
}, 2*time.Minute, 2*time.Second).Should(Succeed())
19761996

1997+
By("waiting for controller pod to be fully Ready")
1998+
Eventually(func() error {
1999+
return utils.ProbeWebhookReady(controllerNamespace)
2000+
}, 2*time.Minute, 2*time.Second).Should(Succeed())
2001+
19772002
By("creating skill discovery test namespace")
19782003
cmd := exec.Command("kubectl", "create", "ns", skillDiscoveryTestNamespace)
19792004
_, err := utils.Run(cmd)
@@ -2134,6 +2159,11 @@ rules:
21342159
g.Expect(err).NotTo(HaveOccurred())
21352160
g.Expect(output).NotTo(BeEmpty(), "webhook endpoint not yet populated")
21362161
}, 2*time.Minute, 2*time.Second).Should(Succeed())
2162+
2163+
By("waiting for controller pod to be fully Ready after restart")
2164+
Eventually(func() error {
2165+
return utils.ProbeWebhookReady(controllerNamespace)
2166+
}, 2*time.Minute, 2*time.Second).Should(Succeed())
21372167
})
21382168

21392169
It("should populate linkedSkills from annotation", func() {
@@ -2438,6 +2468,11 @@ var _ = Describe("Istio Mesh Enrollment E2E", Ordered, func() {
24382468
g.Expect(output).NotTo(BeEmpty(), "webhook endpoint not yet populated")
24392469
}, 2*time.Minute, 2*time.Second).Should(Succeed())
24402470

2471+
By("waiting for controller pod to be fully Ready")
2472+
Eventually(func() error {
2473+
return utils.ProbeWebhookReady(controllerNamespace)
2474+
}, 2*time.Minute, 2*time.Second).Should(Succeed())
2475+
24412476
By("creating test namespace")
24422477
cmd := exec.Command("kubectl", "create", "ns", istioMeshTestNamespace)
24432478
_, err := utils.Run(cmd)

kagenti-operator/test/utils/utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,19 @@ func UncommentCode(filename, target, prefix string) error {
751751
// nolint:gosec
752752
return os.WriteFile(filename, out.Bytes(), 0644)
753753
}
754+
755+
// ProbeWebhookReady checks that the controller pod is fully Ready.
756+
// The readyz endpoint gates on webhookServer.StartedChecker(), so Ready
757+
// means the webhook TLS server is accepting connections on :9443.
758+
func ProbeWebhookReady(namespace string) error {
759+
cmd := exec.Command("kubectl", "wait",
760+
"--for=condition=Ready",
761+
"pod", "-l", "control-plane=controller-manager",
762+
"-n", namespace,
763+
"--timeout=5s")
764+
_, err := Run(cmd)
765+
if err != nil {
766+
return fmt.Errorf("controller pod not yet Ready: %w", err)
767+
}
768+
return nil
769+
}

0 commit comments

Comments
 (0)