sylva-units: reuse _internal.previous_values in more places

follow-up to !2510 (comment 1968564096)

we could reuse _internal.previous_values in these places:

    is_ha: >-
      {{
      lookup "v1" "Secret" .Release.Namespace "sylva-units-values"
        | dig "data" "values" "" | b64dec | fromYaml | default dict
        | dig "_internal" "ha_cluster" "is_ha" (ge (int .Values.cluster.control_plane_replicas) 3 | ternary true false)
        | include "preserve-type"
      }}
    checkpoint: >-
      {{- $current_config := lookup "v1" "Secret" .Release.Namespace "sylva-units-values" | dig "data" "values" "" | b64dec | fromYaml | default dict -}}
{{/*

internalPersistentRandomPasswd 

This named template produces a random password that does not change when the sylva-units Helm release
is updated. This is ensured by storing the password in the "sylva-units-values" Secret and looking
up in this Secret if the password was already generated, before generating a fresh random one.

usage (in values):

  _internal:
     my_password: '{{ include "persistentRandomPasswd" "my_password" }}

NOTE WELL:
* this can be done only under '_internal'
* the named template parameter MUST MATCH the key used under _internal

*/}}
{{- define "internalPersistentRandomPasswd" -}}
{{- $envAll := index . 0 -}}
{{- $key := index . 1 -}}
{{- lookup "v1" "Secret" $envAll.Release.Namespace "sylva-units-values" | dig "data" "values" "" | b64dec | fromYaml | dig "_internal" $key (randAlphaNum 64) -}}
{{- end -}}

/cc @feleouet @baburciu @aseitz

Edited Jun 11, 2025 by Thomas Morin
Assignee Loading
Time tracking Loading