github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/kafka/charts/common/templates/validations/_postgresql.tpl (about) 1 {{/* vim: set filetype=mustache: */}} 2 {{/* 3 Validate PostgreSQL required passwords are not empty. 4 5 Usage: 6 {{ include "common.validations.values.postgresql.passwords" (dict "secret" "secretName" "subchart" false "context" $) }} 7 Params: 8 - secret - String - Required. Name of the secret where postgresql values are stored, e.g: "postgresql-passwords-secret" 9 - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false 10 */}} 11 {{- define "common.validations.values.postgresql.passwords" -}} 12 {{- $existingSecret := include "common.postgresql.values.existingSecret" . -}} 13 {{- $enabled := include "common.postgresql.values.enabled" . -}} 14 {{- $valueKeyPostgresqlPassword := include "common.postgresql.values.key.postgressPassword" . -}} 15 {{- $valueKeyPostgresqlReplicationEnabled := include "common.postgresql.values.key.replicationPassword" . -}} 16 {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") -}} 17 {{- $requiredPasswords := list -}} 18 {{- $requiredPostgresqlPassword := dict "valueKey" $valueKeyPostgresqlPassword "secret" .secret "field" "postgresql-password" -}} 19 {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlPassword -}} 20 21 {{- $enabledReplication := include "common.postgresql.values.enabled.replication" . -}} 22 {{- if (eq $enabledReplication "true") -}} 23 {{- $requiredPostgresqlReplicationPassword := dict "valueKey" $valueKeyPostgresqlReplicationEnabled "secret" .secret "field" "postgresql-replication-password" -}} 24 {{- $requiredPasswords = append $requiredPasswords $requiredPostgresqlReplicationPassword -}} 25 {{- end -}} 26 27 {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}} 28 {{- end -}} 29 {{- end -}} 30 31 {{/* 32 Auxiliary function to decide whether evaluate global values. 33 34 Usage: 35 {{ include "common.postgresql.values.use.global" (dict "key" "key-of-global" "context" $) }} 36 Params: 37 - key - String - Required. Field to be evaluated within global, e.g: "existingSecret" 38 */}} 39 {{- define "common.postgresql.values.use.global" -}} 40 {{- if .context.Values.global -}} 41 {{- if .context.Values.global.postgresql -}} 42 {{- index .context.Values.global.postgresql .key | quote -}} 43 {{- end -}} 44 {{- end -}} 45 {{- end -}} 46 47 {{/* 48 Auxiliary function to get the right value for existingSecret. 49 50 Usage: 51 {{ include "common.postgresql.values.existingSecret" (dict "context" $) }} 52 */}} 53 {{- define "common.postgresql.values.existingSecret" -}} 54 {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "existingSecret" "context" .context) -}} 55 56 {{- if .subchart -}} 57 {{- default (.context.Values.postgresql.existingSecret | quote) $globalValue -}} 58 {{- else -}} 59 {{- default (.context.Values.existingSecret | quote) $globalValue -}} 60 {{- end -}} 61 {{- end -}} 62 63 {{/* 64 Auxiliary function to get the right value for enabled postgresql. 65 66 Usage: 67 {{ include "common.postgresql.values.enabled" (dict "context" $) }} 68 */}} 69 {{- define "common.postgresql.values.enabled" -}} 70 {{- if .subchart -}} 71 {{- printf "%v" .context.Values.postgresql.enabled -}} 72 {{- else -}} 73 {{- printf "%v" (not .context.Values.enabled) -}} 74 {{- end -}} 75 {{- end -}} 76 77 {{/* 78 Auxiliary function to get the right value for the key postgressPassword. 79 80 Usage: 81 {{ include "common.postgresql.values.key.postgressPassword" (dict "subchart" "true" "context" $) }} 82 Params: 83 - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false 84 */}} 85 {{- define "common.postgresql.values.key.postgressPassword" -}} 86 {{- $globalValue := include "common.postgresql.values.use.global" (dict "key" "postgresqlUsername" "context" .context) -}} 87 88 {{- if not $globalValue -}} 89 {{- if .subchart -}} 90 postgresql.postgresqlPassword 91 {{- else -}} 92 postgresqlPassword 93 {{- end -}} 94 {{- else -}} 95 global.postgresql.postgresqlPassword 96 {{- end -}} 97 {{- end -}} 98 99 {{/* 100 Auxiliary function to get the right value for enabled.replication. 101 102 Usage: 103 {{ include "common.postgresql.values.enabled.replication" (dict "subchart" "true" "context" $) }} 104 Params: 105 - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false 106 */}} 107 {{- define "common.postgresql.values.enabled.replication" -}} 108 {{- if .subchart -}} 109 {{- printf "%v" .context.Values.postgresql.replication.enabled -}} 110 {{- else -}} 111 {{- printf "%v" .context.Values.replication.enabled -}} 112 {{- end -}} 113 {{- end -}} 114 115 {{/* 116 Auxiliary function to get the right value for the key replication.password. 117 118 Usage: 119 {{ include "common.postgresql.values.key.replicationPassword" (dict "subchart" "true" "context" $) }} 120 Params: 121 - subchart - Boolean - Optional. Whether postgresql is used as subchart or not. Default: false 122 */}} 123 {{- define "common.postgresql.values.key.replicationPassword" -}} 124 {{- if .subchart -}} 125 postgresql.replication.password 126 {{- else -}} 127 replication.password 128 {{- end -}} 129 {{- end -}}