blob: 80154c7be9320f8bc6c329db065bdedb829bc945 [file] [log] [blame]
Giorgi Lekveishvili35982662024-04-05 13:05:40 +04001{{- if .Capabilities.APIVersions.Has "apps/v1" }}
2apiVersion: apps/v1
3{{- else }}
4apiVersion: apps/v1beta1
5{{- end }}
6kind: StatefulSet
7metadata:
8 name: {{ template "jenkins.fullname" . }}
9 namespace: {{ template "jenkins.namespace" . }}
10 labels:
gio20157e82026-07-22 13:10:48 +040011 {{- include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040012 {{- range $key, $val := .Values.controller.statefulSetLabels }}
13 {{ $key }}: {{ $val | quote }}
14 {{- end}}
15 {{- if .Values.controller.statefulSetAnnotations }}
16 annotations:
17{{ toYaml .Values.controller.statefulSetAnnotations | indent 4 }}
18 {{- end }}
19spec:
20 serviceName: {{ template "jenkins.fullname" . }}
gio20157e82026-07-22 13:10:48 +040021 replicas: {{ include "controller.replicas" . }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040022 selector:
23 matchLabels:
24 "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
25 "app.kubernetes.io/instance": "{{ .Release.Name }}"
26 {{- if .Values.controller.updateStrategy }}
27 updateStrategy:
28{{ toYaml .Values.controller.updateStrategy | indent 4 }}
29 {{- end }}
30 template:
31 metadata:
32 labels:
gio20157e82026-07-22 13:10:48 +040033 {{- include "jenkins.labels" . | nindent 8 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040034 {{- range $key, $val := .Values.controller.podLabels }}
35 {{ $key }}: {{ $val | quote }}
36 {{- end}}
37 annotations:
38 checksum/config: {{ include (print $.Template.BasePath "/config.yaml") . | sha256sum }}
39 {{- if .Values.controller.initScripts }}
40 checksum/config-init-scripts: {{ include (print $.Template.BasePath "/config-init-scripts.yaml") . | sha256sum }}
41 {{- end }}
42 {{- if .Values.controller.podAnnotations }}
43{{ tpl (toYaml .Values.controller.podAnnotations | indent 8) . }}
44 {{- end }}
45 spec:
46 {{- if .Values.controller.schedulerName }}
47 schedulerName: {{ .Values.controller.schedulerName }}
48 {{- end }}
49 {{- if .Values.controller.nodeSelector }}
50 nodeSelector:
51{{ toYaml .Values.controller.nodeSelector | indent 8 }}
52 {{- end }}
53 {{- if .Values.controller.tolerations }}
54 tolerations:
55{{ toYaml .Values.controller.tolerations | indent 8 }}
56 {{- end }}
57 {{- if .Values.controller.affinity }}
58 affinity:
59{{ toYaml .Values.controller.affinity | indent 8 }}
60 {{- end }}
gio20157e82026-07-22 13:10:48 +040061 {{- if .Values.controller.topologySpreadConstraints }}
62 topologySpreadConstraints:
63{{ toYaml .Values.controller.topologySpreadConstraints | indent 8 }}
64 {{- end }}
65 {{- if .Values.controller.dnsConfig }}
66 dnsConfig:
67{{ toYaml .Values.controller.dnsConfig | indent 8 }}
68 {{- end }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040069 {{- if quote .Values.controller.terminationGracePeriodSeconds }}
70 terminationGracePeriodSeconds: {{ .Values.controller.terminationGracePeriodSeconds }}
71 {{- end }}
72 {{- if .Values.controller.priorityClassName }}
73 priorityClassName: {{ .Values.controller.priorityClassName }}
74 {{- end }}
75 {{- if .Values.controller.shareProcessNamespace }}
76 shareProcessNamespace: true
77 {{- end }}
gio20157e82026-07-22 13:10:48 +040078 {{- if not .Values.controller.enableServiceLinks }}
79 enableServiceLinks: false
80 {{- end }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040081{{- if .Values.controller.usePodSecurityContext }}
82 securityContext:
83 {{- if kindIs "map" .Values.controller.podSecurityContextOverride }}
84 {{- tpl (toYaml .Values.controller.podSecurityContextOverride | nindent 8) . -}}
85 {{- else }}
86 {{/* The rest of this section should be replaced with the contents of this comment one the runAsUser, fsGroup, and securityContextCapabilities Helm chart values have been removed:
87 runAsUser: 1000
88 fsGroup: 1000
gio20157e82026-07-22 13:10:48 +040089 fsGroupChangePolicy: OnRootMismatch
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040090 runAsNonRoot: true
91 */}}
92 runAsUser: {{ default 0 .Values.controller.runAsUser }}
93 {{- if and (.Values.controller.runAsUser) (.Values.controller.fsGroup) }}
94 {{- if not (eq (int .Values.controller.runAsUser) 0) }}
95 fsGroup: {{ .Values.controller.fsGroup }}
gio20157e82026-07-22 13:10:48 +040096 fsGroupChangePolicy: {{ .Values.controller.fsGroupChangePolicy }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040097 runAsNonRoot: true
98 {{- end }}
99 {{- if .Values.controller.securityContextCapabilities }}
100 capabilities:
101 {{- toYaml .Values.controller.securityContextCapabilities | nindent 10 }}
102 {{- end }}
103 {{- end }}
104 {{- end }}
105{{- end }}
106 serviceAccountName: "{{ template "jenkins.serviceAccountName" . }}"
gio20157e82026-07-22 13:10:48 +0400107 automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +0400108{{- if .Values.controller.hostNetworking }}
109 hostNetwork: true
110 dnsPolicy: ClusterFirstWithHostNet
111{{- end }}
112 {{- if .Values.controller.hostAliases }}
113 hostAliases:
114 {{- toYaml .Values.controller.hostAliases | nindent 8 }}
115 {{- end }}
116 initContainers:
117{{- if .Values.controller.customInitContainers }}
118{{ tpl (toYaml .Values.controller.customInitContainers) . | indent 8 }}
119{{- end }}
120
121{{- if .Values.controller.sidecars.configAutoReload.enabled }}
122{{- include "jenkins.configReloadContainer" (list $ "config-reload-init" "init") | nindent 8 }}
123{{- end}}
124
125 - name: "init"
126 image: "{{ .Values.controller.image.registry }}/{{ .Values.controller.image.repository }}:{{- include "controller.image.tag" . -}}"
127 imagePullPolicy: "{{ .Values.controller.image.pullPolicy }}"
128 {{- if .Values.controller.containerSecurityContext }}
129 securityContext: {{- toYaml .Values.controller.containerSecurityContext | nindent 12 }}
130 {{- end }}
131 command: [ "sh", "/var/jenkins_config/apply_config.sh" ]
132 {{- if .Values.controller.initContainerEnvFrom }}
133 envFrom:
134{{ (tpl (toYaml .Values.controller.initContainerEnvFrom) .) | indent 12 }}
135 {{- end }}
136 {{- if .Values.controller.initContainerEnv }}
137 env:
138{{ (tpl (toYaml .Values.controller.initContainerEnv) .) | indent 12 }}
139 {{- end }}
140 resources:
141{{- if .Values.controller.initContainerResources }}
142{{ toYaml .Values.controller.initContainerResources | indent 12 }}
143{{- else }}
144{{ toYaml .Values.controller.resources | indent 12 }}
145{{- end }}
146 volumeMounts:
147 {{- if .Values.persistence.mounts }}
148{{ toYaml .Values.persistence.mounts | indent 12 }}
149 {{- end }}
150 - mountPath: {{ .Values.controller.jenkinsHome }}
151 name: jenkins-home
152 {{- if .Values.persistence.subPath }}
153 subPath: {{ .Values.persistence.subPath }}
154 {{- end }}
155 - mountPath: /var/jenkins_config
156 name: jenkins-config
157 {{- if .Values.controller.installPlugins }}
158 {{- if .Values.controller.overwritePluginsFromImage }}
159 - mountPath: {{ .Values.controller.jenkinsRef }}/plugins
160 name: plugins
161 {{- end }}
162 - mountPath: /var/jenkins_plugins
163 name: plugin-dir
164 - mountPath: /tmp
165 name: tmp-volume
166 {{- end }}
167 {{- if or .Values.controller.initScripts .Values.controller.initConfigMap }}
168 - mountPath: {{ .Values.controller.jenkinsHome }}/init.groovy.d
169 name: init-scripts
170 {{- end }}
171 {{- if and .Values.controller.httpsKeyStore.enable (not .Values.controller.httpsKeyStore.disableSecretMount) }}
172 {{- $httpsJKSDirPath := printf "%s" .Values.controller.httpsKeyStore.path }}
173 - mountPath: {{ $httpsJKSDirPath }}
174 name: jenkins-https-keystore
175 {{- end }}
176 containers:
177 - name: jenkins
178 image: "{{ .Values.controller.image.registry }}/{{ .Values.controller.image.repository }}:{{- include "controller.image.tag" . -}}"
179 imagePullPolicy: "{{ .Values.controller.image.pullPolicy }}"
180 {{- if .Values.controller.containerSecurityContext }}
181 securityContext: {{- toYaml .Values.controller.containerSecurityContext | nindent 12 }}
182 {{- end }}
183 {{- if .Values.controller.overrideArgs }}
184 args: [
185 {{- range $overrideArg := .Values.controller.overrideArgs }}
186 "{{- tpl $overrideArg $ }}",
187 {{- end }}
188 ]
189 {{- else if .Values.controller.httpsKeyStore.enable }}
190 {{- $httpsJKSFilePath := printf "%s/%s" .Values.controller.httpsKeyStore.path .Values.controller.httpsKeyStore.fileName }}
191 args: [ "--httpPort={{.Values.controller.httpsKeyStore.httpPort}}", "--httpsPort={{.Values.controller.targetPort}}", '--httpsKeyStore={{ $httpsJKSFilePath }}', "--httpsKeyStorePassword=$(JENKINS_HTTPS_KEYSTORE_PASSWORD)" ]
192 {{- else }}
193 args: [ "--httpPort={{.Values.controller.targetPort}}"]
194 {{- end }}
195 {{- if .Values.controller.lifecycle }}
196 lifecycle:
197{{ toYaml .Values.controller.lifecycle | indent 12 }}
198 {{- end }}
199{{- if .Values.controller.terminationMessagePath }}
200 terminationMessagePath: {{ .Values.controller.terminationMessagePath }}
201{{- end }}
202{{- if .Values.controller.terminationMessagePolicy }}
203 terminationMessagePolicy: {{ .Values.controller.terminationMessagePolicy }}
204{{- end }}
205 {{- if .Values.controller.containerEnvFrom }}
206 envFrom:
207{{ (tpl ( toYaml .Values.controller.containerEnvFrom) .) | indent 12 }}
208 {{- end }}
209 env:
210 {{- if .Values.controller.containerEnv }}
211{{ (tpl ( toYaml .Values.controller.containerEnv) .) | indent 12 }}
212 {{- end }}
213 {{- if or .Values.controller.additionalSecrets .Values.controller.existingSecret .Values.controller.additionalExistingSecrets .Values.controller.admin.createSecret }}
214 - name: SECRETS
215 value: /run/secrets/additional
216 {{- end }}
217 - name: POD_NAME
218 valueFrom:
219 fieldRef:
220 fieldPath: metadata.name
221 - name: JAVA_OPTS
222 value: >-
gio20157e82026-07-22 13:10:48 +0400223 {{ if .Values.controller.sidecars.configAutoReload.enabled }} -Dcasc.reload.token=$(POD_NAME) {{ end }}{{ tpl (default "" .Values.controller.javaOpts) . }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +0400224 - name: JENKINS_OPTS
225 value: >-
gio20157e82026-07-22 13:10:48 +0400226 {{ if .Values.controller.jenkinsUriPrefix }}--prefix={{ .Values.controller.jenkinsUriPrefix }} {{ end }} --webroot=/var/jenkins_cache/war {{ tpl (default "" .Values.controller.jenkinsOpts) . }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +0400227 - name: JENKINS_SLAVE_AGENT_PORT
228 value: "{{ .Values.controller.agentListenerPort }}"
229 {{- if .Values.controller.httpsKeyStore.enable }}
230 - name: JENKINS_HTTPS_KEYSTORE_PASSWORD
231 {{- if not .Values.controller.httpsKeyStore.disableSecretMount }}
232 valueFrom:
233 secretKeyRef:
234 name: {{ if .Values.controller.httpsKeyStore.jenkinsHttpsJksPasswordSecretName }} {{ .Values.controller.httpsKeyStore.jenkinsHttpsJksPasswordSecretName }} {{ else if .Values.controller.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ .Values.controller.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ else }} {{ template "jenkins.fullname" . }}-https-jks {{ end }}
235 key: "{{ .Values.controller.httpsKeyStore.jenkinsHttpsJksPasswordSecretKey }}"
236 {{- else }}
237 value: {{ .Values.controller.httpsKeyStore.password }}
238 {{- end }}
239 {{- end }}
240
241 - name: CASC_JENKINS_CONFIG
242 value: {{ .Values.controller.sidecars.configAutoReload.folder | default (printf "%s/casc_configs" (.Values.controller.jenkinsRef)) }}{{- if .Values.controller.JCasC.configUrls }},{{ join "," .Values.controller.JCasC.configUrls }}{{- end }}
243 ports:
244 {{- if .Values.controller.httpsKeyStore.enable }}
245 - containerPort: {{.Values.controller.httpsKeyStore.httpPort}}
246 {{- else }}
247 - containerPort: {{.Values.controller.targetPort}}
248 {{- end }}
249 name: http
250 - containerPort: {{ .Values.controller.agentListenerPort }}
251 name: agent-listener
252 {{- if .Values.controller.agentListenerHostPort }}
253 hostPort: {{ .Values.controller.agentListenerHostPort }}
254 {{- end }}
255 {{- if .Values.controller.jmxPort }}
256 - containerPort: {{ .Values.controller.jmxPort }}
257 name: jmx
258 {{- end }}
259{{- range $index, $port := .Values.controller.extraPorts }}
260 - containerPort: {{ $port.port }}
261 name: {{ $port.name }}
262{{- end }}
263{{- if and .Values.controller.healthProbes .Values.controller.probes}}
264 {{- if semverCompare ">=1.16-0" .Capabilities.KubeVersion.GitVersion }}
265 startupProbe:
266{{ tpl (toYaml .Values.controller.probes.startupProbe | indent 12) .}}
267 {{- end }}
268 livenessProbe:
269{{ tpl (toYaml .Values.controller.probes.livenessProbe | indent 12) .}}
270 readinessProbe:
271{{ tpl (toYaml .Values.controller.probes.readinessProbe | indent 12) .}}
272{{- end }}
273 resources:
274{{ toYaml .Values.controller.resources | indent 12 }}
275 volumeMounts:
276{{- if .Values.persistence.mounts }}
277{{ toYaml .Values.persistence.mounts | indent 12 }}
278{{- end }}
279 {{- if and .Values.controller.httpsKeyStore.enable (not .Values.controller.httpsKeyStore.disableSecretMount) }}
280 {{- $httpsJKSDirPath := printf "%s" .Values.controller.httpsKeyStore.path }}
281 - mountPath: {{ $httpsJKSDirPath }}
282 name: jenkins-https-keystore
283 {{- end }}
284 - mountPath: {{ .Values.controller.jenkinsHome }}
285 name: jenkins-home
286 readOnly: false
287 {{- if .Values.persistence.subPath }}
288 subPath: {{ .Values.persistence.subPath }}
289 {{- end }}
290 - mountPath: /var/jenkins_config
291 name: jenkins-config
292 readOnly: true
293 {{- if .Values.controller.installPlugins }}
294 - mountPath: {{ .Values.controller.jenkinsRef }}/plugins/
295 name: plugin-dir
296 readOnly: false
297 {{- end }}
298 {{- if or .Values.controller.initScripts .Values.controller.initConfigMap }}
299 - mountPath: {{ .Values.controller.jenkinsHome }}/init.groovy.d
300 name: init-scripts
301 {{- end }}
302 {{- if .Values.controller.sidecars.configAutoReload.enabled }}
303 - name: sc-config-volume
304 mountPath: {{ .Values.controller.sidecars.configAutoReload.folder | default (printf "%s/casc_configs" (.Values.controller.jenkinsRef)) }}
305 {{- end }}
306 {{- if or .Values.controller.additionalSecrets .Values.controller.existingSecret .Values.controller.additionalExistingSecrets .Values.controller.admin.createSecret }}
307 - name: jenkins-secrets
308 mountPath: /run/secrets/additional
309 readOnly: true
310 {{- end }}
311 - name: jenkins-cache
312 mountPath: /var/jenkins_cache
313 - mountPath: /tmp
314 name: tmp-volume
315
316{{- if .Values.controller.sidecars.configAutoReload.enabled }}
317{{- include "jenkins.configReloadContainer" (list $ "config-reload" "sidecar") | nindent 8 }}
318{{- end}}
319
320
321{{- if .Values.controller.sidecars.additionalSidecarContainers}}
322{{ tpl (toYaml .Values.controller.sidecars.additionalSidecarContainers | indent 8) .}}
323{{- end }}
324
325 volumes:
326{{- if .Values.persistence.volumes }}
327{{ tpl (toYaml .Values.persistence.volumes | indent 6) . }}
328{{- end }}
gio20157e82026-07-22 13:10:48 +0400329 {{- if .Values.controller.sidecars.configAutoReload.logging.configuration.override }}
330 - name: auto-reload-config
331 configMap:
332 name: {{ template "jenkins.fullname" . }}-auto-reload-config
333 - name: auto-reload-config-logs
334 emptyDir: {}
335 {{- end }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +0400336 {{- if .Values.controller.installPlugins }}
337 {{- if .Values.controller.overwritePluginsFromImage }}
338 - name: plugins
339 emptyDir: {}
340 {{- end }}
341 {{- end }}
342 {{- if and .Values.controller.initScripts .Values.controller.initConfigMap }}
343 - name: init-scripts
344 projected:
345 sources:
346 - configMap:
347 name: {{ template "jenkins.fullname" . }}-init-scripts
348 - configMap:
349 name: {{ .Values.controller.initConfigMap }}
350 {{- else if .Values.controller.initConfigMap }}
351 - name: init-scripts
352 configMap:
353 name: {{ .Values.controller.initConfigMap }}
354 {{- else if .Values.controller.initScripts }}
355 - name: init-scripts
356 configMap:
357 name: {{ template "jenkins.fullname" . }}-init-scripts
358 {{- end }}
359 - name: jenkins-config
360 configMap:
361 name: {{ template "jenkins.fullname" . }}
362 {{- if .Values.controller.installPlugins }}
363 - name: plugin-dir
364 emptyDir: {}
365 {{- end }}
366 {{- if or .Values.controller.additionalSecrets .Values.controller.existingSecret .Values.controller.additionalExistingSecrets .Values.controller.admin.createSecret }}
367 - name: jenkins-secrets
368 projected:
369 sources:
370 {{- if .Values.controller.additionalSecrets }}
371 - secret:
372 name: {{ template "jenkins.fullname" . }}-additional-secrets
373 {{- end }}
374 {{- if .Values.controller.additionalExistingSecrets }}
375 {{- range $key, $value := .Values.controller.additionalExistingSecrets }}
376 - secret:
377 name: {{ tpl $value.name $ }}
378 items:
379 - key: {{ tpl $value.keyName $ }}
380 path: {{ tpl $value.name $ }}-{{ tpl $value.keyName $ }}
381 {{- end }}
382 {{- end }}
383 {{- if .Values.controller.admin.createSecret }}
384 - secret:
385 name: {{ .Values.controller.admin.existingSecret | default (include "jenkins.fullname" .) }}
386 items:
387 - key: {{ .Values.controller.admin.userKey | default "jenkins-admin-user" }}
388 path: chart-admin-username
389 - key: {{ .Values.controller.admin.passwordKey | default "jenkins-admin-password" }}
390 path: chart-admin-password
391 {{- end }}
392 {{- if .Values.controller.existingSecret }}
393 - secret:
394 name: {{ .Values.controller.existingSecret }}
395 {{- end }}
396 {{- end }}
397 - name: jenkins-cache
398 emptyDir: {}
399 {{- if not (contains "jenkins-home" (quote .Values.persistence.volumes)) }}
400 - name: jenkins-home
401 {{- if .Values.persistence.enabled }}
402 persistentVolumeClaim:
403 claimName: {{ .Values.persistence.existingClaim | default (include "jenkins.fullname" .) }}
404 {{- else }}
405 emptyDir: {}
406 {{- end -}}
407 {{- end }}
408 - name: sc-config-volume
409 emptyDir: {}
410 - name: tmp-volume
411 emptyDir: {}
412
413 {{- if and .Values.controller.httpsKeyStore.enable (not .Values.controller.httpsKeyStore.disableSecretMount) }}
414 - name: jenkins-https-keystore
415 secret:
416 secretName: {{ if .Values.controller.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ .Values.controller.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ else }} {{ template "jenkins.fullname" . }}-https-jks {{ end }}
417 items:
418 - key: {{ .Values.controller.httpsKeyStore.jenkinsHttpsJksSecretKey }}
419 path: {{ .Values.controller.httpsKeyStore.fileName }}
420 {{- end }}
421
422{{- if .Values.controller.imagePullSecretName }}
423 imagePullSecrets:
424 - name: {{ .Values.controller.imagePullSecretName }}
425{{- end -}}