forked from thecasualcoder/kube-fzf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execpod
executable file
·26 lines (18 loc) · 850 Bytes
/
execpod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env bash
set -e
set -o pipefail
[[ -z "${KUBE_FZF_PATH}" ]] && source kube-fzf.sh || source $KUBE_FZF_PATH
execpod() {
local namespace_query pod_query cmd result namespace pod_name
_kube_fzf_handler "execpod" "$@"
IFS=$'|' read -r namespace_query pod_query cmd _unused _unused <<< "$args"
result=$(_kube_fzf_search_pod "$namespace_query" "$pod_query")
IFS=$'|' read -r namespace pod_name <<< "$result"
local fzf_args=$(_kube_fzf_fzf_args "" "--select-1")
local container_name=$(kubectl get pod $pod_name --namespace=$namespace --output=jsonpath='{.spec.containers[*].name}' \
| tr ' ' '\n' \
| fzf $(echo $fzf_args))
_kube_fzf_echo "kubectl exec --namespace='$namespace' $pod_name -c $container_name -it -- $cmd"
kubectl exec --namespace=$namespace $pod_name -c $container_name -it -- $cmd
}
execpod "$@"