-
Notifications
You must be signed in to change notification settings - Fork 52
/
_helpers.tpl
127 lines (117 loc) · 3.76 KB
/
_helpers.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{{/*
Expand the name of the chart.
*/}}
{{- define "zitadel.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "zitadel.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "zitadel.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "zitadel.labels" -}}
helm.sh/chart: {{ include "zitadel.chart" . }}
{{ include "zitadel.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "zitadel.selectorLabels" -}}
app.kubernetes.io/name: {{ include "zitadel.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "zitadel.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "zitadel.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Create copy command or empty string
*/}}
{{- define "zitadel.makecpcommand" -}}
{{- if .value -}}
{{ printf "cp -r %s /chowned-secrets/" .path }}
{{- end -}}
{{- end -}}
{{/*
Join copy commands
*/}}
{{- define "zitadel.joincpcommands" -}}
{{- $cmd := "" }}
{{- range .commands -}}
{{- if . -}}
{{- $cmd = printf "%s && %s" ( default "yes" . ) $cmd -}}
{{- end -}}
{{- end -}}
{{ print $cmd }}
{{- end -}}
{{/*
Returns true if the full path is defined and the value at the end of the path is not empty
*/}}
{{- define "deepCheck" -}}
{{- if empty .root -}}
{{/* Break early */}}
{{- else if eq (len .path) 0 -}}
{{- not (empty .root) -}}
{{- else -}}
{{- $head := index .path 0 -}}
{{- $tail := slice .path 1 (len .path) -}}
{{- if hasKey .root $head -}}
{{- include "deepCheck" (dict "root" (index .root $head) "path" $tail) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Returns the database config from the secreConfig or else from the configmapConfig
*/}}
{{- define "zitadel.dbconfig.json" -}}
{{- if include "deepCheck" (dict "root" . "path" (splitList "." "Values.zitadel.secretConfig.Database")) -}}
{{- .Values.zitadel.secretConfig.Database | toJson -}}
{{- else if include "deepCheck" (dict "root" . "path" (splitList "." "Values.zitadel.configmapConfig.Database")) -}}
{{- .Values.zitadel.configmapConfig.Database | toJson -}}
{{- else -}}
{{- dict | toJson -}}
{{- end -}}
{{- end -}}
{{/*
Returns a dict with the databases key in the yaml and the environment variable part, either COCKROACH or POSTGRES, in uppercase letters.
*/}}
{{- define "zitadel.dbkey.json" -}}
{{- range $i, $key := (include "zitadel.dbconfig.json" . | fromJson | keys ) -}}
{{- if or (eq (lower $key) "postgres" ) (eq (lower $key) "pg" ) -}}
{"key": "{{ $key }}", "env": "POSTGRES" }
{{- else if or (eq (lower $key) "cockroach" ) (eq (lower $key) "crdb" ) -}}
{"key": "{{ $key }}", "env": "COCKROACH" }
{{- end -}}
{{- end -}}
{{- end -}}