Skip to content

Commit

Permalink
better calico resource cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Nov 26, 2024
1 parent 3c77503 commit 6eab432
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion addons/kube-ovn/enable
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import socket
import subprocess
import sys
import re
import time
from pathlib import Path
import shutil

Expand Down Expand Up @@ -73,7 +74,24 @@ Error: kube-ovn requires ha-cluster to be enabled. Please enable with:
click.echo("Remove Calico CNI")
subprocess.run([KUBECTL, "delete", "-f", cni_yaml])
shutil.move(cni_yaml, SNAP_DATA / "args" / "cni-network" / "cni.yaml.backup")

print("Cleaning up Calico resources...")
while True:
result = subprocess.run(
[KUBECTL, "get", "all", "-A", "--no-headers"],
stdout=subprocess.PIPE,
text=True,
)
pods = result.stdout.splitlines()
calico_resources = [pod for pod in pods if "calico" in pod]

if not calico_resources:
print("All Calico resources have been cleaned up.")
break
else:
print(f"Still cleaning up {len(calico_resources)} Calico resources(s)...")
time.sleep(5)

# Run kube-ovn install script
click.echo("Run kube-ovn install script")
subprocess.check_call(["/bin/bash", DIR / "install.sh"])

Expand Down

0 comments on commit 6eab432

Please sign in to comment.