Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add liveness/readiness probes #1487

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ spec:
image: controller:latest
imagePullPolicy: Always
name: manager
ports:
- containerPort: 9440
cpanato marked this conversation as resolved.
Show resolved Hide resolved
name: healthz
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: healthz
livenessProbe:
httpGet:
path: /healthz
port: healthz
terminationGracePeriodSeconds: 10
tolerations:
- effect: NoSchedule
Expand Down
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -64,6 +65,7 @@ func main() {
awsMachineConcurrency int
syncPeriod time.Duration
webhookPort int
healthAddr string
)

flag.StringVar(
Expand Down Expand Up @@ -125,6 +127,12 @@ func main() {
"Webhook server port (set to 0 to disable)",
)

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

flag.Parse()

if watchNamespace != "" {
Expand Down Expand Up @@ -155,6 +163,7 @@ func main() {
Namespace: watchNamespace,
EventBroadcaster: broadcaster,
Port: webhookPort,
HealthProbeBindAddress: healthAddr,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -209,6 +218,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