From a91b7dde6edb2e98833de15893fb044706e03659 Mon Sep 17 00:00:00 2001 From: hophacker Date: Tue, 29 Dec 2020 08:06:20 +0800 Subject: [PATCH] extract function get pod --- zsh/functions.zsh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/zsh/functions.zsh b/zsh/functions.zsh index 4927b94..d29e38b 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -232,6 +232,9 @@ function gitcopy() { fi } function kubectl() { + echo $RUNNING_POD + echo $NAMESPACE + echo $KCONTEXT DEBUG=false finalopts=() while [[ $@ != "" ]] do @@ -255,6 +258,7 @@ function kubectl() { esac done [[ $DEBUG == "true" ]] && echo "kubectl --kubeconfig=$HOME/.kube/${KCONTEXT}_config $finalopts" + echo "kubectl --kubeconfig=$HOME/.kube/${KCONTEXT}_config $finalopts" command kubectl --kubeconfig=$HOME/.kube/${KCONTEXT}_config $finalopts } function stern { @@ -297,9 +301,12 @@ function helm() { [[ $DEBUG == "true" ]] && echo "helm $finalopts --kubeconfig=$HOME/.kube/${KCONTEXT}_config" command helm $finalopts --kubeconfig=$HOME/.kube/${KCONTEXT}_config } -function kexec { +NAMESPACE=default +RUNNING_POD="" +LEFT_ARGS="" +KCONTEXT="" +function getpod { RAN=true - NAMESPACE=default function usage () { echo "Usage : $0 [options] [--] @@ -370,9 +377,15 @@ function kexec { break fi done - if [[ $RUNNING_POD_INDEX != -1 ]]; then - echo "kubectl -it -n $NAMESPACE exec $RUNNING_PODS[$RUNNING_POD_INDEX] -- $@" - kubectl -it -n $NAMESPACE exec $RUNNING_PODS[$RUNNING_POD_INDEX] -- $@ + RUNNING_POD=$RUNNING_PODS[$RUNNING_POD_INDEX] + LEFT_ARGS=$@ +} + +function kexec { + getpod $@ + if [[ $RUNNING_POD != "" ]]; then + echo "kubectl -it -n $NAMESPACE exec $RUNNING_POD -- /bin/sh -c $LEFT_ARGS" + kubectl -it -n $NAMESPACE exec $RUNNING_POD -- /bin/sh -c $LEFT_ARGS fi }