github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/postgresql/templates/_helpers.tpl (about) 1 {{/* 2 Expand the name of the chart. 3 */}} 4 {{- define "postgresql.name" -}} 5 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} 6 {{- end }} 7 8 {{/* 9 Create a default fully qualified app name. 10 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 11 If release name contains chart name it will be used as a full name. 12 */}} 13 {{- define "postgresql.fullname" -}} 14 {{- if .Values.fullnameOverride }} 15 {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} 16 {{- else }} 17 {{- $name := default .Chart.Name .Values.nameOverride }} 18 {{- if contains $name .Release.Name }} 19 {{- .Release.Name | trunc 63 | trimSuffix "-" }} 20 {{- else }} 21 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} 22 {{- end }} 23 {{- end }} 24 {{- end }} 25 26 {{/* 27 Create chart name and version as used by the chart label. 28 */}} 29 {{- define "postgresql.chart" -}} 30 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} 31 {{- end }} 32 33 {{/* 34 Common labels 35 */}} 36 {{- define "postgresql.labels" -}} 37 helm.sh/chart: {{ include "postgresql.chart" . }} 38 {{ include "postgresql.selectorLabels" . }} 39 {{- if .Chart.AppVersion }} 40 app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 41 {{- end }} 42 app.kubernetes.io/managed-by: {{ .Release.Service }} 43 {{- end }} 44 45 {{/* 46 Selector labels 47 */}} 48 {{- define "postgresql.selectorLabels" -}} 49 app.kubernetes.io/name: {{ include "postgresql.name" . }} 50 app.kubernetes.io/instance: {{ .Release.Name }} 51 {{- end }} 52 53 {{/* 54 Create the name of the service account to use 55 */}} 56 {{- define "postgresql.serviceAccountName" -}} 57 {{- if .Values.serviceAccount.create }} 58 {{- default (include "postgresql.fullname" .) .Values.serviceAccount.name }} 59 {{- else }} 60 {{- default "default" .Values.serviceAccount.name }} 61 {{- end }} 62 {{- end }} 63 64 {{/* 65 Return true if a configmap object should be created for PostgreSQL primary with the configuration 66 */}} 67 {{- define "postgresql.primary.createConfigmap" -}} 68 {{- if and (or .Values.primary.configuration .Values.primary.pgHbaConfiguration) (not .Values.primary.existingConfigmap) }} 69 {{- true -}} 70 {{- else -}} 71 {{- end -}} 72 {{- end -}} 73 74 {{/* 75 Return PostgreSQL service port 76 */}} 77 {{- define "postgresql.service.port" -}} 78 {{- .Values.primary.service.ports.postgresql -}} 79 {{- end -}} 80 81 {{/* 82 Return the name for a custom database to create 83 */}} 84 {{- define "postgresql.database" -}} 85 {{- .Values.auth.database -}} 86 {{- end -}} 87 88 {{/* 89 Get the password key. 90 */}} 91 {{/* TODO: use $(RANDOM_PASSWD) instead */}} 92 {{- define "postgresql.postgresPassword" -}} 93 {{- if or (.Release.IsInstall) (not (lookup "apps.kubeblocks.io/v1alpha1" "ClusterDefinition" "" "postgresql")) -}} 94 {{ .Values.auth.postgresPassword | default (randAlphaNum 10) }} 95 {{- else -}} 96 {{ index (lookup "apps.kubeblocks.io/v1alpha1" "ClusterDefinition" "" "postgresql").spec.connectionCredential "password"}} 97 {{- end }} 98 {{- end }} 99 100 {{/* 101 Generate scripts configmap 102 */}} 103 {{- define "postgresql.extend.scripts" -}} 104 {{- range $path, $_ := $.Files.Glob "scripts/**" }} 105 {{ $path | base }}: |- 106 {{- $.Files.Get $path | nindent 2 }} 107 {{- end }} 108 {{- end }} 109 110 {{/* 111 Check if cluster version is enabled, if enabledClusterVersions is empty, return true, 112 otherwise, check if the cluster version is in the enabledClusterVersions list, if yes, return true, 113 else return false. 114 Parameters: cvName, values 115 */}} 116 {{- define "postgresql.isClusterVersionEnabled" -}} 117 {{- $cvName := .cvName -}} 118 {{- $enabledClusterVersions := .values.enabledClusterVersions -}} 119 {{- if eq (len $enabledClusterVersions) 0 -}} 120 {{- true -}} 121 {{- else -}} 122 {{- range $enabledClusterVersions -}} 123 {{- if eq $cvName . -}} 124 {{- true -}} 125 {{- end -}} 126 {{- end -}} 127 {{- end -}} 128 {{- end -}}