Skip to content

Commit

Permalink
Fix registrationToken regenerated every time helm template is executed
Browse files Browse the repository at this point in the history
Signed-off-by: Erwan Vallienne <[email protected]>
  • Loading branch information
erwanval committed Dec 9, 2024
1 parent 3688567 commit ac3a6c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions charts/crowdsec/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/}}
Expand Down
2 changes: 1 addition & 1 deletion charts/crowdsec/templates/lapi-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit ac3a6c4

Please sign in to comment.