Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 2b4567a

Browse files
authored
Merge pull request #175 from cpanato/add-probes
✨ manager: add health probes
2 parents e224933 + 306dc3c commit 2b4567a

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

config/resources/manager/manager.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ spec:
2323
image: packet-controller
2424
imagePullPolicy: IfNotPresent
2525
name: manager
26+
ports:
27+
- containerPort: 9440
28+
name: healthz
29+
protocol: TCP
30+
readinessProbe:
31+
httpGet:
32+
path: /readyz
33+
port: healthz
34+
livenessProbe:
35+
httpGet:
36+
path: /healthz
37+
port: healthz
2638
resources:
2739
limits:
2840
cpu: 100m

main.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
2525
"k8s.io/client-go/tools/record"
2626
ctrl "sigs.k8s.io/controller-runtime"
27+
"sigs.k8s.io/controller-runtime/pkg/healthz"
2728
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2829

2930
packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet"
@@ -47,12 +48,25 @@ func init() {
4748
}
4849

4950
func main() {
50-
var metricsAddr string
51-
var enableLeaderElection bool
51+
52+
var (
53+
metricsAddr string
54+
healthAddr string
55+
enableLeaderElection bool
56+
)
57+
5258
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
59+
5360
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
5461
"Enable leader election for controller manager. "+
5562
"Enabling this will ensure there is only one active controller manager.")
63+
64+
flag.StringVar(&healthAddr,
65+
"health-addr",
66+
":9440",
67+
"The address the health endpoint binds to.",
68+
)
69+
5670
flag.Parse()
5771

5872
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
@@ -64,12 +78,13 @@ func main() {
6478
})
6579

6680
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
67-
Scheme: scheme,
68-
MetricsBindAddress: metricsAddr,
69-
Port: 9443,
70-
EventBroadcaster: broadcaster,
71-
LeaderElection: enableLeaderElection,
72-
LeaderElectionID: "cad3ba79.cluster.x-k8s.io",
81+
Scheme: scheme,
82+
MetricsBindAddress: metricsAddr,
83+
Port: 9443,
84+
EventBroadcaster: broadcaster,
85+
LeaderElection: enableLeaderElection,
86+
LeaderElectionID: "cad3ba79.cluster.x-k8s.io",
87+
HealthProbeBindAddress: healthAddr,
7388
})
7489
if err != nil {
7590
setupLog.Error(err, "unable to start manager")
@@ -105,6 +120,16 @@ func main() {
105120
}
106121
// +kubebuilder:scaffold:builder
107122

123+
if err := mgr.AddReadyzCheck("ping", healthz.Ping); err != nil {
124+
setupLog.Error(err, "unable to create ready check")
125+
os.Exit(1)
126+
}
127+
128+
if err := mgr.AddHealthzCheck("ping", healthz.Ping); err != nil {
129+
setupLog.Error(err, "unable to create health check")
130+
os.Exit(1)
131+
}
132+
108133
setupLog.Info("starting manager")
109134
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
110135
setupLog.Error(err, "problem running manager")

0 commit comments

Comments
 (0)