Skip to content

Commit bf439b1

Browse files
chore: add CronJob to recreate Django superuser for dev/test namespaces after DB reset
1 parent 98edfd7 commit bf439b1

3 files changed

Lines changed: 52 additions & 41 deletions

File tree

dags/bc_obps_reset_data.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def should_cycle_backend(**context):
7474

7575

7676
ROLLOUT_DAG_DOC = """
77-
DAG to wait for the backend rollout to complete. Intended to be triggered after the DB reset.
77+
DAG to wait for the backend rollout to complete, then recreate the django superuser that was
78+
dropped along with the database. Intended to be triggered after the DB reset.
7879
"""
7980

8081

@@ -99,7 +100,12 @@ def wait_for_backend_rollout():
99100
wait_until_job_complete=True,
100101
)
101102

102-
wait_for_backend_rollout_task # NOSONAR
103+
# Must run after the rollout completes, since it hits the backend over its route
104+
@task
105+
def add_django_admin_task():
106+
trigger_k8s_cronjob("add-django-admin", BCIERS_NAMESPACE)
107+
108+
wait_for_backend_rollout_task >> add_django_admin_task()
103109

104110

105111
reset_data() # NOSONAR

helm/cas-bciers/templates/backend/job/add-django-admin.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{{- if or (hasSuffix "-dev" .Release.Namespace) (hasSuffix "-test" .Release.Namespace) }}
2+
3+
apiVersion: batch/v1
4+
kind: CronJob
5+
metadata:
6+
labels: {{- include "cas-bciers.labels" . | nindent 4 }}
7+
component: job-with-database-access
8+
name: add-django-admin
9+
namespace: {{ .Release.Namespace }}
10+
annotations:
11+
"helm.sh/hook": "pre-install,pre-upgrade"
12+
"helm.sh/hook-weight": "-10"
13+
spec:
14+
suspend: true # This cron job is intended to be triggered manually by Airflow
15+
schedule: "0 * * * *"
16+
jobTemplate:
17+
spec:
18+
template:
19+
metadata:
20+
name: {{ template "cas-bciers.fullname" . }}-add-django-admin
21+
spec:
22+
activeDeadlineSeconds: 300
23+
containers:
24+
- name: {{ template "cas-bciers.fullname" . }}-add-django-admin
25+
image: curlimages/curl
26+
env:
27+
- name: BACKEND_HOST
28+
value: {{ .Values.backend.route.host }}
29+
- name: DJANGO_SUPERUSER_USERNAME
30+
valueFrom:
31+
secretKeyRef:
32+
key: username
33+
name: django-superuser
34+
- name: DJANGO_SUPERUSER_PASSWORD
35+
valueFrom:
36+
secretKeyRef:
37+
key: password
38+
name: django-superuser
39+
command:
40+
- /bin/sh
41+
- -ec
42+
- "curl --fail-with-body https://$(BACKEND_HOST)/api/common/create-superuser"
43+
restartPolicy: Never
44+
{{ end }}

0 commit comments

Comments
 (0)