Skip to content

Commit

Permalink
added-all
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Mar 9, 2018
1 parent 599eaae commit 9828262
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
33 changes: 17 additions & 16 deletions docs/setup/uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ section_menu_id: setup
# Uninstall KubeDB

Please follow the steps below to uninstall KubeDB:
To uninstall KubeDB operator, run the following command:

- Delete the deployment and service used for KubeDB operator.
```console
$ curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/kubedb.sh \
| bash -s -- --uninstall [--namespace=NAMESPACE]

```console
$ curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/kubedb.sh \
| bash -s -- --uninstall [--namespace=NAMESPACE]
+ kubectl delete deployment -l app=kubedb -n kube-system
deployment "kubedb-operator" deleted
+ kubectl delete service -l app=kubedb -n kube-system
service "kubedb-operator" deleted
+ kubectl delete serviceaccount -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrolebindings -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrole -l app=kubedb -n kube-system
No resources found
```

The above command will leave the KubeDB crd objects as-is. If you wish to **nuke** all KubeDB crd objects, also pass the `--purge` flag. This will keep a copy of KubeDB crd objects in your current directory.

+ kubectl delete deployment -l app=kubedb -n kube-system
deployment "kubedb-operator" deleted
+ kubectl delete service -l app=kubedb -n kube-system
service "kubedb-operator" deleted
+ kubectl delete serviceaccount -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrolebindings -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrole -l app=kubedb -n kube-system
No resources found
```

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

Expand Down
57 changes: 49 additions & 8 deletions hack/deploy/kubedb.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -eou pipefail

crds=(elasticsearches memcacheds mongodbs mysqls postgreses redises snapshots dormantdatabases)

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 KUBEDB_ENABLE_ADMISSION_WEBHOOK=false
export KUBEDB_DOCKER_REGISTRY=kubedb
export KUBEDB_IMAGE_PULL_SECRET=
export KUBEDB_UNINSTALL=0
export KUBEDB_PURGE=0

KUBE_APISERVER_VERSION=$(kubectl version -o=json | $ONESSL jsonpath '{.serverVersion.gitVersion}')
$ONESSL semver --check='>=1.9.0' $KUBE_APISERVER_VERSION
Expand All @@ -73,6 +76,7 @@ show_help() {
echo " --run-on-master run kubedb operator on master"
echo " --enable-admission-webhook configure admission webhook for kubedb CRDs"
echo " --uninstall uninstall kubedb"
echo " --purge purges kubedb crd objects and crds"
}

while test $# -gt 0; do
Expand Down Expand Up @@ -129,6 +133,10 @@ while test $# -gt 0; do
export KUBEDB_UNINSTALL=1
shift
;;
--purge)
export KUBEDB_PURGE=1
shift
;;
*)
show_help
exit 1
Expand All @@ -150,6 +158,43 @@ if [ "$KUBEDB_UNINSTALL" -eq 1 ]; then
kubectl delete rolebindings -l app=kubedb --namespace $KUBEDB_NAMESPACE
kubectl delete role -l app=kubedb --namespace $KUBEDB_NAMESPACE

echo "waiting for kubedb operator pod to stop running"
for (( ; ; )); do
pods=($(kubectl get pods --all-namespaces -l app=kubedb -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 [ "$KUBEDB_PURGE" -eq 1 ]; then
for crd in "${crds[@]}"; do
pairs=($(kubectl get ${crd}.kubedb.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}.kubedb.com --all-namespaces -o yaml > ${crd}.yaml
fi

for (( i=0; i<$total; i+=2 )); do
# remove finalizers
kubectl patch ${crd}.kubedb.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}.kubedb.com ${pairs[$i]} -n ${pairs[$i + 1]}
done

# delete crd
kubectl delete crd ${crd}.kubedb.com || true
done
fi

echo
echo "Successfully uninstalled KubeDB!"
exit 0
fi

Expand Down Expand Up @@ -189,21 +234,17 @@ if [ "$KUBEDB_ENABLE_ADMISSION_WEBHOOK" = true ]; then
curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/admission.yaml | $ONESSL envsubst | kubectl apply -f -
fi

echo
echo "waiting until kubedb operator deployment is ready"
$ONESSL wait-until-ready deployment kubedb-operator --namespace $KUBEDB_NAMESPACE || { echo "KubeDB operator deployment failed to be ready"; exit 1; }

echo "waiting until kubedb apiservice is available"
$ONESSL wait-until-ready apiservice v1alpha1.admission.kubedb.com || { echo "KubeDB apiservice failed to be ready"; exit 1; }

echo "waiting until kubedb crds are ready"
$ONESSL wait-until-ready crd elasticsearches.kubedb.com || { echo "Elasticsearch CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd memcacheds.kubedb.com || { echo "Memcached CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd mongodbs.kubedb.com || { echo "MongoDB CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd mysqls.kubedb.com || { echo "MySQL CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd postgreses.kubedb.com || { echo "Postgres CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd redises.kubedb.com || { echo "Redis CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd snapshots.kubedb.com || { echo "Snapshot CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd dormantdatabases.kubedb.com || { echo "DormantDatabase CRD failed to be ready"; exit 1; }
for crd in "${crds[@]}"; do
$ONESSL wait-until-ready crd ${crd}.kubedb.com || { echo "$crd crd failed to be ready"; exit 1; }
done

echo
echo "Successfully installed KubeDB operator!"

0 comments on commit 9828262

Please sign in to comment.