Skip to content

Commit

Permalink
Merge pull request #21 from hensur/add-probes-api
Browse files Browse the repository at this point in the history
add probes API
  • Loading branch information
jkmw authored Apr 15, 2020
2 parents c00f101 + 2188f56 commit ca7252e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
22 changes: 19 additions & 3 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"runtime"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"strings"

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

// Set default manager options
options := manager.Options{
MapperProvider: restMapper,
Namespace: namespace,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
MapperProvider: restMapper,
Namespace: namespace,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
HealthProbeBindAddress: ":8080",
}

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

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

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

log.Info("Registering Components.")

// Setup Scheme for all resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: {{ toYaml .Values.args | nindent 12 }}
ports:
- containerPort: 8080
name: healthcheck
livenessProbe:
httpGet:
path: /healthz
port: healthcheck
initialDelaySeconds: 3
periodSeconds: 3
readinessProbe:
httpGet:
path: /readyz
port: healthcheck
initialDelaySeconds: 3
periodSeconds: 3
env:
- name: WATCH_NAMESPACE
value: {{ .Values.watchNamespace }}
Expand All @@ -53,5 +68,5 @@ spec:
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- toYaml . | nindent 8 }}
{{- end }}
15 changes: 15 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ spec:
command:
- kubernetes-secret-generator
imagePullPolicy: Always
ports:
- containerPort: 8080
name: healthcheck
livenessProbe:
httpGet:
path: /healthz
port: healthcheck
initialDelaySeconds: 3
periodSeconds: 3
readinessProbe:
httpGet:
path: /readyz
port: healthcheck
initialDelaySeconds: 3
periodSeconds: 3
env:
- name: WATCH_NAMESPACE
valueFrom:
Expand Down

0 comments on commit ca7252e

Please sign in to comment.