jenkins-controller-statefulset.yaml 18 KB

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