| Giorgi Lekveishvili | 3598266 | 2024-04-05 13:05:40 +0400 | [diff] [blame^] | 1 | {{- $jenkinsHome := .Values.controller.jenkinsHome -}} |
| 2 | |
| 3 | apiVersion: v1 |
| 4 | kind: ConfigMap |
| 5 | metadata: |
| 6 | name: {{ template "jenkins.fullname" . }} |
| 7 | namespace: {{ template "jenkins.namespace" . }} |
| 8 | labels: |
| 9 | "app.kubernetes.io/name": '{{ template "jenkins.name" .}}' |
| 10 | "app.kubernetes.io/managed-by": "{{ .Release.Service }}" |
| 11 | "app.kubernetes.io/instance": "{{ .Release.Name }}" |
| 12 | "app.kubernetes.io/component": "{{ .Values.controller.componentName }}" |
| 13 | data: |
| 14 | apply_config.sh: |- |
| 15 | set -e |
| 16 | {{- if .Values.controller.initializeOnce }} |
| 17 | if [ -f {{ .Values.controller.jenkinsHome }}/initialization-completed ]; then |
| 18 | echo "controller was previously initialized, refusing to re-initialize" |
| 19 | exit 0 |
| 20 | fi |
| 21 | {{- end }} |
| 22 | echo "disable Setup Wizard" |
| 23 | # Prevent Setup Wizard when JCasC is enabled |
| 24 | echo $JENKINS_VERSION > {{ .Values.controller.jenkinsHome }}/jenkins.install.UpgradeWizard.state |
| 25 | echo $JENKINS_VERSION > {{ .Values.controller.jenkinsHome }}/jenkins.install.InstallUtil.lastExecVersion |
| 26 | {{- if .Values.controller.overwritePlugins }} |
| 27 | echo "remove all plugins from shared volume" |
| 28 | # remove all plugins from shared volume |
| 29 | rm -rf {{ .Values.controller.jenkinsHome }}/plugins/* |
| 30 | {{- end }} |
| 31 | {{- if .Values.controller.JCasC.overwriteConfiguration }} |
| 32 | echo "deleting all XML config files" |
| 33 | rm -f {{ .Values.controller.jenkinsHome }}/config.xml |
| 34 | rm -f {{ .Values.controller.jenkinsHome }}/*plugins*.xml |
| 35 | find {{ .Values.controller.jenkinsHome }} -maxdepth 1 -type f -iname '*configuration*.xml' -exec rm -f {} \; |
| 36 | {{- end }} |
| 37 | {{- if .Values.controller.installPlugins }} |
| 38 | echo "download plugins" |
| 39 | # Install missing plugins |
| 40 | cp /var/jenkins_config/plugins.txt {{ .Values.controller.jenkinsHome }}; |
| 41 | rm -rf {{ .Values.controller.jenkinsRef }}/plugins/*.lock |
| 42 | version () { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } |
| 43 | if [ -f "{{ .Values.controller.jenkinsWar }}" ] && [ -n "$(command -v jenkins-plugin-cli)" 2>/dev/null ] && [ $(version $(jenkins-plugin-cli --version)) -ge $(version "2.1.1") ]; then |
| 44 | jenkins-plugin-cli --verbose --war "{{ .Values.controller.jenkinsWar }}" --plugin-file "{{ .Values.controller.jenkinsHome }}/plugins.txt" --latest {{ .Values.controller.installLatestPlugins }}{{- if .Values.controller.installLatestSpecifiedPlugins }} --latest-specified{{- end }}; |
| 45 | else |
| 46 | /usr/local/bin/install-plugins.sh `echo $(cat {{ .Values.controller.jenkinsHome }}/plugins.txt)`; |
| 47 | fi |
| 48 | echo "copy plugins to shared volume" |
| 49 | # Copy plugins to shared volume |
| 50 | yes n | cp -i {{ .Values.controller.jenkinsRef }}/plugins/* /var/jenkins_plugins/; |
| 51 | {{- end }} |
| 52 | {{- if not .Values.controller.sidecars.configAutoReload.enabled }} |
| 53 | echo "copy configuration as code files" |
| 54 | mkdir -p {{ .Values.controller.jenkinsHome }}/casc_configs; |
| 55 | rm -rf {{ .Values.controller.jenkinsHome }}/casc_configs/* |
| 56 | {{- if or .Values.controller.JCasC.defaultConfig .Values.controller.JCasC.configScripts }} |
| 57 | cp -v /var/jenkins_config/*.yaml {{ .Values.controller.jenkinsHome }}/casc_configs |
| 58 | {{- end }} |
| 59 | {{- end }} |
| 60 | echo "finished initialization" |
| 61 | {{- if .Values.controller.initializeOnce }} |
| 62 | touch {{ .Values.controller.jenkinsHome }}/initialization-completed |
| 63 | {{- end }} |
| 64 | {{- if not .Values.controller.sidecars.configAutoReload.enabled }} |
| 65 | # Only add config to this script if we aren't auto-reloading otherwise the pod will restart upon each config change: |
| 66 | {{- if .Values.controller.JCasC.defaultConfig }} |
| 67 | jcasc-default-config.yaml: |- |
| 68 | {{- include "jenkins.casc.defaults" . |nindent 4}} |
| 69 | {{- end }} |
| 70 | {{- range $key, $val := .Values.controller.JCasC.configScripts }} |
| 71 | {{ $key }}.yaml: |- |
| 72 | {{ tpl $val $| indent 4 }} |
| 73 | {{- end }} |
| 74 | {{- end }} |
| 75 | plugins.txt: |- |
| 76 | {{- if .Values.controller.installPlugins }} |
| 77 | {{- range $installPlugin := .Values.controller.installPlugins }} |
| 78 | {{- $installPlugin | nindent 4 }} |
| 79 | {{- end }} |
| 80 | {{- range $addlPlugin := .Values.controller.additionalPlugins }} |
| 81 | {{- /* duplicate plugin check */}} |
| 82 | {{- range $installPlugin := $.Values.controller.installPlugins }} |
| 83 | {{- if eq (splitList ":" $addlPlugin | first) (splitList ":" $installPlugin | first) }} |
| 84 | {{- $message := print "[PLUGIN CONFLICT] controller.additionalPlugins contains '" $addlPlugin "'" }} |
| 85 | {{- $message := print $message " but controller.installPlugins already contains '" $installPlugin "'." }} |
| 86 | {{- $message := print $message " Override controller.installPlugins to use '" $addlPlugin "' plugin." }} |
| 87 | {{- fail $message }} |
| 88 | {{- end }} |
| 89 | {{- end }} |
| 90 | {{- $addlPlugin | nindent 4 }} |
| 91 | {{- end }} |
| 92 | {{- end }} |