summaryrefslogtreecommitdiff
path: root/snippets/helm.snippets
blob: 241cc449ed1b740dd46998652803cd4543db33fd (plain)
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
snippet service_sample_spec
	apiVersion: v1
	kind: Service
	metadata:
	{{- if .Values.$1.service.annotations }}
	  annotations:
	{{ toYaml .Values.$1.service.annotations | indent 4 }}
	{{- end }}
	  labels:
	{{- if .Values.$1.service.labels }}
	{{ toYaml .Values.$1.service.labels | indent 4 }}
	{{- end }}
		app: {{ template "$2.name" . }}
		chart: {{ .Chart.Name }}-{{ .Chart.Version }}
		component: "{{ .Values.$1.name }}"
		heritage: {{ .Release.Service }}
		release: {{ .Release.Name }}
	  name: {{ template "$2.$1.fullname" . }}
	spec:
	  clusterIP: "{{ .Values.$1.service.clusterIP }}"
	{{- if .Values.$1.service.externalIPs }}
	  externalIPs:
	{{ toYaml .Values.$1.service.externalIPs | indent 4 }}
	{{- end }}
	{{- if .Values.$1.service.loadBalancerIP }}
	  loadBalancerIP: "{{ .Values.$1.service.loadBalancerIP }}"
	{{- end }}
	{{- if .Values.$1.service.loadBalancerSourceRanges }}
	  loadBalancerSourceRanges:
	{{ toYaml .Values.$1.service.loadBalancerSourceRanges | indent 4 }}
	{{- end }}
	  healthCheckNodePort: {{ .Values.$1.service.healthCheckNodePort }}
	  ports:
		- name: http
		  port: 80
		  protocol: TCP
		  targetPort: {{ .Values.$1.service.targetPorts.http }}
		  {{- if (and (eq .Values.$1.service.type "NodePort") (not (empty .Values.$1.service.nodePorts.http))) }}
		  nodePort: {{ .Values.$1.service.nodePorts.http }}
		  {{- end }}
		- name: https
		  port: 443
		  protocol: TCP
		  targetPort: {{ .Values.$1.service.targetPorts.https }}
		  {{- if (and (eq .Values.$1.service.type "NodePort") (not (empty .Values.$1.service.nodePorts.https))) }}
		  nodePort: {{ .Values.$1.service.nodePorts.https }}
		  {{- end }}
	  {{- range $key, $value := .Values.tcp }}
		- name: "{{ $key }}-tcp"
		  port: {{ $key }}
		  protocol: TCP
		  targetPort: "{{ $key }}-tcp"
	  {{- end }}
	  {{- range $key, $value := .Values.udp }}
		- name: "{{ $key }}-udp"
		  port: {{ $key }}
		  protocol: UDP
		  targetPort: "{{ $key }}-udp"
	  {{- end }}
	  selector:
		app: {{ template "${2:chartName}.name" . }}
		component: "{{ .Values.$1.name }}"
		release: {{ .Release.Name }}
	  type: "{{ .Values.${1:value_key}.service.type }}"

snippet service_spec
	apiVersion: v1
	kind: Service
	metadata:
	{{- if .Values.$1.service.annotations }}
	  annotations:
	{{ toYaml .Values.$1.service.annotations | indent 4 }}
	{{- end }}
	  labels:
	{{- if .Values.$1.service.labels }}
	{{ toYaml .Values.$1.service.labels | indent 4 }}
	{{- end }}
		app: {{ template "$2.name" . }}
		chart: {{ .Chart.Name }}-{{ .Chart.Version }}
		component: "{{ .Values.$1.name }}"
		heritage: {{ .Release.Service }}
		release: {{ .Release.Name }}
	  name: {{ template "${2:chartName}.${1:value_key}.fullname" . }}
	# spec
	${0}

snippet annotations_spec
	{{- if .Values.$1.service.annotations }}
	  annotations:
	{{ toYaml .Values.${1:value_key}.service.annotations | indent 4 }}
	{{- end }}
	${0}

