_helpers.tpl 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Expand the name of the chart.
  4. */}}
  5. {{- define "jenkins.name" -}}
  6. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
  7. {{- end -}}
  8. {{/*
  9. Expand the label of the chart.
  10. */}}
  11. {{- define "jenkins.label" -}}
  12. {{- printf "%s-%s" (include "jenkins.name" .) .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
  13. {{- end -}}
  14. {{/*
  15. Allow the release namespace to be overridden for multi-namespace deployments in combined charts.
  16. */}}
  17. {{- define "jenkins.namespace" -}}
  18. {{- if .Values.namespaceOverride -}}
  19. {{- .Values.namespaceOverride -}}
  20. {{- else -}}
  21. {{- .Release.Namespace -}}
  22. {{- end -}}
  23. {{- end -}}
  24. {{- define "jenkins.agent.namespace" -}}
  25. {{- if .Values.agent.namespace -}}
  26. {{- tpl .Values.agent.namespace . -}}
  27. {{- else -}}
  28. {{- if .Values.namespaceOverride -}}
  29. {{- .Values.namespaceOverride -}}
  30. {{- else -}}
  31. {{- .Release.Namespace -}}
  32. {{- end -}}
  33. {{- end -}}
  34. {{- end -}}
  35. {{/*
  36. Create a default fully qualified app name.
  37. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  38. If release name contains chart name it will be used as a full name.
  39. */}}
  40. {{- define "jenkins.fullname" -}}
  41. {{- if .Values.fullnameOverride -}}
  42. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  43. {{- else -}}
  44. {{- $name := default .Chart.Name .Values.nameOverride -}}
  45. {{- if contains $name .Release.Name -}}
  46. {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
  47. {{- else -}}
  48. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
  49. {{- end -}}
  50. {{- end -}}
  51. {{- end -}}
  52. {{/*
  53. Returns the admin password
  54. https://github.com/helm/charts/issues/5167#issuecomment-619137759
  55. */}}
  56. {{- define "jenkins.password" -}}
  57. {{ if .Values.controller.adminPassword -}}
  58. {{- .Values.controller.adminPassword | b64enc | quote }}
  59. {{- else -}}
  60. {{- $secret := (lookup "v1" "Secret" .Release.Namespace (include "jenkins.fullname" .)).data -}}
  61. {{- if $secret -}}
  62. {{/*
  63. Reusing current password since secret exists
  64. */}}
  65. {{- index $secret ( .Values.controller.admin.passwordKey | default "jenkins-admin-password" ) -}}
  66. {{- else -}}
  67. {{/*
  68. Generate new password
  69. */}}
  70. {{- randAlphaNum 22 | b64enc | quote }}
  71. {{- end -}}
  72. {{- end -}}
  73. {{- end -}}
  74. {{/*
  75. Returns the Jenkins URL
  76. */}}
  77. {{- define "jenkins.url" -}}
  78. {{- if .Values.controller.jenkinsUrl }}
  79. {{- .Values.controller.jenkinsUrl }}
  80. {{- else }}
  81. {{- if .Values.controller.ingress.hostName }}
  82. {{- if .Values.controller.ingress.tls }}
  83. {{- default "https" .Values.controller.jenkinsUrlProtocol }}://{{ tpl .Values.controller.ingress.hostName $ }}{{ default "" .Values.controller.jenkinsUriPrefix }}
  84. {{- else }}
  85. {{- default "http" .Values.controller.jenkinsUrlProtocol }}://{{ tpl .Values.controller.ingress.hostName $ }}{{ default "" .Values.controller.jenkinsUriPrefix }}
  86. {{- end }}
  87. {{- else }}
  88. {{- default "http" .Values.controller.jenkinsUrlProtocol }}://{{ template "jenkins.fullname" . }}:{{.Values.controller.servicePort}}{{ default "" .Values.controller.jenkinsUriPrefix }}
  89. {{- end}}
  90. {{- end}}
  91. {{- end -}}
  92. {{/*
  93. Returns configuration as code default config
  94. */}}
  95. {{- define "jenkins.casc.defaults" -}}
  96. jenkins:
  97. {{- $configScripts := toYaml .Values.controller.JCasC.configScripts }}
  98. {{- if and (.Values.controller.JCasC.authorizationStrategy) (not (contains "authorizationStrategy:" $configScripts)) }}
  99. authorizationStrategy:
  100. {{- tpl .Values.controller.JCasC.authorizationStrategy . | nindent 4 }}
  101. {{- end }}
  102. {{- if and (.Values.controller.JCasC.securityRealm) (not (contains "securityRealm:" $configScripts)) }}
  103. securityRealm:
  104. {{- tpl .Values.controller.JCasC.securityRealm . | nindent 4 }}
  105. {{- end }}
  106. disableRememberMe: {{ .Values.controller.disableRememberMe }}
  107. {{- if .Values.controller.legacyRemotingSecurityEnabled }}
  108. remotingSecurity:
  109. enabled: true
  110. {{- end }}
  111. mode: {{ .Values.controller.executorMode }}
  112. numExecutors: {{ .Values.controller.numExecutors }}
  113. {{- if not (kindIs "invalid" .Values.controller.customJenkinsLabels) }}
  114. labelString: "{{ join " " .Values.controller.customJenkinsLabels }}"
  115. {{- end }}
  116. {{- if .Values.controller.projectNamingStrategy }}
  117. {{- if kindIs "string" .Values.controller.projectNamingStrategy }}
  118. projectNamingStrategy: "{{ .Values.controller.projectNamingStrategy }}"
  119. {{- else }}
  120. projectNamingStrategy:
  121. {{- toYaml .Values.controller.projectNamingStrategy | nindent 4 }}
  122. {{- end }}
  123. {{- end }}
  124. markupFormatter:
  125. {{- if .Values.controller.enableRawHtmlMarkupFormatter }}
  126. rawHtml:
  127. disableSyntaxHighlighting: true
  128. {{- else }}
  129. {{- toYaml .Values.controller.markupFormatter | nindent 4 }}
  130. {{- end }}
  131. clouds:
  132. - kubernetes:
  133. containerCapStr: "{{ .Values.agent.containerCap }}"
  134. {{- if .Values.agent.jnlpregistry }}
  135. jnlpregistry: "{{ .Values.agent.jnlpregistry }}"
  136. {{- end }}
  137. defaultsProviderTemplate: "{{ .Values.agent.defaultsProviderTemplate }}"
  138. connectTimeout: "{{ .Values.agent.kubernetesConnectTimeout }}"
  139. readTimeout: "{{ .Values.agent.kubernetesReadTimeout }}"
  140. {{- if .Values.agent.directConnection }}
  141. directConnection: true
  142. {{- else }}
  143. {{- if .Values.agent.jenkinsUrl }}
  144. jenkinsUrl: "{{ tpl .Values.agent.jenkinsUrl . }}"
  145. {{- else }}
  146. jenkinsUrl: "http://{{ template "jenkins.fullname" . }}.{{ template "jenkins.namespace" . }}.svc.{{.Values.clusterZone}}:{{.Values.controller.servicePort}}{{ default "" .Values.controller.jenkinsUriPrefix }}"
  147. {{- end }}
  148. {{- if not .Values.agent.websocket }}
  149. {{- if .Values.agent.jenkinsTunnel }}
  150. jenkinsTunnel: "{{ tpl .Values.agent.jenkinsTunnel . }}"
  151. {{- else }}
  152. jenkinsTunnel: "{{ template "jenkins.fullname" . }}-agent.{{ template "jenkins.namespace" . }}.svc.{{.Values.clusterZone}}:{{ .Values.controller.agentListenerPort }}"
  153. {{- end }}
  154. {{- else }}
  155. webSocket: true
  156. {{- end }}
  157. {{- end }}
  158. maxRequestsPerHostStr: {{ .Values.agent.maxRequestsPerHostStr | quote }}
  159. retentionTimeout: {{ .Values.agent.retentionTimeout | quote }}
  160. waitForPodSec: {{ .Values.agent.waitForPodSec | quote }}
  161. name: "{{ .Values.controller.cloudName }}"
  162. namespace: "{{ template "jenkins.agent.namespace" . }}"
  163. serverUrl: "{{ .Values.kubernetesURL }}"
  164. {{- if .Values.agent.enabled }}
  165. podLabels:
  166. - key: "jenkins/{{ .Release.Name }}-{{ .Values.agent.componentName }}"
  167. value: "true"
  168. {{- range $key, $val := .Values.agent.podLabels }}
  169. - key: {{ $key | quote }}
  170. value: {{ $val | quote }}
  171. {{- end }}
  172. templates:
  173. {{- if not .Values.agent.disableDefaultAgent }}
  174. {{- include "jenkins.casc.podTemplate" . | nindent 8 }}
  175. {{- end }}
  176. {{- if .Values.additionalAgents }}
  177. {{- /* save .Values.agent */}}
  178. {{- $agent := .Values.agent }}
  179. {{- range $name, $additionalAgent := .Values.additionalAgents }}
  180. {{- $additionalContainersEmpty := and (hasKey $additionalAgent "additionalContainers") (empty $additionalAgent.additionalContainers) }}
  181. {{- /* merge original .Values.agent into additional agent to ensure it at least has the default values */}}
  182. {{- $additionalAgent := merge $additionalAgent $agent }}
  183. {{- /* clear list of additional containers in case it is configured empty for this agent (merge might have overwritten that) */}}
  184. {{- if $additionalContainersEmpty }}
  185. {{- $_ := set $additionalAgent "additionalContainers" list }}
  186. {{- end }}
  187. {{- /* set .Values.agent to $additionalAgent */}}
  188. {{- $_ := set $.Values "agent" $additionalAgent }}
  189. {{- include "jenkins.casc.podTemplate" $ | nindent 8 }}
  190. {{- end }}
  191. {{- /* restore .Values.agent */}}
  192. {{- $_ := set .Values "agent" $agent }}
  193. {{- end }}
  194. {{- if .Values.agent.podTemplates }}
  195. {{- range $key, $val := .Values.agent.podTemplates }}
  196. {{- tpl $val $ | nindent 8 }}
  197. {{- end }}
  198. {{- end }}
  199. {{- end }}
  200. {{- if .Values.controller.csrf.defaultCrumbIssuer.enabled }}
  201. crumbIssuer:
  202. standard:
  203. excludeClientIPFromCrumb: {{ if .Values.controller.csrf.defaultCrumbIssuer.proxyCompatability }}true{{ else }}false{{- end }}
  204. {{- end }}
  205. {{- include "jenkins.casc.security" . }}
  206. {{- if .Values.controller.scriptApproval }}
  207. scriptApproval:
  208. approvedSignatures:
  209. {{- range $key, $val := .Values.controller.scriptApproval }}
  210. - "{{ $val }}"
  211. {{- end }}
  212. {{- end }}
  213. unclassified:
  214. location:
  215. adminAddress: {{ default "" .Values.controller.jenkinsAdminEmail }}
  216. url: {{ template "jenkins.url" . }}
  217. {{- end -}}
  218. {{/*
  219. Returns a name template to be used for jcasc configmaps, using
  220. suffix passed in at call as index 0
  221. */}}
  222. {{- define "jenkins.casc.configName" -}}
  223. {{- $name := index . 0 -}}
  224. {{- $root := index . 1 -}}
  225. "{{- include "jenkins.fullname" $root -}}-jenkins-{{ $name }}"
  226. {{- end -}}
  227. {{/*
  228. Returns kubernetes pod template configuration as code
  229. */}}
  230. {{- define "jenkins.casc.podTemplate" -}}
  231. - name: "{{ .Values.agent.podName }}"
  232. namespace: "{{ template "jenkins.agent.namespace" . }}"
  233. {{- if .Values.agent.annotations }}
  234. annotations:
  235. {{- range $key, $value := .Values.agent.annotations }}
  236. - key: {{ $key }}
  237. value: {{ $value | quote }}
  238. {{- end }}
  239. {{- end }}
  240. id: {{ sha256sum (toYaml .Values.agent) }}
  241. containers:
  242. - name: "{{ .Values.agent.sideContainerName }}"
  243. alwaysPullImage: {{ .Values.agent.alwaysPullImage }}
  244. args: "{{ .Values.agent.args | replace "$" "^$" }}"
  245. command: {{ .Values.agent.command }}
  246. envVars:
  247. - envVar:
  248. {{- if .Values.agent.directConnection }}
  249. key: "JENKINS_DIRECT_CONNECTION"
  250. {{- if .Values.agent.jenkinsTunnel }}
  251. value: "{{ tpl .Values.agent.jenkinsTunnel . }}"
  252. {{- else }}
  253. value: "{{ template "jenkins.fullname" . }}-agent.{{ template "jenkins.namespace" . }}.svc.{{.Values.clusterZone}}:{{ .Values.controller.agentListenerPort }}"
  254. {{- end }}
  255. {{- else }}
  256. key: "JENKINS_URL"
  257. {{- if .Values.agent.jenkinsUrl }}
  258. value: {{ tpl .Values.agent.jenkinsUrl . }}
  259. {{- else }}
  260. value: "http://{{ template "jenkins.fullname" . }}.{{ template "jenkins.namespace" . }}.svc.{{.Values.clusterZone}}:{{.Values.controller.servicePort}}{{ default "/" .Values.controller.jenkinsUriPrefix }}"
  261. {{- end }}
  262. {{- end }}
  263. image: "{{ .Values.agent.image }}:{{ .Values.agent.tag }}"
  264. {{- if .Values.agent.livenessProbe }}
  265. livenessProbe:
  266. execArgs: {{.Values.agent.livenessProbe.execArgs | quote}}
  267. failureThreshold: {{.Values.agent.livenessProbe.failureThreshold}}
  268. initialDelaySeconds: {{.Values.agent.livenessProbe.initialDelaySeconds}}
  269. periodSeconds: {{.Values.agent.livenessProbe.periodSeconds}}
  270. successThreshold: {{.Values.agent.livenessProbe.successThreshold}}
  271. timeoutSeconds: {{.Values.agent.livenessProbe.timeoutSeconds}}
  272. {{- end }}
  273. privileged: "{{- if .Values.agent.privileged }}true{{- else }}false{{- end }}"
  274. resourceLimitCpu: {{.Values.agent.resources.limits.cpu}}
  275. resourceLimitMemory: {{.Values.agent.resources.limits.memory}}
  276. {{- if .Values.agent.resources.limits.ephemeralStorage }}
  277. resourceLimitEphemeralStorage: {{.Values.agent.resources.limits.ephemeralStorage}}
  278. {{- end }}
  279. resourceRequestCpu: {{.Values.agent.resources.requests.cpu}}
  280. resourceRequestMemory: {{.Values.agent.resources.requests.memory}}
  281. {{- if .Values.agent.resources.requests.ephemeralStorage }}
  282. resourceRequestEphemeralStorage: {{.Values.agent.resources.requests.ephemeralStorage}}
  283. {{- end }}
  284. runAsUser: {{ .Values.agent.runAsUser }}
  285. runAsGroup: {{ .Values.agent.runAsGroup }}
  286. ttyEnabled: {{ .Values.agent.TTYEnabled }}
  287. workingDir: {{ .Values.agent.workingDir }}
  288. {{- range $additionalContainers := .Values.agent.additionalContainers }}
  289. - name: "{{ $additionalContainers.sideContainerName }}"
  290. alwaysPullImage: {{ $additionalContainers.alwaysPullImage | default $.Values.agent.alwaysPullImage }}
  291. args: "{{ $additionalContainers.args | replace "$" "^$" }}"
  292. command: {{ $additionalContainers.command }}
  293. envVars:
  294. - envVar:
  295. key: "JENKINS_URL"
  296. {{- if $additionalContainers.jenkinsUrl }}
  297. value: {{ tpl ($additionalContainers.jenkinsUrl) . }}
  298. {{- else }}
  299. value: "http://{{ template "jenkins.fullname" $ }}.{{ template "jenkins.namespace" $ }}.svc.{{ $.Values.clusterZone }}:{{ $.Values.controller.servicePort }}{{ default "/" $.Values.controller.jenkinsUriPrefix }}"
  300. {{- end }}
  301. image: "{{ $additionalContainers.image }}:{{ $additionalContainers.tag }}"
  302. {{- if $additionalContainers.livenessProbe }}
  303. livenessProbe:
  304. execArgs: {{$additionalContainers.livenessProbe.execArgs | quote}}
  305. failureThreshold: {{$additionalContainers.livenessProbe.failureThreshold}}
  306. initialDelaySeconds: {{$additionalContainers.livenessProbe.initialDelaySeconds}}
  307. periodSeconds: {{$additionalContainers.livenessProbe.periodSeconds}}
  308. successThreshold: {{$additionalContainers.livenessProbe.successThreshold}}
  309. timeoutSeconds: {{$additionalContainers.livenessProbe.timeoutSeconds}}
  310. {{- end }}
  311. privileged: "{{- if $additionalContainers.privileged }}true{{- else }}false{{- end }}"
  312. resourceLimitCpu: {{ if $additionalContainers.resources }}{{ $additionalContainers.resources.limits.cpu }}{{ else }}{{ $.Values.agent.resources.limits.cpu }}{{ end }}
  313. resourceLimitMemory: {{ if $additionalContainers.resources }}{{ $additionalContainers.resources.limits.memory }}{{ else }}{{ $.Values.agent.resources.limits.memory }}{{ end }}
  314. resourceRequestCpu: {{ if $additionalContainers.resources }}{{ $additionalContainers.resources.requests.cpu }}{{ else }}{{ $.Values.agent.resources.requests.cpu }}{{ end }}
  315. resourceRequestMemory: {{ if $additionalContainers.resources }}{{ $additionalContainers.resources.requests.memory }}{{ else }}{{ $.Values.agent.resources.requests.memory }}{{ end }}
  316. runAsUser: {{ $additionalContainers.runAsUser | default $.Values.agent.runAsUser }}
  317. runAsGroup: {{ $additionalContainers.runAsGroup | default $.Values.agent.runAsGroup }}
  318. ttyEnabled: {{ $additionalContainers.TTYEnabled | default $.Values.agent.TTYEnabled }}
  319. workingDir: {{ $additionalContainers.workingDir | default $.Values.agent.workingDir }}
  320. {{- end }}
  321. {{- if or .Values.agent.envVars .Values.agent.secretEnvVars }}
  322. envVars:
  323. {{- range $index, $var := .Values.agent.envVars }}
  324. - envVar:
  325. key: {{ $var.name }}
  326. value: {{ tpl $var.value $ }}
  327. {{- end }}
  328. {{- range $index, $var := .Values.agent.secretEnvVars }}
  329. - secretEnvVar:
  330. key: {{ $var.key }}
  331. secretName: {{ $var.secretName }}
  332. secretKey: {{ $var.secretKey }}
  333. optional: {{ $var.optional | default false }}
  334. {{- end }}
  335. {{- end }}
  336. idleMinutes: {{ .Values.agent.idleMinutes }}
  337. instanceCap: 2147483647
  338. {{- if .Values.agent.hostNetworking }}
  339. hostNetwork: {{ .Values.agent.hostNetworking }}
  340. {{- end }}
  341. {{- if .Values.agent.imagePullSecretName }}
  342. imagePullSecrets:
  343. - name: {{ .Values.agent.imagePullSecretName }}
  344. {{- end }}
  345. label: "{{ .Release.Name }}-{{ .Values.agent.componentName }} {{ .Values.agent.customJenkinsLabels | join " " }}"
  346. {{- if .Values.agent.nodeSelector }}
  347. nodeSelector:
  348. {{- $local := dict "first" true }}
  349. {{- range $key, $value := .Values.agent.nodeSelector }}
  350. {{- if $local.first }} {{ else }},{{ end }}
  351. {{- $key }}={{ tpl $value $ }}
  352. {{- $_ := set $local "first" false }}
  353. {{- end }}
  354. {{- end }}
  355. nodeUsageMode: {{ quote .Values.agent.nodeUsageMode }}
  356. podRetention: {{ .Values.agent.podRetention }}
  357. showRawYaml: {{ .Values.agent.showRawYaml }}
  358. serviceAccount: "{{ include "jenkins.serviceAccountAgentName" . }}"
  359. slaveConnectTimeoutStr: "{{ .Values.agent.connectTimeout }}"
  360. {{- if .Values.agent.volumes }}
  361. volumes:
  362. {{- range $index, $volume := .Values.agent.volumes }}
  363. -{{- if (eq $volume.type "ConfigMap") }} configMapVolume:
  364. {{- else if (eq $volume.type "EmptyDir") }} emptyDirVolume:
  365. {{- else if (eq $volume.type "HostPath") }} hostPathVolume:
  366. {{- else if (eq $volume.type "Nfs") }} nfsVolume:
  367. {{- else if (eq $volume.type "PVC") }} persistentVolumeClaim:
  368. {{- else if (eq $volume.type "Secret") }} secretVolume:
  369. {{- else }} {{ $volume.type }}:
  370. {{- end }}
  371. {{- range $key, $value := $volume }}
  372. {{- if not (eq $key "type") }}
  373. {{ $key }}: {{ if kindIs "string" $value }}{{ tpl $value $ | quote }}{{ else }}{{ $value }}{{ end }}
  374. {{- end }}
  375. {{- end }}
  376. {{- end }}
  377. {{- end }}
  378. {{- if .Values.agent.workspaceVolume }}
  379. workspaceVolume:
  380. {{- if (eq .Values.agent.workspaceVolume.type "DynamicPVC") }}
  381. dynamicPVC:
  382. {{- else if (eq .Values.agent.workspaceVolume.type "EmptyDir") }}
  383. emptyDirWorkspaceVolume:
  384. {{- else if (eq .Values.agent.workspaceVolume.type "HostPath") }}
  385. hostPathWorkspaceVolume:
  386. {{- else if (eq .Values.agent.workspaceVolume.type "Nfs") }}
  387. nfsWorkspaceVolume:
  388. {{- else if (eq .Values.agent.workspaceVolume.type "PVC") }}
  389. persistentVolumeClaimWorkspaceVolume:
  390. {{- else }}
  391. {{ .Values.agent.workspaceVolume.type }}:
  392. {{- end }}
  393. {{- range $key, $value := .Values.agent.workspaceVolume }}
  394. {{- if not (eq $key "type") }}
  395. {{ $key }}: {{ if kindIs "string" $value }}{{ tpl $value $ | quote }}{{ else }}{{ $value }}{{ end }}
  396. {{- end }}
  397. {{- end }}
  398. {{- end }}
  399. {{- if .Values.agent.yamlTemplate }}
  400. yaml: |-
  401. {{- tpl (trim .Values.agent.yamlTemplate) . | nindent 4 }}
  402. {{- end }}
  403. yamlMergeStrategy: {{ .Values.agent.yamlMergeStrategy }}
  404. {{- end -}}
  405. {{- define "jenkins.kubernetes-version" -}}
  406. {{- if .Values.controller.installPlugins -}}
  407. {{- range .Values.controller.installPlugins -}}
  408. {{ if hasPrefix "kubernetes:" . }}
  409. {{- $split := splitList ":" . }}
  410. {{- printf "%s" (index $split 1 ) -}}
  411. {{- end -}}
  412. {{- end -}}
  413. {{- end -}}
  414. {{- end -}}
  415. {{- define "jenkins.casc.security" }}
  416. security:
  417. {{- with .Values.controller.JCasC }}
  418. {{- if .security }}
  419. {{- .security | toYaml | nindent 2 }}
  420. {{- end }}
  421. {{- end }}
  422. {{- end -}}
  423. {{/*
  424. Create the name of the service account to use
  425. */}}
  426. {{- define "jenkins.serviceAccountName" -}}
  427. {{- if .Values.serviceAccount.create -}}
  428. {{ default (include "jenkins.fullname" .) .Values.serviceAccount.name }}
  429. {{- else -}}
  430. {{ default "default" .Values.serviceAccount.name }}
  431. {{- end -}}
  432. {{- end -}}
  433. {{/*
  434. Create the name of the service account for Jenkins agents to use
  435. */}}
  436. {{- define "jenkins.serviceAccountAgentName" -}}
  437. {{- if .Values.serviceAccountAgent.create -}}
  438. {{ default (printf "%s-%s" (include "jenkins.fullname" .) "agent") .Values.serviceAccountAgent.name }}
  439. {{- else -}}
  440. {{ default "default" .Values.serviceAccountAgent.name }}
  441. {{- end -}}
  442. {{- end -}}
  443. {{/*
  444. Create the name of the service account for Jenkins backup to use
  445. */}}
  446. {{- define "backup.serviceAccountBackupName" -}}
  447. {{- if .Values.backup.serviceAccount.create -}}
  448. {{ default (printf "%s-%s" (include "jenkins.fullname" .) "backup") .Values.backup.serviceAccount.name }}
  449. {{- else -}}
  450. {{ default "default" .Values.backup.serviceAccount.name }}
  451. {{- end -}}
  452. {{- end -}}
  453. {{/*
  454. Create a full tag name for controller image
  455. */}}
  456. {{- define "controller.tag" -}}
  457. {{- if .Values.controller.tagLabel -}}
  458. {{- default (printf "%s-%s" .Chart.AppVersion .Values.controller.tagLabel) .Values.controller.tag -}}
  459. {{- else -}}
  460. {{- default .Chart.AppVersion .Values.controller.tag -}}
  461. {{- end -}}
  462. {{- end -}}
  463. {{/*
  464. Create the HTTP port for interacting with the controller
  465. */}}
  466. {{- define "controller.httpPort" -}}
  467. {{- if .Values.controller.httpsKeyStore.enable -}}
  468. {{- .Values.controller.httpsKeyStore.httpPort -}}
  469. {{- else -}}
  470. {{- .Values.controller.targetPort -}}
  471. {{- end -}}
  472. {{- end -}}
  473. {{- define "jenkins.configReloadContainer" -}}
  474. {{- $root := index . 0 -}}
  475. {{- $containerName := index . 1 -}}
  476. {{- $containerType := index . 2 -}}
  477. - name: {{ $containerName }}
  478. image: "{{ $root.Values.controller.sidecars.configAutoReload.image }}"
  479. imagePullPolicy: {{ $root.Values.controller.sidecars.configAutoReload.imagePullPolicy }}
  480. {{- if $root.Values.controller.sidecars.configAutoReload.containerSecurityContext }}
  481. securityContext: {{- toYaml $root.Values.controller.sidecars.configAutoReload.containerSecurityContext | nindent 4 }}
  482. {{- end }}
  483. {{- if $root.Values.controller.sidecars.configAutoReload.envFrom }}
  484. envFrom:
  485. {{ (tpl (toYaml $root.Values.controller.sidecars.configAutoReload.envFrom) $root) | indent 4 }}
  486. {{- end }}
  487. env:
  488. - name: POD_NAME
  489. valueFrom:
  490. fieldRef:
  491. fieldPath: metadata.name
  492. - name: LABEL
  493. value: "{{ template "jenkins.fullname" $root }}-jenkins-config"
  494. - name: FOLDER
  495. value: "{{ $root.Values.controller.sidecars.configAutoReload.folder }}"
  496. - name: NAMESPACE
  497. value: '{{ $root.Values.controller.sidecars.configAutoReload.searchNamespace | default (include "jenkins.namespace" $root) }}'
  498. {{- if eq $containerType "init" }}
  499. - name: METHOD
  500. value: "LIST"
  501. {{- else if $root.Values.controller.sidecars.configAutoReload.sleepTime }}
  502. - name: METHOD
  503. value: "SLEEP"
  504. - name: SLEEP_TIME
  505. value: "{{ $root.Values.controller.sidecars.configAutoReload.sleepTime }}"
  506. {{- end }}
  507. {{- if eq $containerType "sidecar" }}
  508. - name: REQ_URL
  509. value: "http://localhost:{{- include "controller.httpPort" $root -}}{{- $root.Values.controller.jenkinsUriPrefix -}}/reload-configuration-as-code/?casc-reload-token=$(POD_NAME)"
  510. - name: REQ_METHOD
  511. value: "POST"
  512. - name: REQ_RETRY_CONNECT
  513. value: "{{ $root.Values.controller.sidecars.configAutoReload.reqRetryConnect }}"
  514. {{- end }}
  515. {{- if $root.Values.controller.sidecars.configAutoReload.env }}
  516. {{- range $envVarItem := $root.Values.controller.sidecars.configAutoReload.env -}}
  517. {{- if or (ne $containerType "init") (ne .name "METHOD") }}
  518. {{- (tpl (toYaml (list $envVarItem)) $root) | nindent 4 }}
  519. {{- end -}}
  520. {{- end -}}
  521. {{- end }}
  522. resources:
  523. {{ toYaml $root.Values.controller.sidecars.configAutoReload.resources | indent 4 }}
  524. volumeMounts:
  525. - name: sc-config-volume
  526. mountPath: {{ $root.Values.controller.sidecars.configAutoReload.folder | quote }}
  527. - name: jenkins-home
  528. mountPath: {{ $root.Values.controller.jenkinsHome }}
  529. {{- if $root.Values.persistence.subPath }}
  530. subPath: {{ $root.Values.persistence.subPath }}
  531. {{- end }}
  532. {{- end -}}