Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup default Functions & Tasks while uninstall+ refactor installer script #4

Merged
merged 9 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion chart/stash/templates/cleaner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ spec:
command:
- sh
- -c
- "sleep 2; kubectl delete validatingwebhookconfigurations admission.stash.appscode.com || true; kubectl delete mutatingwebhookconfiguration admission.stash.appscode.com || true"
- "sleep 2; \
kubectl delete validatingwebhookconfigurations admission.stash.appscode.com || true; \
kubectl delete mutatingwebhookconfiguration admission.stash.appscode.com || true; \
kubectl delete functions.stash.appscode.com update-status pvc-backup pvc-restore || true; \
kubectl delete tasks.stash.appscode.com pvc-backup pvc-restore"
imagePullPolicy: {{ .Values.imagePullPolicy }}
restartPolicy: Never
103 changes: 73 additions & 30 deletions deploy/stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,59 @@ kubectl config current-context || {
}
echo ""

OS=""
ARCH=""
DOWNLOAD_URL=""
DOWNLOAD_DIR=""
TEMP_DIRS=()
ONESSL=""

# http://redsymbol.net/articles/bash-exit-traps/
function cleanup() {
hossainemruz marked this conversation as resolved.
Show resolved Hide resolved
rm -rf $ONESSL ca.crt ca.key server.crt server.key
rm -rf ca.crt ca.key server.crt server.key
# remove temporary directories
for dir in "${TEMP_DIRS[@]}"; do
rm -rf "${dir}"
done
}

# detect operating system
# ref: https://raw.githubusercontent.com/helm/helm/master/scripts/get
function detectOS() {
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')

case "$OS" in
# Minimalist GNU for Windows
cygwin* | mingw* | msys*) OS='windows';;
esac
}

# detect machine architecture
function detectArch() {
ARCH=$(uname -m)
case $ARCH in
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}

detectOS
detectArch

# download file pointed by DOWNLOAD_URL variable
# store download file to the directory pointed by DOWNLOAD_DIR variable
# you have to sent the output file name as argument. i.e. downloadFile myfile.tar.gz
function downloadFile() {
if curl --output /dev/null --silent --head --fail "$DOWNLOAD_URL"; then
curl -fsSL ${DOWNLOAD_URL} -o $DOWNLOAD_DIR/$1
else
echo "File does not exist"
exit 1
fi
}

export APPSCODE_ENV=${APPSCODE_ENV:-prod}
Expand All @@ -35,37 +85,26 @@ onessl_found() {
return 1
}

# download onessl if it does not exist
onessl_found || {
echo "Downloading onessl ..."
if [[ "$(uname -m)" == "aarch64" ]]; then
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-linux-arm64
chmod +x onessl
export ONESSL=./onessl
else
# ref: https://stackoverflow.com/a/27776822/244009
case "$(uname -s)" in
Darwin)
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-darwin-amd64
chmod +x onessl
export ONESSL=./onessl
;;

Linux)
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-linux-amd64
chmod +x onessl
export ONESSL=./onessl
;;

CYGWIN* | MINGW* | MSYS*)
curl -fsSL -o onessl.exe https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-windows-amd64.exe
chmod +x onessl.exe
export ONESSL=./onessl.exe
;;
*)
echo 'other OS'
;;
esac
fi

ARTIFACT="https://github.com/kubepack/onessl/releases/download/0.12.0"
ONESSL_BIN=onessl-${OS}-${ARCH}
case "$OS" in
cygwin* | mingw* | msys*)
ONESSL_BIN=${ONESSL_BIN}.exe
;;
esac

DOWNLOAD_URL=${ARTIFACT}/${ONESSL_BIN}
DOWNLOAD_DIR="$(mktemp -dt onessl-XXXXXX)"
TEMP_DIRS+=($DOWNLOAD_DIR) # store DOWNLOAD_DIR to cleanup later

downloadFile $ONESSL_BIN # downloaded file name will be saved as the value of ONESSL_BIN variable

export ONESSL=${DOWNLOAD_DIR}/${ONESSL_BIN}
chmod +x $ONESSL
}

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

echo "waiting for stash operator pod to stop running"
for (( ; ; )); do
Expand Down