Skip to content

Instantly share code, notes, and snippets.

@tanelmae
Created May 23, 2023 07:06
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 tanelmae/39ab04b950ea4584a32c1092a5131748 to your computer and use it in GitHub Desktop.
Save tanelmae/39ab04b950ea4584a32c1092a5131748 to your computer and use it in GitHub Desktop.
Test kube auth command
#!/usr/bin/env bash
set -ue
# Resolve config to be used
export KUBECONFIG=${KUBECONFIG:-$HOME/.kube/config}
export CLUSTER=${1:-$(kubectl config current-context)}
echo "Running against ${CLUSTER}"
# Read auth command from the kubeconfig and use it to get the auth token
CMD_PATH=$(yq '.users | map(select(.name == env(CLUSTER))) | .[] | .user.exec.command' "${KUBECONFIG}")
CMD_ARGS=$(yq '.users | map(select(.name == env(CLUSTER))) | .[] | .user.exec.args | join(" ")' "${KUBECONFIG}")
echo "Running $CMD_PATH $CMD_ARGS"
$CMD_PATH $CMD_ARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment