#!/usr/bin/env bash # Generate kubeconfig for the using-cash-deployer ServiceAccount. # Run this ONCE with cluster-admin credentials after applying # k8s/cluster/deployer-sa.yaml. # # Usage: # KUBECONFIG=/path/to/admin.kubeconfig bash scripts/bootstrap-kubeconfig.sh # # Outputs KUBECONFIG_B64 to stdout — store in Johan's adapter env + CI secrets. set -euo pipefail SA_NAME="using-cash-deployer" SA_NS="kube-system" SECRET_NAME="using-cash-deployer-token" CLUSTER_NAME="using-cash" CONTEXT_NAME="using-cash-deployer" echo "==> Applying RBAC manifests..." >&2 kubectl apply -f k8s/cluster/deployer-sa.yaml echo "==> Waiting for token secret to be populated..." >&2 for i in $(seq 1 30); do TOKEN=$(kubectl get secret "$SECRET_NAME" -n "$SA_NS" \ -o jsonpath='{.data.token}' 2>/dev/null || true) if [ -n "$TOKEN" ]; then break fi sleep 2 done if [ -z "$TOKEN" ]; then echo "ERROR: Token not populated in secret $SECRET_NAME after 60s" >&2 exit 1 fi # Get cluster CA and server from current kubeconfig CA_DATA=$(kubectl config view --raw -o jsonpath="{.clusters[0].cluster.certificate-authority-data}") SERVER=$(kubectl config view --raw -o jsonpath="{.clusters[0].cluster.server}") echo "==> Cluster server: $SERVER" >&2 echo "==> Generating kubeconfig..." >&2 KUBECONFIG_YAML=$(cat <&2 echo "==> Done. Set these in Johan's adapter env AND the CI repo secrets:" >&2 echo "" >&2 echo "KUBECONFIG_B64 (adapter env):" >&2 echo "$KUBECONFIG_YAML" | base64 -w0 echo "" >&2 echo "" >&2 echo "KUBECONFIG (CI secret — raw YAML, no base64 wrapper):" >&2 echo "$KUBECONFIG_YAML" >&2