-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubectl.sh
executable file
·52 lines (47 loc) · 1.62 KB
/
kubectl.sh
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
if which kubectl &>/dev/null; then
# Kubectl
alias k=kubectl
alias kcc="kubectl config current-context"
alias kcn="kubectl config get-contexts $(kcc) | tail -n +2 | sed 's/.* //'"
alias ktx="kubectl config use-context"
alias kgp="kubectl get po"
alias kns="kubectl config set-context --current --namespace "
alias kevents="kubectl get events -o custom-columns=FirstSeen:.firstTimestamp,LastSeen:.lastTimestamp,Count:.count,From:.source.component,Type:.type,Reason:.reason,Message:.message"
complete -F __start_kubectl k
complete -F _complete_alias ktx
complete -F _complete_alias kgp
complete -F _complete_alias kns
klabels() {
local VARS="-v NAME=1"
local PASSTHROUGH
local FILTER
while [ $1 ]; do
case $1 in
--all-namespaces | -A )
VARS="-v NAME=2"
PASSTHROUGH+=" $1"
;;
--filter | -f )
shift
if [ "$FILTER" ]; then
FILTER="$FILTER|$1"
else
FILTER=$1
fi
;;
* )
PASSTHROUGH+=" $1"
;;
esac
shift
done
_klabels() {
kubectl get ${PASSTHROUGH:-pods} --show-labels | tail -n +2 | awk $VARS '{print $NAME"\n "$NF"\n"}' | sed 's/,/\n /g; s/=/: /g'
}
if [ "$FILTER" ]; then
_klabels | grep -E "$FILTER|^[^ ]*$" --color=never
else
_klabels
fi
}
fi