forked from thecasualcoder/kube-fzf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tailpod
executable file
·27 lines (19 loc) · 899 Bytes
/
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
27
#!/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
_kube_fzf_handler "tailpod" "$@"
namespace_query=$(echo $args | awk -F '|' '{ print $1 }')
pod_query=$(echo $args | awk -F '|' '{ print $2 }')
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 logs --namespace='$namespace' --follow --tail=200 $pod_name -c $container_name"
kubectl logs --namespace=$namespace --follow --tail=200 $pod_name -c $container_name
}
tailpod "$@"