From f29d4685801ac2ddf3a592f438242d50a229d0ec Mon Sep 17 00:00:00 2001 From: Manjunath Kumatagi Date: Thu, 16 Dec 2021 15:27:20 +0530 Subject: [PATCH] support for healthz (#492) --- config/manager/manager.yaml | 12 ++++++++++++ main.go | 33 ++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index c158a0df2..a9866e13a 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -30,6 +30,18 @@ spec: - "--metrics-bind-addr=127.0.0.1:8080" image: controller:latest name: manager + ports: + - containerPort: 9440 + name: healthz + protocol: TCP + readinessProbe: + httpGet: + path: /readyz + port: healthz + livenessProbe: + httpGet: + path: /healthz + port: healthz resources: limits: cpu: 100m diff --git a/main.go b/main.go index 35d7eff38..fc37a41fe 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,7 @@ var ( watchNamespace string metricsAddr string enableLeaderElection bool + healthAddr string scheme = runtime.NewScheme() setupLog = ctrl.Log.WithName("setup") @@ -72,13 +73,14 @@ func main() { syncPeriod := 15 * time.Second mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - MetricsBindAddress: metricsAddr, - Port: 9443, - LeaderElection: enableLeaderElection, - LeaderElectionID: "effcf9b8.cluster.x-k8s.io", - SyncPeriod: &syncPeriod, - Namespace: watchNamespace, + Scheme: scheme, + MetricsBindAddress: metricsAddr, + Port: 9443, + LeaderElection: enableLeaderElection, + LeaderElectionID: "effcf9b8.cluster.x-k8s.io", + SyncPeriod: &syncPeriod, + Namespace: watchNamespace, + HealthProbeBindAddress: healthAddr, }) if err != nil { setupLog.Error(err, "unable to start manager") @@ -131,6 +133,16 @@ func main() { } // +kubebuilder:scaffold:builder + 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) + } + setupLog.Info("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") @@ -160,4 +172,11 @@ func initFlags(fs *pflag.FlagSet) { "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.", ) + + fs.StringVar( + &healthAddr, + "health-addr", + ":9440", + "The address the health endpoint binds to.", + ) }