prole/etc/render_manifest.py
chrisfu f47c18fef7 feat(infrastructure): enhance k3s automation and OpenTofu integration
- Infrastructure:
    - Updated k3s Ansible role with mountpoint preflight checks and better permission management.
    - Automated deployment of prole configuration and port-forwarding scripts to cluster hosts.
    - Added systemd service for managing port forwards on k3s nodes.
    - Added prole-installer service account token automation.
- K8s Manifests:
    - Renamed and added Persistent Volumes in iscsi-pvs.yaml (including OpenBao support).
    - Updated StatefulSets for garage and openbao.
    - Migrated prole-db to CloudNativePG-based configuration.
    - Added comprehensive OpenTofu manifests for cluster deployment.
- Configuration:
    - Added cluster-specific configurations (k3d, k3s-hosts).
    - Added PostgreSQL configuration templates.
    - Updated .gitignore to track the conf/ directory.
- Tools:
    - Updated install.py and port-forwarding scripts.
    - Added render_manifest.py for manifest generation.
2026-02-07 22:53:18 -08:00

91 lines
2.4 KiB
Python

#!/usr/bin/env python3
import os
import sys
from pathlib import Path
def _strip_blocks(text: str) -> str:
lines = text.splitlines()
out = []
skip_block = False
skip_indent = 0
i = 0
while i < len(lines):
line = lines[i]
stripped = line.lstrip()
if skip_block:
if not stripped:
i += 1
continue
indent = len(line) - len(stripped)
if indent > skip_indent:
i += 1
continue
skip_block = False
skip_indent = 0
continue
if stripped.startswith("affinity:"):
block_indent = len(line) - len(stripped)
block_lines = [line]
j = i + 1
while j < len(lines):
next_line = lines[j]
next_stripped = next_line.lstrip()
if not next_stripped:
block_lines.append(next_line)
j += 1
continue
next_indent = len(next_line) - len(next_stripped)
if next_indent <= block_indent:
break
block_lines.append(next_line)
j += 1
if any("kubernetes.io/hostname" in bl for bl in block_lines):
i = j
continue
out.extend(block_lines)
i = j
continue
if stripped.startswith("nodeSelector:"):
skip_block = True
skip_indent = len(line) - len(stripped)
i += 1
continue
if stripped.startswith("storageClassName:") and "prole-iscsi" in stripped:
i += 1
continue
out.append(line)
i += 1
tail = "\n" if text.endswith("\n") else ""
return "\n".join(out) + tail
def main() -> int:
if len(sys.argv) < 2:
print("Usage: render_manifest.py <manifest.yaml>", file=sys.stderr)
return 2
path = Path(sys.argv[1]).expanduser()
if not path.exists():
print(f"ERROR: manifest not found: {path}", file=sys.stderr)
return 1
text = path.read_text()
mode = os.environ.get("PROLE_MODE", "").strip().lower()
if mode != "k3d":
sys.stdout.write(text)
return 0
sys.stdout.write(_strip_blocks(text))
return 0
if __name__ == "__main__":
raise SystemExit(main())