|
| 1 | +{{- if .Values.timeStampCron.enabled }} |
| 2 | +apiVersion: v1 |
| 3 | +kind: ServiceAccount |
| 4 | +metadata: |
| 5 | + name: {{ include "blueapi.fullname" . }}-last-used-stamper |
| 6 | + namespace: {{ .Release.Namespace }} |
| 7 | +automountServiceAccountToken: true |
| 8 | +--- |
| 9 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 10 | +kind: Role |
| 11 | +metadata: |
| 12 | + name: {{ include "blueapi.fullname" . }}-last-used-stamper |
| 13 | + namespace: {{ .Release.Namespace }} |
| 14 | +rules: |
| 15 | +- apiGroups: [""] |
| 16 | + resources: ["pods", "persistentvolumeclaims"] |
| 17 | + verbs: ["get", "list", "patch"] |
| 18 | +--- |
| 19 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 20 | +kind: RoleBinding |
| 21 | +metadata: |
| 22 | + name: {{ include "blueapi.fullname" . }}-last-used-stamper |
| 23 | + namespace: {{ .Release.Namespace }} |
| 24 | +subjects: |
| 25 | +- kind: ServiceAccount |
| 26 | + name: {{ include "blueapi.fullname" . }}-last-used-stamper |
| 27 | + namespace: {{ .Release.Namespace }} |
| 28 | +roleRef: |
| 29 | + kind: Role |
| 30 | + name: {{ include "blueapi.fullname" . }}-last-used-stamper |
| 31 | + apiGroup: rbac.authorization.k8s.io |
| 32 | +--- |
| 33 | +apiVersion: batch/v1 |
| 34 | +kind: CronJob |
| 35 | +metadata: |
| 36 | + name: {{ include "blueapi.fullname" . }}-last-used-stamper |
| 37 | + namespace: {{ .Release.Namespace }} |
| 38 | +spec: |
| 39 | + concurrencyPolicy: Forbid |
| 40 | + successfulJobsHistoryLimit: 3 |
| 41 | + failedJobsHistoryLimit: 1 |
| 42 | + schedule: "*/5 * * * *" |
| 43 | + |
| 44 | + jobTemplate: |
| 45 | + spec: |
| 46 | + # amount of attempts of labeling a pvc |
| 47 | + backoffLimit: 3 |
| 48 | + # job stops after 180 seconds |
| 49 | + activeDeadlineSeconds: 180 |
| 50 | + template: |
| 51 | + spec: |
| 52 | + serviceAccountName: {{ include "blueapi.fullname" . }}-last-used-stamper |
| 53 | + {{- with .Values.tolerations }} |
| 54 | + tolerations: |
| 55 | + {{- toYaml . | nindent 12 }} |
| 56 | + {{- end }} |
| 57 | + {{- with .Values.nodeSelector }} |
| 58 | + nodeSelector: |
| 59 | + {{- toYaml . | nindent 12 }} |
| 60 | + {{- end }} |
| 61 | + {{- with .Values.affinity }} |
| 62 | + affinity: |
| 63 | + {{- toYaml . | nindent 12 }} |
| 64 | + {{- end }} |
| 65 | + volumes: |
| 66 | + - name: {{include "blueapi.fullname" . }}-pvc-stamper-script |
| 67 | + configMap: |
| 68 | + name: {{include "blueapi.fullname" . }}-pvc-stamper-script |
| 69 | + defaultMode: 0555 |
| 70 | + containers: |
| 71 | + - name: last-used-stamper |
| 72 | + env: |
| 73 | + - name: RELEASE_NAME |
| 74 | + value: {{ .Release.Name }} |
| 75 | + - name: RELEASE_NAMESPACE |
| 76 | + value: {{ .Release.Namespace }} |
| 77 | + volumeMounts: |
| 78 | + - name: {{include "blueapi.fullname" . }}-pvc-stamper-script |
| 79 | + mountPath: /scripts |
| 80 | + image: bitnami/kubectl:latest |
| 81 | + imagePullPolicy: IfNotPresent |
| 82 | + command: ["/scripts/time-stamper.sh"] |
| 83 | + restartPolicy: OnFailure |
| 84 | +{{- end }} |
| 85 | +{{- if .Values.pvcAutoDeletion.enabled }} |
| 86 | +--- |
| 87 | +apiVersion: v1 |
| 88 | +kind: ServiceAccount |
| 89 | +metadata: |
| 90 | + name: {{ include "blueapi.fullname" . }}-pvc-auto-deletion |
| 91 | + namespace: {{ .Release.Namespace }} |
| 92 | +automountServiceAccountToken: true |
| 93 | +--- |
| 94 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 95 | +kind: Role |
| 96 | +metadata: |
| 97 | + name: {{ include "blueapi.fullname" . }}-pvc-auto-deletion |
| 98 | + namespace: {{ .Release.Namespace }} |
| 99 | +rules: |
| 100 | +- apiGroups: [""] |
| 101 | + resources: ["pods", "persistentvolumeclaims"] |
| 102 | + verbs: ["get", "list", "patch","delete"] |
| 103 | +--- |
| 104 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 105 | +kind: RoleBinding |
| 106 | +metadata: |
| 107 | + name: {{ include "blueapi.fullname" . }}-pvc-auto-deletion |
| 108 | + namespace: {{ .Release.Namespace }} |
| 109 | +subjects: |
| 110 | +- kind: ServiceAccount |
| 111 | + name: {{ include "blueapi.fullname" . }}-pvc-auto-deletion |
| 112 | + namespace: {{ .Release.Namespace }} |
| 113 | +roleRef: |
| 114 | + kind: Role |
| 115 | + name: {{ include "blueapi.fullname" . }}-pvc-auto-deletion |
| 116 | + apiGroup: rbac.authorization.k8s.io |
| 117 | +--- |
| 118 | +apiVersion: batch/v1 |
| 119 | +kind: CronJob |
| 120 | +metadata: |
| 121 | + name: {{ include "blueapi.fullname" . }}-pvc-auto-deletion |
| 122 | + namespace: {{ .Release.Namespace }} |
| 123 | +spec: |
| 124 | + concurrencyPolicy: Forbid |
| 125 | + successfulJobsHistoryLimit: 3 |
| 126 | + failedJobsHistoryLimit: 1 |
| 127 | + schedule: "@weekly" |
| 128 | + |
| 129 | + jobTemplate: |
| 130 | + spec: |
| 131 | + # amount of attempts of labeling a pvc |
| 132 | + backoffLimit: 3 |
| 133 | + # job stops after 300 seconds |
| 134 | + activeDeadlineSeconds: 300 |
| 135 | + template: |
| 136 | + spec: |
| 137 | + serviceAccountName: {{ include "blueapi.fullname" . }}-pvc-auto-deletion |
| 138 | + {{- with .Values.tolerations }} |
| 139 | + tolerations: |
| 140 | + {{- toYaml . | nindent 12 }} |
| 141 | + {{- end }} |
| 142 | + {{- with .Values.nodeSelector }} |
| 143 | + nodeSelector: |
| 144 | + {{- toYaml . | nindent 12 }} |
| 145 | + {{- end }} |
| 146 | + {{- with .Values.affinity }} |
| 147 | + affinity: |
| 148 | + {{- toYaml . | nindent 12 }} |
| 149 | + {{- end }} |
| 150 | + volumes: |
| 151 | + - name: {{include "blueapi.fullname" . }}-pvc-auto-deletion-script |
| 152 | + configMap: |
| 153 | + name: {{include "blueapi.fullname" . }}-pvc-auto-deletion-script |
| 154 | + defaultMode: 0555 |
| 155 | + containers: |
| 156 | + - name: pvc-auto-deletion |
| 157 | + env: |
| 158 | + - name: RELEASE_NAME |
| 159 | + value: {{ .Release.Name }} |
| 160 | + - name: RELEASE_NAMESPACE |
| 161 | + value: {{ .Release.Namespace }} |
| 162 | + volumeMounts: |
| 163 | + - name: {{include "blueapi.fullname" . }}-pvc-auto-deletion-script |
| 164 | + mountPath: /scripts |
| 165 | + image: bitnami/kubectl:latest |
| 166 | + imagePullPolicy: IfNotPresent |
| 167 | + command: ["/scripts/pvc-deletion.sh"] |
| 168 | + restartPolicy: OnFailure |
| 169 | +{{- end }} |
0 commit comments