snippet labels_spec
	 labels:
	{{- if .Values.$1.service.labels }}
	{{ toYaml .Values.$1.service.labels | indent 4 }}
	{{- end }}
		app: {{ template "$2.name" . }}
		chart: {{ .Chart.Name }}-{{ .Chart.Version }}
		component: "{{ .Values.$1.name }}"
		heritage: {{ .Release.Service }}
		release: {{ .Release.Name }}
	  name: {{ template "${2:chartName}.${1:value_key}.fullname" . }}
	${0}

snippet service_spec
	spec:
	  type: "{{ .Values.$1.service.type }}"
	  clusterIP: "{{ .Values.$1.service.clusterIP }}"
	{{- if .Values.$1.service.externalIPs }}
	  externalIPs:
	{{ toYaml .Values.$1.service.externalIPs | indent 4 }}
	{{- end }}
	{{- if .Values.$1.service.loadBalancerIP }}
	  loadBalancerIP: "{{ .Values.$1.service.loadBalancerIP }}"
	{{- end }}
	{{- if .Values.$1.service.loadBalancerSourceRanges }}
	  loadBalancerSourceRanges:
	{{ toYaml .Values.$1.service.loadBalancerSourceRanges | indent 4 }}
	{{- end }}
	{{- if and (semverCompare ">=1.7-0" .Capabilities.KubeVersion.GitVersion) (.Values.$1.service.externalTrafficPolicy) }}
	  externalTrafficPolicy: "{{ .Values.$1.service.externalTrafficPolicy }}"
	{{- end }}
	{{- if and (semverCompare ">=1.7-0" .Capabilities.KubeVersion.GitVersion) (.Values.$1.service.healthCheckNodePort) }}
	  healthCheckNodePort: {{ .Values.${1:value_key}.service.healthCheckNodePort }}
	{{- end }}
	${0}

snippet ports_spec
	ports:
	${0}

snippet portHTTP_spec
	- name: http
	  port: 80
	  protocol: TCP
	  targetPort: {{ .Values.$1.service.targetPorts.http }}
	  {{- if (and (eq .Values.$1.service.type "NodePort") (not (empty .Values.$1.service.nodePorts.http))) }}
	  nodePort: {{ .Values.${1:value_key}.service.nodePorts.http }}
	  {{- end }}
	  ${0}

snippet portHTTPS_spec
	- name: https
	  port: 443
	  protocol: TCP
	  targetPort: {{ .Values.$1.service.targetPorts.https }}
	  {{- if (and (eq .Values.$1.service.type "NodePort") (not (empty .Values.$1.service.nodePorts.https))) }}
	  nodePort: {{ .Values.${1:value_key}.service.nodePorts.https }}
	  {{- end }}
	  ${0}

snippet portTCP_spec
	{{- range $key, $value := .Values.tcp }}
	  - name: "{{ $key }}-tcp"
		port: {{ $key }}
		protocol: TCP
		targetPort: "{{ $key }}-tcp"
	{{- end }}
	${0}

snippet portUDP_spec
	{{- range $key, $value := .Values.udp }}
	  - name: "{{ $key }}-udp"
		port: {{ $key }}
		protocol: UDP
		targetPort: "{{ $key }}-udp"
	{{- end }}
	${0}


snippet selector_spec
	selector:
	  app: {{ template "${2:chartName}.name" . }}
	  component: "{{ .Values.${1:value_key}.name }}"
	  release: {{ .Release.Name }}
	  ${0}


