38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import paramiko
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
|
|
|
with open(r'c:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\homelab-gitops-repo\manifests\aerodrome\prometheus\prometheus.yaml', 'r', encoding='utf-8') as f:
|
|
text = f.read()
|
|
|
|
# Extract just the ConfigMap section
|
|
# It starts with "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: prometheus-config" and ends with "---"
|
|
parts = text.split("---")
|
|
cm_part = None
|
|
for p in parts:
|
|
if "name: prometheus-config" in p:
|
|
cm_part = p
|
|
break
|
|
|
|
if cm_part:
|
|
print("Found prometheus-config ConfigMap! Size:", len(cm_part))
|
|
stdin, stdout, stderr = c.exec_command("cat > /tmp/prom_cm_clean.yaml")
|
|
stdin.write(cm_part)
|
|
stdin.close()
|
|
stdout.channel.recv_exit_status()
|
|
|
|
_, o, e = c.exec_command("kubectl apply -f /tmp/prom_cm_clean.yaml")
|
|
print("Apply result:\n", o.read().decode().strip())
|
|
err = e.read().decode().strip()
|
|
if err:
|
|
print("Apply err:\n", err)
|
|
|
|
# Reload prometheus via lifecycle endpoint
|
|
_, o, _ = c.exec_command("kubectl exec deploy/prometheus -- wget -qO- --post-action='' http://localhost:9090/-/reload")
|
|
print("Reload endpoint output:", o.read().decode().strip())
|
|
|
|
c.close()
|
|
|