Skip to content

Commit

Permalink
[nats helm] fix healthz liveness/readiness probes (#613)
Browse files Browse the repository at this point in the history
* [nats helm] fix healthz liveness/readiness probes

Signed-off-by: Caleb Lloyd <[email protected]>

* bump chart version

Signed-off-by: Caleb Lloyd <[email protected]>

* paramaterize healthzStartupEndpoint

Signed-off-by: Caleb Lloyd <[email protected]>

Signed-off-by: Caleb Lloyd <[email protected]>
  • Loading branch information
caleblloyd committed Dec 9, 2022
1 parent ae2eab6 commit 1b7b596
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion helm/charts/nats/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords:
- nats
- messaging
- cncf
version: 0.19.2
version: 0.19.3
home: http://github.com/nats-io/k8s
maintainers:
- name: Waldemar Quevedo
Expand Down
25 changes: 19 additions & 6 deletions helm/charts/nats/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ spec:
{{- $serverVersion := .Values.nats.image.tag | regexFind "\\d+(\\.\\d+)?(\\.\\d+)?" | default "2.9.0" }}
{{- $enableHealthzStartup := and .Values.nats.healthcheck.enableHealthz (or (not .Values.nats.healthcheck.detectHealthz) (semverCompare ">=2.7.1" $serverVersion)) }}
{{- $enableHealthzLivenessReadiness := and .Values.nats.healthcheck.enableHealthzLivenessReadiness (or (not .Values.nats.healthcheck.detectHealthz) (semverCompare ">=2.9.0" $serverVersion)) }}
{{- $healthzStartupEndpoint := "/healthz" }}
{{- $healthzLivenessEndpoint := "/healthz?js-enabled-only=true" }}
{{- $healthzReadinessEndpoint := "/healthz?js-server-only=true" }}

{{- /* healthz options behaved differently in 2.9.0 - 2.9.9 https://github.com/nats-io/nats-server/pull/3704 */}}
{{- if (semverCompare "<=2.9.9" $serverVersion) }}
{{- $healthzLivenessEndpoint = "/healthz?js-server-only=true" }}
{{- $healthzReadinessEndpoint = "/healthz?js-server-only=true" }}
{{- if .Values.nats.jetstream.enabled }}
{{- $healthzLivenessEndpoint = print $healthzLivenessEndpoint "&js-enabled=true" }}
{{- $healthzReadinessEndpoint = print $healthzReadinessEndpoint "&js-enabled=true" }}
{{- end }}
{{- end }}

{{- with .Values.nats.healthcheck.liveness }}
{{- if .enabled }}
Expand All @@ -431,9 +444,9 @@ spec:
{{- $_ := unset $probe "enabled" }}
{{- $probeDefault := dict "httpGet" (dict "path" "/" "port" 8222) }}
{{- if $enableHealthzLivenessReadiness }}
# for NATS server versions >=2.9.0, /healthz?js-enabled=true will be enabled
# for NATS server versions >=2.9.0, {{ $healthzLivenessEndpoint }} will be enabled
# liveness probe checks that the JS server is enabled
{{- $_ := set $probeDefault.httpGet "path" "/healthz?js-enabled=true" }}
{{- $_ := set $probeDefault.httpGet "path" $healthzLivenessEndpoint }}
{{- end }}
{{- $probe := merge $probe $probeDefault }}
{{- toYaml $probe | nindent 10}}
Expand All @@ -447,9 +460,9 @@ spec:
{{- $_ := unset $probe "enabled" }}
{{- $probeDefault := dict "httpGet" (dict "path" "/" "port" 8222) }}
{{- if $enableHealthzLivenessReadiness }}
# for NATS server versions >=2.9.0, /healthz?js-server-only=true will be enabled
# for NATS server versions >=2.9.0, {{ $healthzReadinessEndpoint }} will be enabled
# readiness probe checks that the JS server is enabled, and is current with the meta leader
{{- $_ := set $probeDefault.httpGet "path" "/healthz?js-server-only=true" }}
{{- $_ := set $probeDefault.httpGet "path" $healthzReadinessEndpoint }}
{{- end }}
{{- $probe := merge $probe $probeDefault }}
{{- toYaml $probe | nindent 10}}
Expand All @@ -463,10 +476,10 @@ spec:
{{- $_ := unset $probe "enabled" }}
{{- $probeDefault := dict "httpGet" (dict "path" "/" "port" 8222) }}
{{- if $enableHealthzStartup }}
# for NATS server versions >=2.7.1, /healthz will be enabled
# for NATS server versions >=2.7.1, {{ $healthzStartupEndpoint}} will be enabled
# startup probe checks that the JS server is enabled, is current with the meta leader,
# and that all streams and consumers assigned to this JS server are current
{{- $_ := set $probeDefault.httpGet "path" "/healthz" }}
{{- $_ := set $probeDefault.httpGet "path" $healthzStartupEndpoint }}
{{- end }}
{{- $probe := merge $probe $probeDefault }}
{{- toYaml $probe | nindent 10}}
Expand Down

0 comments on commit 1b7b596

Please sign in to comment.