snippet deploy_sample_spec
	{{- if .Values.$1.enabled }}
	apiVersion: extensions/v1beta1
	kind: Deployment
	metadata:
	  labels:
		app: {{ template "$2.name" . }}
		chart: {{ .Chart.Name }}-{{ .Chart.Version }}
		component: "{{ .Values.$1.name }}"
		heritage: {{ .Release.Service }}
		release: {{ .Release.Name }}
	  name: {{ template "$2.$1.fullname" . }}
	spec:
	  replicas: {{ .Values.$1.replicaCount }}
	  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
	  template:
		metadata:
		{{- if .Values.$1.podAnnotations }}
		  annotations:
	{{ toYaml .Values.$1.podAnnotations | indent 8 }}
		{{- end }}
		  labels:
			app: {{ template "$2.name" . }}
			component: "{{ .Values.$1.name }}"
			release: {{ .Release.Name }}
			{{- if .Values.$1.podLabels }}
	{{ toYaml .Values.$1.podLabels | indent 8 }}
			{{- end }}
		spec:
		  {{- if .Values.imagePullSecrets }}
		  imagePullSecrets:
	{{ toYaml .Values.imagePullSecrets | indent 8 }}
		  {{- end }}
		  containers:
			- name: {{ template "${2:chartName}.name" . }}-{{ .Values.$1.name }}
			  image: "{{ .Values.$1.image.repository }}:{{ .Values.$1.image.tag }}"
			  imagePullPolicy: "{{ .Values.$1.image.pullPolicy }}"
			  args:
			  {{- range $key, $value := .Values.$1.extraArgs }}
				{{- if $value }}
				- --{{ $key }}={{ $value }}
				{{- else }}
				- --{{ $key }}
				{{- end }}
			  {{- end }}
			  livenessProbe:
				httpGet:
				  path: /healthz
				  port: 8080
				  scheme: HTTP
				initialDelaySeconds: 30
				timeoutSeconds: 5
			  ports:
				- name: http
				  containerPort: 8080
				  protocol: TCP
			  resources:
	{{ toYaml .Values.$1.resources | indent 12 }}
		{{- if .Values.$1.nodeSelector }}
		  nodeSelector:
	{{ toYaml .Values.$1.nodeSelector | indent 8 }}
		{{- end }}
		{{- if .Values.$1.tolerations }}
		  tolerations:
	{{ toYaml .Values.$1.tolerations | indent 8 }}
		{{- end }}
		{{- if .Values.$1.affinity }}
		  affinity:
	{{ toYaml .Values.${1:value_key}.affinity | indent 8 }}
		{{- end }}
		  terminationGracePeriodSeconds: 60
	{{- end }}



snippet deploy_spec
	{{- if .Values.$1.enabled }}
	apiVersion: extensions/v1beta1
	kind: Deployment
	metadata:
	  labels:
		app: {{ template "$2.name" . }}
		chart: {{ .Chart.Name }}-{{ .Chart.Version }}
		component: "{{ .Values.$1.name }}"
		heritage: {{ .Release.Service }}
		release: {{ .Release.Name }}
	  name: {{ template "${2:chartName}.${1:value_key}.fullname" . }}
	# spec
		# containers_spec
		# livenessProbe_spec
		# PersistentVolumeClaim_spec
		# initContainers_spec
		# resources_spec
		# nodeselector_spec
		# tolerations_spec
		# affinity_spec
	${0}

snippet spec_spec
	spec:
	  replicas: {{ .Values.$1.replicaCount }}
	  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
	  template:
		metadata:
		{{- if .Values.$1.podAnnotations }}
		  annotations:
	{{ toYaml .Values.$1.podAnnotations | indent 8 }}
		{{- end }}
		  labels:
			app: {{ template "${2:chartName}.name" . }}
			component: "{{ .Values.$1.name }}"
			release: {{ .Release.Name }}
			{{- if .Values.$1.podLabels }}
	{{ toYaml .Values.${1:value_key}.podLabels | indent 8 }}
			{{- end }}
		spec:
		  {{- if .Values.imagePullSecrets }}
		  imagePullSecrets:
	{{ toYaml .Values.imagePullSecrets | indent 8 }}
		  {{- end }}
		  ${0}

snippet imagePullSecrets_spec
		  {{- if .Values.imagePullSecrets }}
		  imagePullSecrets:
	{{ toYaml .Values.imagePullSecrets | indent 8 }}
		  {{- end }}
	${0}

snippet imagePullPolicy_spec
	imagePullPolicy: ${1:imagePullPolicy}
	${0}

snippet containers_spec
	containers:
	  - name: {{ template "${2:chartName}.name" . }}-{{ .Values.$1.name }}
		image: "{{ .Values.$1.image.repository }}:{{ .Values.$1.image.tag }}"
		imagePullPolicy: "{{ .Values.${1:value_key}.image.pullPolicy }}"
	${0}
