#!/usr/bin/env bash # Apache Airflow — the cluster half of the airflow cabinet (one `standalone` pod). # Requires the postgres addon; refuses to install without it. # Notes: docs/notes/addons.md set -euo pipefail cd "$(dirname "$0")/.." source ./lib/config.sh load_config K="kubectl --context ${KUBECONTEXT}" NS="${DATA_NAMESPACE:-data}" if ! $K get deployment -n "$NS" postgres >/dev/null 2>&1; then echo " ! airflow needs the postgres addon, and it is not installed" >&2 echo " add it before airflow in the profile's ADDONS:" >&2 echo " ADDONS=\"... postgres airflow\"" >&2 exit 1 fi # Reuse the credential postgres generated rather than storing a second copy. db_user=$($K get secret -n "$NS" postgres -o jsonpath='{.data.POSTGRES_USER}' | base64 -d) db_pass=$($K get secret -n "$NS" postgres -o jsonpath='{.data.POSTGRES_PASSWORD}' | base64 -d) db_name=$($K get secret -n "$NS" postgres -o jsonpath='{.data.POSTGRES_DB}' | base64 -d) if $K get secret -n "$NS" airflow >/dev/null 2>&1; then echo " secret exists, keeping the current admin password and fernet key" else admin_password=$(head -c 18 /dev/urandom | base64 | tr -d '/+=' | head -c 24) # Airflow requires a 32-byte urlsafe-base64 key; without a fixed one every # restart invalidates every stored connection. fernet_key=$(head -c 32 /dev/urandom | base64 | tr '+/' '-_') $K create secret generic airflow -n "$NS" \ --from-literal=ADMIN_USER="${AIRFLOW_ADMIN_USER:-admin}" \ --from-literal=ADMIN_PASSWORD="$admin_password" \ --from-literal=FERNET_KEY="$fernet_key" \ --from-literal=SQL_ALCHEMY_CONN="postgresql+psycopg2://${db_user}:${db_pass}@postgres:5432/${db_name}" \ >/dev/null echo " generated an admin password (read it back with the command below)" fi echo " applying manifests" $K apply -n "$NS" -f - >/dev/null <