Created
May 23, 2023 07:06
-
-
Save tanelmae/39ab04b950ea4584a32c1092a5131748 to your computer and use it in GitHub Desktop.
Test kube auth command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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