From 543e3e2f224fa70cab9278f6ffb47e8c39f1f111 Mon Sep 17 00:00:00 2001 From: wsq Date: Tue, 6 Aug 2019 11:10:55 +0800 Subject: [PATCH] fix kexec --- zsh/functions.zsh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/zsh/functions.zsh b/zsh/functions.zsh index c22ba21..254c008 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -233,12 +233,12 @@ function k() { case ${opt} in c) CONTEXT=$OPTARG - shift; shift ;; \?) echo "Usage: h [-c CONTEXT]" ;; esac done + shift $((OPTIND-1)) kubectl $* --kubeconfig=$HOME/.kube/${CONTEXT}_config } function h() { @@ -262,8 +262,12 @@ function h() { } function kexec { RAN=false - while getopts ":rp:" opt; do + CONTEXT=gcloud + while getopts ":c:rp:" opt; do case "${opt}" in + c) + CONTEXT=$OPTARG + ;; r) RAN=true ;; @@ -280,14 +284,14 @@ function kexec { echo 'waiting...' while true; do - POD_NAME=`k get pods | grep $PROJECT | awk '{print $1}'` + POD_NAME=`k -c $CONTEXT get pods | grep $PROJECT | awk '{print $1}'` POD_NAMES=("${(f)POD_NAME}") echo ${POD_NAMES[@]} OK=true for i in $POD_NAMES; do - READY=`k get pods $i | grep $PROJECT | awk '{print $2}'` + READY=`k -c $CONTEXT get pods $i | grep $PROJECT | awk '{print $2}'` READYS=("${(@s|/|)READY}") - STATE=`k get pods $i | grep $PROJECT | awk '{print $3}'` + STATE=`k -c $CONTEXT get pods $i | grep $PROJECT | awk '{print $3}'` if [[ ${READYS[1]} -eq 0 || "${STATE}" -ne "Running" ]]; then OK=false break @@ -324,7 +328,7 @@ function kexec { fi done echo "executing pod $POD_NAMES[$input]..." - kubectl exec -it $POD_NAMES[$input] $@ + k -c $CONTEXT exec -it $POD_NAMES[$input] $@ } function klogs {