forked from thecasualcoder/kube-fzf
-
Notifications
You must be signed in to change notification settings - Fork 4
/
tailpod
executable file
·26 lines (20 loc) · 1.01 KB
/
tailpod
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
tailpod() {
local namespace_query pod_query result namespace pod_name context_selector
_kube_fzf_handler "tailpod" "$@"
namespace_query=$(echo $args | awk -F '|' '{ print $1 }')
pod_query=$(echo $args | awk -F '|' '{ print $2 }')
context_selector=$(echo $args | awk -F '|' '{ print $5 }')
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 --namespace=$namespace --output=jsonpath='{.spec.containers[*].name}' \
| tr ' ' '\n' \
| fzf $(echo $fzf_args))
_kube_fzf_echo "kubectl logs --namespace='$namespace' --context $context_selector --follow $pod_name -c $container_name"
kubectl logs --namespace=$namespace --context $context_selector --follow $pod_name -c $container_name
}
tailpod "$@"