Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilithmooncohen/01b180b897b0eac4f1c0f09088cb2da4 to your computer and use it in GitHub Desktop.
Save lilithmooncohen/01b180b897b0eac4f1c0f09088cb2da4 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
if [ "$#" -lt 4 ]; then
>&2 echo "Not all expected arguments set."
exit 1
fi
PROJECT_ID=$1
CREDENTIALS=$2
LOCATION=$3
CLUSTER_NAME=$4
shift 4
export CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=$CREDENTIALS
RANDOM_ID="${RANDOM}_${RANDOM}"
export TMPDIR="/tmp/kube_auth_wrapper_${CLUSTER_NAME}_${RANDOM_ID}"
function cleanup {
rm -rf ${TMPDIR}
echo "CLEANUP"
}
trap cleanup EXIT
mkdir ${TMPDIR}
export KUBECONFIG="${TMPDIR}/config"
gcloud --project="${PROJECT_ID}" container clusters --zone="${LOCATION}" get-credentials ${CLUSTER_NAME}
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment