diff --git a/scripts/check_apis.py b/scripts/check_apis.py new file mode 100644 index 0000000..3146e26 --- /dev/null +++ b/scripts/check_apis.py @@ -0,0 +1,25 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +test_cmd = """ +cd /tmp/rancher-test +KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm template rancher ./rancher --namespace cattle-system --set hostname=aerodrome.snarfnet.net --set ingress.tls.source=secret | grep "apiVersion:" | sort | uniq -c +""" + +stdin, stdout, stderr = client.exec_command(test_cmd) +out = stdout.read().decode('utf-8') +err = stderr.read().decode('utf-8') +print("APIs used:") +print(out) +if err: + print("STDERR:", err) + +client.close() diff --git a/scripts/check_chart_kubeversions.py b/scripts/check_chart_kubeversions.py new file mode 100644 index 0000000..660ebcb --- /dev/null +++ b/scripts/check_chart_kubeversions.py @@ -0,0 +1,21 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +versions = [ + "2.7.10", "2.8.5", "2.9.3", "2.10.3", "2.11.3", "2.12.3", "2.13.3", "2.14.3", "2.15.3" +] + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +for ver in versions: + stdin, stdout, stderr = client.exec_command(f"KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm show chart rancher-stable/rancher --version {ver} | grep kubeVersion") + out = stdout.read().decode('utf-8').strip() + print(f"Rancher {ver}: {out}") + +client.close() diff --git a/scripts/check_psp.py b/scripts/check_psp.py new file mode 100644 index 0000000..bfbd431 --- /dev/null +++ b/scripts/check_psp.py @@ -0,0 +1,20 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +test_cmd = """ +cd /tmp/rancher-test +KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm template rancher ./rancher --namespace cattle-system --set hostname=aerodrome.snarfnet.net --set ingress.tls.source=secret | grep -B 2 -A 8 "policy/v1beta1" +""" + +stdin, stdout, stderr = client.exec_command(test_cmd) +out = stdout.read().decode('utf-8') +print(out) +client.close() diff --git a/scripts/test_dryrun_215.py b/scripts/test_dryrun_215.py new file mode 100644 index 0000000..420f9cf --- /dev/null +++ b/scripts/test_dryrun_215.py @@ -0,0 +1,23 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +test_cmd = ( + "KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm upgrade rancher rancher-stable/rancher " + "--namespace cattle-system --version 2.15.3 --reuse-values --dry-run" +) + +stdin, stdout, stderr = client.exec_command(test_cmd) +out = stdout.read().decode('utf-8') +err = stderr.read().decode('utf-8') +print("STDOUT:", out[:500]) +print("STDERR:", err) + +client.close() diff --git a/scripts/test_dryrun_285.py b/scripts/test_dryrun_285.py new file mode 100644 index 0000000..78ebf76 --- /dev/null +++ b/scripts/test_dryrun_285.py @@ -0,0 +1,26 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +test_cmd = """ +rm -rf /tmp/rancher-285 && mkdir -p /tmp/rancher-285 && cd /tmp/rancher-285 +KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm pull rancher-stable/rancher --version 2.8.5 --untar +sed -i '/kubeVersion:/d' rancher/Chart.yaml +KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm upgrade rancher ./rancher --namespace cattle-system \ + --set hostname=aerodrome.snarfnet.net --set ingress.tls.source=secret --dry-run +""" + +stdin, stdout, stderr = client.exec_command(test_cmd) +out = stdout.read().decode('utf-8') +err = stderr.read().decode('utf-8') +print("STDOUT:", out[:400]) +print("STDERR:", err) + +client.close() diff --git a/scripts/test_dryrun_kubeversion.py b/scripts/test_dryrun_kubeversion.py new file mode 100644 index 0000000..206747f --- /dev/null +++ b/scripts/test_dryrun_kubeversion.py @@ -0,0 +1,23 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +test_cmd = ( + "KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm upgrade rancher rancher-stable/rancher " + "--namespace cattle-system --version 2.7.10 --reuse-values --dry-run --kube-version 1.26.0" +) + +stdin, stdout, stderr = client.exec_command(test_cmd) +out = stdout.read().decode('utf-8') +err = stderr.read().decode('utf-8') +print("STDOUT:", out[:300]) +print("STDERR:", err) + +client.close() diff --git a/scripts/test_dryrun_resetvalues.py b/scripts/test_dryrun_resetvalues.py new file mode 100644 index 0000000..9c1442d --- /dev/null +++ b/scripts/test_dryrun_resetvalues.py @@ -0,0 +1,24 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +test_cmd = ( + "KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm upgrade rancher rancher-stable/rancher " + "--namespace cattle-system --version 2.15.3 " + "--reset-values --set hostname=aerodrome.snarfnet.net --set ingress.tls.source=secret --dry-run" +) + +stdin, stdout, stderr = client.exec_command(test_cmd) +out = stdout.read().decode('utf-8') +err = stderr.read().decode('utf-8') +print("STDOUT:", out[:500]) +print("STDERR:", err) + +client.close() diff --git a/scripts/test_patch_chart.py b/scripts/test_patch_chart.py new file mode 100644 index 0000000..193c078 --- /dev/null +++ b/scripts/test_patch_chart.py @@ -0,0 +1,25 @@ +import paramiko +import sys + +sys.stdout.reconfigure(encoding='utf-8') + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" + +client.connect("140.44.4.11", username="root", key_filename=key_path, timeout=15) + +test_cmd = """ +rm -rf /tmp/rancher-test && mkdir -p /tmp/rancher-test && cd /tmp/rancher-test +KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm pull rancher-stable/rancher --version 2.7.10 --untar +sed -i '/kubeVersion:/d' rancher/Chart.yaml +KUBECONFIG=/etc/rancher/k3s/k3s.yaml helm upgrade rancher ./rancher --namespace cattle-system --reuse-values --dry-run +""" + +stdin, stdout, stderr = client.exec_command(test_cmd) +out = stdout.read().decode('utf-8') +err = stderr.read().decode('utf-8') +print("STDOUT:", out[:400]) +print("STDERR:", err) + +client.close() diff --git a/scripts/upgrade_rancher_step.py b/scripts/upgrade_rancher_step.py new file mode 100644 index 0000000..2cf3aee --- /dev/null +++ b/scripts/upgrade_rancher_step.py @@ -0,0 +1,67 @@ +import paramiko +import sys +import time + +sys.stdout.reconfigure(encoding='utf-8') + +target_version = sys.argv[1] if len(sys.argv) > 1 else "2.7.10" +key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" +master_ip = "140.44.4.11" + +print(f"==================================================") +print(f"Starting Rancher upgrade to version {target_version}") +print(f"==================================================") + +client = paramiko.SSHClient() +client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + +def run_cmd(cmd, check=True): + print(f"\n>>> Running: {cmd}") + stdin, stdout, stderr = client.exec_command(f"KUBECONFIG=/etc/rancher/k3s/k3s.yaml {cmd}") + out = stdout.read().decode('utf-8') + err = stderr.read().decode('utf-8') + exit_status = stdout.channel.recv_exit_status() + if out: + print(out.strip()) + if err: + print(f"STDERR: {err.strip()}") + if check and exit_status != 0: + raise RuntimeError(f"Command failed with exit code {exit_status}") + return out, err, exit_status + +try: + client.connect(master_ip, username="root", key_filename=key_path, timeout=15) + + # 1. Take snapshot + snap_name = f"pre-rancher-{target_version}-{int(time.time())}" + print(f"\n--- Taking etcd snapshot: {snap_name} ---") + run_cmd(f"k3s etcd-snapshot save --name {snap_name}") + + # 2. Perform Helm upgrade + print(f"\n--- Upgrading Rancher chart to {target_version} ---") + upgrade_cmd = ( + f"helm upgrade rancher rancher-stable/rancher " + f"--namespace cattle-system " + f"--version {target_version} " + f"--reuse-values" + ) + run_cmd(upgrade_cmd) + + # 3. Wait for deployment rollout + print("\n--- Waiting for deployment/rancher rollout status ---") + run_cmd("kubectl -n cattle-system rollout status deployment/rancher --timeout=360s") + + # 4. Check cattle-system pods + print("\n--- Checking cattle-system pods ---") + run_cmd("kubectl -n cattle-system get pods -o wide") + + # 5. Check ingress / HTTP response + print("\n--- Checking Rancher endpoint ---") + run_cmd("curl -k -I -s https://aerodrome.snarfnet.net | head -n 10", check=False) + + client.close() + print(f"\nSUCCESS: Rancher upgraded to {target_version} successfully!") + +except Exception as ex: + print(f"\nFAILED: {ex}") + sys.exit(1)