Skip to content

Commit

Permalink
manager: add liveness/readiness probes
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Mar 2, 2020
1 parent 66da166 commit 302f85d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"k8s.io/klog"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

Expand All @@ -33,8 +34,14 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/record"
)

var (
//flags
healthAddr string
)

func main() {
klog.InitFlags(nil)
flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.")
flag.Parse()

klog.Info("Starting controller of IBM cloud provider for cluster api")
Expand All @@ -46,7 +53,8 @@ func main() {

// Setup a Manager
mgr, err := manager.New(cfg, manager.Options{
LeaderElectionID: "controller-leader-election-cluster-api-provider-ibmcloud",
LeaderElectionID: "controller-leader-election-cluster-api-provider-ibmcloud",
HealthProbeBindAddress: healthAddr,
})
if err != nil {
klog.Fatalf("unable to set up overall controller manager: %v", err)
Expand All @@ -66,6 +74,14 @@ func main() {
klog.Fatalf("Error initializing controllers: %v", err)
}

if err := mgr.AddReadyzCheck("ping", healthz.Ping); err != nil {
klog.Fatalf("unable to create health check: %v", err)
}

if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
klog.Fatalf("unable to create health check: %v", err)
}

if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
klog.Fatalf("Failed starting controller: %v", err)
}
Expand Down
11 changes: 11 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ spec:
cpu: 100m
memory: 20Mi
ports:
- containerPort: 9440
name: healthz
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
port: healthz
livenessProbe:
httpGet:
path: /healthz
port: healthz
volumeMounts:
- mountPath: /etc/ibmcloud/
readOnly: true
Expand Down

0 comments on commit 302f85d

Please sign in to comment.