diff --git a/chart/stash/templates/cleaner.yaml b/chart/stash/templates/cleaner.yaml index a5ad6a0a5..b0229c82e 100644 --- a/chart/stash/templates/cleaner.yaml +++ b/chart/stash/templates/cleaner.yaml @@ -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 diff --git a/deploy/stash.sh b/deploy/stash.sh index ca55b5772..fb635cf39 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -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() { - 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} @@ -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 @@ -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