Skip to content

Commit fcf2297

Browse files
hossainemruztamalsaha
authored andcommitted
Cleanup default Functions & Tasks while uninstall+ refactor installer script (#4)
1 parent 68de871 commit fcf2297

File tree

2 files changed

+78
-31
lines changed

2 files changed

+78
-31
lines changed

chart/stash/templates/cleaner.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ spec:
2323
command:
2424
- sh
2525
- -c
26-
- "sleep 2; kubectl delete validatingwebhookconfigurations admission.stash.appscode.com || true; kubectl delete mutatingwebhookconfiguration admission.stash.appscode.com || true"
26+
- "sleep 2; \
27+
kubectl delete validatingwebhookconfigurations admission.stash.appscode.com || true; \
28+
kubectl delete mutatingwebhookconfiguration admission.stash.appscode.com || true; \
29+
kubectl delete functions.stash.appscode.com update-status pvc-backup pvc-restore || true; \
30+
kubectl delete tasks.stash.appscode.com pvc-backup pvc-restore"
2731
imagePullPolicy: {{ .Values.imagePullPolicy }}
2832
restartPolicy: Never

deploy/stash.sh

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,59 @@ kubectl config current-context || {
1313
}
1414
echo ""
1515

16+
OS=""
17+
ARCH=""
18+
DOWNLOAD_URL=""
19+
DOWNLOAD_DIR=""
20+
TEMP_DIRS=()
21+
ONESSL=""
22+
1623
# http://redsymbol.net/articles/bash-exit-traps/
1724
function cleanup() {
18-
rm -rf $ONESSL ca.crt ca.key server.crt server.key
25+
rm -rf ca.crt ca.key server.crt server.key
26+
# remove temporary directories
27+
for dir in "${TEMP_DIRS[@]}"; do
28+
rm -rf "${dir}"
29+
done
30+
}
31+
32+
# detect operating system
33+
# ref: https://raw.githubusercontent.com/helm/helm/master/scripts/get
34+
function detectOS() {
35+
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
36+
37+
case "$OS" in
38+
# Minimalist GNU for Windows
39+
cygwin* | mingw* | msys*) OS='windows';;
40+
esac
41+
}
42+
43+
# detect machine architecture
44+
function detectArch() {
45+
ARCH=$(uname -m)
46+
case $ARCH in
47+
armv7*) ARCH="arm";;
48+
aarch64) ARCH="arm64";;
49+
x86) ARCH="386";;
50+
x86_64) ARCH="amd64";;
51+
i686) ARCH="386";;
52+
i386) ARCH="386";;
53+
esac
54+
}
55+
56+
detectOS
57+
detectArch
58+
59+
# download file pointed by DOWNLOAD_URL variable
60+
# store download file to the directory pointed by DOWNLOAD_DIR variable
61+
# you have to sent the output file name as argument. i.e. downloadFile myfile.tar.gz
62+
function downloadFile() {
63+
if curl --output /dev/null --silent --head --fail "$DOWNLOAD_URL"; then
64+
curl -fsSL ${DOWNLOAD_URL} -o $DOWNLOAD_DIR/$1
65+
else
66+
echo "File does not exist"
67+
exit 1
68+
fi
1969
}
2070

2171
export APPSCODE_ENV=${APPSCODE_ENV:-prod}
@@ -35,37 +85,26 @@ onessl_found() {
3585
return 1
3686
}
3787

88+
# download onessl if it does not exist
3889
onessl_found || {
3990
echo "Downloading onessl ..."
40-
if [[ "$(uname -m)" == "aarch64" ]]; then
41-
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-linux-arm64
42-
chmod +x onessl
43-
export ONESSL=./onessl
44-
else
45-
# ref: https://stackoverflow.com/a/27776822/244009
46-
case "$(uname -s)" in
47-
Darwin)
48-
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-darwin-amd64
49-
chmod +x onessl
50-
export ONESSL=./onessl
51-
;;
52-
53-
Linux)
54-
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-linux-amd64
55-
chmod +x onessl
56-
export ONESSL=./onessl
57-
;;
58-
59-
CYGWIN* | MINGW* | MSYS*)
60-
curl -fsSL -o onessl.exe https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-windows-amd64.exe
61-
chmod +x onessl.exe
62-
export ONESSL=./onessl.exe
63-
;;
64-
*)
65-
echo 'other OS'
66-
;;
67-
esac
68-
fi
91+
92+
ARTIFACT="https://github.com/kubepack/onessl/releases/download/0.12.0"
93+
ONESSL_BIN=onessl-${OS}-${ARCH}
94+
case "$OS" in
95+
cygwin* | mingw* | msys*)
96+
ONESSL_BIN=${ONESSL_BIN}.exe
97+
;;
98+
esac
99+
100+
DOWNLOAD_URL=${ARTIFACT}/${ONESSL_BIN}
101+
DOWNLOAD_DIR="$(mktemp -dt onessl-XXXXXX)"
102+
TEMP_DIRS+=($DOWNLOAD_DIR) # store DOWNLOAD_DIR to cleanup later
103+
104+
downloadFile $ONESSL_BIN # downloaded file name will be saved as the value of ONESSL_BIN variable
105+
106+
export ONESSL=${DOWNLOAD_DIR}/${ONESSL_BIN}
107+
chmod +x $ONESSL
69108
}
70109

71110
# ref: https://stackoverflow.com/a/7069755/244009
@@ -311,6 +350,10 @@ if [ "$STASH_UNINSTALL" -eq 1 ]; then
311350
kubectl delete secret stash-apiserver-cert --namespace $PROMETHEUS_NAMESPACE || true
312351
# delete psp resources
313352
kubectl delete psp stash-operator-psp stash-backup-job stash-backupsession-cron stash-restore-job || true
353+
# delete default functions
354+
kubectl delete functions.stash.appscode.com update-status pvc-backup pvc-restore || true
355+
# delete default tasks
356+
kubectl delete tasks.stash.appscode.com pvc-backup pvc-restore || true
314357

315358
echo "waiting for stash operator pod to stop running"
316359
for (( ; ; )); do

0 commit comments

Comments
 (0)