diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 9e3059f417c..07007cf9f97 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -189,13 +189,26 @@ function detect-master () { } # Ensure that we have a password created for validating to the master. Will -# read from $HOME/.kubernetres_auth if available. +# read from the kubernetes auth-file for the current context if available. +# +# Assumed vars +# KUBE_ROOT # # Vars set: # KUBE_USER # KUBE_PASSWORD function get-password { - local file="$HOME/.kubernetes_auth" + local get_auth_path=''' +import yaml, sys +cfg = yaml.load(sys.stdin) +try: + current = cfg["current-context"] + user = cfg["contexts"][current]["user"] + print cfg["users"][user]["auth-path"] +except KeyError: + pass +''' + local file=$("${KUBE_ROOT}/cluster/kubectl.sh" config view --global | python -c "${get_auth_path}") if [[ -r "$file" ]]; then KUBE_USER=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["User"]') KUBE_PASSWORD=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["Password"]')