Skip to content

Commit b3f04dd

Browse files
authored
Merge pull request intel#1232 from mythi/PR-2022-080
operator: add support for Liveness and Readiness probes
2 parents 6d92ee0 + 5876882 commit b3f04dd

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

cmd/operator/main.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2626
"k8s.io/klog/v2/klogr"
2727
ctrl "sigs.k8s.io/controller-runtime"
28+
"sigs.k8s.io/controller-runtime/pkg/healthz"
2829
"sigs.k8s.io/controller-runtime/pkg/webhook"
2930
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3031

@@ -97,6 +98,7 @@ func contains(arr []string, val string) bool {
9798
func main() {
9899
var (
99100
metricsAddr string
101+
probeAddr string
100102
devicePluginNamespace string
101103
enableLeaderElection bool
102104
pm *patcher.Manager
@@ -105,6 +107,7 @@ func main() {
105107
ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))
106108

107109
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
110+
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
108111
flag.StringVar(&devicePluginNamespace, "deviceplugin-namespace", metav1.NamespaceSystem, "The namespace where deviceplugin daemonsets are created")
109112
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
110113
"Enable leader election for controller manager. "+
@@ -132,12 +135,13 @@ func main() {
132135
}
133136

134137
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
135-
Scheme: scheme,
136-
MetricsBindAddress: metricsAddr,
137-
Logger: ctrl.Log.WithName("intel-device-plugins-manager"),
138-
WebhookServer: webHook,
139-
LeaderElection: enableLeaderElection,
140-
LeaderElectionID: "d1c7b6d5.intel.com",
138+
Scheme: scheme,
139+
MetricsBindAddress: metricsAddr,
140+
Logger: ctrl.Log.WithName("intel-device-plugins-manager"),
141+
WebhookServer: webHook,
142+
HealthProbeBindAddress: probeAddr,
143+
LeaderElection: enableLeaderElection,
144+
LeaderElectionID: "d1c7b6d5.intel.com",
141145
})
142146
if err != nil {
143147
setupLog.Error(err, "unable to start manager")
@@ -190,6 +194,16 @@ func main() {
190194
}
191195
}
192196

197+
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
198+
setupLog.Error(err, "unable to set up health check")
199+
os.Exit(1)
200+
}
201+
202+
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
203+
setupLog.Error(err, "unable to set up ready check")
204+
os.Exit(1)
205+
}
206+
193207
setupLog.Info("starting manager")
194208

195209
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {

deployments/operator/manager/manager.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ spec:
2626
- image: intel/intel-deviceplugin-operator:devel
2727
imagePullPolicy: IfNotPresent
2828
name: manager
29+
livenessProbe:
30+
httpGet:
31+
path: /healthz
32+
port: 8081
33+
initialDelaySeconds: 15
34+
periodSeconds: 20
35+
readinessProbe:
36+
httpGet:
37+
path: /readyz
38+
port: 8081
39+
initialDelaySeconds: 5
40+
periodSeconds: 10
2941
resources:
3042
limits:
3143
cpu: 100m

0 commit comments

Comments
 (0)