mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
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:
commit
c5fcd9d568
@ -198,17 +198,9 @@ function detect-master () {
|
|||||||
# KUBE_USER
|
# KUBE_USER
|
||||||
# KUBE_PASSWORD
|
# KUBE_PASSWORD
|
||||||
function get-password {
|
function get-password {
|
||||||
local get_auth_path='''
|
# go template to extract the auth-path of the current-context user
|
||||||
import yaml, sys
|
local template='{{$ctx := index . "current-context"}}{{$user := index . "contexts" $ctx "user"}}{{index . "users" $user "auth-path"}}'
|
||||||
cfg = yaml.load(sys.stdin)
|
local file=$("${KUBE_ROOT}/cluster/kubectl.sh" config view -o template --template="${template}")
|
||||||
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
|
if [[ -r "$file" ]]; then
|
||||||
KUBE_USER=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["User"]')
|
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"]')
|
KUBE_PASSWORD=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["Password"]')
|
||||||
|
Loading…
Reference in New Issue
Block a user