From a07cecb6f3c0ca2d12da234095831d051d16cc51 Mon Sep 17 00:00:00 2001 From: Snarf Date: Sat, 7 Nov 2026 12:42:44 -0500 Subject: [PATCH] feat: add script to apply DNS manifests via SSH and kubectl --- homelab-gitops-repo | 2 +- scripts/apply_dns_updates.py | 59 +++++++++++++++++------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/homelab-gitops-repo b/homelab-gitops-repo index 0d23a1e..2bd6604 160000 --- a/homelab-gitops-repo +++ b/homelab-gitops-repo @@ -1 +1 @@ -Subproject commit 0d23a1eb2dd55635a27a1f2f9d91d79deff08742 +Subproject commit 2bd66045c399fc9f41df81c0d095b25b105921b2 diff --git a/scripts/apply_dns_updates.py b/scripts/apply_dns_updates.py index 0083c32..1d03eaa 100644 --- a/scripts/apply_dns_updates.py +++ b/scripts/apply_dns_updates.py @@ -1,38 +1,35 @@ import paramiko -import sys -import time -sys.stdout.reconfigure(encoding='utf-8') +SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" -key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet" - -def apply_to_cluster(ip, name, manifest_path): - print(f"Connecting to {name} ({ip})...") - with open(manifest_path, "r", encoding="utf-8") as f: - content = f.read() - - c = paramiko.SSHClient() - c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - c.connect(ip, username="root", key_filename=key_path, timeout=10) +def apply_manifest(host, local_file): + with open(local_file, "r") as f: + manifest_content = f.read() - stdin, stdout, stderr = c.exec_command("k3s kubectl apply -f -") - stdin.write(content) - stdin.channel.shutdown_write() + client = paramiko.SSHClient() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + client.connect(host, username="root", key_filename=SSH_KEY, timeout=10) - out = stdout.read().decode('utf-8') - err = stderr.read().decode('utf-8') - print(f"[{name}] Apply Output:\n{out}") - if err.strip(): - print(f"[{name}] Apply Error:\n{err}") - c.close() - -aero_path = r"c:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\homelab-gitops-repo\manifests\aerodrome\dns\dns-stack.yaml" -space_path = r"c:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\homelab-gitops-repo\manifests\spaceport\dns\dns-stack.yaml" - -apply_to_cluster("140.44.4.11", "Aerodrome", aero_path) -time.sleep(2) -apply_to_cluster("140.44.4.41", "Spaceport", space_path) -print("Finished applying manifests to both clusters!") - + # Write to remote /tmp/dns-stack.yaml and kubectl apply + sftp = client.open_sftp() + with sftp.open("/tmp/dns-stack.yaml", "w") as f: + f.write(manifest_content) + sftp.close() + + stdin, stdout, stderr = client.exec_command("k3s kubectl apply -f /tmp/dns-stack.yaml") + out = stdout.read().decode() + err = stderr.read().decode() + client.close() + return out, err +print("=== Applying to Aerodrome (140.44.4.11) ===") +out, err = apply_manifest("140.44.4.11", r"homelab-gitops-repo\manifests\aerodrome\dns\dns-stack.yaml") +print(out) +if err: + print("Stderr:", err) +print("=== Applying to Spaceport (140.44.4.41) ===") +out, err = apply_manifest("140.44.4.41", r"homelab-gitops-repo\manifests\spaceport\dns\dns-stack.yaml") +print(out) +if err: + print("Stderr:", err)