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

     1  {{/* vim: set filetype=mustache: */}}
     2  {{/*
     3  Validate MariaDB required passwords are not empty.
     4  
     5  Usage:
     6  {{ include "common.validations.values.mariadb.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
     7  Params:
     8    - secret - String - Required. Name of the secret where MariaDB values are stored, e.g: "mysql-passwords-secret"
     9    - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
    10  */}}
    11  {{- define "common.validations.values.mariadb.passwords" -}}
    12    {{- $existingSecret := include "common.mariadb.values.auth.existingSecret" . -}}
    13    {{- $enabled := include "common.mariadb.values.enabled" . -}}
    14    {{- $architecture := include "common.mariadb.values.architecture" . -}}
    15    {{- $authPrefix := include "common.mariadb.values.key.auth" . -}}
    16    {{- $valueKeyRootPassword := printf "%s.rootPassword" $authPrefix -}}
    17    {{- $valueKeyUsername := printf "%s.username" $authPrefix -}}
    18    {{- $valueKeyPassword := printf "%s.password" $authPrefix -}}
    19    {{- $valueKeyReplicationPassword := printf "%s.replicationPassword" $authPrefix -}}
    20  
    21    {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
    22      {{- $requiredPasswords := list -}}
    23  
    24      {{- $requiredRootPassword := dict "valueKey" $valueKeyRootPassword "secret" .secret "field" "mariadb-root-password" -}}
    25      {{- $requiredPasswords = append $requiredPasswords $requiredRootPassword -}}
    26  
    27      {{- $valueUsername := include "common.utils.getValueFromKey" (dict "key" $valueKeyUsername "context" .context) }}
    28      {{- if not (empty $valueUsername) -}}
    29          {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "mariadb-password" -}}
    30          {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
    31      {{- end -}}
    32  
    33      {{- if (eq $architecture "replication") -}}
    34          {{- $requiredReplicationPassword := dict "valueKey" $valueKeyReplicationPassword "secret" .secret "field" "mariadb-replication-password" -}}
    35          {{- $requiredPasswords = append $requiredPasswords $requiredReplicationPassword -}}
    36      {{- end -}}
    37  
    38      {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
    39  
    40    {{- end -}}
    41  {{- end -}}
    42  
    43  {{/*
    44  Auxiliary function to get the right value for existingSecret.
    45  
    46  Usage:
    47  {{ include "common.mariadb.values.auth.existingSecret" (dict "context" $) }}
    48  Params:
    49    - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
    50  */}}
    51  {{- define "common.mariadb.values.auth.existingSecret" -}}
    52    {{- if .subchart -}}
    53      {{- .context.Values.mariadb.auth.existingSecret | quote -}}
    54    {{- else -}}
    55      {{- .context.Values.auth.existingSecret | quote -}}
    56    {{- end -}}
    57  {{- end -}}
    58  
    59  {{/*
    60  Auxiliary function to get the right value for enabled mariadb.
    61  
    62  Usage:
    63  {{ include "common.mariadb.values.enabled" (dict "context" $) }}
    64  */}}
    65  {{- define "common.mariadb.values.enabled" -}}
    66    {{- if .subchart -}}
    67      {{- printf "%v" .context.Values.mariadb.enabled -}}
    68    {{- else -}}
    69      {{- printf "%v" (not .context.Values.enabled) -}}
    70    {{- end -}}
    71  {{- end -}}
    72  
    73  {{/*
    74  Auxiliary function to get the right value for architecture
    75  
    76  Usage:
    77  {{ include "common.mariadb.values.architecture" (dict "subchart" "true" "context" $) }}
    78  Params:
    79    - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
    80  */}}
    81  {{- define "common.mariadb.values.architecture" -}}
    82    {{- if .subchart -}}
    83      {{- .context.Values.mariadb.architecture -}}
    84    {{- else -}}
    85      {{- .context.Values.architecture -}}
    86    {{- end -}}
    87  {{- end -}}
    88  
    89  {{/*
    90  Auxiliary function to get the right value for the key auth
    91  
    92  Usage:
    93  {{ include "common.mariadb.values.key.auth" (dict "subchart" "true" "context" $) }}
    94  Params:
    95    - subchart - Boolean - Optional. Whether MariaDB is used as subchart or not. Default: false
    96  */}}
    97  {{- define "common.mariadb.values.key.auth" -}}
    98    {{- if .subchart -}}
    99      mariadb.auth
   100    {{- else -}}
   101      auth
   102    {{- end -}}
   103  {{- end -}}