-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path_helpers.tpl
277 lines (254 loc) · 8.13 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "ztka.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels.
*/}}
{{- define "ztka.labels" -}}
helm.sh/chart: {{ include "ztka.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/part-of: paralus
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.additionalLabels }}
{{ toYaml .Values.additionalLabels }}
{{- end }}
{{- end }}
{{- define "ztka.kratos.hooks.labels" -}}
helm.sh/chart: {{ include "ztka.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/component: kratos
app.kubernetes.io/part-of: paralus
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels.
*/}}
{{- define "ztka.selectorLabels" -}}
app.kubernetes.io/name: {{ .image.name }}
app.kubernetes.io/instance: {{ .release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "ztka.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-") .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Validate storage options
*/}}
{{- define "ztka.auditlogStorage" -}}
{{- if eq .Values.auditLogs.storage "database" -}}
database
{{- else if eq .Values.auditLogs.storage "elasticsearch" -}}
elasticsearch
{{- else -}}
{{ required "A valid .Values.auditLogs.storage entry required!" .Values.auditLogs.storage }}
{{- end -}}
{{- end}}
{{/*
Get Kratos public address.
*/}}
{{- define "ztka.kratos.publicAddr" -}}
{{- if .Values.deploy.kratos.enable -}}
http://{{.Release.Name}}-kratos-public
{{- else -}}
{{ required "A valid .Values.deploy.kratos.publicAddr entry required!" .Values.deploy.kratos.publicAddr }}
{{- end -}}
{{- end }}
{{/*
Get Kratos admin address.
*/}}
{{- define "ztka.kratos.adminAddr" -}}
{{- if .Values.deploy.kratos.enable -}}
http://{{.Release.Name}}-kratos-admin
{{- else -}}
{{ required "A valid .Values.deploy.kratos.adminAddr entry required!" .Values.deploy.kratos.adminAddr }}
{{- end -}}
{{- end }}
{{/*
Get Elasticsearch Address.
*/}}
{{- define "ztka.esAddr" -}}
{{- if eq .Values.auditLogs.storage "elasticsearch" -}}
{{- if .Values.deploy.elasticsearch.enable -}}
http://elasticsearch-master:9200
{{- else -}}
{{ required "A valid .Values.deploy.elasticsearch.address entry required!" .Values.deploy.elasticsearch.address }}
{{- end -}}
{{- end -}}
{{- end }}
{{/*
Get DB Address.
*/}}
{{- define "ztka.dbAddr" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Release.Name}}-postgresql.{{.Release.Namespace}}.svc.cluster.local
{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.address entry required!" .Values.deploy.postgresql.address }}
{{- end -}}
{{- end }}
{{/*
Get DB Username.
*/}}
{{- define "ztka.dbUser" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Values.postgresql.auth.username}}
{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.username entry required!" .Values.deploy.postgresql.username }}
{{- end -}}
{{- end }}
{{/*
Get DB Password.
*/}}
{{- define "ztka.dbPassword" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Values.postgresql.auth.password}}
{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.password entry required!" .Values.deploy.postgresql.password }}
{{- end -}}
{{- end }}
{{/*
Get DB Name.
*/}}
{{- define "ztka.dbName" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Values.postgresql.auth.database}}
{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.database entry required!" .Values.deploy.postgresql.database }}
{{- end -}}
{{- end }}
{{/*
Get DSN
*/}}
{{- define "ztka.dsn" -}}
{{- if .Values.deploy.postgresql.enable -}}
postgres://{{ .Values.postgresql.auth.username }}:{{ .Values.postgresql.auth.password }}@{{.Release.Name}}-postgresql.{{.Release.Namespace}}.svc.cluster.local:5432/{{ .Values.postgresql.auth.database }}?sslmode=disable
{{- else if .Values.deploy.postgresql.dsn -}}
{{ .Values.deploy.postgresql.dsn }}
{{- else -}}
{{- $username := required "A valid .Values.deploy.postgresql.username entry required!" .Values.deploy.postgresql.username -}}
{{- $password := required "A valid .Values.deploy.postgresql.password entry required!" .Values.deploy.postgresql.password -}}
{{- $address := required "A valid .Values.deploy.postgresql.address entry required!" .Values.deploy.postgresql.address -}}
{{- $database := required "A valid .Values.deploy.postgresql.database entry required!" .Values.deploy.postgresql.database -}}
postgres://{{ $username }}:{{ $password }}@{{ $address }}:5432/{{ $database }}?sslmode=disable
{{- end -}}
{{- end }}
{{/*
External Secrets Environment Variables
*/}}
{{- define "ztka.externalSecretsEnv" -}}
- name: DB_ADDR
valueFrom:
secretKeyRef:
name: {{ .Values.deploy.postgresql.existingSecret.name }}
key: {{ .Values.deploy.postgresql.existingSecret.keys.address | default "DB_ADDR" }}
- name: DB_USER
valueFrom:
secretKeyRef:
name: {{ .Values.deploy.postgresql.existingSecret.name }}
key: {{ .Values.deploy.postgresql.existingSecret.keys.username | default "DB_USER" }}
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.deploy.postgresql.existingSecret.name }}
key: {{ .Values.deploy.postgresql.existingSecret.keys.password | default "DB_PASSWORD" }}
- name: DB_NAME
valueFrom:
secretKeyRef:
name: {{ .Values.deploy.postgresql.existingSecret.name }}
key: {{ .Values.deploy.postgresql.existingSecret.keys.database | default "DB_NAME" }}
- name: DSN
valueFrom:
secretKeyRef:
name: {{ .Values.deploy.postgresql.existingSecret.name }}
key: {{ .Values.deploy.postgresql.existingSecret.keys.dsn | default "DSN" }}
{{- end }}
{{/*
Get console full-qualified domain.
*/}}
{{- define "ztka.consoleFQDN" -}}
{{.Values.fqdn.hostname}}.{{.Values.fqdn.domain}}
{{- end -}}
{{/*
Get console full-qualified domain with scheme.
*/}}
{{- define "ztka.consoleFQDNWithScheme" -}}
{{- $url := printf "%s.%s" .Values.fqdn.hostname .Values.fqdn.domain -}}
{{- if .Values.deploy.contour.enable -}}
{{- if .Values.deploy.contour.tls -}}
https://{{$url}}
{{- else -}}
http://{{$url}}
{{- end -}}
{{- else if .Values.ingress.enabled -}}
{{- if .Values.ingress.tls -}}
https://{{$url}}
{{- else -}}
http://{{$url}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Get console full-qualified domain with port.
*/}}
{{- define "ztka.consoleFQDNWithPort" -}}
{{- $url := printf "%s.%s" .Values.fqdn.hostname .Values.fqdn.domain -}}
{{- if .Values.deploy.contour.enable -}}
{{- if .Values.deploy.contour.tls -}}
{{$url}}:443
{{- else -}}
{{$url}}:80
{{- end -}}
{{- else if .Values.ingress.enabled -}}
{{- if .Values.ingress.tls -}}
{{$url}}:443
{{- else -}}
{{$url}}:80
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Get core-connector full-qualified domain.
*/}}
{{- define "ztka.coreConnectorFQDN" -}}
{{.Values.fqdn.coreConnectorSubdomain}}.{{.Values.fqdn.domain}}
{{- end -}}
{{/*
TCP port for connection.
*/}}
{{- define "ztka.tcpPort" -}}
{{- $tcpPort := 443 -}}
{{- if and $.Values.contour.envoy.hostPorts .Values.contour.envoy.hostPorts.https -}}
{{- $tcpPort = .Values.contour.envoy.hostPorts.https -}}
{{- end -}}
{{ $tcpPort }}
{{- end -}}
{{/*
Get user full-qualified domain.
*/}}
{{- define "ztka.userFQDN" -}}
{{.Values.fqdn.userSubdomain}}.{{.Values.fqdn.domain}}
{{- end -}}
{{/*
Get paralus service with port that is endpoint for kratos after login webhook.
*/}}
{{- define "ztka.afterLoginWebhookWithPort" -}}
{{ $url := "http://localhost:11000"}}
{{- range .Values.services.paralus.ports -}}
{{- if eq .name "http" -}}
{{- $url = printf "http://%s:%.0f" $.Values.services.paralus.name .containerPort -}}
{{- end -}}
{{- end -}}
{{ $url }}
{{- end -}}