#!/usr/bin/env bash # PostgreSQL — the cluster half of the postgres cabinet. # # A cabinet is a public service dropped into the environment as-is — the # upstream image, unmodified, reachable at a known address. This is the cluster # half of it; the compose half is a `service.yml` beside a `cabinet.json`. The # declaration is made once and both paths read it, so nothing is remembered # twice. # # Plain manifests rather than a helm chart, matching the other addons: a chart # repo is a network dependency, and the offline example profile exists precisely so # there is a path with none. The image is pinned in ctrl/versions.env and can be # preloaded into a local registry like every other image here. # # One replica on a PVC. This models a dependency for local work, not a # highly-available database, and pretending otherwise on a kind node would be a # more elaborate lie rather than a more useful one. set -euo pipefail cd "$(dirname "$0")/.." source ./lib/config.sh load_config K="kubectl --context ${KUBECONTEXT}" NS="${DATA_NAMESPACE:-data}" $K get namespace "$NS" >/dev/null 2>&1 || $K create namespace "$NS" # The password is generated once and then left alone, so re-running this does # not rotate the credential out from under whatever is already connected. if $K get secret -n "$NS" postgres >/dev/null 2>&1; then echo " secret exists, keeping the current password" else password=$(head -c 18 /dev/urandom | base64 | tr -d '/+=' | head -c 24) $K create secret generic postgres -n "$NS" \ --from-literal=POSTGRES_DB="${POSTGRES_DB:-postgres}" \ --from-literal=POSTGRES_USER="${POSTGRES_USER:-postgres}" \ --from-literal=POSTGRES_PASSWORD="$password" >/dev/null echo " generated a password (read it back with the command printed below)" fi echo " applying manifests" $K apply -n "$NS" -f - >/dev/null <