From ac3a6c4013b48105156d90da157b643d6e133889 Mon Sep 17 00:00:00 2001 From: Erwan Vallienne Date: Mon, 9 Dec 2024 17:53:29 +0100 Subject: [PATCH] Fix registrationToken regenerated every time helm template is executed Signed-off-by: Erwan Vallienne --- charts/crowdsec/templates/_helpers.tpl | 14 ++++++++++++++ charts/crowdsec/templates/lapi-secrets.yaml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/charts/crowdsec/templates/_helpers.tpl b/charts/crowdsec/templates/_helpers.tpl index 08c2c1f..ee873ea 100644 --- a/charts/crowdsec/templates/_helpers.tpl +++ b/charts/crowdsec/templates/_helpers.tpl @@ -15,6 +15,20 @@ Generate CS_LAPI_SECRET if not specified in values {{- end -}} {{- end -}} +{{/* +Generate REGISTRATION_TOKEN if not specified in values +*/}} +{{ define "lapi.registrationToken" }} +{{- if .Values.lapi.secrets.registrationToken }} + {{- .Values.lapi.secrets.registrationToken -}} +{{- else if (lookup "v1" "Secret" .Release.Namespace "crowdsec-lapi-secrets").data }} + {{- $obj := (lookup "v1" "Secret" .Release.Namespace "crowdsec-lapi-secrets").data -}} + {{- index $obj "registrationToken" | b64dec -}} +{{- else -}} + {{- randAlphaNum 48 | b64enc -}} +{{- end -}} +{{- end -}} + {{/* notifications parameters check */}} diff --git a/charts/crowdsec/templates/lapi-secrets.yaml b/charts/crowdsec/templates/lapi-secrets.yaml index 67efe1d..c0a3fe6 100644 --- a/charts/crowdsec/templates/lapi-secrets.yaml +++ b/charts/crowdsec/templates/lapi-secrets.yaml @@ -12,7 +12,7 @@ metadata: type: Opaque data: csLapiSecret: {{ include "lapi.csLapiSecret" . | b64enc }} - registrationToken: {{ randAlphaNum 48 | b64enc }} + registrationToken: {{ include "lapi.registrationToken" . | b64enc }} {{- with .Values.lapi.extraSecrets }} {{- range $key, $value := . }} {{ $key }}: {{ $value | b64enc }}