-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_helpers.tpl
301 lines (275 loc) · 12.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
{{/*
Expand the name of the chart.
*/}}
{{- define "flink-job.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 "flink-job.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | 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 "flink-job.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end -}}
{{/*
Builds the image identifier with either sha or tag
*/}}
{{- define "flink-job.image" -}}
{{- $repository := coalesce .Values.global.image.repository .Values.image.repository }}
{{- if .Values.image.sha }}
{{- printf "%s@sha256:%s" $repository .Values.image.sha }}
{{- else }}
{{- printf "%s:%s" $repository (.Values.image.tag | toString) }}
{{- end }}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "flink-job.labels" -}}
helm.sh/chart: {{ include "flink-job.chart" . }}
{{ include "flink-job.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.Version | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{/*
Selector labels
*/}}
{{- define "flink-job.selectorLabels" -}}
app.kubernetes.io/name: {{ include "flink-job.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{/*
Pod labels
*/}}
{{- define "flink-job.podLabels" -}}
{{ include "flink-job.labels" . }}
app.kubernetes.io/component: metrics
backstage.io/kubernetes-id: {{ .Release.Name }}
{{ with .Values.metrics.serviceMonitor.selectors -}}
{{- toYaml . }}
{{- end }}
{{ with .Values.podLabels -}}
{{- toYaml . }}
{{- end }}
{{- end -}}
{{/*
Pod annotations
*/}}
{{- define "flink-job.podAnnotations" -}}
{{- with .Values.podAnnotations }}
{{- toYaml . }}
{{- end }}
{{ include "flink-job.backstageTopicAnnotations" . }}
{{- end -}}
{{/*
Taskmanager Pod annotations
*/}}
{{- define "flink-job.taskManagerPodAnnotations" -}}
{{- with .Values.taskManager.podAnnotations }}
{{- toYaml . }}
{{- end }}
{{- if .Values.istio.enabled }}
{{- if not (hasKey .Values.taskManager.podAnnotations "traffic.sidecar.istio.io/excludeOutboundPorts")}}
traffic.sidecar.istio.io/excludeOutboundPorts: "6123,6124,41475"
{{- end -}}
{{- if not (hasKey .Values.taskManager.podAnnotations "traffic.sidecar.istio.io/excludeInboundPorts")}}
traffic.sidecar.istio.io/excludeInboundPorts: "6122,6124,34101,41475"
{{- end -}}
{{- end }}
{{- end -}}
{{/*
Jobmanager Pod annotations
*/}}
{{- define "flink-job.jobManagerPodAnnotations" -}}
{{- with .Values.jobManager.podAnnotations }}
{{- toYaml . }}
{{- end }}
{{- if .Values.istio.enabled }}
{{- if not (hasKey .Values.jobManager.podAnnotations "traffic.sidecar.istio.io/excludeOutboundPorts")}}
traffic.sidecar.istio.io/excludeOutboundPorts: "6122,6123,6124,34101,41475"
{{- end -}}
{{- if not (hasKey .Values.jobManager.podAnnotations "traffic.sidecar.istio.io/excludeInboundPorts")}}
traffic.sidecar.istio.io/excludeInboundPorts: "6123,6124,34101,41475"
{{- end -}}
{{- end }}
{{- end -}}
{{/*
Create the name of the FlinkDeployment resource
Needed to make sure that resource names does not surpass the character requirements
*/}}
{{- define "flink-job.flinkDeploymentName" -}}
{{ include "flink-job.fullname" . | trunc 45 }}
{{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "flink-job.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "flink-job.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end -}}
{{- define "flink-job.backstageTopicAnnotations" -}}
{{- $inputs := "" -}}
{{- $outputs := "" -}}
{{- range .Values.job.topics -}}
{{- if eq .type "input" -}}
{{- $inputs = printf "%s,%s" $inputs .name -}}
{{- else if eq .type "output" -}}
{{- $outputs = printf "%s,%s" $outputs .name -}}
{{- end -}}
{{- end -}}
{{- with $inputs -}}
backstage.io/input-kafka-topics: {{ . | trimPrefix "," }}
{{- end }}
{{- with $outputs }}
backstage.io/output-kafka-topics: {{ . | trimPrefix "," }}
{{- end }}
{{- end -}}
{{/*
Calculate the flinkConfiguration
*/}}
{{- define "flink-job.calculateConfigurations" -}}
{{- $configs := .Values.flinkConfiguration -}}
{{- $fullname := include "flink-job.fullname" . -}}
{{- $configs = fromJson (include "flink-job.metricsConfiguration" (dict "configs" $configs "global" $.Values "fullname" $fullname)) -}}
{{- $configs = fromJson (include "flink-job.haConfiguration" (dict "configs" $configs "global" $.Values "fullname" $fullname)) -}}
{{- $configs = fromJson (include "flink-job.storageConfiguration" (dict "configs" $configs "global" $.Values "fullname" $fullname)) -}}
{{- $configs = fromJson (include "flink-job.istioConfiguration" (dict "configs" $configs "global" $.Values "fullname" $fullname)) -}}
{{- $configs = fromJson (include "flink-job.sslConfiguration" (dict "configs" $configs "global" $.Values "fullname" $fullname)) -}}
{{- $configs = fromJson (include "flink-job.java17CompatibilityConfiguration" (dict "configs" $configs "global" $.Values "fullname" $fullname)) -}}
{{ toYaml $configs }}
{{- end -}}
{{/*
Add necessary metrics configuration
*/}}
{{- define "flink-job.metricsConfiguration" -}}
{{- $configs := .configs -}}
{{- if .global.metrics.enabled -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "metrics.reporters" "prom")) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "metrics.reporter.prom.port" (toString .global.metrics.port))) -}}
{{- if eq "v1_15" .global.version -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "metrics.reporter.prom.class" "org.apache.flink.metrics.prometheus.PrometheusReporter")) -}}
{{- else if has .global.version (list "v1_16" "v1_17" "v1_18") -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "metrics.reporter.prom.factory.class" "org.apache.flink.metrics.prometheus.PrometheusReporterFactory")) -}}
{{- end -}}
{{- end -}}
{{- $configs | toJson -}}
{{- end -}}
{{/*
Add necessary ssl configuration
*/}}
{{- define "flink-job.sslConfiguration" -}}
{{- $configs := .configs -}}
{{- $password := sha1sum (nospace (toString .global.image)) | trunc 10 }}
{{- if .global.internalSsl.customCiphers.enabled -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.customCiphers.protocol" (toString .global.internalSsl.customCiphers.protocol))) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.customCiphers.algorithms" (toString .global.internalSsl.customCiphers.algorithms))) -}}
{{- end -}}
{{- if .global.internalSsl.enabled -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.internal.enabled" "true")) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.internal.keystore" "/flinkkeystore/keystore.jks")) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.internal.truststore" "/flinkkeystore/truststore.jks")) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.internal.keystore-password" (toString $password))) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.internal.truststore-password" (toString $password))) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "security.ssl.internal.key-password" (toString $password))) -}}
{{- end -}}
{{- $configs | toJson -}}
{{- end -}}
{{/*
Add necessary istio configuration
*/}}
{{- define "flink-job.istioConfiguration" -}}
{{- $configs := .configs -}}
{{- if .global.istio.enabled -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "metrics.internal.query-service.port" "34101")) -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "taskmanager.data.port" "41475")) -}}
{{- end -}}
{{- $configs | toJson -}}
{{- end -}}
{{/*
Add necessary configuration for running in HA mode
*/}}
{{- define "flink-job.haConfiguration" -}}
{{- $configs := .configs -}}
{{- if or (gt (int .global.jobManager.replicas) 1) (eq .global.job.upgradeMode "last-state") -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "high-availability" "org.apache.flink.kubernetes.highavailability.KubernetesHaServicesFactory")) -}}
{{- if and .global.storage.scheme .global.storage.baseDir -}}
{{- $haDir := printf "%s://%s/%s/ha" (trimSuffix "://" .global.storage.scheme) .global.storage.baseDir .fullname -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "high-availability.storageDir" $haDir)) -}}
{{- end -}}
{{- end -}}
{{- $configs | toJson -}}
{{- end -}}
{{/*
Add necessary java 17 compatibility configuration
*/}}
{{- define "flink-job.java17CompatibilityConfiguration" -}}
{{- $configs := .configs -}}
{{- if .global.java17Compatability -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "env.java.opts.all" "--add-exports=java.base/sun.net.util=ALL-UNNAMED --add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED")) -}}
{{- end -}}
{{- $configs | toJson -}}
{{- end -}}
{{/*
Validate the configuration
*/}}
{{- define "flink-job.storageConfiguration" -}}
{{- $configs := .configs -}}
{{- if and .global.storage.scheme .global.storage.baseDir (has .global.job.upgradeMode (list "last-state" "savepoint")) -}}
{{- $checkpointsDir := printf "%s://%s/%s/checkpoints" (trimSuffix "://" .global.storage.scheme) .global.storage.baseDir .fullname -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "state.checkpoints.dir" $checkpointsDir)) -}}
{{- if eq .global.job.upgradeMode "savepoint" -}}
{{- $savepointsDir := printf "%s://%s/%s/savepoints" (trimSuffix "://" .global.storage.scheme) .global.storage.baseDir .fullname -}}
{{- $configs = fromJson (include "flink-job._dictSet" (list $configs "state.savepoints.dir" $savepointsDir)) -}}
{{- end -}}
{{- end -}}
{{- $configs | toJson -}}
{{- end -}}
{{/*
Set a key=value in a dictionary, if the key is not defined
*/}}
{{- define "flink-job._dictSet" -}}
{{- $dict := index . 0 -}}
{{- $key := index . 1 -}}
{{- $value := index . 2 -}}
{{- if not (hasKey $dict $key) -}}
{{- $_ := set $dict $key $value -}}
{{- end -}}
{{- $dict | toJson -}}
{{- end -}}
{{- define "flink-job.sslVolumes" -}}
{{- if $.Values.internalSsl.enabled -}}
{{ (dict "name" "truststore" "secret" (dict "secretName" (print (include "flink-job.nameWithimageHash" . ) "-mtls-secret"))) | toYaml }}
{{- end -}}
{{- end -}}
{{- define "flink-job.sslVolumeMounts" -}}
{{- if $.Values.internalSsl.enabled -}}
{{ (dict "name" "truststore" "mountPath" "/flinkkeystore" "readOnly" true) | toYaml}}
{{- end -}}
{{- end -}}
{{- define "flink-job.nameWithimageHash" -}}
{{ include "flink-job.fullname" . }}{{ (sha256sum (nospace (toString .Values.image))) | trunc 10 }}
{{- end -}}
{{- define "flink-job.dnsForKubernetesHostEnv" -}}
{{- if $.Values.dnsForKubernetesHost -}}
{{ (dict "name" "KUBERNETES_SERVICE_HOST" "value" "kubernetes.default.svc.cluster.local" | toYaml) }}
{{- end }}
{{- end -}}