Created
January 31, 2023 06:49
-
-
Save IronCore864/ad21130aa796d407624805c5342201db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from concurrent import futures | |
def get_releases(namespace: str = "default"): | |
ret = subprocess.run( | |
["helm", "list", "-n", namespace, "-q"], | |
capture_output=True, | |
check=True, | |
) | |
return ret.stdout.decode().splitlines() | |
def helm_uninstall(release: str, namespace: str): | |
subprocess.run( | |
["helm", "uninstall", release, "--namespace", namespace], | |
capture_output=True, | |
check=True, | |
) | |
def uninstall_all_releases_in_ns(namespace: str): | |
releases = get_releases(namespace) | |
with futures.ThreadPoolExecutor(max_workers=5) as executor: | |
future_to_release = { | |
executor.submit(helm_uninstall, rel, namespace): rel for rel in releases | |
} | |
for f in futures.as_completed(future_to_release): | |
release = future_to_release[f] | |
print(f"release {release} uninstalled") | |
if __name__ == "__main__": | |
uninstall_all_releases_in_ns("default") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment