Files
brave-sync-deployment/create-ci-kubeconfig.sh
feedc0de ea50a260fa
Validate, publish, and deploy Brave Sync / validate (push) Failing after 15s
Validate, publish, and deploy Brave Sync / image (push) Skipped
Validate, publish, and deploy Brave Sync / chart (push) Skipped
Validate, publish, and deploy Brave Sync / deploy (push) Skipped
Initial commit with the existing deployment files
2026-10-09 11:39:38 +02:00

37 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
project_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
[[ "$(kubectl config current-context)" == kubernetes-admin@kubernetes ]] || {
echo "Expected homelab context kubernetes-admin@kubernetes" >&2
exit 1
}
kubectl apply --filename "${project_dir}/namespace.yaml" >&2
kubectl apply --filename "${project_dir}/ci-deployer.yaml" >&2
for attempt in {1..30}; do
token=$(kubectl --namespace brave-sync get secret brave-sync-deployer-token \
--output=jsonpath='{.data.token}' 2>/dev/null || true)
[[ -n "${token}" ]] && break
sleep 1
done
[[ -n "${token:-}" ]] || { echo "Token was not issued" >&2; exit 1; }
workdir=$(mktemp --directory)
trap 'rm -rf -- "${workdir}"' EXIT
server=$(kubectl config view --minify --output=jsonpath='{.clusters[0].cluster.server}')
kubectl --namespace brave-sync get secret brave-sync-deployer-token \
--output=jsonpath='{.data.ca\.crt}' | base64 --decode > "${workdir}/ca.crt"
export KUBECONFIG="${workdir}/config"
kubectl config set-cluster cluster --server="${server}" \
--certificate-authority="${workdir}/ca.crt" --embed-certs=true >/dev/null
kubectl config set-credentials brave-sync-deployer \
--token="$(printf '%s' "${token}" | base64 --decode)" >/dev/null
kubectl config set-context brave-sync --cluster=cluster --user=brave-sync-deployer \
--namespace=brave-sync >/dev/null
kubectl config use-context brave-sync >/dev/null
echo "Store the next line as Gitea secret KUBE_CONFIG_BASE64; do not commit it." >&2
base64 --wrap=0 "${KUBECONFIG}"
printf '\n'