Skip to content

Commit

Permalink
add check
Browse files Browse the repository at this point in the history
Signed-off-by: forsaken628 <[email protected]>
  • Loading branch information
forsaken628 committed Jun 16, 2024
1 parent 0d190b9 commit 2d60736
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions cmd/katib-controller/v1beta1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package main

import (
"flag"
"fmt"
"net/http"
"os"

"github.com/spf13/viper"
Expand Down Expand Up @@ -131,27 +133,40 @@ func main() {
CertDir: consts.CertDir,
})

if err := mgr.AddReadyzCheck("webhook", hookServer.StartedChecker()); err != nil {
log.Error(err, "Unable to add readyz check cert")
os.Exit(1)
}

ctx := signals.SetupSignalHandler()
certsReady := make(chan struct{})
defer close(certsReady)

// The setupControllers will register controllers to the manager
// after generated certs for the admission webhooks.
go setupControllers(mgr, certsReady, hookServer)

if initConfig.CertGeneratorConfig.Enable {
err := mgr.AddReadyzCheck("cert", func(_ *http.Request) error {
select {
case <-certsReady:
return nil
default:
return fmt.Errorf("cert not ready")
}
})
if err != nil {
log.Error(err, "Unable to add readyz check cert")
os.Exit(1)
}
if err = cert.AddToManager(mgr, initConfig.CertGeneratorConfig, certsReady); err != nil {
log.Error(err, "Failed to set up cert-generator")
os.Exit(1)
}
} else {
certsReady <- struct{}{}
close(certsReady)
}

log.Info("Setting up health checker.")
if err := mgr.AddReadyzCheck("readyz", hookServer.StartedChecker()); err != nil {
log.Error(err, "Unable to add readyz endpoint to the manager")
os.Exit(1)
}
if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.Error(err, "Add webhook server health checker to the manager failed")
os.Exit(1)
Expand Down

0 comments on commit 2d60736

Please sign in to comment.