jenkins-backup-cronjob.yaml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {{- if .Values.backup.enabled }}
  2. apiVersion: {{ .Values.cronJob.apiVersion }}
  3. kind: CronJob
  4. metadata:
  5. name: {{ template "jenkins.fullname" . }}-backup
  6. namespace: {{ template "jenkins.namespace" . }}
  7. labels:
  8. "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
  9. {{- if .Values.renderHelmLabels }}
  10. "helm.sh/chart": "{{ template "jenkins.label" .}}"
  11. {{- end }}
  12. "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
  13. "app.kubernetes.io/instance": "{{ .Release.Name }}"
  14. "app.kubernetes.io/component": "{{ .Values.backup.componentName }}"
  15. spec:
  16. schedule: {{ .Values.backup.schedule | quote }}
  17. concurrencyPolicy: Forbid
  18. startingDeadlineSeconds: 120
  19. jobTemplate:
  20. spec:
  21. {{- if .Values.backup.activeDeadlineSeconds }}
  22. activeDeadlineSeconds: {{ .Values.backup.activeDeadlineSeconds }}
  23. {{- end }}
  24. template:
  25. metadata:
  26. {{- if .Values.backup.labels }}
  27. labels:
  28. {{- toYaml .Values.backup.labels | trim | nindent 12 }}
  29. {{- end }}
  30. {{- if .Values.backup.annotations }}
  31. annotations:
  32. {{- toYaml .Values.backup.annotations | trim | nindent 12 }}
  33. {{- end }}
  34. spec:
  35. restartPolicy: OnFailure
  36. serviceAccountName: {{ include "backup.serviceAccountBackupName" . }}
  37. {{- if .Values.backup.usePodSecurityContext }}
  38. securityContext:
  39. {{- if hasKey .Values.backup "podSecurityContextOverride" }}
  40. {{- tpl (toYaml .Values.backup.podSecurityContextOverride | nindent 12) . }}
  41. {{- else }}
  42. runAsUser: {{ default 0 .Values.backup.runAsUser }}
  43. {{- if and (.Values.backup.runAsUser) (.Values.backup.fsGroup) }}
  44. {{- if not (eq (int .Values.backup.runAsUser) 0) }}
  45. fsGroup: {{ .Values.backup.fsGroup }}
  46. {{- end }}
  47. {{- end }}
  48. {{- if .Values.backup.securityContextCapabilities }}
  49. capabilities:
  50. {{- toYaml .Values.backup.securityContextCapabilities | nindent 12 }}
  51. {{- end }}
  52. {{- end }}
  53. {{- end }}
  54. containers:
  55. - name: jenkins-backup
  56. image: "{{ .Values.backup.image.repository }}:{{ .Values.backup.image.tag }}"
  57. command: ["kube-tasks"]
  58. args:
  59. - simple-backup
  60. - -n
  61. - {{ template "jenkins.namespace" . }}
  62. - -l
  63. - app.kubernetes.io/instance={{ .Release.Name }}
  64. - --container
  65. - jenkins
  66. - --path
  67. {{- if .Values.backup.onlyJobs }}
  68. - {{ .Values.controller.jenkinsHome }}/jobs
  69. {{- else}}
  70. - {{ .Values.controller.jenkinsHome }}
  71. {{- end}}
  72. - --dst
  73. - {{ .Values.backup.destination }}
  74. {{- with .Values.backup.extraArgs }}
  75. {{- toYaml . | nindent 12 }}
  76. {{- end }}
  77. env:
  78. {{- with .Values.backup.env }}
  79. {{- toYaml . | trim | nindent 12 }}
  80. {{- end }}
  81. {{- if .Values.backup.existingSecret }}
  82. {{- range $key,$value := .Values.backup.existingSecret }}
  83. {{- if $value.awsaccesskey }}
  84. - name: AWS_ACCESS_KEY_ID
  85. valueFrom:
  86. secretKeyRef:
  87. name: {{ $key }}
  88. key: {{ $value.awsaccesskey | quote }}
  89. {{- end }}
  90. {{- if $value.awssecretkey }}
  91. - name: AWS_SECRET_ACCESS_KEY
  92. valueFrom:
  93. secretKeyRef:
  94. name: {{ $key }}
  95. key: {{ $value.awssecretkey | quote}}
  96. {{- end }}
  97. {{- if $value.azstorageaccount }}
  98. - name: AZURE_STORAGE_ACCOUNT
  99. valueFrom:
  100. secretKeyRef:
  101. name: {{ $key }}
  102. key: {{ $value.azstorageaccount | quote}}
  103. {{- end }}
  104. {{- if $value.azstoragekey }}
  105. - name: AZURE_STORAGE_ACCESS_KEY
  106. valueFrom:
  107. secretKeyRef:
  108. name: {{ $key }}
  109. key: {{ $value.azstoragekey | quote}}
  110. {{- end }}
  111. {{- if $value.gcpcredentials }}
  112. - name: GOOGLE_APPLICATION_CREDENTIALS
  113. value: "/var/run/secrets/{{ $key }}/{{ $value.gcpcredentials }}"
  114. {{- end }}
  115. {{- end }}
  116. {{- end }}
  117. {{- with .Values.backup.resources }}
  118. resources:
  119. {{- toYaml . | trim | nindent 14 }}
  120. {{- end }}
  121. volumeMounts:
  122. {{- if .Values.backup.existingSecret }}
  123. {{- range $key,$value := .Values.backup.existingSecret }}
  124. {{- if $value.gcpcredentials }}
  125. - mountPath: /var/run/secrets/{{ $key }}
  126. name: {{ $key }}
  127. {{- end }}
  128. {{- end }}
  129. {{- end }}
  130. volumes:
  131. {{- if .Values.backup.existingSecret }}
  132. {{- range $key,$value := .Values.backup.existingSecret }}
  133. {{- if $value.gcpcredentials }}
  134. - name: {{ $key }}
  135. secret:
  136. secretName: {{ $key }}
  137. {{- end }}
  138. {{- end }}
  139. {{- end }}
  140. affinity:
  141. podAffinity:
  142. preferredDuringSchedulingIgnoredDuringExecution:
  143. - weight: 100
  144. podAffinityTerm:
  145. topologyKey: "kubernetes.io/hostname"
  146. labelSelector:
  147. matchExpressions:
  148. - key: app
  149. operator: In
  150. values:
  151. - {{ template "jenkins.fullname" . }}
  152. - key: release
  153. operator: In
  154. values:
  155. - {{ .Release.Name }}
  156. {{- with .Values.controller.tolerations }}
  157. tolerations:
  158. {{- toYaml . | nindent 10 }}
  159. {{- end }}
  160. {{- with .Values.controller.nodeSelector }}
  161. nodeSelector:
  162. {{- toYaml . | nindent 12 }}
  163. {{- end }}
  164. {{- if .Values.backup.imagePullSecretName }}
  165. imagePullSecrets:
  166. - name: {{ .Values.backup.imagePullSecretName }}
  167. {{- end -}}
  168. {{- end }}