Skip to content

Commit 5a65e4a

Browse files
Merge pull request #3162 from MahnoorAsghar/webhook-readiness-check
🐛Add webhook readiness check before starting manager
2 parents a3b6f4c + 6bf1527 commit 5a65e4a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ func setupChecks(mgr ctrl.Manager) {
100100
}
101101
}
102102

103+
// setupWebhookReadinessCheck adds a readiness check that blocks the pod from
104+
// entering "Ready" state (and thus from being added to the Service's endpoints)
105+
// until the webhook server is actually listening. This prevents a race where
106+
// the Kubernetes API server tries to route admission webhook calls to this pod
107+
// before the webhook TLS server is up, which would cause "no endpoints
108+
// available" errors for BareMetalHost operations.
109+
func setupWebhookReadinessCheck(mgr ctrl.Manager) {
110+
if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
111+
setupLog.Error(err, "unable to create ready check for webhook server")
112+
os.Exit(1)
113+
}
114+
}
115+
103116
func setupWebhooks(mgr ctrl.Manager) {
104117
if err := (&webhooks.BareMetalHost{}).SetupWebhookWithManager(mgr); err != nil {
105118
setupLog.Error(err, "unable to create webhook", "webhook", "BareMetalHost")
@@ -401,6 +414,7 @@ func main() {
401414
setupChecks(mgr)
402415

403416
if enableWebhook {
417+
setupWebhookReadinessCheck(mgr)
404418
setupWebhooks(mgr)
405419
}
406420

0 commit comments

Comments
 (0)