-
Notifications
You must be signed in to change notification settings - Fork 0
/
lkubectl.sh
45 lines (42 loc) · 905 Bytes
/
lkubectl.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
#!/bin/bash
function lkubectl {
env=${e:=$env}
# set the kube config file
file="dev.kube"
if [ "$env" != "" ]; then
file="${env}.kube"
fi
if [ "$f" != "" ]; then
file="$f"
fi
echo "file:$file"
kubectl --kubeconfig="$file" $@
reset
}
function reset {
e=""
env=""
}
function kubectx {
env=${e:=$env}
# set the kube config file
file="dev.kube"
if [ "$env" != "" ]; then
file="${env}.kube"
fi
if [ "$f" != "" ]; then
file="$f"
fi
# set cluster by regex match found in $1
clusters=$(kubectl --kubeconfig=$file config get-contexts -o name)
# for c in $clusters; do # bash
for c in ${(f)clusters}; do # zsh fix to split by newlines
if [[ "$1" == "list" ]]; then
echo "$c"
elif [[ $c =~ $1 ]]; then
echo "cluster set to $c"
kubectl --kubeconfig=$file config use-context $c
fi
done
reset
}