Skip to content

Commit

Permalink
support for healthz (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumatag authored Dec 16, 2021
1 parent 7d78ed5 commit f29d468
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
12 changes: 12 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 26 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
watchNamespace string
metricsAddr string
enableLeaderElection bool
healthAddr string

scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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.",
)
}

0 comments on commit f29d468

Please sign in to comment.