-
Notifications
You must be signed in to change notification settings - Fork 2
/
ksh.sh
executable file
·76 lines (63 loc) · 1.33 KB
/
ksh.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
#
function log () {
echo "$1" # >> /tmp/ksh.log
}
while getopts "n:p:c:N:P:C:h" opt; do
case "${opt}" in
n)
NAMESPACE_KEYWORD=$OPTARG
;;
N)
NAMESPACE=$OPTARG
;;
p)
POD_KEYWORD=$OPTARG
;;
P)
POD=$OPTARG
;;
c)
CONTAINER_KEYWORD=$OPTARG
;;
C)
CONTAINER=$OPTARG
;;
h)
cat ./help.txt
exit
;;
esac
done
if [[ -z "$NAMESPACE" ]]
then
NAMESPACE=$("$SCRIPT_PATH/kns.sh" "$NAMESPACE_KEYWORD")
fi
if [[ $? -ne 0 ]]
then
log "Namespace not found"
exit 1 # Namespace not found
fi
log "Found namespace: $NAMESPACE"
if [[ -z "$POD" ]]
then
POD=$("$SCRIPT_PATH/kpod.sh" -N "$NAMESPACE" "$POD_KEYWORD")
fi
if [[ $? -ne 0 ]]
then
log "Pod not found"
exit 1 # Pod not found
fi
log "Found pod: $POD"
if [[ -z "$CONTAINER" ]]
then
CONTAINER=$("$SCRIPT_PATH/kctn.sh" -N "$NAMESPACE" -P "$POD" "$CONTAINER_KEYWORD")
fi
if [[ $? -ne 0 ]]
then
log "Container not found"
exit 1 # Container not found
fi
log "Found container: $CONTAINER"
kubectl exec -it pods/"$POD" -n "$NAMESPACE" -c "$CONTAINER" -- /bin/sh