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 7fde8d4
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 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,33 @@ if [ "$VOYAGER_UNINSTALL" -eq 1 ]; then
kubectl delete rolebindings -l app=voyager --namespace $VOYAGER_NAMESPACE
kubectl delete role -l app=voyager --namespace $VOYAGER_NAMESPACE

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
kubectl get ${crd}.voyager.appscode.com --all-namespaces -o yaml > ${crd}.yaml

# capture name namespace pairs
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
kubectl patch ${crd}.voyager.appscode.com ${pairs[$i]} -n ${pairs[$i + 1]} -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl delete ${crd}.voyager.appscode.com ${pairs[$i]} -n ${pairs[$i + 1]}
done

kubectl delete crd ${crd}.voyager.appscode.com
done
fi

exit 0
fi

Expand Down Expand Up @@ -270,15 +305,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 7fde8d4

Please sign in to comment.