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

     1  
     2  {{/* vim: set filetype=mustache: */}}
     3  {{/*
     4  Validate Redis® required passwords are not empty.
     5  
     6  Usage:
     7  {{ include "common.validations.values.redis.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
     8  Params:
     9    - secret - String - Required. Name of the secret where redis values are stored, e.g: "redis-passwords-secret"
    10    - subchart - Boolean - Optional. Whether redis is used as subchart or not. Default: false
    11  */}}
    12  {{- define "common.validations.values.redis.passwords" -}}
    13    {{- $enabled := include "common.redis.values.enabled" . -}}
    14    {{- $valueKeyPrefix := include "common.redis.values.keys.prefix" . -}}
    15    {{- $standarizedVersion := include "common.redis.values.standarized.version" . }}
    16  
    17    {{- $existingSecret := ternary (printf "%s%s" $valueKeyPrefix "auth.existingSecret") (printf "%s%s" $valueKeyPrefix "existingSecret") (eq $standarizedVersion "true") }}
    18    {{- $existingSecretValue := include "common.utils.getValueFromKey" (dict "key" $existingSecret "context" .context) }}
    19  
    20    {{- $valueKeyRedisPassword := ternary (printf "%s%s" $valueKeyPrefix "auth.password") (printf "%s%s" $valueKeyPrefix "password") (eq $standarizedVersion "true") }}
    21    {{- $valueKeyRedisUseAuth := ternary (printf "%s%s" $valueKeyPrefix "auth.enabled") (printf "%s%s" $valueKeyPrefix "usePassword") (eq $standarizedVersion "true") }}
    22  
    23    {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}}
    24      {{- $requiredPasswords := list -}}
    25  
    26      {{- $useAuth := include "common.utils.getValueFromKey" (dict "key" $valueKeyRedisUseAuth "context" .context) -}}
    27      {{- if eq $useAuth "true" -}}
    28        {{- $requiredRedisPassword := dict "valueKey" $valueKeyRedisPassword "secret" .secret "field" "redis-password" -}}
    29        {{- $requiredPasswords = append $requiredPasswords $requiredRedisPassword -}}
    30      {{- end -}}
    31  
    32      {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
    33    {{- end -}}
    34  {{- end -}}
    35  
    36  {{/*
    37  Auxiliary function to get the right value for enabled redis.
    38  
    39  Usage:
    40  {{ include "common.redis.values.enabled" (dict "context" $) }}
    41  */}}
    42  {{- define "common.redis.values.enabled" -}}
    43    {{- if .subchart -}}
    44      {{- printf "%v" .context.Values.redis.enabled -}}
    45    {{- else -}}
    46      {{- printf "%v" (not .context.Values.enabled) -}}
    47    {{- end -}}
    48  {{- end -}}
    49  
    50  {{/*
    51  Auxiliary function to get the right prefix path for the values
    52  
    53  Usage:
    54  {{ include "common.redis.values.key.prefix" (dict "subchart" "true" "context" $) }}
    55  Params:
    56    - subchart - Boolean - Optional. Whether redis is used as subchart or not. Default: false
    57  */}}
    58  {{- define "common.redis.values.keys.prefix" -}}
    59    {{- if .subchart -}}redis.{{- else -}}{{- end -}}
    60  {{- end -}}
    61  
    62  {{/*
    63  Checks whether the redis chart's includes the standarizations (version >= 14)
    64  
    65  Usage:
    66  {{ include "common.redis.values.standarized.version" (dict "context" $) }}
    67  */}}
    68  {{- define "common.redis.values.standarized.version" -}}
    69  
    70    {{- $standarizedAuth := printf "%s%s" (include "common.redis.values.keys.prefix" .) "auth" -}}
    71    {{- $standarizedAuthValues := include "common.utils.getValueFromKey" (dict "key" $standarizedAuth "context" .context) }}
    72  
    73    {{- if $standarizedAuthValues -}}
    74      {{- true -}}
    75    {{- end -}}
    76  {{- end -}}