Merge pull request #4205 from jlowdermilk/gce-kube-up

Use kubectl config -o template to get password in gce kube-up
This commit is contained in:
Zach Loafman 2015-02-05 18:43:32 -08:00
commit c5fcd9d568

View File

@ -198,17 +198,9 @@ function detect-master () {
# KUBE_USER
# KUBE_PASSWORD
function get-password {
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}")
# go template to extract the auth-path of the current-context user
local template='{{$ctx := index . "current-context"}}{{$user := index . "contexts" $ctx "user"}}{{index . "users" $user "auth-path"}}'
local file=$("${KUBE_ROOT}/cluster/kubectl.sh" config view -o template --template="${template}")
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"]')