Skip to content

Commit

Permalink
Add --purge flag
Browse files Browse the repository at this point in the history
Also uses removed finalizers before deleting crds. kubernetes/kubernetes#60538
  • Loading branch information
tamalsaha committed Mar 8, 2018
1 parent 1a7ee23 commit ec4362f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
4 changes: 3 additions & 1 deletion docs/setup/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ options:
--image-pull-secret name of secret used to pull voyager operator images
--restrict-to-namespace restrict voyager to its own namespace
--run-on-master run voyager operator on master
--enable-admission-webhook configure admission webhook for Voyager CRDs
--enable-admission-webhook configure admission webhook for voyager CRDs
--template-cfgmap=CONFIGMAP name of configmap with custom templates
--uninstall uninstall voyager
--purge purges Voyager crd objects and crds
```

If you would like to run Voyager operator pod in `master` instances, pass the `--run-on-master` flag:
Expand Down
30 changes: 2 additions & 28 deletions docs/setup/uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ section_menu_id: setup

# Uninstall Voyager

Please follow the steps below to uninstall Voyager:

- Delete the deployment and service used for Voyager operator.
To uninstall Voyager operator, run the following command:

```console
$ curl -fsSL https://raw.githubusercontent.com/appscode/voyager/6.0.0-rc.2/hack/deploy/voyager.sh \
Expand All @@ -34,28 +32,4 @@ No resources found
No resources found
```

- Now, wait several seconds for Voyager to stop running. To confirm that Voyager operator pod(s) have stopped running, run:

```console
$ kubectl get pods --all-namespaces -l app=voyager
```

- To keep a copy of your existing Voyager objects, run:

```console
$ kubectl get ingress.voyager.appscode.com --all-namespaces -o yaml > ingress.yaml
$ kubectl get certificate.voyager.appscode.com --all-namespaces -o yaml > certificate.yaml
```

- To delete existing Voyager objects from all namespaces, run the following command in each namespace one by one.

```console
$ kubectl delete ingress.voyager.appscode.com --all --cascade=false
$ kubectl delete certificate.voyager.appscode.com --all --cascade=false
```

- Delete the old CRD-registration.

```console
kubectl delete crd -l app=voyager
```
The above command will leave the Voyager crd object as-is. If you wish to **nuke** the Voyager crd objects, also pass the `--purge` flag. This will dump the crd objects in your current directory.
47 changes: 45 additions & 2 deletions hack/deploy/voyager.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

crds=(certificates ingresses)

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 @@ -52,6 +54,7 @@ export VOYAGER_ROLE_TYPE=ClusterRole
export VOYAGER_DOCKER_REGISTRY=appscode
export VOYAGER_IMAGE_PULL_SECRET=
export VOYAGER_UNINSTALL=0
export VOYAGER_PURGE=0

KUBE_APISERVER_VERSION=$(kubectl version -o=json | $ONESSL jsonpath '{.serverVersion.gitVersion}')
$ONESSL semver --check='>=1.9.0' $KUBE_APISERVER_VERSION
Expand All @@ -76,6 +79,7 @@ show_help() {
echo " --enable-admission-webhook configure admission webhook for voyager CRDs"
echo " --template-cfgmap=CONFIGMAP name of configmap with custom templates"
echo " --uninstall uninstall voyager"
echo " --purge purges Voyager crd objects and crds"
}

while test $# -gt 0; do
Expand Down Expand Up @@ -155,6 +159,10 @@ while test $# -gt 0; do
export VOYAGER_UNINSTALL=1
shift
;;
--purge)
export VOYAGER_PURGE=1
shift
;;
*)
show_help
exit 1
Expand All @@ -176,6 +184,39 @@ if [ "$VOYAGER_UNINSTALL" -eq 1 ]; then
kubectl delete rolebindings -l app=voyager --namespace $VOYAGER_NAMESPACE
kubectl delete role -l app=voyager --namespace $VOYAGER_NAMESPACE

echo "waiting for voyager operator pods to stop running"
for (( ; ; )); do
pods=$(kubectl get pods --all-namespaces -l app=voyager -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 [ "$VOYAGER_PURGE" -eq 1 ]; then
for crd in "${crds[@]}"; do
# save objects
echo "dumping ${crd} objects into ${crd}.yaml"
kubectl get ${crd}.voyager.appscode.com --all-namespaces -o yaml > ${crd}.yaml

pairs=$(kubectl get ${crd}.voyager.appscode.com --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name} {.metadata.namespace} {end}')
total=${#pairs[*]}
for (( i=0; i<=$(( $total -1 )); i+=2 )); do
# remove finalizers
kubectl patch ${crd}.voyager.appscode.com ${pairs[$i]} -n ${pairs[$i + 1]} -p '{"metadata":{"finalizers":[]}}' --type=merge
# delete crd object
echo "deleting ${crd} ${pairs[$i + 1]}/${pairs[$i]}"
kubectl delete ${crd}.voyager.appscode.com ${pairs[$i]} -n ${pairs[$i + 1]}
done

# delete crd
echo "deleting crd ${crd}.voyager.appscode.com"
kubectl delete crd ${crd}.voyager.appscode.com
done
fi

exit 0
fi

Expand Down Expand Up @@ -270,15 +311,17 @@ if [ "$VOYAGER_ENABLE_ADMISSION_WEBHOOK" = true ]; then
curl -fsSL https://raw.githubusercontent.com/appscode/voyager/6.0.0-rc.2/hack/deploy/admission.yaml | $ONESSL envsubst | kubectl apply -f -
fi

echo
echo "waiting until voyager operator deployment is ready"
$ONESSL wait-until-ready deployment voyager-operator --namespace $VOYAGER_NAMESPACE || { echo "Voyager operator deployment failed to be ready"; exit 1; }

echo "waiting until voyager apiservice is available"
$ONESSL wait-until-ready apiservice v1beta1.admission.voyager.appscode.com || { echo "Voyager apiservice failed to be ready"; exit 1; }

echo "waiting until voyager crds are ready"
$ONESSL wait-until-ready crd certificates.voyager.appscode.com || { echo "Certificate CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd ingresses.voyager.appscode.com || { echo "Ingress CRD failed to be ready"; exit 1; }
for crd in "${crds[@]}"; do
$ONESSL wait-until-ready crd ${crd}.voyager.appscode.com || { echo "$crd crd failed to be ready"; exit 1; }
done

echo
echo "Successfully installed Voyager!"

0 comments on commit ec4362f

Please sign in to comment.