-
Notifications
You must be signed in to change notification settings - Fork 5
/
auto-deployments.yaml
187 lines (184 loc) · 7.46 KB
/
auto-deployments.yaml
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
{{- define "deploy_utils.deployment" }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .app.harness.deployment.name| quote }}
namespace: {{ .root.Values.namespace }}
labels:
app: {{ .app.harness.deployment.name| quote }}
{{- if .app.harness.deployment.volume }}
usesvolume: {{ .app.harness.deployment.volume.name }}
{{- end }}
{{- include "deploy_utils.labels" .root | indent 4 }}
spec:
replicas: {{ .app.harness.deployment.replicas | default 1 }}
selector:
matchLabels:
app: {{ .app.harness.deployment.name| quote }}
{{- include "deploy_utils.labels" .root | indent 6 }}
template:
metadata:
{{- if .app.harvest }}
annotations:
co.elastic.logs/enabled: "true"
metricbeat: "true"
{{- end }}
labels:
app: {{ .app.harness.deployment.name| quote }}
{{- if .app.harness.deployment.volume }}
usesvolume: {{ .app.harness.deployment.volume.name }}
{{- end }}
{{- include "deploy_utils.labels" .root | indent 8 }}
spec:
{{- if and .root.Values.registry.secret (contains .root.Values.registry.name .app.harness.deployment.image) }}
imagePullSecrets:
- name: {{ .root.Values.registry.secret }}
{{- end }}
{{- if and .app.harness.deployment.volume }}
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: usesvolume
operator: In
values:
- {{ .app.harness.deployment.volume.name }}
topologyKey: "kubernetes.io/hostname"
{{- end }}
containers:
- name: {{ .app.harness.deployment.name| default "cloudharness-docs" | quote }}
image: {{ .app.harness.deployment.image }}
imagePullPolicy: {{ include "deploy_utils.pullpolicy" .root }}
{{- if .app.harness.deployment.command }}
command: {{ .app.harness.deployment.command }}
{{- end }}
{{- if .app.harness.deployment.args }}
args: {{ .app.harness.deployment.args }}
{{- end }}
env:
- name: CH_CURRENT_APP_NAME
value: {{ .app.harness.name | quote }}
{{- include "deploy_utils.env" .root | nindent 8 }}
{{- include "deploy_utils.privenv" .root | nindent 8 }}
{{- if .app.harness.env }}
{{- .app.harness.env | toYaml | nindent 8 }}
{{- end }}
{{ if .app.harness.livenessProbe }}
livenessProbe:
httpGet:
path: {{ .app.harness.livenessProbe.path }}
port: {{ .app.harness.deployment.port | default 8080 }}
periodSeconds: {{ .app.harness.livenessProbe.periodSeconds | default 10 }}
failureThreshold: {{ .app.harness.livenessProbe.failureThreshold | default 3 }}
initialDelaySeconds: {{ .app.harness.livenessProbe.initialDelaySeconds | default 0 }}
{{ end }}
{{ if .app.harness.readinessProbe }}
readinessProbe:
httpGet:
path: {{ .app.harness.readinessProbe.path }}
port: {{ .app.harness.deployment.port | default 8080 }}
periodSeconds: {{ .app.harness.readinessProbe.periodSeconds | default 10 }}
failureThreshold: {{ .app.harness.readinessProbe.failureThreshold | default 3 }}
initialDelaySeconds: {{ .app.harness.readinessProbe.initialDelaySeconds | default 0 }}
{{ end }}
{{ if .app.harness.startupProbe }}
startupProbe:
httpGet:
path: {{ .app.harness.startupProbe.path }}
port: {{ .app.harness.deployment.port | default 8080 }}
periodSeconds: {{ .app.harness.startupProbe.periodSeconds | default 10 }}
failureThreshold: {{ .app.harness.startupProbe.failureThreshold | default 30 }}
initialDelaySeconds: {{ .app.harness.startupProbe.initialDelaySeconds | default 0 }}
{{ end }}
ports:
- containerPort: {{ .app.harness.deployment.port | default 8080 }}
resources:
requests:
memory: {{ .app.harness.deployment.resources.requests.memory | default "32Mi" }}
cpu: {{ .app.harness.deployment.resources.requests.cpu | default "25m" }}
limits:
memory: {{ .app.harness.deployment.resources.limits.memory | default "64Mi" }}
cpu: {{ .app.harness.deployment.resources.limits.cpu | default "50m" }}
volumeMounts:
- name: cloudharness-allvalues
mountPath: /opt/cloudharness/resources
readOnly: true
{{- if or (has "accounts" .app.harness.dependencies.hard) (eq .app.harness.name "accounts") }}
- name: cloudharness-kc-accounts
mountPath: /opt/cloudharness/resources/auth
readOnly: true
{{- end }}
{{- if .app.harness.deployment.volume }}
- name: {{ .app.harness.deployment.volume.name }}
mountPath: {{ .app.harness.deployment.volume.mountpath }}
readOnly: {{ .app.harness.deployment.volume.readonly | default false }}
{{- end }}
{{- $app := .app}}
{{- range $resource := .app.harness.resources }}
- name: "{{ $app.harness.deployment.name }}-{{ $resource.name }}"
mountPath: {{ $resource.dst }}
subPath: {{ base $resource.dst }}
readOnly: true
{{- end}}
{{- if .app.harness.secrets }}
- name: secrets
mountPath: "/opt/cloudharness/resources/secrets"
readOnly: true
{{- end }}
volumes:
- name: cloudharness-allvalues
configMap:
name: cloudharness-allvalues
{{- if or (has "accounts" .app.harness.dependencies.hard) (eq .app.harness.name "accounts") }}
- name: cloudharness-kc-accounts
secret:
secretName: accounts
{{- end }}
{{- if .app.harness.deployment.volume }}
- name: {{ .app.harness.deployment.volume.name }}
persistentVolumeClaim:
claimName: {{ .app.harness.deployment.volume.name }}
{{- end }}
{{ $app := .app }}
{{- range $resource := .app.harness.resources }}
- name: "{{ $app.harness.deployment.name }}-{{ $resource.name }}"
configMap:
name: "{{ $app.harness.deployment.name }}-{{ $resource.name }}"
{{- end }}
{{- if .app.harness.secrets }}
- name: secrets
secret:
secretName: {{ .app.harness.deployment.name }}
{{- end }}
---
{{- end }}
{{- define "deploy_utils.resource"}}
kind: ConfigMap
apiVersion: v1
metadata:
name: "{{ .app.harness.deployment.name }}-{{ .resource.name }}"
labels:
app: {{ .app.harness.deployment.name | quote }}
{{ include "deploy_utils.labels" .root | indent 4 }}
data:
{{ base .resource.dst }}: {{ tpl (.root.Files.Get (print "resources/" .app.harness.deployment.name "/" .resource.src)) .root | quote }}
---
{{- end}}
{{- range $app := .Values.apps }}
{{- if and (hasKey $app "port") $app.harness.deployment.auto | default false }}
---
{{- include "deploy_utils.deployment" (dict "root" $ "app" $app) }}
{{- range $resource := $app.harness.resources }}
{{- include "deploy_utils.resource" (dict "app" $app "resource" $resource "root" $) }}
{{- end }}
{{- end }}
{{- range $subapp := $app }}
{{- if contains "map" (typeOf $subapp) }}
{{- if hasKey $subapp "harness" }}
---
{{- include "deploy_utils.deployment" (dict "root" $ "app" $subapp) }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}