snippet args_spec
	args:
	{{- range $key, $value := .Values.${1:value_key}.extraArgs }}
	  {{- if $value }}
	  - --{{ $key }}={{ $value }}
	  {{- else }}
	  - --{{ $key }}
	  {{- end }}
	{{- end }}
	${0}
snippet livenessProbe_spec
	livenessProbe:
	  httpGet:
		path: /healthz
		port: 8080
		scheme: HTTP
	  initialDelaySeconds: 30
	  timeoutSeconds: 5
	${0}
snippet readinessProbe_spec
	readinessProbe:
	  httpGet:
		path: /go/api/v1/health
		port: 8153
	  initialDelaySeconds: {{ .Values.$1.healthCheck.initialDelaySeconds }}
	  periodSeconds: {{ .Values.$1.healthCheck.periodSeconds }}
	  failureThreshold: {{ .Values.$1.healthCheck.failureThreshold }}
	${0}
snippet resources_spec
	resources:
	{{ toYaml .Values.${1:value_key}.resources | indent 12 }}
	${0}
snippet nodeselector_spec
	{{- if .Values.$1.nodeSelector }}
	  nodeSelector:
	{{ toYaml .Values.${1:value_key}.nodeSelector | indent 8 }}
	{{- end }}
	${0}
snippet tolerations_spec
	{{- if .Values.$1.tolerations }}
	  tolerations:
	{{ toYaml .Values.${1:value_key}.tolerations | indent 8 }}
	{{- end }}
	${0}
snippet affinity_spec
	{{- if .Values.$1.affinity }}
	  affinity:
	{{ toYaml .Values.${1:value_key}.affinity | indent 8 }}
	{{- end }}
	  terminationGracePeriodSeconds: 60
	{{- end }}
	${0}

snippet PersistentVolumeClaim_spec
	kind: PersistentVolumeClaim
	apiVersion: v1
	metadata:
	  name: {{ template "${2}.$1.fullname" . }}
	  labels:
		app: {{ template "${2:chartName}.name" . }}
		chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
		release: "{{ .Release.Name }}"
		heritage: "{{ .Release.Service }}"
	spec:
	  accessModes:
		- {{ .Values.$1.persistence.accessMode | quote }}
	  resources:
		requests:
		  storage: {{ .Values.$1.persistence.size | quote }}
	{{- if .Values.$1.persistence.storageClass }}
	{{- if (eq "-" .Values.$1.persistence.storageClass) }}
	  storageClassName: ""
	{{- else }}
	  storageClassName: "{{ .Values.${1:value_key}.persistence.storageClass }}"
	{{- end }}
	{{- end }}
	{{- end }}
	{{- end }}
	${0}

snippet configMap_spec
	{{- if .Values.artifactory.enabled -}}
	  apiVersion: v1
	  kind: ConfigMap
	  metadata:
		name: {{ template "${2:chartName}.fullname" . }}-${1:value_key}-config
		labels:
		  app: {{ template "${2}.name" . }}
		  chart: {{ .Chart.Name }}-{{ .Chart.Version }}
		  heritage: {{ .Release.Service }}
		  release: {{ .Release.Name }}
	  data:
		${3:nameOfConfigFile}.conf: |
		  # data goes here
	{{- end -}}
	${0}

snippet initContainers_spec
	{{- if .Values.$1.initContainers }}
		  initContainers:
		  - name: wait-workers
			image: "{{ .Values.$1.image.repository }}:{{ .Values.$1.image.tag }}"
			imagePullPolicy: {{ .Values.${1:value_key}.image.pullPolicy }}
			# env
			command:
			  - sh
			  - -c
			  - |
				until printf "." && nc -z -w 2 {{ template "${2:chartName}.fullname" . }} {{ .Values.postgresql.service.port }}; do
					sleep 2;
				done;

				echo 'PostgreSQL OK ✓'
			# args
	{{- end }}
	${0}

