-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path_helpers.tpl
314 lines (288 loc) · 13.5 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
{{/* Validation for secretKeyRef to avoid conflicting secret names with secrets created by controllers */}}
{{- define "codefresh-gitops-runtime.secret-name-validation"}}
{{- $reservedSecretNames := list "codefresh-token" }}
{{- if has .name $reservedSecretNames }}
{{- fail (printf "%s is a reserved name and is not allowed. Please use a different secret name" .name) }}
{{- end }}
{{- end }}
{{/*
Expand the name of the chart.
*/}}
{{- define "codefresh-gitops-runtime.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 "codefresh-gitops-runtime.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 "codefresh-gitops-runtime.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "codefresh-gitops-runtime.labels" -}}
helm.sh/chart: {{ include "codefresh-gitops-runtime.chart" . }}
{{ include "codefresh-gitops-runtime.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: codefresh-gitops-runtime
{{- end }}
{{/*
Selector labels
*/}}
{{- define "codefresh-gitops-runtime.selectorLabels" -}}
app: "codefresh-gitops-runtime"
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "codefresh-gitops-runtime.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "codefresh-gitops-runtime.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{- define "codefresh-gitops-runtime.installation-token-secret-name" }}
{{- print "codefresh-user-token" }}
{{- end }}
{{/*
Determine argocd server service name. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.argocd.server.servicename" -}}
{{/* For now use template from ArgoCD chart until better approach */}}
{{- template "argo-cd.server.fullname" (dict "Values" (get .Values "argo-cd")) }}
{{- end }}
{{/*
Determine argocd repo server service name. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.argocd.reposerver.servicename" -}}
{{/* For now use template from ArgoCD chart until better approach */}}
{{- template "argo-cd.repoServer.fullname" (dict "Values" (get .Values "argo-cd")) }}
{{- end }}
{{/*
Determine argocd argocd repo server port
*/}}
{{- define "codefresh-gitops-runtime.argocd.reposerver.serviceport" -}}
{{/* For now use template from ArgoCD chart until better approach */}}
{{- index .Values "argo-cd" "repoServer" "service" "port" }}
{{- end }}
{{/*
Determine argocd servicename. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.argocd.appcontroller.serviceAccountName" -}}
{{/* For now use template from ArgoCD chart until better approach */}}
{{- template "argo-cd.controllerServiceAccountName" (dict "Values" (get .Values "argo-cd")) }}
{{- end }}
{{/*
Determine rollouts name
*/}}
{{- define "codefresh-gitops-runtime.argo-rollouts.name" -}}
{{/* For now use template from rollouts chart until better approach */}}
{{- template "argo-rollouts.fullname" (dict "Values" (get .Values "argo-rollouts")) }}
{{- end }}
{{/*
Determine argocd server service port. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.argocd.server.serviceport" -}}
{{- $argoCDValues := (get .Values "argo-cd") }}
{{- $port := 443 }}
{{- if hasKey $argoCDValues "configs" }}
{{- if hasKey $argoCDValues.configs "params" }}
{{- if hasKey $argoCDValues.configs.params "server.insecure" }}
{{- if (get $argoCDValues.configs.params "server.insecure") }}
{{- $port = 80 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- print $port }}
{{- end}}
{{/*
Determine argocd server url. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.argocd.server.url" -}}
{{- $protocol := "https" }}
{{- $port := include "codefresh-gitops-runtime.argocd.server.serviceport" . }}
{{- if (eq $port "80") }}
{{- $protocol = "http" }}
{{- end }}
{{- $url := include "codefresh-gitops-runtime.argocd.server.no-protocol-url" . }}
{{- printf "%s://%s" $protocol $url }}
{{- end}}
{{/*
Determine argocd server url witout the protocol. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.argocd.server.no-protocol-url" -}}
{{- $argoCDValues := (get .Values "argo-cd") }}
{{- $serverName := include "codefresh-gitops-runtime.argocd.server.servicename" . }}
{{- $port := include "codefresh-gitops-runtime.argocd.server.serviceport" . }}
{{- $path := (get $argoCDValues.configs.params "server.rootpath") }}
{{- printf "%s:%s%s" $serverName $port $path }}
{{- end}}
{{/*
Determine argo worklofws server name
*/}}
{{- define "codefresh-gitops-runtime.argo-workflows.server.name" -}}
{{/* For now use template from argo worklow chart until better approach */}}
{{- template "argo-workflows.server.fullname" (dict "Values" (get .Values "argo-workflows")) }}
{{- end }}
{{/*
Determine argo workflows server url. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.argo-workflows.server.url" -}}
{{- $protocol := "http" }}
{{- if index (get .Values "argo-workflows") "server" "secure" }}
{{- $protocol = "https" }}
{{- end -}}
{{/* For now use template from Argo workflows chart until better approach */}}
{{- printf "%s://%s:2746" $protocol (include "codefresh-gitops-runtime.argo-workflows.server.name" .) }}
{{- end }}
{{/*
Determine app proxy url. Must be called with chart root context
*/}}
{{- define "codefresh-gitops-runtime.app-proxy.url" -}}
{{/* Using templates from app-proxy */}}
{{- printf "http://%s:%s" (include "cap-app-proxy.fullname" (dict "Values" (get .Values "app-proxy"))) (index (get .Values "app-proxy") "service" "port" | toString ) }}
{{- end }}
{{/*
Environemnt variable value of Codefresh installation token
*/}}
{{- define "codefresh-gitops-runtime.installation-token-env-var-value" -}}
{{- if .Values.global.codefresh.userToken.token }}
valueFrom:
secretKeyRef:
name: {{ include "codefresh-gitops-runtime.installation-token-secret-name" . }}
key: token
optional: true
{{- else if .Values.global.codefresh.userToken.secretKeyRef }}
{{- include "codefresh-gitops-runtime.secret-name-validation" .Values.global.codefresh.userToken.secretKeyRef }}
valueFrom:
secretKeyRef:
{{- .Values.global.codefresh.userToken.secretKeyRef | toYaml | nindent 4 }}
{{- else }}
{{- fail "global.codefresh.userToken is mandatory. Set token or secretKeyRef!" }}
{{- end }}
{{- end }}
{{/*
Get ingress url for both tunnel based and ingress based runtimes
*/}}
{{- define "codefresh-gitops-runtime.ingress-url"}}
{{- $supportedProtocols := list "http" "https" }}
{{- if .Values.global.runtime.ingress.enabled }}
{{- if has .Values.global.runtime.ingress.protocol $supportedProtocols }}
{{- printf "%s://%s" .Values.global.runtime.ingress.protocol (index .Values.global.runtime.ingress.hosts 0)}}
{{- else }}
{{ fail (printf "ERROR: Unsupported protocol %s for ingress. Only http and https supported" .Values.global.runtime.ingress.protocol)}}
{{- end }}
{{/* If tunnel client is enabled - ingress url is <accoundId>-<runtimename>.<tunnel-subdomain> */}}
{{- else if index .Values "tunnel-client" "enabled" }}
{{- $accoundId := required "global.codefresh.accountId is required for tunnel based runtime" .Values.global.codefresh.accountId }}
{{- $runtimeName := required "global.runtime.name is required for tunnel based runtime" .Values.global.runtime.name }}
{{- $tunnelPrefix := printf "%s-%s" .Values.global.codefresh.accountId .Values.global.runtime.name }}
{{- $tunnelHost := index (get .Values "tunnel-client") "tunnelServer" "subdomainHost"}}
{{- printf "https://%s.%s" $tunnelPrefix $tunnelHost }}
{{- else }}
{{/* If ingress is disabled and tunnel-client is disabled, the ingressHost must be explicitly defined in the values*/}}
{{- if .Values.global.runtime.ingressUrl }}
{{- if or (hasPrefix "http" .Values.global.runtime.ingressUrl) (hasPrefix "https" .Values.global.runtime.ingressUrl)}}
{{- print .Values.global.runtime.ingressUrl }}
{{- else }}
{{- fail "ERROR: Only http and https are supported for global.runtime.ingressUrl"}}
{{- end }}
{{- else }}
{{- fail "ERROR: When global.runtime.ingress.enabled is false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Output comma separated list of installed runtime components
*/}}
{{- define "codefresh-gitops-runtime.component-list"}}
{{- $argoCD := dict "name" "argocd" "version" (get .Subcharts "argo-cd").Chart.AppVersion }}
{{- $argoEvents := dict "name" "argo-events" "version" (get .Subcharts "argo-events").Chart.AppVersion }}
{{- $internalRouter := dict "name" "internal-router" "version" .Chart.AppVersion }}
{{- $appProxy := dict "name" "app-proxy" "version" (index (get .Values "app-proxy") "image" "tag") }}
{{- $comptList := list $argoCD $argoEvents $appProxy $internalRouter}}
{{- if index (get .Values "sealed-secrets") "enabled" }}
{{- $sealedSecrets := dict "name" "sealed-secrets" "version" (get .Subcharts "sealed-secrets").Chart.AppVersion }}
{{- $comptList = append $comptList $sealedSecrets }}
{{- end }}
{{- if index (get .Values "argo-rollouts") "enabled" }}
{{- $rolloutReporter := dict "name" "rollout-reporter" "version" .Chart.AppVersion }}
{{- $argoRollouts := dict "name" "argo-rollouts" "version" (get .Subcharts "argo-rollouts").Chart.AppVersion }}
{{- $comptList = append $comptList $argoRollouts }}
{{- $comptList = append $comptList $rolloutReporter }}
{{- end }}
{{- if index (get .Values "argo-workflows") "enabled" }}
{{- $workflowReporter := dict "name" "workflow-reporter" "version" .Chart.AppVersion }}
{{- $argoWorkflows := dict "name" "argo-workflows" "version" (get .Subcharts "argo-workflows").Chart.AppVersion }}
{{- $comptList = append $comptList $workflowReporter}}
{{- $comptList = append $comptList $argoWorkflows }}
{{- end }}
{{- if and ( not .Values.global.runtime.ingress.enabled) (index .Values "tunnel-client" "enabled") }}
{{- $tunnelClient := dict "name" "codefresh-tunnel-client" "version" (get .Subcharts "tunnel-client").Chart.AppVersion }}
{{- $comptList = append $comptList $tunnelClient }}
{{- end }}
{{- if index (get .Values "gitops-operator") "enabled" }}
{{- $gitopsOperator := dict "name" "gitops-operator" "version" (get .Subcharts "gitops-operator").Chart.AppVersion }}
{{- $comptList = append $comptList $gitopsOperator }}
{{- end }}
{{- $comptList | toYaml }}
{{- end }}
# ------------------------------------------------------------------------------------------------------------
# runtime git credentials
# ------------------------------------------------------------------------------------------------------------
{{- define "codefresh-gitops-runtime.runtime-gitcreds.password.default-secret-name" }}
{{- printf "%s-git-password" .Values.global.runtime.name }}
{{- end }}
{{- define "codefresh-gitops-runtime.runtime-gitcreds.password.secretname" }}
{{- if .Values.global.runtime.gitCredentials.password.value}}
{{- include "codefresh-gitops-runtime.runtime-gitcreds.password.default-secret-name" . }}
{{- else if .Values.global.runtime.gitCredentials.password.secretKeyRef }}
{{- if hasKey .Values.global.runtime.gitCredentials.password.secretKeyRef "name" }}
{{- include "codefresh-gitops-runtime.secret-name-validation" .Values.global.runtime.gitCredentials.password.secretKeyRef }}
{{- print .Values.global.runtime.gitCredentials.password.secretKeyRef.name }}
{{- else }}
{{ fail "secretKeyRef for global.runtime.gitCredentials.password illegal - must have name field"}}
{{- end }}
{{- end }}
{{- end }}
{{- define "codefresh-gitops-runtime.runtime-gitcreds.password.secretkey" }}
{{- if .Values.global.runtime.gitCredentials.password.value}}
{{- print "password" }}
{{- else if .Values.global.runtime.gitCredentials.password.secretKeyRef }}
{{- if hasKey .Values.global.runtime.gitCredentials.password.secretKeyRef "key" }}
{{- print .Values.global.runtime.gitCredentials.password.secretKeyRef.key }}
{{- else }}
{{ fail "secretKeyRef for global.runtime.gitCredentials.password illegal - must have key field"}}
{{- end }}
{{- end }}
{{- end }}
{{- define "codefresh-gitops-runtime.runtime-gitcreds.password.env-var-value"}}
valueFrom:
secretKeyRef:
name: {{ include "codefresh-gitops-runtime.runtime-gitcreds.password.secretname" . }}
key: {{ include "codefresh-gitops-runtime.runtime-gitcreds.password.secretkey" . }}
optional: true
{{- end }}
# ------------------------------------------------------------------------------------------------------------