From 8f6d9c1039df4364a167d01a86e4ba1cfd0047f9 Mon Sep 17 00:00:00 2001 From: Jeff Lowdermilk Date: Thu, 5 Feb 2015 14:54:45 -0800 Subject: [PATCH] Use config output formatting to get password in gce kube-up Gets rid of e2e dependency on pyyaml. --- cluster/gce/util.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 07007cf9f97..268b4398bdc 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -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"]')