jenkins-master-deployment.yaml 16.7 KB
Newer Older
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
{{- if .Capabilities.APIVersions.Has "apps/v1" }}
apiVersion: apps/v1
{{- else }}
apiVersion: apps/v1beta1
{{- end }}
kind: Deployment
metadata:
  name: {{ template "jenkins.fullname" . }}
  namespace: {{ template "jenkins.namespace" . }}
  labels:
    "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
    "helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
    "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
    "app.kubernetes.io/instance": "{{ .Release.Name }}"
    "app.kubernetes.io/component": "{{ .Values.master.componentName }}"
    {{- range $key, $val := .Values.master.deploymentLabels }}
    {{ $key }}: {{ $val | quote }}
    {{- end}}
  {{- if .Values.master.deploymentAnnotations }}
  annotations:
{{ toYaml .Values.master.deploymentAnnotations | indent 4 }}
  {{- end }}
spec:
  replicas: 1
  strategy:
    type: {{ if .Values.persistence.enabled }}Recreate{{ else }}RollingUpdate
    rollingUpdate:
{{ toYaml .Values.master.rollingUpdate | indent 6 }}
    {{- end }}
  selector:
    matchLabels:
      "app.kubernetes.io/component": "{{ .Values.master.componentName }}"
      "app.kubernetes.io/instance": "{{ .Release.Name }}"
  template:
    metadata:
      labels:
        "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
        "helm.sh/chart": "{{ .Chart.Name }}-{{ .Chart.Version }}"
        "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
        "app.kubernetes.io/instance": "{{ .Release.Name }}"
        "app.kubernetes.io/component": "{{ .Values.master.componentName }}"
        {{- range $key, $val := .Values.master.podLabels }}
        {{ $key }}: {{ $val | quote }}
        {{- end}}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/config.yaml") . | sha256sum }}
        {{- if .Values.master.podAnnotations }}
{{ toYaml .Values.master.podAnnotations | indent 8 }}
        {{- end }}
    spec:
      {{- if .Values.master.schedulerName }}
      schedulerName: {{ .Values.master.schedulerName }}
      {{- end }}
      {{- if .Values.master.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.master.nodeSelector | indent 8 }}
      {{- end }}
      {{- if .Values.master.tolerations }}
      tolerations:
{{ toYaml .Values.master.tolerations | indent 8 }}
      {{- end }}
      {{- if .Values.master.affinity }}
      affinity:
{{ toYaml .Values.master.affinity | indent 8 }}
      {{- end }}
      {{- if quote .Values.master.terminationGracePeriodSeconds }}
      terminationGracePeriodSeconds: {{ .Values.master.terminationGracePeriodSeconds }}
      {{- end }}
      {{- if and (.Capabilities.APIVersions.Has "scheduling.k8s.io/v1beta1") (.Values.master.priorityClassName) }}
      priorityClassName: {{ .Values.master.priorityClassName }}
      {{- end }}
{{- if .Values.master.usePodSecurityContext }}
      securityContext:
        runAsUser: {{ default 0 .Values.master.runAsUser }}
{{- if and (.Values.master.runAsUser) (.Values.master.fsGroup) }}
{{- if not (eq .Values.master.runAsUser 0.0) }}
        fsGroup: {{ .Values.master.fsGroup }}
{{- end }}
{{- end }}
{{- end }}
      serviceAccountName: "{{ template "jenkins.serviceAccountName" . }}"
{{- if .Values.master.hostNetworking }}
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
{{- end }}
      {{- if .Values.master.hostAliases }}
      hostAliases:
        {{- toYaml .Values.master.hostAliases | nindent 8 }}
      {{- end }}
      initContainers:
{{- if .Values.master.customInitContainers }}
{{ tpl (toYaml .Values.master.customInitContainers) . | indent 8 }}
{{- end }}
        - name: "copy-default-config"
{{- if .Values.master.imageTag }}
          image: "{{ .Values.master.image }}:{{ .Values.master.imageTag }}"
{{- else }}
          image: "{{ .Values.master.image }}:{{ .Values.master.tag }}"
{{- end }}
          imagePullPolicy: "{{ .Values.master.imagePullPolicy }}"
          command: [ "sh", "/var/jenkins_config/apply_config.sh" ]
          env:
          {{- if .Values.master.useSecurity }}
            - name: ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "jenkins.fullname" . }}
                  key: jenkins-admin-password
            - name: ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: {{ template "jenkins.fullname" . }}
                  key: jenkins-admin-user
            {{- end }}
            {{- if .Values.master.initContainerEnv }}
{{ toYaml .Values.master.initContainerEnv | indent 12 }}
            {{- end }}
          resources:
{{ toYaml .Values.master.resources | indent 12 }}
          volumeMounts:
            - mountPath: /tmp
              name: tmp
            - mountPath: {{ .Values.master.jenkinsHome }}
              name: jenkins-home
              {{- if .Values.persistence.subPath }}
              subPath: {{ .Values.persistence.subPath }}
              {{- end }}
            - mountPath: /var/jenkins_config
              name: jenkins-config
            {{- if .Values.master.enableXmlConfig }}
            {{- if .Values.master.credentialsXmlSecret }}
            - mountPath: /var/jenkins_credentials
              name: jenkins-credentials
              readOnly: true
            {{- end }}
            {{- if .Values.master.jobs }}
            - mountPath: /var/jenkins_jobs
              name: jenkins-jobs
              readOnly: true
            {{- end }}
            - mountPath: {{ .Values.master.jenkinsRef }}/secrets/
              name: secrets-dir
            {{- end }}
            {{- if .Values.master.secretsFilesSecret }}
            - mountPath: /var/jenkins_secrets
              name: jenkins-secrets
              readOnly: true
            {{- end }}
            {{- if .Values.master.installPlugins }}
            - mountPath: {{ .Values.master.jenkinsRef }}/plugins
              name: plugins
            - mountPath: /var/jenkins_plugins
              name: plugin-dir
            {{- end }}
      containers:
        - name: jenkins
{{- if .Values.master.imageTag }}
          image: "{{ .Values.master.image }}:{{ .Values.master.imageTag }}"
{{- else }}
          image: "{{ .Values.master.image }}:{{ .Values.master.tag }}"
{{- end }}
          imagePullPolicy: "{{ .Values.master.imagePullPolicy }}"
          {{- if .Values.master.httpsKeyStore.enable }}
          {{- $httpsJKSFilePath :=  printf "%s/%s" .Values.master.httpsKeyStore.path .Values.master.httpsKeyStore.fileName -}}
              {{- if .Values.master.useSecurity }}
          args: [ "--argumentsRealm.passwd.$(ADMIN_USER)=$(ADMIN_PASSWORD)",  "--argumentsRealm.roles.$(ADMIN_USER)=admin", "--httpPort={{.Values.master.httpsKeyStore.httpPort}}", "--httpsPort={{.Values.master.targetPort}}", '--httpsKeyStore={{ $httpsJKSFilePath }}', "--httpsKeyStorePassword=$(JENKINS_HTTPS_KEYSTORE_PASSWORD)" ]
              {{- else }}
          args: [ "--httpPort={{.Values.master.httpsKeyStore.httpPort}}", "--httpsPort={{.Values.master.targetPort}}", '--httpsKeyStore={{ $httpsJKSFilePath | quote }}', "--httpsKeyStorePassword=$(JENKINS_HTTPS_KEYSTORE_PASSWORD)" ]
              {{- end }}
          {{- else if .Values.master.useSecurity }}
          args: [ "--argumentsRealm.passwd.$(ADMIN_USER)=$(ADMIN_PASSWORD)",  "--argumentsRealm.roles.$(ADMIN_USER)=admin", "--httpPort={{.Values.master.targetPort}}"]
          {{- end }}
          {{- if .Values.master.lifecycle }}
          lifecycle:
{{ toYaml .Values.master.lifecycle | indent 12 }}
          {{- end }}
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: JAVA_OPTS
              value: >
                {{ default "" .Values.master.javaOpts }}
                {{ if .Values.master.sidecars.configAutoReload.enabled }} -Dcasc.reload.token=$(POD_NAME) {{ end }}
            - name: JENKINS_OPTS
              value: "{{ if .Values.master.jenkinsUriPrefix }}--prefix={{ .Values.master.jenkinsUriPrefix }} {{ end }}{{ default "" .Values.master.jenkinsOpts}}"
            - name: JENKINS_SLAVE_AGENT_PORT
              value: "{{ .Values.master.slaveListenerPort }}"
            {{- if .Values.master.useSecurity }}
            - name: ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "jenkins.fullname" . }}
                  key: jenkins-admin-password
            - name: ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: {{ template "jenkins.fullname" . }}
                  key: jenkins-admin-user
            {{- end }}
            {{- if .Values.master.httpsKeyStore.enable }}
            - name: JENKINS_HTTPS_KEYSTORE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ if .Values.master.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ .Values.master.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ else }} {{ template "jenkins.fullname" . }}-https-jks  {{ end }}
                  key: {{ "https-jks-password" | quote }}
            {{- end }}

            {{- if .Values.master.containerEnv }}
{{ toYaml .Values.master.containerEnv | indent 12 }}
            {{- end }}
            {{- if .Values.master.JCasC.enabled }}
            - name: CASC_JENKINS_CONFIG
              value: {{ .Values.master.sidecars.configAutoReload.folder | default (printf "%s/casc_configs" (.Values.master.jenkinsRef)) }}
            {{- end }}
          ports:
            {{- if .Values.master.httpsKeyStore.enable }}
            - containerPort: {{.Values.master.httpsKeyStore.httpPort}}
            {{- else }}
            - containerPort: {{.Values.master.targetPort}}
            {{- end }}
              name: http
            - containerPort: {{ .Values.master.slaveListenerPort }}
              name: slavelistener
              {{- if .Values.master.slaveHostPort }}
              hostPort: {{ .Values.master.slaveHostPort }}
              {{- end }}
            {{- if .Values.master.jmxPort }}
            - containerPort: {{ .Values.master.jmxPort }}
              name: jmx
            {{- end }}
{{- range $index, $port := .Values.master.extraPorts }}
            - containerPort: {{ $port.port }}
              name: {{ $port.name }}
{{- end }}
{{- if .Values.master.healthProbes }}
          livenessProbe:
            httpGet:
              path: "{{ default "" .Values.master.jenkinsUriPrefix }}/login"
              port: http
            initialDelaySeconds: {{ .Values.master.healthProbeLivenessInitialDelay }}
            periodSeconds: {{ .Values.master.healthProbeLivenessPeriodSeconds }}
            timeoutSeconds: {{ .Values.master.healthProbesLivenessTimeout }}
            failureThreshold: {{ .Values.master.healthProbeLivenessFailureThreshold }}
          readinessProbe:
            httpGet:
              path: "{{ default "" .Values.master.jenkinsUriPrefix }}/login"
              port: http
            initialDelaySeconds: {{ .Values.master.healthProbeReadinessInitialDelay }}
            periodSeconds: {{ .Values.master.healthProbeReadinessPeriodSeconds }}
            timeoutSeconds: {{ .Values.master.healthProbesReadinessTimeout }}
            failureThreshold: {{ .Values.master.healthProbeReadinessFailureThreshold }}
{{- end }}

          resources:
{{ toYaml .Values.master.resources | indent 12 }}
          volumeMounts:
{{- if .Values.persistence.mounts }}
{{ toYaml .Values.persistence.mounts | indent 12 }}
{{- end }}
            {{- if .Values.master.httpsKeyStore.enable }}
            - mountPath: {{ .Values.master.httpsKeyStore.path }}
              name: jenkins-https-keystore
            {{- end }}
            - mountPath: /tmp
              name: tmp
            - mountPath: {{ .Values.master.jenkinsHome }}
              name: jenkins-home
              readOnly: false
              {{- if .Values.persistence.subPath }}
              subPath: {{ .Values.persistence.subPath }}
              {{- end }}
            - mountPath: /var/jenkins_config
              name: jenkins-config
              readOnly: true
            {{- if .Values.master.enableXmlConfig }}
            {{- if .Values.master.credentialsXmlSecret }}
            - mountPath: /var/jenkins_credentials
              name: jenkins-credentials
              readOnly: true
            {{- end }}
            {{- if .Values.master.jobs }}
            - mountPath: /var/jenkins_jobs
              name: jenkins-jobs
              readOnly: true
            {{- end }}
            - mountPath: {{ .Values.master.jenkinsRef }}/secrets/
              name: secrets-dir
              readOnly: false
            {{- end }}
            {{- if or .Values.master.secretsFilesSecret }}
            - mountPath: /var/jenkins_secrets
              name: jenkins-secrets
              readOnly: true
            {{- end }}
            {{- if .Values.master.installPlugins }}
            - mountPath: {{ .Values.master.jenkinsRef }}/plugins/
              name: plugin-dir
              readOnly: false
            {{- end }}
            {{- if and (.Values.master.JCasC.enabled) (.Values.master.sidecars.configAutoReload.enabled) }}
            - name: sc-config-volume
              mountPath: {{ .Values.master.sidecars.configAutoReload.folder | default (printf "%s/casc_configs" (.Values.master.jenkinsRef)) }}
            {{- end }}

