forked from thecasualcoder/kube-fzf
-
Notifications
You must be signed in to change notification settings - Fork 4
/
execpod
executable file
·26 lines (18 loc) · 993 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 context_selector
_kube_fzf_handler "execpod" "$@"
IFS=$'|' read -r namespace_query pod_query cmd _unused context_selector _unused _unused <<< "$args"
result=$(_kube_fzf_search "$namespace_query" "$pod_query" "$context_selector" "pod")
IFS=$'|' read -r namespace pod_name <<< "$result"
local fzf_args=$(_kube_fzf_fzf_args "" "--select-1")
local container_name=$(kubectl get pod $pod_name --context $context_selector --namespace=$namespace --output=jsonpath='{.spec.containers[*].name}' \
| tr ' ' '\n' \
| fzf $(echo $fzf_args))
_kube_fzf_echo "kubectl exec --namespace='$namespace' --context $context_selector $pod_name -c $container_name -it $cmd"
kubectl exec --namespace=$namespace --context $context_selector $pod_name -c $container_name -it $cmd
}
execpod "$@"