|
| 1 | +{{/* Chart name */}} |
| 2 | +{{- define "cogstack-postgresql.name" -}} |
| 3 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} |
| 4 | +{{- end -}} |
| 5 | + |
| 6 | +{{/* Fully qualified name */}} |
| 7 | +{{- define "cogstack-postgresql.fullname" -}} |
| 8 | +{{- if .Values.fullnameOverride -}} |
| 9 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} |
| 10 | +{{- else -}} |
| 11 | +{{- $name := default .Chart.Name .Values.nameOverride -}} |
| 12 | +{{- if contains $name .Release.Name -}} |
| 13 | +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} |
| 14 | +{{- else -}} |
| 15 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} |
| 16 | +{{- end -}} |
| 17 | +{{- end -}} |
| 18 | +{{- end -}} |
| 19 | + |
| 20 | +{{/* Common labels */}} |
| 21 | +{{- define "cogstack-postgresql.labels" -}} |
| 22 | +helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" }} |
| 23 | +app.kubernetes.io/name: {{ include "cogstack-postgresql.name" . }} |
| 24 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 25 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 26 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 27 | +{{- end -}} |
| 28 | + |
| 29 | +{{/* Application credentials secret name */}} |
| 30 | +{{- define "cogstack-postgresql.appSecretName" -}} |
| 31 | +{{- if .Values.credentials.existingAppSecret -}} |
| 32 | +{{- .Values.credentials.existingAppSecret -}} |
| 33 | +{{- else -}} |
| 34 | +{{- printf "%s-app" (include "cogstack-postgresql.fullname" .) -}} |
| 35 | +{{- end -}} |
| 36 | +{{- end -}} |
| 37 | + |
| 38 | +{{/* Bootstrap SQL configmap name */}} |
| 39 | +{{- define "cogstack-postgresql.initdbConfigMapName" -}} |
| 40 | +{{- printf "%s-initdb" (include "cogstack-postgresql.fullname" .) -}} |
| 41 | +{{- end -}} |
| 42 | + |
| 43 | +{{/* Normalize docker-style memory strings to Kubernetes quantities */}} |
| 44 | +{{- define "cogstack-postgresql.normalizeMemory" -}} |
| 45 | +{{- $value := toString . | trim -}} |
| 46 | +{{- if regexMatch "^[0-9]+g$" $value -}} |
| 47 | +{{- printf "%sGi" (trimSuffix "g" $value) -}} |
| 48 | +{{- else if regexMatch "^[0-9]+m$" $value -}} |
| 49 | +{{- printf "%sMi" (trimSuffix "m" $value) -}} |
| 50 | +{{- else if regexMatch "^[0-9]+k$" $value -}} |
| 51 | +{{- printf "%sKi" (trimSuffix "k" $value) -}} |
| 52 | +{{- else -}} |
| 53 | +{{- $value -}} |
| 54 | +{{- end -}} |
| 55 | +{{- end -}} |
| 56 | + |
| 57 | +{{/* Parse deploy/database.env into a filtered YAML map */}} |
| 58 | +{{- define "cogstack-postgresql.parsedEnvFile" -}} |
| 59 | +{{- $root := . -}} |
| 60 | +{{- $envData := dict -}} |
| 61 | +{{- $rawEnv := $root.Values.envFile.raw | default ($root.Files.Get "files/deploy-database.envfile") -}} |
| 62 | +{{- if $rawEnv -}} |
| 63 | +{{- $renderedEnv := tpl $rawEnv $root -}} |
| 64 | +{{- range $line := splitList "\n" $renderedEnv }} |
| 65 | + {{- $clean := trim (replace "\r" "" $line) -}} |
| 66 | + {{- if and $clean (not (hasPrefix "#" $clean)) -}} |
| 67 | + {{- if regexMatch "^[A-Za-z_][A-Za-z0-9_]*=" $clean -}} |
| 68 | + {{- $key := regexFind "^[A-Za-z_][A-Za-z0-9_]*" $clean -}} |
| 69 | + {{- $val := trim (regexReplaceAll "^[A-Za-z_][A-Za-z0-9_]*=" $clean "") -}} |
| 70 | + {{- if has $key $root.Values.envFile.includeKeys -}} |
| 71 | + {{- if and (hasPrefix "\"" $val) (hasSuffix "\"" $val) -}} |
| 72 | + {{- $val = trimSuffix "\"" (trimPrefix "\"" $val) -}} |
| 73 | + {{- else if and (hasPrefix "'" $val) (hasSuffix "'" $val) -}} |
| 74 | + {{- $val = trimSuffix "'" (trimPrefix "'" $val) -}} |
| 75 | + {{- end -}} |
| 76 | + {{- if regexMatch "^\\$[A-Za-z_][A-Za-z0-9_]*$" $val -}} |
| 77 | + {{- $refKey := trimPrefix "$" $val -}} |
| 78 | + {{- if hasKey $envData $refKey -}} |
| 79 | + {{- $val = index $envData $refKey -}} |
| 80 | + {{- end -}} |
| 81 | + {{- end -}} |
| 82 | + {{- $_ := set $envData $key $val -}} |
| 83 | + {{- end -}} |
| 84 | + {{- end -}} |
| 85 | + {{- end -}} |
| 86 | +{{- end -}} |
| 87 | +{{- end -}} |
| 88 | +{{ toYaml $envData }} |
| 89 | +{{- end -}} |
| 90 | + |
| 91 | +{{/* Parse security/env/users_database.env into a filtered YAML map */}} |
| 92 | +{{- define "cogstack-postgresql.parsedUsersEnvFile" -}} |
| 93 | +{{- $root := . -}} |
| 94 | +{{- $usersData := dict -}} |
| 95 | +{{- $rawUsers := $root.Values.usersEnvFile.raw | default ($root.Files.Get "files/users-database.envfile") -}} |
| 96 | +{{- if $rawUsers -}} |
| 97 | +{{- $renderedUsers := tpl $rawUsers $root -}} |
| 98 | +{{- range $line := splitList "\n" $renderedUsers }} |
| 99 | + {{- $clean := trim (replace "\r" "" $line) -}} |
| 100 | + {{- if and $clean (not (hasPrefix "#" $clean)) -}} |
| 101 | + {{- if regexMatch "^[A-Za-z_][A-Za-z0-9_]*=" $clean -}} |
| 102 | + {{- $key := regexFind "^[A-Za-z_][A-Za-z0-9_]*" $clean -}} |
| 103 | + {{- $val := trim (regexReplaceAll "^[A-Za-z_][A-Za-z0-9_]*=" $clean "") -}} |
| 104 | + {{- if has $key $root.Values.usersEnvFile.includeKeys -}} |
| 105 | + {{- if and (hasPrefix "\"" $val) (hasSuffix "\"" $val) -}} |
| 106 | + {{- $val = trimSuffix "\"" (trimPrefix "\"" $val) -}} |
| 107 | + {{- else if and (hasPrefix "'" $val) (hasSuffix "'" $val) -}} |
| 108 | + {{- $val = trimSuffix "'" (trimPrefix "'" $val) -}} |
| 109 | + {{- end -}} |
| 110 | + {{- $_ := set $usersData $key $val -}} |
| 111 | + {{- end -}} |
| 112 | + {{- end -}} |
| 113 | + {{- end -}} |
| 114 | +{{- end -}} |
| 115 | +{{- end -}} |
| 116 | +{{ toYaml $usersData }} |
| 117 | +{{- end -}} |
0 commit comments