diff --git a/builtin/capkk/roles/uninstall/kubernetes/tasks/network.yaml b/builtin/capkk/roles/uninstall/kubernetes/tasks/network.yaml index 8ec4b5e9..dab774d6 100644 --- a/builtin/capkk/roles/uninstall/kubernetes/tasks/network.yaml +++ b/builtin/capkk/roles/uninstall/kubernetes/tasks/network.yaml @@ -33,7 +33,7 @@ {{- end }} - name: Delete arp by kube-vip - when: eq .kubernetes.control_plane_endpoint.type "vip" + when: eq .kubernetes.control_plane_endpoint.type "kube_vip" command: | ip neigh show | grep {{ .kubernetes.control_plane_endpoint.kube_vip.address }} | awk '{print $1 " dev " $3}' | xargs -r -L1 ip neigh delete \ No newline at end of file diff --git a/builtin/core/roles/uninstall/kubernetes/tasks/kubernetes.yaml b/builtin/core/roles/uninstall/kubernetes/tasks/kubernetes.yaml new file mode 100644 index 00000000..3c37f4e4 --- /dev/null +++ b/builtin/core/roles/uninstall/kubernetes/tasks/kubernetes.yaml @@ -0,0 +1,19 @@ +--- +- name: Delete Node + ignore_errors: true + command: | + kubeadm reset -f + +- name: Stop kubelet service + command: | + rm -rf /etc/systemd/system/kubelet.service + rm -rf /etc/systemd/system/kubelet.service.d + systemctl daemon-reload + +- name: Delete residue files + command: | + rm -rf /usr/local/bin/kubeadm && rm -rf /usr/local/bin/kubelet && rm -rf /usr/local/bin/kubectl + rm -rf /var/lib/kubelet/ + rm -rf /etc/kubernetes/ + rm -rf .kube/config + rm -rf /var/lib/etcd \ No newline at end of file diff --git a/builtin/core/roles/uninstall/kubernetes/tasks/main.yaml b/builtin/core/roles/uninstall/kubernetes/tasks/main.yaml index 90b6c529..3b5afa07 100644 --- a/builtin/core/roles/uninstall/kubernetes/tasks/main.yaml +++ b/builtin/core/roles/uninstall/kubernetes/tasks/main.yaml @@ -1,53 +1,4 @@ --- -- name: Reset kubeadm - ignore_errors: true - command: | - kubeadm reset -f +- include_tasks: kubernetes.yaml -- name: Stop kubelet service - command: | - rm -rf /etc/systemd/system/kubelet.service - rm -rf /etc/systemd/system/kubelet.service.d - systemctl daemon-reload - -- name: Delete residue files - command: | - rm -rf /usr/local/bin/kubeadm && rm -rf /usr/local/bin/kubelet && rm -rf /usr/local/bin/kubectl - rm -rf /var/lib/kubelet/ - # If /var/log/pods/ is not cleaned up, static pods may accumulate unexpected restarts due to lingering log files interfering with their lifecycle. - rm -rf /var/log/pods/ - rm -rf /etc/kubernetes/ - rm -rf .kube/config - -- name: Reset iptables - command: | - iptables -F - iptables -X - iptables -F -t nat - iptables -X -t nat - ipvsadm -C - ip link del kube-ipvs0 - ip link del nodelocaldns - ip link del cni0 - {{- if .kubernetes.kube_network_plugin | eq "flannel" }} - ip link del flannel.1 - ip link del flannel-v6.1 - ip link del flannel-wg - ip link del flannel-wg-v6 - {{- end }} - {{- if .kubernetes.kube_network_plugin | eq "cilium" }} - ip link del cilium_host - ip link del cilium_vxlan - {{- end }} - {{- if .kubernetes.kube_network_plugin | eq "calico" }} - ip -br link show | grep cali[a-f0-9]* | awk -F @ '{print $1}' | xargs -r -t -n 1 ip link del - {{- end }} - ip netns show 2>/dev/null | grep cni- | awk '{print $1}' | xargs -r -t -n 1 ip netns del - -- name: Delete net.d - command: | - rm -rf /etc/cni/net.d/ - rm -rf /var/lib/cni/ - {{- if .kubernetes.kube_network_plugin | eq "calico" }} - rm -rf /usr/local/bin/calicoctl - {{- end }} \ No newline at end of file +- include_tasks: network.yaml \ No newline at end of file diff --git a/builtin/core/roles/uninstall/kubernetes/tasks/network.yaml b/builtin/core/roles/uninstall/kubernetes/tasks/network.yaml new file mode 100644 index 00000000..dab774d6 --- /dev/null +++ b/builtin/core/roles/uninstall/kubernetes/tasks/network.yaml @@ -0,0 +1,39 @@ +--- +- name: Reset iptables + command: | + iptables -F + iptables -X + iptables -F -t nat + iptables -X -t nat + ipvsadm -C + ip link del kube-ipvs0 + ip link del nodelocaldns + ip link del cni0 + {{- if .cni.type | eq "flannel" }} + ip link del flannel.1 + ip link del flannel-v6.1 + ip link del flannel-wg + ip link del flannel-wg-v6 + {{- end }} + {{- if .cni.type | eq "cilium" }} + ip link del cilium_host + ip link del cilium_vxlan + {{- end }} + {{- if .cni.type | eq "calico" }} + ip -br link show | grep cali[a-f0-9]* | awk -F @ '{print $1}' | xargs -r -t -n 1 ip link del + {{- end }} + ip netns show 2>/dev/null | grep cni- | awk '{print $1}' | xargs -r -t -n 1 ip netns del + +- name: Delete net.d + command: | + rm -rf /etc/cni/net.d/ + rm -rf /var/lib/cni/ + {{- if .cni.type | eq "calico" }} + rm -rf /usr/local/bin/calicoctl + {{- end }} + +- name: Delete arp by kube-vip + when: eq .kubernetes.control_plane_endpoint.type "kube_vip" + command: | + ip neigh show | grep {{ .kubernetes.control_plane_endpoint.kube_vip.address }} | awk '{print $1 " dev " $3}' | xargs -r -L1 ip neigh delete + \ No newline at end of file diff --git a/pkg/executor/playbook_executor.go b/pkg/executor/playbook_executor.go index 8cc6e948..a27ff46f 100644 --- a/pkg/executor/playbook_executor.go +++ b/pkg/executor/playbook_executor.go @@ -69,16 +69,16 @@ func (e playbookExecutor) Exec(ctx context.Context) (retErr error) { defer e.syncStatus(ctx, retErr) fmt.Fprint(e.logOutput, ` - _ __ _ _ __ - | | / / | | | | / / - | |/ / _ _| |__ ___| |/ / ___ _ _ - | \| | | | '_ \ / _ \ \ / _ \ | | | - | |\ \ |_| | |_) | __/ |\ \ __/ |_| | - \_| \_/\__,_|_.__/ \___\_| \_/\___|\__, | - __/ | - |___/ - - `) + _ __ _ _ __ +| | / / | | | | / / +| |/ / _ _| |__ ___| |/ / ___ _ _ +| \| | | | '_ \ / _ \ \ / _ \ | | | +| |\ \ |_| | |_) | __/ |\ \ __/ |_| | +\_| \_/\__,_|_.__/ \___\_| \_/\___|\__, | + __/ | + |___/ + +`) fmt.Fprintf(e.logOutput, "%s [Playbook %s] start\n", time.Now().Format(time.TimeOnly+" MST"), ctrlclient.ObjectKeyFromObject(e.playbook)) klog.V(5).InfoS("deal project", "playbook", ctrlclient.ObjectKeyFromObject(e.playbook)) pj, err := project.New(ctx, *e.playbook, true)