26 lines
994 B
Bash
Executable File
26 lines
994 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
namespace=default
|
|
secret=immich-sync-deployer-token
|
|
workdir=$(mktemp --directory)
|
|
trap 'rm -rf "${workdir}"' EXIT
|
|
|
|
server=$(kubectl config view --minify --output 'jsonpath={.clusters[0].cluster.server}')
|
|
kubectl --namespace "${namespace}" get secret "${secret}" --output 'jsonpath={.data.ca\.crt}' \
|
|
| base64 --decode > "${workdir}/ca.crt"
|
|
token=$(kubectl --namespace "${namespace}" get secret "${secret}" --output 'jsonpath={.data.token}' \
|
|
| base64 --decode)
|
|
|
|
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 immich-sync-deployer --token "${token}" > /dev/null
|
|
kubectl config set-context immich-sync --cluster cluster --user immich-sync-deployer --namespace "${namespace}" \
|
|
> /dev/null
|
|
kubectl config use-context immich-sync > /dev/null
|
|
|
|
base64 --wrap=0 "${KUBECONFIG}"
|
|
printf '\n'
|