jenkins-backup-cronjob.yaml 4.13 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
{{- if .Values.backup.enabled }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ template "jenkins.fullname" . }}-backup
  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.backup.componentName }}"
spec:
  schedule: {{ .Values.backup.schedule | quote }}
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 120
  jobTemplate:
    spec:
      template:
        metadata:
          {{- if .Values.backup.labels }}
          labels:
{{ toYaml .Values.backup.labels | trim | indent 12 }}
          {{- end }}
          {{- if .Values.backup.annotations }}
          annotations:
{{ toYaml .Values.backup.annotations | trim | indent 12 }}
          {{- end }}
        spec:
          restartPolicy: OnFailure
          serviceAccountName: {{ template "jenkins.fullname" . }}-backup
          containers:
          - name: jenkins-backup
            image: "{{ .Values.backup.image.repository }}:{{ .Values.backup.image.tag }}"
            command: ["kube-tasks"]
            args:
            - simple-backup
            - -n
            - {{ template "jenkins.namespace" . }}
            - -l
            - app.kubernetes.io/instance={{ .Release.Name }}
            - --container
            - jenkins
            - --path
            - {{ .Values.master.jenkinsHome }}
            - --dst
            - {{ .Values.backup.destination }}
            {{- with .Values.backup.extraArgs }}
{{ toYaml . | indent 12 }}
            {{- end }}
            env:
            {{- with .Values.backup.env }}
{{ toYaml . | trim | indent 12 }}
            {{- end }}
            {{- if .Values.backup.existingSecret }}
            {{- range $key,$value := .Values.backup.existingSecret }}
            {{- if $value.awsaccesskey }}
            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                secretKeyRef:
                  name: {{ $key }}
                  key: {{ $value.awsaccesskey | quote }}
            {{- end }}
            {{- if $value.awssecretkey }}
            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ $key }}
                  key: {{ $value.awssecretkey | quote}}
            {{- end }}
            {{- if $value.gcpcredentials }}
            - name: GOOGLE_APPLICATION_CREDENTIALS
              value: "/var/run/secrets/{{ $key }}/{{ $value.gcpcredentials }}"
            {{- end }}
            {{- end }}
            {{- end }}
          {{- with .Values.backup.resources }}
            resources:
{{ toYaml . | trim | indent 14 }}
          {{- end }}
            volumeMounts:
          {{- if .Values.backup.existingSecret }}
          {{- range $key,$value := .Values.backup.existingSecret }}
          {{- if $value.gcpcredentials }}
            - mountPath: /var/run/secrets/{{ $key }}
              name: {{ $key }}
          {{- end }}
          {{- end }}
          {{- end }}
          volumes:
          {{- if .Values.backup.existingSecret }}
          {{- range $key,$value := .Values.backup.existingSecret }}
          {{- if $value.gcpcredentials }}
          - name:  {{ $key }}
            secret:
              secretName:  {{ $key }}
          {{- end }}
          {{- end }}
          {{- end }}
          affinity:
            podAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 100
                podAffinityTerm:
                  topologyKey: "kubernetes.io/hostname"
                  labelSelector:
                    matchExpressions:
                    - key: app
                      operator: In
                      values:
                      - {{ template "jenkins.fullname" . }}
                    - key: release
                      operator: In
                      values:
                      - {{ .Release.Name }}
      {{- with .Values.tolerations }}
        tolerations:
{{ toYaml . | indent 10 }}
      {{- end }}
{{- end }}