Skip to content

Commit

Permalink
Add --purge flag (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha authored Mar 9, 2018
1 parent 3e9ac0b commit 9f14db3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 33 deletions.
20 changes: 15 additions & 5 deletions docs/setup/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
28 changes: 2 additions & 26 deletions docs/setup/uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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.
51 changes: 49 additions & 2 deletions hack/deploy/stash.sh
Original file line number Diff line number Diff line change
@@ -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 <context>) out of the following:"; echo; kubectl config get-contexts; exit 1; }
echo ""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -135,6 +139,10 @@ while test $# -gt 0; do
export STASH_UNINSTALL=1
shift
;;
--purge)
export STASH_PURGE=1
shift
;;
*)
show_help
exit 1
Expand All @@ -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

Expand Down Expand Up @@ -199,15 +244,17 @@ 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; }

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!"

0 comments on commit 9f14db3

Please sign in to comment.