Skip to content

Commit

Permalink
fix: Add readiness/liveness check (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiannistri authored Feb 12, 2025
1 parent 8a1d7e6 commit 9f5e274
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions exp/day2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
)
Expand Down Expand Up @@ -175,8 +176,8 @@ func main() {
// Setup the context that's going to be used in controllers and for the manager.
ctx := ctrl.SetupSignalHandler()

setupChecks(mgr)
if feature.Gates.Enabled(feature.EtcdBackupRestore) {
setupChecks(mgr)
setupReconcilers(ctx, mgr)
setupWebhooks(mgr)
}
Expand All @@ -191,15 +192,27 @@ func main() {
}

func setupChecks(mgr ctrl.Manager) {
if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to create ready check")
os.Exit(1)
}

if err := mgr.AddHealthzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to create health check")
os.Exit(1)
}

if feature.Gates.Enabled(feature.EtcdBackupRestore) {
if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
setupLog.Error(err, "unable to create ready check")
os.Exit(1)
}

if err := mgr.AddHealthzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
setupLog.Error(err, "unable to create health check")
os.Exit(1)
}
}
}

func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
Expand Down

0 comments on commit 9f5e274

Please sign in to comment.