Created
December 6, 2022 11:14
-
-
Save james-hinton/12bf640f016c592cc64662d06972f286 to your computer and use it in GitHub Desktop.
Download all helm values from Kubernetes cluster
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
# Script to download all helm values from helm-enabled kubernetes cluster | |
# If on remote cluster download this using scp <USER>@<IP>:<PATH>/helm-values.zip helm-values.zip | |
import subprocess | |
import zipfile | |
import os | |
def get_all_helm_values(): | |
helm_list = subprocess.check_output(["helm", "list", "--all-namespaces"]) | |
helm_list = helm_list.decode("utf-8") | |
helm_list = helm_list.split("\n") | |
helm_values = {} | |
for line in helm_list: | |
if line.startswith("NAME"): | |
continue | |
line = line.split() | |
if len(line) == 0: | |
continue | |
name = line[0] | |
namespace = line[1] | |
# Now get the helm values | |
helm_values[name] = subprocess.check_output( | |
["helm", "get", "values", name, "-n", namespace] | |
) | |
helm_values[name] = helm_values[name].decode("utf-8") | |
# Save the values to a file for later use with namespace-name as the filename | |
with open(f"{namespace}-{name}.yaml", "w") as f: | |
f.write(helm_values[name]) | |
with zipfile.ZipFile("helm-values.zip", "w") as zip: | |
# Loop through all the files in the directory and if its a yaml add to zip | |
for file in os.listdir(): | |
if file.endswith(".yaml"): | |
zip.write(file) | |
get_all_helm_values() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment