-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkubectl.sh
executable file
·50 lines (43 loc) · 1.51 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
#!/usr/bin/env bash
if [ "${1}" == "loop" ]; then
# can be used to wait track progress of changes
# e.g.
# ./kubectl.sh loop get pods
while true; do
kubectl "${@:2}"
sleep 1
done
elif [ "${1}" == "port-forward" ]; then
# port-forward based on app label
if [ "${3}" == "" ]; then
PORT_FORWARD_DEFAULT_ARGS=""
[ -e charts-external/${2}/default.sh ] && source charts-external/${2}/default.sh
[ -z "${PORT_FORWARD_DEFAULT_ARGS}" ] && echo missing port-forward args && exit 1
ARGS="${PORT_FORWARD_DEFAULT_ARGS}"
else
ARGS="${@:3}"
fi
kubectl port-forward $(./kubectl.sh get-pod-name "${2}") $ARGS
elif [ "${1}" == "get-pod-name" ]; then
# get pod name based on app label
kubectl get pods -l "app=${2}" -o 'jsonpath={.items[0].metadata.name}'
elif [ "${1}" == "exec" ]; then
if [ "${3}" == "" ]; then
EXEC_DEFAULT_ARGS=""
[ -e charts-external/${2}/default.sh ] && source charts-external/${2}/default.sh
[ -z "${EXEC_DEFAULT_ARGS}" ] && echo missing exec args && exit 1
ARGS="${EXEC_DEFAULT_ARGS}"
else
ARGS="${@:3}"
fi
kubectl exec $(./kubectl.sh get-pod-name "${2}") $ARGS
elif [ "${1}" == "logs" ]; then
if [ "${3}" == "" ]; then
LOGS_DEFAULT_ARGS=""
[ -e charts-external/${2}/default.sh ] && source charts-external/${2}/default.sh
ARGS="${LOGS_DEFAULT_ARGS}"
else
ARGS="${@:3}"
fi
kubectl logs $(./kubectl.sh get-pod-name "${2}") $ARGS
fi