Skip to content

Commit

Permalink
Add liveness and readiness probes
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Jan 29, 2020
1 parent 767b0c0 commit 047ff08
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
12 changes: 12 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ spec:
image: controller:latest
imagePullPolicy: Always
name: manager
ports:
- containerPort: 9440
name: healthz
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: healthz
livenessProbe:
httpGet:
path: /healthz
port: healthz
terminationGracePeriodSeconds: 10
31 changes: 25 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"sigs.k8s.io/cluster-api/util/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
// +kubebuilder:scaffold:imports
)

Expand All @@ -59,6 +60,7 @@ func main() {
azureClusterConcurrency int
azureMachineConcurrency int
syncPeriod time.Duration
healthAddr string
)

flag.StringVar(
Expand Down Expand Up @@ -107,6 +109,12 @@ func main() {
"The minimum interval at which watched resources are reconciled (e.g. 15m)",
)

flag.StringVar(&healthAddr,
"health-addr",
":9440",
"The address the health endpoint binds to.",
)

flag.Parse()

if watchNamespace != "" {
Expand All @@ -123,12 +131,13 @@ func main() {
ctrl.SetLogger(klogr.New())

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "controller-leader-election-capz",
SyncPeriod: &syncPeriod,
Namespace: watchNamespace,
Scheme: scheme,
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "controller-leader-election-capz",
SyncPeriod: &syncPeriod,
Namespace: watchNamespace,
HealthProbeBindAddress: healthAddr,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand All @@ -154,6 +163,16 @@ func main() {
}
// +kubebuilder:scaffold:builder

if err := mgr.AddReadyzCheck("ping", healthz.Ping); err != nil {
setupLog.Error(err, "unable to create ready check")
os.Exit(1)
}

if err := mgr.AddHealthzCheck("ping", healthz.Ping); 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

0 comments on commit 047ff08

Please sign in to comment.