Skip to content

Commit

Permalink
Fix the reset wrapper - do a proper reset (canonical#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsakalozos authored and ianbibby committed Jan 10, 2020
1 parent 630329a commit aa05cc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions microk8s-resources/wrappers/microk8s-reset.wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ 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
echo "Cleaning resources in namespace $NS"
# 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
Expand All @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions tests/test-addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down

0 comments on commit aa05cc2

Please sign in to comment.