From 209b36526710bdd3283e33b2c2595b99ac916484 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Wed, 23 Oct 2024 17:40:08 +0200 Subject: [PATCH] Setup health endpoints --- main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.go b/main.go index 239b859..9ee902f 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,7 @@ import ( "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/cache" + "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/metrics/server" @@ -146,6 +147,15 @@ func runManager(metricsAddr, probeAddr, watchNamespace string, enableLeaderElect os.Exit(1) } + if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up health check") + os.Exit(1) + } + if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up ready check") + os.Exit(1) + } + versionString := "unknown" if v, ok := debug.ReadBuildInfo(); ok { versionString = fmt.Sprintf("%s (%s)", v.Main.Version, v.GoVersion) @@ -226,6 +236,15 @@ func runMachineAPIControllersManager(metricsAddr, probeAddr, watchNamespace stri os.Exit(1) } + if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up health check") + os.Exit(1) + } + if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { + setupLog.Error(err, "unable to set up ready check") + os.Exit(1) + } + if err := (&controllers.MachineAPIControllersReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(),