diff --git a/microk8s-resources/wrappers/microk8s-reset.wrapper b/microk8s-resources/wrappers/microk8s-reset.wrapper index cddfc42d18..dfa71397ff 100755 --- a/microk8s-resources/wrappers/microk8s-reset.wrapper +++ b/microk8s-resources/wrappers/microk8s-reset.wrapper @@ -9,6 +9,11 @@ KUBECTL="$SNAP/kubectl --kubeconfig=${SNAP_DATA}/credentials/client.config" clean_cluster() { echo "Calling clean_cluster" # Clean the cluster + REMOVEABLE_NSES=$($KUBECTL get ns -o=name | awk -F/ '{if ($2 !~ /^(default|kube-public|kube-system|kube-node-lease)$/) print}' | paste -s --delimiters=' ') + if [ -n "$REMOVEABLE_NSES" ] + then + $KUBECTL delete $REMOVEABLE_NSES + fi NSES=$($KUBECTL get ns -o=name | awk -F/ '{print $2}' | paste -s --delimiters=' ') for NS in $NSES do @@ -16,11 +21,6 @@ clean_cluster() { # Remove all resource types except the standard k8s apiservices themselves $KUBECTL delete --all $($KUBECTL api-resources -o name --verbs=delete --namespaced=true | grep -v '^apiservices$' | paste -s --delimiters=',') --namespace="$NS" done - REMOVEABLE_NSES=$($KUBECTL get ns -o=name | awk -F/ '{if ($2 !~ /^(default|kube-public|kube-system)$/) print}' | paste -s --delimiters=' ') - if [ -n "$REMOVEABLE_NSES" ] - then - $KUBECTL delete $REMOVEABLE_NSES - fi echo "Removing CRDs" $KUBECTL delete --all customresourcedefinitions.apiextensions.k8s.io @@ -36,7 +36,7 @@ clean_cluster() { done echo "Cleaning up addons client binaries.." - if [ -d "$SNAP_DATA/bin/" ] + if [ -d "$SNAP_DATA/bin/" ] then sudo rm -rf "$SNAP_DATA/bin/" fi @@ -45,6 +45,8 @@ clean_cluster() { exit_if_stopped exit_if_no_permissions +clean_cluster + ${SNAP}/microk8s-stop.wrapper sleep 5 ${SNAP}/microk8s-start.wrapper diff --git a/tests/test-addons.py b/tests/test-addons.py index 4ac6eb0d40..7b00d058de 100644 --- a/tests/test-addons.py +++ b/tests/test-addons.py @@ -62,9 +62,6 @@ def test_basic(self): microk8s_enable("storage") print("Validating storage") validate_storage() - print("Disabling storage") - p = Popen("/snap/bin/microk8s.disable storage".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT) - p.communicate(input=b'Y\n')[0] microk8s_enable("registry") print("Validating registry") validate_registry() @@ -74,6 +71,9 @@ def test_basic(self): microk8s_disable("registry") print("Disabling dashboard") microk8s_disable("dashboard") + print("Disabling storage") + p = Popen("/snap/bin/microk8s.disable storage".split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT) + p.communicate(input=b'Y\n')[0] ''' We would disable DNS here but this freezes any terminating pods. We let microk8s.reset to do the cleanup.