Skip to content

Commit ca7252e

Browse files
authored
Merge pull request #21 from hensur/add-probes-api
add probes API
2 parents c00f101 + 2188f56 commit ca7252e

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

cmd/manager/main.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"runtime"
1212
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
13+
"sigs.k8s.io/controller-runtime/pkg/healthz"
1314
"strings"
1415

1516
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
@@ -127,9 +128,10 @@ func main() {
127128

128129
// Set default manager options
129130
options := manager.Options{
130-
MapperProvider: restMapper,
131-
Namespace: namespace,
132-
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
131+
MapperProvider: restMapper,
132+
Namespace: namespace,
133+
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
134+
HealthProbeBindAddress: ":8080",
133135
}
134136

135137
// Add support for MultiNamespace set in WATCH_NAMESPACE (e.g ns1,ns2)
@@ -148,6 +150,20 @@ func main() {
148150
os.Exit(1)
149151
}
150152

153+
// Add liveness probe
154+
err = mgr.AddHealthzCheck("health-ping", healthz.Ping)
155+
if err != nil {
156+
log.Error(err, "couldn't add liveness probe")
157+
os.Exit(1)
158+
}
159+
160+
// Add readiness probe
161+
err = mgr.AddReadyzCheck("ready-ping", healthz.Ping)
162+
if err != nil {
163+
log.Error(err, "couldn't add readiness probe")
164+
os.Exit(1)
165+
}
166+
151167
log.Info("Registering Components.")
152168

153169
// Setup Scheme for all resources

deploy/helm-chart/kubernetes-secret-generator/templates/deployment.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ spec:
2828
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
2929
imagePullPolicy: {{ .Values.image.pullPolicy }}
3030
args: {{ toYaml .Values.args | nindent 12 }}
31+
ports:
32+
- containerPort: 8080
33+
name: healthcheck
34+
livenessProbe:
35+
httpGet:
36+
path: /healthz
37+
port: healthcheck
38+
initialDelaySeconds: 3
39+
periodSeconds: 3
40+
readinessProbe:
41+
httpGet:
42+
path: /readyz
43+
port: healthcheck
44+
initialDelaySeconds: 3
45+
periodSeconds: 3
3146
env:
3247
- name: WATCH_NAMESPACE
3348
value: {{ .Values.watchNamespace }}
@@ -53,5 +68,5 @@ spec:
5368
{{- end }}
5469
{{- with .Values.tolerations }}
5570
tolerations:
56-
{{- toYaml . | nindent 8 }}
71+
{{- toYaml . | nindent 8 }}
5772
{{- end }}

deploy/operator.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ spec:
2020
command:
2121
- kubernetes-secret-generator
2222
imagePullPolicy: Always
23+
ports:
24+
- containerPort: 8080
25+
name: healthcheck
26+
livenessProbe:
27+
httpGet:
28+
path: /healthz
29+
port: healthcheck
30+
initialDelaySeconds: 3
31+
periodSeconds: 3
32+
readinessProbe:
33+
httpGet:
34+
path: /readyz
35+
port: healthcheck
36+
initialDelaySeconds: 3
37+
periodSeconds: 3
2338
env:
2439
- name: WATCH_NAMESPACE
2540
valueFrom:

0 commit comments

Comments
 (0)