github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/kafka/charts/common/templates/validations/_cassandra.tpl (about)

     1  {{/* vim: set filetype=mustache: */}}
     2  {{/*
     3  Validate Cassandra required passwords are not empty.
     4  
     5  Usage:
     6  {{ include "common.validations.values.cassandra.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
     7  Params:
     8    - secret - String - Required. Name of the secret where Cassandra values are stored, e.g: "cassandra-passwords-secret"
     9    - subchart - Boolean - Optional. Whether Cassandra is used as subchart or not. Default: false
    10  */}}
    11  {{- define "common.validations.values.cassandra.passwords" -}}
    12    {{- $existingSecret := include "common.cassandra.values.existingSecret" . -}}
    13    {{- $enabled := include "common.cassandra.values.enabled" . -}}
    14    {{- $dbUserPrefix := include "common.cassandra.values.key.dbUser" . -}}
    15    {{- $valueKeyPassword := printf "%s.password" $dbUserPrefix -}}
    16  
    17    {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
    18      {{- $requiredPasswords := list -}}
    19  
    20      {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "cassandra-password" -}}
    21      {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
    22  
    23      {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
    24  
    25    {{- end -}}
    26  {{- end -}}
    27  
    28  {{/*
    29  Auxiliary function to get the right value for existingSecret.
    30  
    31  Usage:
    32  {{ include "common.cassandra.values.existingSecret" (dict "context" $) }}
    33  Params:
    34    - subchart - Boolean - Optional. Whether Cassandra is used as subchart or not. Default: false
    35  */}}
    36  {{- define "common.cassandra.values.existingSecret" -}}
    37    {{- if .subchart -}}
    38      {{- .context.Values.cassandra.dbUser.existingSecret | quote -}}
    39    {{- else -}}
    40      {{- .context.Values.dbUser.existingSecret | quote -}}
    41    {{- end -}}
    42  {{- end -}}
    43  
    44  {{/*
    45  Auxiliary function to get the right value for enabled cassandra.
    46  
    47  Usage:
    48  {{ include "common.cassandra.values.enabled" (dict "context" $) }}
    49  */}}
    50  {{- define "common.cassandra.values.enabled" -}}
    51    {{- if .subchart -}}
    52      {{- printf "%v" .context.Values.cassandra.enabled -}}
    53    {{- else -}}
    54      {{- printf "%v" (not .context.Values.enabled) -}}
    55    {{- end -}}
    56  {{- end -}}
    57  
    58  {{/*
    59  Auxiliary function to get the right value for the key dbUser
    60  
    61  Usage:
    62  {{ include "common.cassandra.values.key.dbUser" (dict "subchart" "true" "context" $) }}
    63  Params:
    64    - subchart - Boolean - Optional. Whether Cassandra is used as subchart or not. Default: false
    65  */}}
    66  {{- define "common.cassandra.values.key.dbUser" -}}
    67    {{- if .subchart -}}
    68      cassandra.dbUser
    69    {{- else -}}
    70      dbUser
    71    {{- end -}}
    72  {{- end -}}