use traditional way to parse kexec arguments, making it support namespace and left arguments
This commit is contained in:
parent
6b23e135af
commit
8dac47564f
@ -318,28 +318,40 @@ function helm() {
|
|||||||
function kexec {
|
function kexec {
|
||||||
RAN=false
|
RAN=false
|
||||||
KCONTEXT=${KCONTEXT:-gcloud}
|
KCONTEXT=${KCONTEXT:-gcloud}
|
||||||
while getopts ":c:rp:" opt; do
|
NAMESPACE=default
|
||||||
case "${opt}" in
|
finalopts=()
|
||||||
c)
|
while [[ $@ != "" ]] do
|
||||||
KCONTEXT=$OPTARG
|
case $1 in
|
||||||
|
-c)
|
||||||
|
KCONTEXT="$2"
|
||||||
|
shift; shift
|
||||||
;;
|
;;
|
||||||
r)
|
--context=*)
|
||||||
|
KCONTEXT="${i#*=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-r)
|
||||||
RAN=true
|
RAN=true
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
p)
|
-p)
|
||||||
PROJECT=$OPTARG
|
PROJECT="$2"
|
||||||
|
shift; shift
|
||||||
|
;;
|
||||||
|
-n)
|
||||||
|
NAMESPACE="$2"
|
||||||
|
shift; shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: cmd [-h]"
|
finalopts+=($1)
|
||||||
return
|
shift
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $(($OPTIND - 1))
|
|
||||||
|
|
||||||
RUNNING_POD_INDEX=-1
|
RUNNING_POD_INDEX=-1
|
||||||
while true; do
|
while true; do
|
||||||
ALL_PODS=$(kubectl -c $KCONTEXT get pods | grep "$PROJECT")
|
ALL_PODS=$(kubectl -c $KCONTEXT -n $NAMESPACE get pods | grep "$PROJECT")
|
||||||
echo $fg[green]"All Pods:"$reset_color
|
echo $fg[green]"All Pods:"$reset_color
|
||||||
echo $ALL_PODS
|
echo $ALL_PODS
|
||||||
if [[ ${#ALL_PODS[@]} == 0 ]]; then
|
if [[ ${#ALL_PODS[@]} == 0 ]]; then
|
||||||
@ -383,8 +395,8 @@ function kexec {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [[ $RUNNING_POD_INDEX != -1 ]]; then
|
if [[ $RUNNING_POD_INDEX != -1 ]]; then
|
||||||
echo "executing pod $fg[green]$RUNNING_PODS[$RUNNING_POD_INDEX]$reset_color"
|
echo "kubectl -c $KCONTEXT exec -it $RUNNING_PODS[$RUNNING_POD_INDEX] $finalopts"
|
||||||
kubectl -c $KCONTEXT exec -it $RUNNING_PODS[$RUNNING_POD_INDEX] $@
|
kubectl -n $NAMESPACE -c $KCONTEXT exec -it $RUNNING_PODS[$RUNNING_POD_INDEX] $finalopts
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user