Skip to content

Commit

Permalink
quick fix for klog kfor
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiidb committed Jan 28, 2020
1 parent 7cd472b commit 282bc63
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fubectl.source
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ klog() {
fi

local arg_pair=$(kubectl get po --all-namespaces | _inline_fzf | awk '{print $1, $2}')
local ns=$(echo $arg_pair | awk '{print $1}')
local pod=$(echo $arg_pair | awk '{print $2}')
[ -z "$arg_pair" ] && printf "klog: no pods found. no logs can be shown.\n" && return
local containers_out=$(echo "$arg_pair" | xargs kubectl get po -o=jsonpath='{.spec.containers[*].name} {.spec.initContainers[*].name}' -n | sed 's/ $//')
local container_choosen=$(echo "$containers_out" | tr ' ' "\n" | _inline_fzf_nh)
kubectl logs -n ${arg_pair} -c "${container_choosen}" --tail="${line_count}" "$@"
kubectl logs -n ${ns} -c "${container_choosen}" --tail="${line_count}" "$@" ${pod}
}

# [kex] execute command in container
Expand All @@ -142,9 +144,11 @@ kfor() {
local port="$1"
[ -z "$port" ] && printf "kfor: missing argument.\nUsage: kfor PORT_TO_FORWARD\n" && return 255
local arg_pair="$(kubectl get po --all-namespaces | _inline_fzf | awk '{print $1, $2}')"
local ns=$(echo $arg_pair | awk '{print $1}')
local pod=$(echo $arg_pair | awk '{print $2}')
[ -z "$arg_pair" ] && printf "kfor: no pods found. no forwarding.\n" && return
echo "kubectl port-forward -n $arg_pair $port"
kubectl port-forward -n $arg_pair "$port"
kubectl port-forward -n $ns $pod "$port"
}

# [ksearch] search for string in resources
Expand Down

0 comments on commit 282bc63

Please sign in to comment.