{{- if and (.Values.master.JCasC.enabled) (.Values.master.sidecars.configAutoReload.enabled) }}
        - name: jenkins-sc-config
          image: "{{ .Values.master.sidecars.configAutoReload.image }}"
          imagePullPolicy: {{ .Values.master.sidecars.configAutoReload.imagePullPolicy }}
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: LABEL
              value: "{{ template "jenkins.fullname" . }}-jenkins-config"
            - name: FOLDER
              value: "{{ .Values.master.sidecars.configAutoReload.folder }}"
            - name: NAMESPACE
              value: "{{ .Values.master.sidecars.configAutoReload.searchNamespace | default .Release.Namespace }}"
            - name: REQ_URL
              value: "http://localhost:8080{{- .Values.master.jenkinsUriPrefix -}}/reload-configuration-as-code/?casc-reload-token=$(POD_NAME)"
            - name: REQ_METHOD
              value: "POST"
          resources:
{{ toYaml .Values.master.sidecars.configAutoReload.resources | indent 12 }}
          volumeMounts:
            - name: sc-config-volume
              mountPath: {{ .Values.master.sidecars.configAutoReload.folder | quote }}
            - name: jenkins-home
              mountPath: {{ .Values.master.jenkinsHome }}
              {{- if .Values.persistence.subPath }}
              subPath: {{ .Values.persistence.subPath }}
              {{- end }}
{{- end}}