snippet pvc_spec
	kind: PersistentVolumeClaim
	apiVersion: v1
	metadata:
	  name: {{ template "$2.fullname" . }}
	  labels:
		chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
		release: "{{ .Release.Name }}"
		heritage: "{{ .Release.Service }}"
		app: {{ template "${2:chartName}.fullname" . }}
	spec:
	  accessModes:
		- {{ .Values.persistence.accessMode | quote }}
	  resources:
		requests:
		  storage: {{ .Values.persistence.size | quote }}
	{{- if .Values.persistence.storageClass }}
	{{- if (eq "-" .Values.persistence.storageClass) }}
	  storageClassName: ""
	{{- else }}
	  storageClassName: "{{ .Values.persistence.storageClass }}"
	{{- end }}
	{{- end }}
	{{- end }}
	${0}

snippet pv_nfs_spec
	apiVersion: v1
	kind: PersistentVolume
	metadata:
	  name: {{ template "$2.fullname" . }}-data-pv
	  labels:
		app: {{ template "$2.name" . }}
		chart: {{ .Chart.Name }}-{{ .Chart.Version }}
		heritage: {{ .Release.Service }}
		release: {{ .Release.Name }}
		id: {{ template "${2:chartName}.name" . }}-data-pv
		type: nfs-volume
	spec:
	  capacity:
		storage: {{ .Values.$1.persistence.nfs.capacity }}
	  accessModes:
	  - ReadWriteOnce
	  persistentVolumeReclaimPolicy: Retain
	  nfs:
		server: {{ .Values.$1.persistence.nfs.ip }}
		path: "{{ .Values.${1:value_key}.persistence.nfs.haDataMount }}"
		readOnly: false
	${0}

snippet pvc_hostpath_spec
	{{- if and .Values.persistence.enabled .Values.persistence.$1.hostPath (not
	.Values.persistence.$1.existingClaim) -}}
	apiVersion: v1
	kind: PersistentVolume
	metadata:
	  name: {{ template "${2:chartName}.fullname" . }}-$1
	spec:
	  accessModes:
		- {{ .Values.persistence.$1.accessMode | quote }}
	  capacity:
		storage: {{ .Values.persistence.$1.size | quote }}
	  hostPath:
		path: {{ .Values.persistence.${1:value_key}.hostPath | quote }}
	{{- end -}}
	${0}

snippet deploy_values
	$1:
	  name: ${1:value_key}
	  image:
		repository: 
		tag: 
		pullPolicy: IfNotPresent
	  hostNetwork: false
	  dnsPolicy: ClusterFirst
	  daemonset:
		useHostPort: false
	  podLabels: {}
	  scope:
		enabled: false
		namespace: ""   # defaults to .Release.Namespace
	  extraArgs: {}
	  extraEnvs: []
	  kind: Deployment
	  updateStrategy: {}
	  minReadySeconds: 0
	  tolerations: []
	  affinity: {}
	  nodeSelector: {}
	  podAnnotations: {}
	  replicaCount: 1
	  minAvailable: 1
	  resources: {}
	  autoscaling:
		enabled: false
	  extraContainers: {}
	  extraVolumeMounts: {}
	  extraVolumes: {}
	  extraInitContainers: []
	  lifecycle: {}
	revisionHistoryLimit: 10
	${0}

snippet rbac_values
	${1:value_key}:
	rbac:
	  create: true
	serviceAccount:
	  create: true
	  name:
	imagePullSecrets: []
	${0}

snippet service_values
	${1:value_key}:
	  service:
		annotations: {}
		labels: {}
		clusterIP: ""
		externalIPs: []
		loadBalancerIP: ""
		loadBalancerSourceRanges: []
		externalTrafficPolicy: ""
		healthCheckNodePort: 0
		targetPorts:
		  http: http
		  https: https
		type: LoadBalancer
		nodePorts:
		  http: ""
		  https: ""
	${0}

snippet readinessProbe_values
	${1:value_key}:
	  readinessProbe:
		failureThreshold: 3
		initialDelaySeconds: 10
		periodSeconds: 10
		successThreshold: 1
		timeoutSeconds: 1
		port: 10254
	${0}

snippet livenessProbe_values
	${1:value_key}:
	  livenessProbe:
		failureThreshold: 3
		initialDelaySeconds: 10
		periodSeconds: 10
		successThreshold: 1
		timeoutSeconds: 1
		port: 10254
	${0}