This repository has been archived by the owner on Jan 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
tiller.sh
executable file
·155 lines (135 loc) · 3.41 KB
/
tiller.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
set -o errexit
CURRENT_FOLDER=$(pwd)
cd "$HELM_PLUGIN_DIR"
function usage() {
if [[ -n "$1" ]]; then
printf "%s\\n\\n" "$1"
fi
cat <<' EOF'
Helm plugin for using Tiller locally
Usage:
helm tiller install
helm tiller start [tiller_namespace]
helm tiller start-ci [tiller_namespace] (without new bash shell)
helm tiller stop
helm tiller run [tiller_namespace] -- [command] [args]
Available Commands:
install Manually install/upgrade Tiller binary
start Start Tiller
start-ci Start Tiller without opening new bash shell
run Start Tiller and run arbitrary command within the environment
stop Stop Tiller
Example use with the set namespace:
$ helm tiller start my-tiller-namespace
Example use of `run`, that starts/stops tiller before/after the specified command:
$ helm tiller run helm list
$ helm tiller run my-tiller-namespace -- helm list
$ helm tiller run my-tiller-namespace -- bash -c 'echo running helm; helm list'
EOF
}
check_helm() {
# Check if helm is installed
if ! command -v helm >/dev/null 2>&1; then
echo "Helm client is not installed!"
exit 0
fi
}
check_install_tiller() {
INSTALLED_HELM=$(helm version -c --short | awk -F[:+] '{print $2}' | cut -d ' ' -f 2)
echo "Installed Helm version $INSTALLED_HELM"
# check if the tiller binary exists
if [ ! -f ./bin/tiller ]; then
# check if tiller binary is already installed in the path
if command -v tiller >/dev/null 2>&1; then
EXISTING_TILLER=$(command -v tiller)
mkdir -p ./bin
cp "${EXISTING_TILLER}" ./bin/
INSTALLED_TILLER=$(./bin/tiller --version)
echo "Copied found $EXISTING_TILLER to helm-tiller/bin"
else
INSTALLED_TILLER=v0.0.0
fi
else
INSTALLED_TILLER=$(./bin/tiller --version)
echo "Installed Tiller version $INSTALLED_TILLER"
fi
# check if tiller and helm versions match
if [[ "${INSTALLED_HELM}" == "${INSTALLED_TILLER}" ]]; then
echo "Helm and Tiller are the same version!"
else
./scripts/install.sh "$INSTALLED_HELM"
fi
}
helm_env() {
if [[ -n "$1" ]]
then
# Set namespace
echo export TILLER_NAMESPACE="${1}"
fi
echo export HELM_HOST=localhost:44134
}
start_tiller() {
echo "Starting Tiller..."
{ ./bin/tiller --storage=secret --listen=localhost:44134 & } 2>/dev/null
echo "Tiller namespace: $TILLER_NAMESPACE"
}
run_tiller() {
echo "Starting Tiller..."
{ ./bin/tiller --storage=secret --listen=localhost:44134 & } 2>/dev/null
cd "${CURRENT_FOLDER}"
}
stop_tiller() {
echo "Stopping Tiller..."
pkill -f ./bin/tiller
}
COMMAND=$1
# do shift only if some argument is provided
if [[ -n "$1" ]]; then
shift
fi
case $COMMAND in
install)
check_helm
check_install_tiller
;;
start)
check_helm
check_install_tiller
eval '$(helm_env "$@")'
start_tiller
cd "${CURRENT_FOLDER}"
bash
;;
start-ci)
check_helm
check_install_tiller
eval '$(helm_env "$@")'
start_tiller
;;
run)
check_helm
check_install_tiller
start_args=()
args=()
while [[ $# -gt 0 ]]; do
case "$1" in
-- ) start_args=( "${args[@]}" ); args=(); shift ;;
* ) args+=("${1}"); shift ;;
esac
done
trap stop_tiller EXIT
eval '$(helm_env "${start_args[@]}")'
run_tiller "${start_args[@]}"
# shellcheck disable=SC2145
echo Running: "${args[@]}"
echo
"${args[@]}"
;;
stop)
stop_tiller
;;
*)
usage "$@"
;;
esac