{{- if .Values.master.sidecars.other}}
{{ tpl (toYaml .Values.master.sidecars.other | indent 8) .}}
{{- end }}

      volumes:
{{- if .Values.persistence.volumes }}
{{ tpl (toYaml .Values.persistence.volumes | indent 6) . }}
{{- end }}
      - name: plugins
        emptyDir: {}
      - name: tmp
        emptyDir: {}
      - name: jenkins-config
        configMap:
          name: {{ template "jenkins.fullname" . }}
      {{- if .Values.master.enableXmlConfig }}
      {{- if .Values.master.credentialsXmlSecret }}
      - name: jenkins-credentials
        secret:
          secretName: {{ .Values.master.credentialsXmlSecret }}
      {{- end }}
      {{- if .Values.master.jobs }}
      - name: jenkins-jobs
        configMap:
          name: {{ template "jenkins.fullname" . }}-jobs
      {{- end }}
      - name: secrets-dir
        emptyDir: {}
      {{- end }}
      {{- if .Values.master.secretsFilesSecret }}
      - name: jenkins-secrets
        secret:
          secretName: {{ .Values.master.secretsFilesSecret }}
      {{- end }}
      {{- if .Values.master.installPlugins }}
      - name: plugin-dir
        emptyDir: {}
      {{- end }}
      {{- if not (contains "jenkins-home" (quote .Values.persistence.volumes)) }}
      - name: jenkins-home
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim | default (include "jenkins.fullname" .) }}
      {{- else }}
        emptyDir: {}
      {{- end -}}
      {{- end -}}
      {{- if .Values.master.JCasC.enabled }}
      - name: sc-config-volume
        emptyDir: {}
      {{- end }}

      {{- if .Values.master.httpsKeyStore.enable }}
      - name: jenkins-https-keystore
        secret:
          secretName: {{ if .Values.master.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ .Values.master.httpsKeyStore.jenkinsHttpsJksSecretName }} {{ else }} {{ template "jenkins.fullname" . }}-https-jks  {{ end }}
          items:
          - key: jenkins-jks-file
            path: {{ .Values.master.httpsKeyStore.fileName }}
      {{- end }}

{{- if .Values.master.imagePullSecretName }}
      imagePullSecrets:
      - name: {{ .Values.master.imagePullSecretName }}
{{- end -}}