Skip to content

Commit

Permalink
[kueue] Check certificates readiness before the webhook server. (kube…
Browse files Browse the repository at this point in the history
…rnetes-sigs#1707)

* [kueue] Check certificates readiness before the webhook server.

* Don't keep the caller busy.
  • Loading branch information
trasc authored and kannon92 committed Nov 19, 2024
1 parent e5d523c commit b59f4b1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/kueue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"context"
"errors"
"flag"
"net/http"
"os"
Expand Down Expand Up @@ -165,7 +166,7 @@ func main() {

serverVersionFetcher := setupServerVersionFetcher(mgr, kubeConfig)

setupProbeEndpoints(mgr)
setupProbeEndpoints(mgr, certsReady)
// Cert won't be ready until manager starts, so start a goroutine here which
// will block until the cert is ready before setting up the controllers.
// Controllers who register after manager starts will start directly.
Expand Down Expand Up @@ -276,7 +277,7 @@ func setupControllers(mgr ctrl.Manager, cCache *cache.Cache, queues *queue.Manag
}

// setupProbeEndpoints registers the health endpoints
func setupProbeEndpoints(mgr ctrl.Manager) {
func setupProbeEndpoints(mgr ctrl.Manager, certsReady <-chan struct{}) {
defer setupLog.Info("Probe endpoints are configured on healthz and readyz")

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand All @@ -292,7 +293,12 @@ func setupProbeEndpoints(mgr ctrl.Manager) {
// the function, otherwise a not fully-initialized webhook server (without
// ready certs) fails the start of the manager.
if err := mgr.AddReadyzCheck("readyz", func(req *http.Request) error {
return mgr.GetWebhookServer().StartedChecker()(req)
select {
case <-certsReady:
return mgr.GetWebhookServer().StartedChecker()(req)
default:
return errors.New("certificates are not ready")
}
}); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
Expand Down

0 comments on commit b59f4b1

Please sign in to comment.