apiVersion: batch/v1
kind: Job
metadata:
  name: airflow-create-user
  namespace: airflow
spec:
  backoffLimit: 2
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: airflow-init
        image: apache/airflow:latest
        command: ["/bin/sh", "-c"]
        args: ["airflow users create --username ${AIRFLOW_USERNAME} --firstname Admin --lastname Admin --role Admin --password ${AIRFLOW_PASSWORD} --email example@example.com"]
        envFrom:
        - configMapRef:
            name: airflow-config
        env:
        - name: AWS_S3_DAGS_BUCKET
          value: "tht-airflow-dags"
        - name: AWS_S3_LOGS_BUCKET
          value: "tht-airflow-logs"
        - name: AIRFLOW_USERNAME
          valueFrom:
            secretKeyRef:
              name: airflow-init-user-credentials
              key: username
        - name: AIRFLOW_PASSWORD
          valueFrom:
            secretKeyRef:
              name: airflow-init-user-credentials
              key: password
