From 9f14db3b0a69821cb6603ae483a3a88503b3348b Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Fri, 9 Mar 2018 01:11:51 -0800 Subject: [PATCH] Add --purge flag (#369) --- docs/setup/install.md | 20 ++++++++++++---- docs/setup/uninstall.md | 28 ++-------------------- hack/deploy/stash.sh | 51 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 33 deletions(-) diff --git a/docs/setup/install.md b/docs/setup/install.md index dd1b1317f..342f4ba75 100644 --- a/docs/setup/install.md +++ b/docs/setup/install.md @@ -14,17 +14,26 @@ section_menu_id: setup # Installation Guide -## Using YAML -Stash can be installed via installer script included in the [/hack/deploy](https://github.com/appscode/stash/tree/0.7.0-rc.0/hack/deploy) folder. +Stash operator can be installed via a script or as a Helm chart. + +## Using Script + +To install Stash in your Kubernetes cluster, run the following command: ```console -$ curl -fsSL https://raw.githubusercontent.com/appscode/stash/0.7.0-rc.0/hack/deploy/stash.sh \ - | bash +$ curl -fsSL https://raw.githubusercontent.com/appscode/stash/0.7.0-rc.0/hack/deploy/stash.sh | bash +``` + +After successful installation, you should have a `stash-operator-***` pod running in the `kube-system` namespace. + +```console +$ kubectl get pods -n kube-system | grep stash-operator +stash-operator-846d47f489-jrb58 1/1 Running 0 48s ``` #### Customizing Installer -You can see the full list of flags available to installer using `-h` flag. +The installer script and associated yaml files can be found in the [/hack/deploy](https://github.com/appscode/stash/tree/0.7.0-rc.0/hack/deploy) folder. You can see the full list of flags available to installer using `-h` flag. ```console $ curl -fsSL https://raw.githubusercontent.com/appscode/stash/0.7.0-rc.0/hack/deploy/stash.sh | bash -s -- -h @@ -42,6 +51,7 @@ options: --enable-admission-webhook configure admission webhook for stash CRDs --enable-initializer configure stash operator as workload initializer --uninstall uninstall stash + --purge purges stash crd objects and crds ``` If you would like to run Stash operator pod in `master` instances, pass the `--run-on-master` flag: diff --git a/docs/setup/uninstall.md b/docs/setup/uninstall.md index 9fdfd43f6..e459caf70 100644 --- a/docs/setup/uninstall.md +++ b/docs/setup/uninstall.md @@ -13,9 +13,7 @@ section_menu_id: setup --- # Uninstall Stash -Please follow the steps below to uninstall Stash: - -- Delete the deployment and service used for Stash operator. +To uninstall Stash operator, run the following command: ```console $ curl -fsSL https://raw.githubusercontent.com/appscode/stash/0.7.0-rc.0/hack/deploy/stash.sh \ @@ -37,26 +35,4 @@ No resources found initializerconfiguration "stash-initializer" deleted ``` -- Now, wait several seconds for Stash to stop running. To confirm that Stash operator pod(s) have stopped running, run: - -```console -$ kubectl get pods --all-namespaces -l app=stash -``` - -- To keep a copy of your existing `Restic` objects, run: - -```console -kubectl get restic.stash.appscode.com --all-namespaces -o yaml > data.yaml -``` - -- To delete existing `Restic` objects from all namespaces, run the following command in each namespace one by one. - -``` -kubectl delete restic.stash.appscode.com --all --cascade=false -``` - -- Delete the old CRD-registration. - -```console -kubectl delete crd -l app=stash -``` +The above command will leave the Stash crd objects as-is. If you wish to **nuke** all Stash crd objects, also pass the `--purge` flag. This will keep a copy of Stash crd objects in your current directory. diff --git a/hack/deploy/stash.sh b/hack/deploy/stash.sh index 78f87ed98..38b70a289 100755 --- a/hack/deploy/stash.sh +++ b/hack/deploy/stash.sh @@ -1,6 +1,8 @@ #!/bin/bash set -eou pipefail +crds=(restics recoveries) + echo "checking kubeconfig context" kubectl config current-context || { echo "Set a context (kubectl use-context ) out of the following:"; echo; kubectl config get-contexts; exit 1; } echo "" @@ -53,6 +55,7 @@ export STASH_ENABLE_ADMISSION_WEBHOOK=false export STASH_DOCKER_REGISTRY=appscode export STASH_IMAGE_PULL_SECRET= export STASH_UNINSTALL=0 +export STASH_PURGE=0 KUBE_APISERVER_VERSION=$(kubectl version -o=json | $ONESSL jsonpath '{.serverVersion.gitVersion}') $ONESSL semver --check='>=1.9.0' $KUBE_APISERVER_VERSION @@ -75,6 +78,7 @@ show_help() { echo " --enable-admission-webhook configure admission webhook for stash CRDs" echo " --enable-initializer configure stash operator as workload initializer" echo " --uninstall uninstall stash" + echo " --purge purges stash crd objects and crds" } while test $# -gt 0; do @@ -135,6 +139,10 @@ while test $# -gt 0; do export STASH_UNINSTALL=1 shift ;; + --purge) + export STASH_PURGE=1 + shift + ;; *) show_help exit 1 @@ -156,6 +164,43 @@ if [ "$STASH_UNINSTALL" -eq 1 ]; then kubectl delete rolebindings -l app=stash --namespace $STASH_NAMESPACE kubectl delete role -l app=stash --namespace $STASH_NAMESPACE + echo "waiting for stash operator pod to stop running" + for (( ; ; )); do + pods=($(kubectl get pods --all-namespaces -l app=stash -o jsonpath='{range .items[*]}{.metadata.name} {end}')) + total=${#pods[*]} + if [ $total -eq 0 ] ; then + break + fi + sleep 2 + done + + # https://github.com/kubernetes/kubernetes/issues/60538 + if [ "$STASH_PURGE" -eq 1 ]; then + for crd in "${crds[@]}"; do + pairs=($(kubectl get ${crd}.stash.appscode.com --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name} {.metadata.namespace} {end}' || true)) + total=${#pairs[*]} + + # save objects + if [ $total -gt 0 ]; then + echo "dumping ${crd} objects into ${crd}.yaml" + kubectl get ${crd}.stash.appscode.com --all-namespaces -o yaml > ${crd}.yaml + fi + + for (( i=0; i<$total; i+=2 )); do + name=${pairs[$i]} + namespace=${pairs[$i + 1]} + # delete crd object + echo "deleting ${crd} $namespace/$name" + kubectl delete ${crd}.stash.appscode.com $name -n $namespace + done + + # delete crd + kubectl delete crd ${crd}.stash.appscode.com || true + done + fi + + echo + echo "Successfully uninstalled Stash!" exit 0 fi @@ -199,6 +244,7 @@ if [ "$STASH_ENABLE_ADMISSION_WEBHOOK" = true ]; then curl -fsSL https://raw.githubusercontent.com/appscode/stash/0.7.0-rc.0/hack/deploy/admission.yaml | $ONESSL envsubst | kubectl apply -f - fi +echo echo "waiting until stash operator deployment is ready" $ONESSL wait-until-ready deployment stash-operator --namespace $STASH_NAMESPACE || { echo "Stash operator deployment failed to be ready"; exit 1; } @@ -206,8 +252,9 @@ echo "waiting until stash apiservice is available" $ONESSL wait-until-ready apiservice v1alpha1.admission.stash.appscode.com || { echo "Stash apiservice failed to be ready"; exit 1; } echo "waiting until stash crds are ready" -$ONESSL wait-until-ready crd restics.stash.appscode.com || { echo "Restic CRD failed to be ready"; exit 1; } -$ONESSL wait-until-ready crd recoveries.stash.appscode.com || { echo "Recovery CRD failed to be ready"; exit 1; } +for crd in "${crds[@]}"; do + $ONESSL wait-until-ready crd ${crd}.stash.appscode.com || { echo "$crd crd failed to be ready"; exit 1; } +done echo echo "Successfully installed Stash!"