-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtide
More file actions
executable file
·132 lines (112 loc) · 2.73 KB
/
tide
File metadata and controls
executable file
·132 lines (112 loc) · 2.73 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# File configuration
CFG_FILE="${CFG_FILE:-$HOME/.config/tide/tiderc}"
# Check for configuration file and source it
if [[ -e "$CFG_FILE" ]]; then
source "$CFG_FILE"
fi
# Display help
usage() {
cat << EOF
DESCRIPTION:
tide: tool for managing pods
COMMANDS:
ls: list pods
rm <release>: delete a release
install <release_name> <service_name> <yaml_env>: install a release
upgrade <release_name> <service_name> <yaml_env>: update yaml files for a release
exec [<pod>] [<command>]: execute <command> on specified <pod> omit args to use fzf to select
clean: delete all persistent volume claims
tail <pod>: view logs of running pod
show <pod>: view pod metadata
OPTIONS:
-c: display helm/kubectl command for confirmation before execution
-h: display this message
EOF
}
confirm() {
# echo "Are you sure you want to run \"$@\"? [y/N] "
if [ "$confirm" = "true" ]; then
command_to_confirm="$@"
read -p "Are you sure you want to run \"$@\"? [y/N] " >&1 response
case "$response" in
[yY][eE][sS]|[yY])
$@ >&1 && exit 0
;;
*)
exit 0
;;
esac
else
$@ >&1
fi
}
sub_ls() {
confirm "kubectl get pods"
exit 0
}
sub_rm() {
confirm "helm delete $1"
exit 0
}
sub_exec() {
if [[ $# -eq 0 ]]; then
if [ -z "$COMMANDS" ]; then error 'No commands set in ~/.config/tide/tiderc'; fi
app=$(sub_ls | tail -n +2 | awk '{print $1}' | fzf)
exe=$(printf "%s\n" "${COMMANDS[@]}" | fzf)
sub_exec $app -- $exe
else
confirm "kubectl exec -it $@"
fi
exit 0
}
sub_tail() {
confirm "kubectl logs -f $1"
exit 0
}
sub_clean() {
confirm "kubectl delete pvc --all"
exit 0
}
sub_show() {
confirm "kubectl describe pod $1"
exit 0
}
sub_install() {
confirm "helm ssm install $1 callrail/$2 -f $3-values.yaml --timeout 20m"
exit 0
}
sub_upgrade() {
confirm "helm ssm upgrade $1 callrail/$2 -f $3-values.yaml --timeout 12m"
exit 0
}
error() {
echo -e "\033[0;31m$1\033[0m" >&2
echo
usage
exit 1
}
# Set flag options
while getopts "ch" opt; do
case "$opt" in
h) usage && exit 0;;
c) confirm=true;;
*) error "Invalid flag.";;
esac
done 2>/dev/null
shift "$((OPTIND-1))"
command=$1
case $command in
*)
for arg in "$@"; do
shift
sub_${command} $@ # 2>/dev/null
if [ $? = 127 ]; then
error "Error: '$command' is not a known command."
exit 1
fi
shift
done
;;
esac
usage && exit 0