Skip to content

Commit 37a303c

Browse files
authored
[elasticsearch] do not regenerate certs when they already exists (#1691)
This commit update the way we generate the Elasticsearch certs to lookup if the certs secret already exists and reuse the secrets instead of regenerate the certs. This fix the issue when upgrading from a previous version of the chart that doesn't include the certs secret by ensuring that the certs secret is created if it doesn't exists. This method also add more flexibility than charts hooks by ensuring that the certs won't be rotated each time we upgrade the chart. Found in https://stackoverflow.com/a/61715870
1 parent ff9c8ab commit 37a303c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

elasticsearch/templates/_helpers.tpl

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
2828
{{- end -}}
2929

3030
{{/*
31-
Generate certificates
31+
Generate certificates when the secret doesn't exist
3232
*/}}
3333
{{- define "elasticsearch.gen-certs" -}}
34+
{{- $certs := lookup "v1" "Secret" .Release.Namespace ( printf "%s-certs" (include "elasticsearch.uname" . ) ) -}}
35+
{{- if $certs -}}
36+
tls.crt: {{ index $certs.data "tls.crt" }}
37+
tls.key: {{ index $certs.data "tls.key" }}
38+
ca.crt: {{ index $certs.data "ca.crt" }}
39+
{{- else -}}
3440
{{- $altNames := list ( include "elasticsearch.masterService" . ) ( printf "%s.%s" (include "elasticsearch.masterService" .) .Release.Namespace ) ( printf "%s.%s.svc" (include "elasticsearch.masterService" .) .Release.Namespace ) -}}
3541
{{- $ca := genCA "elasticsearch-ca" 365 -}}
3642
{{- $cert := genSignedCert ( include "elasticsearch.masterService" . ) nil $altNames 365 $ca -}}
3743
tls.crt: {{ $cert.Cert | toString | b64enc }}
3844
tls.key: {{ $cert.Key | toString | b64enc }}
3945
ca.crt: {{ $ca.Cert | toString | b64enc }}
4046
{{- end -}}
47+
{{- end -}}
4148
4249
{{- define "elasticsearch.masterService" -}}
4350
{{- if empty .Values.masterService -}}

elasticsearch/templates/secret-cert.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ metadata:
99
chart: "{{ .Chart.Name }}"
1010
heritage: {{ .Release.Service }}
1111
release: {{ .Release.Name }}
12-
annotations:
13-
"helm.sh/hook": "pre-install"
14-
"helm.sh/hook-delete-policy": "before-hook-creation"
1512
data:
1613
{{ ( include "elasticsearch.gen-certs" . ) | indent 2 }}
1714
{{- end }}

0 commit comments

Comments
 (0)