feat: add various infrastructure check and automation scripts

This commit is contained in:
2026-11-15 17:17:41 -05:00
parent 336b7759d0
commit b301aa3ece
232 changed files with 8274 additions and 298 deletions

37
scripts/test_salvage.py Normal file
View File

@@ -0,0 +1,37 @@
import paramiko
import json
import time
SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("140.44.4.90", username="rancher", key_filename=SSH_KEY, timeout=10)
def k8s(cmd):
full_cmd = f"echo Katzir476! | sudo -S sh -c 'export KUBECONFIG=/etc/rancher/rke2/rke2.yaml; PATH=$PATH:/var/lib/rancher/rke2/bin; {cmd}'"
_, o, e = c.exec_command(full_cmd)
return o.read().decode().strip(), e.read().decode().strip()
# Check replicas for pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495
print("Replicas for pvc-4da99c48:")
out, _ = k8s("kubectl get replicas.longhorn.io -n longhorn-system -l longhornvolume=pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495 -o custom-columns=NAME:.metadata.name,FAILED:.spec.failedAt,SALVAGE:.spec.salvageRequested,NODE:.spec.nodeID")
print(out)
# Let's test patching salvageRequested: true on replicas of pvc-4da99c48
print("\nPatching replicas of pvc-4da99c48 to salvageRequested=true...")
patch_cmd = """
for r in $(kubectl get replicas.longhorn.io -n longhorn-system -l longhornvolume=pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495 -o jsonpath='{.items[*].metadata.name}'); do
kubectl patch replica.longhorn.io $r -n longhorn-system --type merge -p '{"spec":{"salvageRequested":true}}'
done
"""
out, err = k8s(patch_cmd)
print("Patch result:", out, err)
time.sleep(3)
# Check volume status now
out, _ = k8s("kubectl get volume.longhorn.io pvc-4da99c48-f52e-4adf-9b4c-16e8878eb495 -n longhorn-system -o custom-columns=NAME:.metadata.name,STATE:.status.state,ROBUSTNESS:.status.robustness")
print("Volume status after patch:")
print(out)
c.close()