|
| 1 | +{{- if not (hasSuffix "-prod" .Release.Namespace) }} |
| 2 | +apiVersion: batch/v1 |
| 3 | +kind: CronJob |
| 4 | +metadata: |
| 5 | + name: reset-attachment-storage |
| 6 | + labels: {{- include "cas-bciers.labels" . | nindent 4 }} |
| 7 | + namespace: {{ .Release.Namespace }} |
| 8 | + annotations: |
| 9 | + "helm.sh/hook": "pre-install,pre-upgrade" |
| 10 | + "helm.sh/hook-weight": "-10" |
| 11 | +spec: |
| 12 | + suspend: true # triggered manually via Airflow |
| 13 | + schedule: "0 * * * *" |
| 14 | + jobTemplate: |
| 15 | + spec: |
| 16 | + backoffLimit: 0 |
| 17 | + activeDeadlineSeconds: 600 |
| 18 | + template: |
| 19 | + metadata: |
| 20 | + labels: {{ include "cas-bciers.labels" . | nindent 12 }} |
| 21 | + component: job-with-database-access |
| 22 | + spec: |
| 23 | + activeDeadlineSeconds: 600 |
| 24 | + restartPolicy: Never |
| 25 | + serviceAccountName: deployer |
| 26 | + containers: |
| 27 | + - name: reset-attachment-storage |
| 28 | + image: "gcr.io/google.com/cloudsdktool/google-cloud-cli:stable" |
| 29 | + imagePullPolicy: "Always" |
| 30 | + env: |
| 31 | + - name: GOOGLE_APPLICATION_CREDENTIALS |
| 32 | + value: "/attachment-credentials/attachment-credentials.json" |
| 33 | + - name: GS_CLEAN_BUCKET_NAME |
| 34 | + value: {{ .Release.Namespace }}-bciers-attach-clean |
| 35 | + command: |
| 36 | + - /usr/bin/env |
| 37 | + - bash |
| 38 | + - -c |
| 39 | + - | |
| 40 | + set -x; |
| 41 | +
|
| 42 | + gcloud auth login --cred-file=$GOOGLE_APPLICATION_CREDENTIALS; |
| 43 | + gcloud storage rm --recursive "gs://$GS_CLEAN_BUCKET_NAME/report_attachments/**"; |
| 44 | + gcloud storage rm --recursive "gs://$GS_CLEAN_BUCKET_NAME/documents/**"; |
| 45 | +
|
| 46 | + exit 0; |
| 47 | +
|
| 48 | + volumeMounts: |
| 49 | + - mountPath: "/attachment-credentials" |
| 50 | + name: gcs-attachment-credentials |
| 51 | + readOnly: true |
| 52 | + - mountPath: "/.config" |
| 53 | + name: config-volume |
| 54 | + volumes: |
| 55 | + - name: gcs-attachment-credentials |
| 56 | + secret: |
| 57 | + secretName: gcp-{{ .Release.Namespace }}-bciers-attach-service-account-key |
| 58 | + items: |
| 59 | + - key: credentials.json |
| 60 | + path: attachment-credentials.json |
| 61 | + - name: config-volume |
| 62 | + emptyDir: |
| 63 | + sizeLimit: 50Mi |
| 64 | +{{- end}} |
0 commit comments