Skip to content

📖 CR-855: added example of probes usage with controller #856

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

Closed
Closed
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
36 changes: 36 additions & 0 deletions pkg/manager/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
Expand Down Expand Up @@ -86,3 +87,38 @@ func ExampleManager_start() {
os.Exit(1)
}
}

// This example adds liveness/readiness probes to the Manager
func ExampleManager_probes() {
cfg, err := config.GetConfig()
if err != nil {
log.Error(err, "unable to get kubeconfig")
os.Exit(1)
}

// Set health probes address(required to run probes)
// and desired liveness and readiness endpoints(optional)
mgr, err := manager.New(cfg, manager.Options{
HealthProbeBindAddress: ":8080",
LivenessEndpointName: "health",
ReadinessEndpointName: "ready",
})
if err != nil {
log.Error(err, "unable to set up manager")
os.Exit(1)
}

// Add readiness probe
err = mgr.AddReadyzCheck("ready-ping", healthz.Ping)
if err != nil {
log.Error(err, "unable add a readiness check")
os.Exit(1)
}

// Add liveness probe
err = mgr.AddHealthzCheck("health-ping", healthz.Ping)
if err != nil {
log.Error(err, "unable add a health check")
os.Exit(1)
}
}