Skip to content

Commit

Permalink
fix: cleanup in offline environment
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Mar 8, 2020
1 parent c6e7039 commit 479437a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ kind-init:
kind delete cluster --name=kube-ovn
kind create cluster --config yamls/kind.yaml --name kube-ovn
kind load docker-image --name kube-ovn ${REGISTRY}/kube-ovn:${RELEASE_TAG}
kubectl label node kube-ovn-control-plane kube-ovn/role=master
kubectl label node kube-ovn-control-plane kube-ovn/role=master --overwrite
kubectl apply -f yamls/crd.yaml
kubectl apply -f yamls/ovn.yaml
kubectl apply -f yamls/kube-ovn.yaml
Expand All @@ -68,7 +68,7 @@ kind-init-ha:
kind delete cluster --name=kube-ovn
kind create cluster --config yamls/kind.yaml --name kube-ovn
kind load docker-image --name kube-ovn ${REGISTRY}/kube-ovn:${RELEASE_TAG}
kubectl label node --all kube-ovn/role=master
kubectl label node --all kube-ovn/role=master --overwrite
kubectl apply -f yamls/crd.yaml
kubectl apply -f yamls/ovn-ha.yaml
kubectl apply -f yamls/kube-ovn.yaml
Expand All @@ -80,6 +80,9 @@ kind-reload:
kind-clean:
kind delete cluster --name=kube-ovn

uninstall:
bash dist/images/cleanup.sh

e2e:
ginkgo -p --slowSpecThreshold=60 test/e2e

Expand Down
49 changes: 33 additions & 16 deletions dist/images/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,53 @@
set -eu

for subnet in $(kubectl get subnet -o name); do
kubectl patch "$subnet" --type='json' -p '[{"op": "remove", "path": "/metadata/finalizers"}]'
kubectl patch "$subnet" --type='json' -p '[{"op": "replace", "path": "/metadata/finalizers", "value": []}]'
done

# Delete Kube-OVN components
kubectl delete -f https://raw.githubusercontent.com/alauda/kube-ovn/master/yamls/kube-ovn.yaml --ignore-not-found=true
kubectl delete -f https://raw.githubusercontent.com/alauda/kube-ovn/master/yamls/ovn.yaml --ignore-not-found=true
kubectl delete -f https://raw.githubusercontent.com/alauda/kube-ovn/master/yamls/crd.yaml --ignore-not-found=true
kubectl delete cm ovn-config -n kube-system --ignore-not-found=true
kubectl delete sa ovn -n kube-system --ignore-not-found=true
kubectl delete clusterrole system:ovn --ignore-not-found=true
kubectl delete clusterrolebinding ovn --ignore-not-found=true
kubectl delete svc ovn-nb ovn-sb kube-ovn-pinger kube-ovn-controller kube-ovn-cni -n kube-system --ignore-not-found=true

# Remove annotations in all pods of all namespaces
for ns in $(kubectl get ns -o name |cut -c 11-); do
echo "annotating pods in ns:$ns"
kubectl annotate pod --all ovn.kubernetes.io/cidr- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/gateway- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/ip_address- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/logical_switch- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/mac_address- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/port_name- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/allocated- -n "$ns"
kubectl delete deployment ovn-central kube-ovn-controller -n kube-system --ignore-not-found=true
for ovs in $(kubectl get pod --no-headers -n kube-system -lapp=ovs | awk '{print $1}')
do
kubectl exec -n kube-system "$ovs" -- bash /kube-ovn/uninstall.sh
done

# Remove annotations in namespaces and nodes
kubectl delete ds ovs-ovn kube-ovn-cni kube-ovn-pinger -n kube-system --ignore-not-found=true
kubectl delete crd ips.kubeovn.io subnets.kubeovn.io --ignore-not-found=true

# Remove annotations/labels in namespaces and nodes
kubectl annotate no --all ovn.kubernetes.io/cidr-
kubectl annotate no --all ovn.kubernetes.io/gateway-
kubectl annotate no --all ovn.kubernetes.io/ip_address-
kubectl annotate no --all ovn.kubernetes.io/logical_switch-
kubectl annotate no --all ovn.kubernetes.io/mac_address-
kubectl annotate no --all ovn.kubernetes.io/port_name-
kubectl annotate no --all ovn.kubernetes.io/allocated-
kubectl label node --all kube-ovn/role-

kubectl annotate ns --all ovn.kubernetes.io/cidr-
kubectl annotate ns --all ovn.kubernetes.io/exclude_ips-
kubectl annotate ns --all ovn.kubernetes.io/gateway-
kubectl annotate ns --all ovn.kubernetes.io/logical_switch-
kubectl annotate ns --all ovn.kubernetes.io/private-
kubectl annotate ns --all ovn.kubernetes.io/allow-
kubectl annotate ns --all ovn.kubernetes.io/allocated-

# Wait Pod Deletion
sleep 5

# Remove annotations in all pods of all namespaces
for ns in $(kubectl get ns -o name |cut -c 11-); do
echo "annotating pods in ns:$ns"
kubectl annotate pod --all ovn.kubernetes.io/cidr- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/gateway- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/ip_address- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/logical_switch- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/mac_address- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/port_name- -n "$ns"
kubectl annotate pod --all ovn.kubernetes.io/allocated- -n "$ns"
done
11 changes: 11 additions & 0 deletions dist/images/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
/usr/share/openvswitch/scripts/ovs-ctl stop
ovs-dpctl del-dp ovs-system

rm -rf /var/run/openvswitch/*
rm -rf /var/run/ovn/*
rm -rf /etc/openvswitch/*
rm -rf /etc/ovn/*
rm -rf /var/log/openvswitch/*
rm -rf /var/log/ovn/*
rm -rf /etc/cni/net.d/00-kube-ovn.conflist

0 comments on commit 479437a

Please sign in to comment.