|
| 1 | +{{/* vim: set filetype=mustache: */}} |
| 2 | +{{/* |
| 3 | +Expand the name of the chart. |
| 4 | +*/}} |
| 5 | +{{- define "patroni.name" -}} |
| 6 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} |
| 7 | +{{- end -}} |
| 8 | + |
| 9 | +{{/* |
| 10 | +Create a default fully qualified app name. |
| 11 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 12 | +If release name contains chart name it will be used as a full name. |
| 13 | +*/}} |
| 14 | +{{- define "patroni.fullname" -}} |
| 15 | +{{- if .Values.fullnameOverride -}} |
| 16 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} |
| 17 | +{{- else -}} |
| 18 | +{{- $name := default .Chart.Name .Values.nameOverride -}} |
| 19 | +{{- if contains $name .Release.Name -}} |
| 20 | +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} |
| 21 | +{{- else -}} |
| 22 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} |
| 23 | +{{- end -}} |
| 24 | +{{- end -}} |
| 25 | +{{- end -}} |
| 26 | + |
| 27 | +{{/* |
| 28 | +Create chart name and version as used by the chart label. |
| 29 | +*/}} |
| 30 | +{{- define "patroni.chart" -}} |
| 31 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} |
| 32 | +{{- end -}} |
| 33 | + |
| 34 | +{{/* |
| 35 | +Create the name of the service account to use. |
| 36 | +*/}} |
| 37 | +{{- define "patroni.serviceAccountName" -}} |
| 38 | +{{- if .Values.serviceAccount.create -}} |
| 39 | + {{ default (include "patroni.fullname" .) .Values.serviceAccount.name }} |
| 40 | +{{- else -}} |
| 41 | + {{ default "default" .Values.serviceAccount.name }} |
| 42 | +{{- end -}} |
| 43 | +{{- end -}} |
| 44 | + |
| 45 | +{{/* |
| 46 | +Return true if a cronjob object should be created for Postgresql HA patroni ## TODO feature |
| 47 | +*/}} |
| 48 | +{{- define "patroni.createCronJob" -}} |
| 49 | +{{- if and .Values.backup.enabled }} |
| 50 | + {{- true -}} |
| 51 | +{{- else -}} |
| 52 | +{{- end -}} |
| 53 | +{{- end -}} |
| 54 | + |
| 55 | +{{/* |
| 56 | +Return true if a cronjob object should be created for Postgresql HA patroni ## TODO feature |
| 57 | +*/}} |
| 58 | +{{- define "patroni.createLogicalBackupCronJob" -}} |
| 59 | +{{- if and .Values.logicalbackup.enabled }} |
| 60 | + {{- true -}} |
| 61 | +{{- else -}} |
| 62 | +{{- end -}} |
| 63 | +{{- end -}} |
| 64 | + |
| 65 | +{{/* |
| 66 | +Return true if a configmap object should be created for Postgresql HA patroni |
| 67 | +*/}} |
| 68 | +{{- define "patroni.createConfigmap" -}} |
| 69 | +{{- if and .Values.preInitScript }} |
| 70 | + {{- true -}} |
| 71 | +{{- else -}} |
| 72 | +{{- end -}} |
| 73 | +{{- end -}} |
| 74 | + |
| 75 | +{{/* |
| 76 | +Create patroni envs. |
| 77 | +*/}} |
| 78 | +{{- define "patroni.envs" }} |
| 79 | +{{- if .Values.kubernetes.configmaps.enable }} |
| 80 | +- name: KUBERNETES_USE_CONFIGMAPS |
| 81 | + value: "true" |
| 82 | +{{- end }} |
| 83 | +{{- if .Values.kubernetes.endpoints.enable }} |
| 84 | +- name: PATRONI_KUBERNETES_USE_ENDPOINTS |
| 85 | + value: 'true' |
| 86 | +{{- end }} |
| 87 | +- name: PATRONI_KUBERNETES_POD_IP |
| 88 | + valueFrom: |
| 89 | + fieldRef: |
| 90 | + fieldPath: status.podIP |
| 91 | +- name: PATRONI_KUBERNETES_NAMESPACE |
| 92 | + valueFrom: |
| 93 | + fieldRef: |
| 94 | + fieldPath: metadata.namespace |
| 95 | +- name: PATRONI_KUBERNETES_BYPASS_API_SERVICE |
| 96 | + value: 'true' |
| 97 | +- name: PATRONI_KUBERNETES_LABELS |
| 98 | + value: '{application: {{ template "patroni.fullname" . }},release: {{ .Release.Name }},cluster-name: {{ template "patroni.fullname" . }}}' |
| 99 | +- name: PATRONI_SUPERUSER_USERNAME |
| 100 | + value: postgres |
| 101 | +- name: PATRONI_SUPERUSER_PASSWORD |
| 102 | + valueFrom: |
| 103 | + secretKeyRef: |
| 104 | + name: {{ template "patroni.fullname" . }} |
| 105 | + key: password-superuser |
| 106 | +- name: PATRONI_REPLICATION_USERNAME |
| 107 | + value: standby |
| 108 | +- name: PATRONI_REPLICATION_PASSWORD |
| 109 | + valueFrom: |
| 110 | + secretKeyRef: |
| 111 | + name: {{ template "patroni.fullname" . }} |
| 112 | + key: password-replication |
| 113 | +- name: PATRONI_REWIND_USERNAME |
| 114 | + value: rewinder |
| 115 | +- name: PATRONI_REWIND_PASSWORD |
| 116 | + valueFrom: |
| 117 | + secretKeyRef: |
| 118 | + name: {{ template "patroni.fullname" . }} |
| 119 | + key: password-rewind |
| 120 | +- name: ADMIN_USER |
| 121 | + valueFrom: |
| 122 | + secretKeyRef: |
| 123 | + name: {{ template "patroni.fullname" . }} |
| 124 | + key: admin-user |
| 125 | +- name: ADMIN_PASSWORD |
| 126 | + valueFrom: |
| 127 | + secretKeyRef: |
| 128 | + name: {{ template "patroni.fullname" . }} |
| 129 | + key: admin-password |
| 130 | +- name: PATRONI_SCOPE |
| 131 | + value: {{ template "patroni.fullname" . }} |
| 132 | +- name: PATRONI_NAME |
| 133 | + valueFrom: |
| 134 | + fieldRef: |
| 135 | + fieldPath: metadata.name |
| 136 | +- name: PATRONI_POSTGRESQL_DATA_DIR |
| 137 | + value: "{{ .Values.persistentVolume.mountPath }}/data" |
| 138 | +- name: PGDATA |
| 139 | + value: "{{ .Values.persistentVolume.mountPath }}/data" |
| 140 | +- name: PATRONI_POSTGRESQL_PGPASS |
| 141 | + value: /tmp/pgpass |
| 142 | +- name: PATRONI_POSTGRESQL_LISTEN |
| 143 | + value: '0.0.0.0:5432' |
| 144 | +- name: PATRONI_RESTAPI_LISTEN |
| 145 | + value: '0.0.0.0:8008' |
| 146 | +{{- end -}} |
| 147 | + |
| 148 | +{{/* |
| 149 | +Return true if a configmap object should be created for PG backup. |
| 150 | +*/}} |
| 151 | +{{- define "backup.createConfigmap" -}} |
| 152 | +{{- if and .Values.backup.enabled }} |
| 153 | + {{- true -}} |
| 154 | +{{- else -}} |
| 155 | +{{- end -}} |
| 156 | +{{- end -}} |
| 157 | + |
| 158 | +{{/* |
| 159 | +Generate random password |
| 160 | +*/}} |
| 161 | + |
| 162 | +{{/* |
| 163 | +Get the super user password ; |
| 164 | +*/}} |
| 165 | +{{- define "credentials.superuserValue" }} |
| 166 | +{{- if .Values.credentials.superuser }} |
| 167 | + {{- .Values.credentials.superuser -}} |
| 168 | +{{- else -}} |
| 169 | + {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 10 "Key" "password-superuser") -}} |
| 170 | +{{- end -}} |
| 171 | +{{- end }} |
| 172 | + |
| 173 | +{{/* |
| 174 | +Get the rewind password ; |
| 175 | +*/}} |
| 176 | +{{- define "credentials.rewindValue" }} |
| 177 | +{{- if .Values.credentials.rewind }} |
| 178 | + {{- .Values.credentials.rewind -}} |
| 179 | +{{- else -}} |
| 180 | + {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 10 "Key" "password-rewind") -}} |
| 181 | +{{- end -}} |
| 182 | +{{- end }} |
| 183 | + |
| 184 | +{{/* |
| 185 | +Get the replication password ; |
| 186 | +*/}} |
| 187 | +{{- define "credentials.replicationValue" }} |
| 188 | +{{- if .Values.credentials.replication }} |
| 189 | + {{- .Values.credentials.replication -}} |
| 190 | +{{- else -}} |
| 191 | + {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 10 "Key" "password-replication") -}} |
| 192 | +{{- end -}} |
| 193 | +{{- end }} |
| 194 | + |
| 195 | +{{/* |
| 196 | +Get the administrator password ; |
| 197 | +*/}} |
| 198 | +{{- define "adminRole.passwordValue" }} |
| 199 | +{{- if .Values.adminRole.password }} |
| 200 | + {{- .Values.adminRole.password -}} |
| 201 | +{{- else -}} |
| 202 | + {{- include "getValueFromSecret" (dict "Namespace" .Release.Namespace "Name" (include "common.names.fullname" .) "Length" 10 "Key" "admin-password") -}} |
| 203 | +{{- end -}} |
| 204 | +{{- end }} |
| 205 | + |
| 206 | +{{/* |
| 207 | +Returns the available value for certain key in an existing secret (if it exists), |
| 208 | +otherwise it generates a random value. |
| 209 | +*/}} |
| 210 | +{{- define "getValueFromSecret" }} |
| 211 | +{{- $len := (default 16 .Length) | int -}} |
| 212 | +{{- $obj := (lookup "v1" "Secret" .Namespace .Name).data -}} |
| 213 | +{{- if $obj }} |
| 214 | +{{- index $obj .Key | b64dec -}} |
| 215 | +{{- else -}} |
| 216 | +{{- randAlphaNum $len -}} |
| 217 | +{{- end -}} |
| 218 | +{{- end }} |
| 219 | + |
0 commit comments