From 2d87f9ba51dde17794d5133d7f97587ab5b0f93a Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Wed, 12 Jun 2019 13:23:09 +0600 Subject: [PATCH 1/9] Add update-status function in chart and script --- .../templates/update-status-function.yaml | 16 +++++++++++++ deploy/stash.sh | 23 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 chart/stash/templates/update-status-function.yaml diff --git a/chart/stash/templates/update-status-function.yaml b/chart/stash/templates/update-status-function.yaml new file mode 100644 index 000000000..98d1e5b30 --- /dev/null +++ b/chart/stash/templates/update-status-function.yaml @@ -0,0 +1,16 @@ +apiVersion: stash.appscode.com/v1beta1 +kind: Function +metadata: + name: update-status + labels: + {{- include "stash.labels" . | nindent 4 }} +spec: + image: {{ .Values.operator.registry }}/{{ .Values.operator.repository }}:{{ .Values.operator.tag }} + args: + - update-status + - --namespace=${NAMESPACE:=default} + - --repository=${REPOSITORY_NAME:=} + - --backup-session=${BACKUP_SESSION:=} + - --restore-session=${RESTORE_SESSION:=} + - --output-dir=${outputDir:=} + - --enable-status-subresource=${ENABLE_STATUS_SUBRESOURCE:=false} diff --git a/deploy/stash.sh b/deploy/stash.sh index ca55b5772..12b775d15 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -472,6 +472,29 @@ for crd in "${non_namespaced_crds[@]}"; do } done +# Install "update-status" Function. +# we only need to resolve the variables of 'spec.image' part and keep others. +# we can't use onessl to resolve the variables as it will try to resolve all the variables. +# we will use helm to generate yaml from template then apply it. +if [ -x "$(command -v helm)" ]; then + echo "Helm found! Installing update-status Function." + export STASH_CHART=$SCRIPT_LOCATION + + if [[ "$SCRIPT_LOCATION" == "cat " ]]; then + export STASH_CHART="chart/stash" + fi + + helm template ${STASH_CHART} -x templates/update-status-function.yaml \ + --set operator.registry=${STASH_DOCKER_REGISTRY} \ + --set operator.tag=${STASH_IMAGE_TAG} \ + | kubectl apply -f - +else + echo "Skipping Installing update-status Function. \ + Reason: Helm is not installed. \ + You won't be able to backup Database. \ + Install helm and try again." +fi + if [ "$STASH_ENABLE_VALIDATING_WEBHOOK" = true ]; then echo "checking whether admission webhook(s) are activated or not" active=$($ONESSL wait-until-has annotation \ From 6b6b0429609aaf2bafbdd73f837039225bc8f259 Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Wed, 12 Jun 2019 20:21:34 +0600 Subject: [PATCH 2/9] download helm if not present --- deploy/stash.sh | 147 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 44 deletions(-) diff --git a/deploy/stash.sh b/deploy/stash.sh index 12b775d15..0dbf5467d 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -13,9 +13,61 @@ kubectl config current-context || { } echo "" +OS="" +ARCH="" +DOWNLOAD_URL="" +DOWNLOAD_DIR="" +TEMP_DIRS=() +ONESSL="" +HELM="" + # 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 +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 + armv5*) ARCH="armv5";; + armv6*) ARCH="armv6";; + 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 +87,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.10.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 @@ -477,24 +518,42 @@ done # we can't use onessl to resolve the variables as it will try to resolve all the variables. # we will use helm to generate yaml from template then apply it. if [ -x "$(command -v helm)" ]; then - echo "Helm found! Installing update-status Function." - export STASH_CHART=$SCRIPT_LOCATION + export HELM=helm +else + echo "Helm is not installed!. Downloading Helm." + ARTIFACT="https://get.helm.sh" + HELM_VERSION="v2.14.1" + HELM_BIN=helm + HELM_DIST=${HELM_BIN}-${HELM_VERSION}-${OS}-${ARCH}.tar.gz + + case "$OS" in + cygwin* | mingw* | msys*) + HELM_BIN=${HELM_BIN}.exe + ;; + esac - if [[ "$SCRIPT_LOCATION" == "cat " ]]; then - export STASH_CHART="chart/stash" - fi + DOWNLOAD_URL=${ARTIFACT}/${HELM_DIST} + DOWNLOAD_DIR="$(mktemp -dt helm-XXXXXX)" + TEMP_DIRS+=($DOWNLOAD_DIR) - helm template ${STASH_CHART} -x templates/update-status-function.yaml \ - --set operator.registry=${STASH_DOCKER_REGISTRY} \ - --set operator.tag=${STASH_IMAGE_TAG} \ - | kubectl apply -f - -else - echo "Skipping Installing update-status Function. \ - Reason: Helm is not installed. \ - You won't be able to backup Database. \ - Install helm and try again." + downloadFile $HELM_DIST + + tar xf ${DOWNLOAD_DIR}/${HELM_DIST} -C ${DOWNLOAD_DIR} + export HELM=${DOWNLOAD_DIR}/${OS}-${ARCH}/${HELM_BIN} + chmod +x $HELM fi +export STASH_CHART=$SCRIPT_LOCATION + +if [[ "$SCRIPT_LOCATION" == "cat " ]]; then + export STASH_CHART="chart/stash" +fi + +$HELM template ${STASH_CHART} -x templates/update-status-function.yaml \ +--set operator.registry=${STASH_DOCKER_REGISTRY} \ +--set operator.tag=${STASH_IMAGE_TAG} \ +| kubectl apply -f - + if [ "$STASH_ENABLE_VALIDATING_WEBHOOK" = true ]; then echo "checking whether admission webhook(s) are activated or not" active=$($ONESSL wait-until-has annotation \ From ea201f36d8cefec616640669c66ba4ad7bbeb9cb Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Thu, 20 Jun 2019 19:24:14 +0600 Subject: [PATCH 3/9] updated script --- deploy/stash.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/deploy/stash.sh b/deploy/stash.sh index 0dbf5467d..1754f8620 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -19,7 +19,10 @@ DOWNLOAD_URL="" DOWNLOAD_DIR="" TEMP_DIRS=() ONESSL="" + HELM="" +CHART_NAME="stash" +CHART_LOCATION="chart" # http://redsymbol.net/articles/bash-exit-traps/ function cleanup() { @@ -352,7 +355,8 @@ 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 update-status function + kubectl delete function update-status || true echo "waiting for stash operator pod to stop running" for (( ; ; )); do pods=($(kubectl get pods --namespace $STASH_NAMESPACE -l app=stash -o jsonpath='{range .items[*]}{.metadata.name} {end}')) @@ -543,13 +547,19 @@ else chmod +x $HELM fi -export STASH_CHART=$SCRIPT_LOCATION - -if [[ "$SCRIPT_LOCATION" == "cat " ]]; then - export STASH_CHART="chart/stash" +if [[ "$APPSCODE_ENV" == "dev" ]]; then + CHART_LOCATION="chart" +else + # download chart from remove repository and extract into a temporary directory + CHART_LOCATION="$(mktemp -dt appscode-XXXXXX)" + TEMP_DIRS+=(${CHART_LOCATION}) + TEMP_INSTALLER_REPO="${CHART_NAME}-installer" + $HELM repo add "${TEMP_INSTALLER_REPO}" "https://charts.appscode.com/stable" + $HELM fetch --untar --untardir ${CHART_LOCATION} "${TEMP_INSTALLER_REPO}/${CHART_NAME}" + $HELM repo remove "${TEMP_INSTALLER_REPO}" fi -$HELM template ${STASH_CHART} -x templates/update-status-function.yaml \ +$HELM template ${CHART_LOCATION}/${CHART_NAME} -x templates/update-status-function.yaml \ --set operator.registry=${STASH_DOCKER_REGISTRY} \ --set operator.tag=${STASH_IMAGE_TAG} \ | kubectl apply -f - From eee958778f09e32016e2d531820fa0df20e006fc Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Mon, 1 Jul 2019 17:34:39 +0600 Subject: [PATCH 4/9] delete update-status function --- .../templates/update-status-function.yaml | 16 ------ deploy/stash.sh | 51 ------------------- 2 files changed, 67 deletions(-) delete mode 100644 chart/stash/templates/update-status-function.yaml diff --git a/chart/stash/templates/update-status-function.yaml b/chart/stash/templates/update-status-function.yaml deleted file mode 100644 index 98d1e5b30..000000000 --- a/chart/stash/templates/update-status-function.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: stash.appscode.com/v1beta1 -kind: Function -metadata: - name: update-status - labels: - {{- include "stash.labels" . | nindent 4 }} -spec: - image: {{ .Values.operator.registry }}/{{ .Values.operator.repository }}:{{ .Values.operator.tag }} - args: - - update-status - - --namespace=${NAMESPACE:=default} - - --repository=${REPOSITORY_NAME:=} - - --backup-session=${BACKUP_SESSION:=} - - --restore-session=${RESTORE_SESSION:=} - - --output-dir=${outputDir:=} - - --enable-status-subresource=${ENABLE_STATUS_SUBRESOURCE:=false} diff --git a/deploy/stash.sh b/deploy/stash.sh index 1754f8620..c8f30f3b6 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -20,10 +20,6 @@ DOWNLOAD_DIR="" TEMP_DIRS=() ONESSL="" -HELM="" -CHART_NAME="stash" -CHART_LOCATION="chart" - # http://redsymbol.net/articles/bash-exit-traps/ function cleanup() { rm -rf ca.crt ca.key server.crt server.key @@ -517,53 +513,6 @@ for crd in "${non_namespaced_crds[@]}"; do } done -# Install "update-status" Function. -# we only need to resolve the variables of 'spec.image' part and keep others. -# we can't use onessl to resolve the variables as it will try to resolve all the variables. -# we will use helm to generate yaml from template then apply it. -if [ -x "$(command -v helm)" ]; then - export HELM=helm -else - echo "Helm is not installed!. Downloading Helm." - ARTIFACT="https://get.helm.sh" - HELM_VERSION="v2.14.1" - HELM_BIN=helm - HELM_DIST=${HELM_BIN}-${HELM_VERSION}-${OS}-${ARCH}.tar.gz - - case "$OS" in - cygwin* | mingw* | msys*) - HELM_BIN=${HELM_BIN}.exe - ;; - esac - - DOWNLOAD_URL=${ARTIFACT}/${HELM_DIST} - DOWNLOAD_DIR="$(mktemp -dt helm-XXXXXX)" - TEMP_DIRS+=($DOWNLOAD_DIR) - - downloadFile $HELM_DIST - - tar xf ${DOWNLOAD_DIR}/${HELM_DIST} -C ${DOWNLOAD_DIR} - export HELM=${DOWNLOAD_DIR}/${OS}-${ARCH}/${HELM_BIN} - chmod +x $HELM -fi - -if [[ "$APPSCODE_ENV" == "dev" ]]; then - CHART_LOCATION="chart" -else - # download chart from remove repository and extract into a temporary directory - CHART_LOCATION="$(mktemp -dt appscode-XXXXXX)" - TEMP_DIRS+=(${CHART_LOCATION}) - TEMP_INSTALLER_REPO="${CHART_NAME}-installer" - $HELM repo add "${TEMP_INSTALLER_REPO}" "https://charts.appscode.com/stable" - $HELM fetch --untar --untardir ${CHART_LOCATION} "${TEMP_INSTALLER_REPO}/${CHART_NAME}" - $HELM repo remove "${TEMP_INSTALLER_REPO}" -fi - -$HELM template ${CHART_LOCATION}/${CHART_NAME} -x templates/update-status-function.yaml \ ---set operator.registry=${STASH_DOCKER_REGISTRY} \ ---set operator.tag=${STASH_IMAGE_TAG} \ -| kubectl apply -f - - if [ "$STASH_ENABLE_VALIDATING_WEBHOOK" = true ]; then echo "checking whether admission webhook(s) are activated or not" active=$($ONESSL wait-until-has annotation \ From e74b4e849e66a9305938ff3ee2f3cbe82bf78b67 Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Mon, 1 Jul 2019 19:20:27 +0600 Subject: [PATCH 5/9] Cleanup default Function & Tasks while uninstall --- chart/stash/templates/cleaner.yaml | 6 +++++- deploy/stash.sh | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chart/stash/templates/cleaner.yaml b/chart/stash/templates/cleaner.yaml index a5ad6a0a5..17ce94a8b 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 function update-status pvc-backup pvc-restore || true; \ + kubectl delete task pvc-backup pvc-restore" imagePullPolicy: {{ .Values.imagePullPolicy }} restartPolicy: Never diff --git a/deploy/stash.sh b/deploy/stash.sh index c8f30f3b6..38cb02bb6 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -351,8 +351,11 @@ 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 update-status function - kubectl delete function update-status || true + # delete default functions + kubectl delete function update-status pvc-backup pvc-restore || true + # delete default tasks + kubectl delete task pvc-backup pvc-restore || true + echo "waiting for stash operator pod to stop running" for (( ; ; )); do pods=($(kubectl get pods --namespace $STASH_NAMESPACE -l app=stash -o jsonpath='{range .items[*]}{.metadata.name} {end}')) From bd56e6face7869ff310423755e032bd59db1c0e2 Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Thu, 4 Jul 2019 10:18:36 +0600 Subject: [PATCH 6/9] Use full resource name for function & task --- deploy/stash.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/stash.sh b/deploy/stash.sh index 38cb02bb6..7f7932685 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -352,9 +352,9 @@ if [ "$STASH_UNINSTALL" -eq 1 ]; then # delete psp resources kubectl delete psp stash-operator-psp stash-backup-job stash-backupsession-cron stash-restore-job || true # delete default functions - kubectl delete function update-status pvc-backup pvc-restore || true + kubectl delete functions.stash.appscode.com update-status pvc-backup pvc-restore || true # delete default tasks - kubectl delete task pvc-backup pvc-restore || true + kubectl delete tasks.stash.appscode.com pvc-backup pvc-restore || true echo "waiting for stash operator pod to stop running" for (( ; ; )); do From 482370ae9a66287796635a3cb3d985fc7423569b Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Thu, 4 Jul 2019 14:16:42 +0600 Subject: [PATCH 7/9] use full name of task and function in chart cleaner --- chart/stash/templates/cleaner.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chart/stash/templates/cleaner.yaml b/chart/stash/templates/cleaner.yaml index 17ce94a8b..b0229c82e 100644 --- a/chart/stash/templates/cleaner.yaml +++ b/chart/stash/templates/cleaner.yaml @@ -26,7 +26,7 @@ spec: - "sleep 2; \ kubectl delete validatingwebhookconfigurations admission.stash.appscode.com || true; \ kubectl delete mutatingwebhookconfiguration admission.stash.appscode.com || true; \ - kubectl delete function update-status pvc-backup pvc-restore || true; \ - kubectl delete task pvc-backup pvc-restore" + 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 From de59ec3b14f808a358df8938d681da323a6c3aff Mon Sep 17 00:00:00 2001 From: hossainemruz Date: Thu, 4 Jul 2019 14:25:54 +0600 Subject: [PATCH 8/9] Remove armv5 and armv6 + add reference to OS detection code. --- deploy/stash.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deploy/stash.sh b/deploy/stash.sh index 7f7932685..2488107a9 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -30,6 +30,7 @@ function cleanup() { } # detect operating system +# ref: https://raw.githubusercontent.com/helm/helm/master/scripts/get function detectOS() { OS=$(echo `uname`|tr '[:upper:]' '[:lower:]') @@ -43,8 +44,6 @@ function detectOS() { function detectArch() { ARCH=$(uname -m) case $ARCH in - armv5*) ARCH="armv5";; - armv6*) ARCH="armv6";; armv7*) ARCH="arm";; aarch64) ARCH="arm64";; x86) ARCH="386";; From 371bedc3b6ffc28a7f3a931c7c79188bd64485d7 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Thu, 4 Jul 2019 01:30:53 -0700 Subject: [PATCH 9/9] Update stash.sh --- deploy/stash.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/stash.sh b/deploy/stash.sh index 2488107a9..fb635cf39 100755 --- a/deploy/stash.sh +++ b/deploy/stash.sh @@ -89,7 +89,7 @@ onessl_found() { onessl_found || { echo "Downloading onessl ..." - ARTIFACT="https://github.com/kubepack/onessl/releases/download/0.10.0" + ARTIFACT="https://github.com/kubepack/onessl/releases/download/0.12.0" ONESSL_BIN=onessl-${OS}-${ARCH} case "$OS" in cygwin* | mingw* | msys*)