mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 11:03:59 +00:00
79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import configparser
|
|
import importlib.util
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
|
|
def _load_render_supabase_module():
|
|
repo_root = Path(__file__).resolve().parents[1]
|
|
mod_path = repo_root / "supabase" / "helm" / "render_supabase.py"
|
|
spec = importlib.util.spec_from_file_location("knoe_render_supabase", mod_path)
|
|
assert spec is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
assert spec.loader is not None
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def _minimal_cfg() -> configparser.ConfigParser:
|
|
cfg = configparser.ConfigParser(interpolation=None)
|
|
cfg.read_string(
|
|
"""
|
|
[Global]
|
|
NAMESPACE = knoe
|
|
STORAGE_BACKEND = local
|
|
"""
|
|
)
|
|
return cfg
|
|
|
|
|
|
def test_supabase_overlay_pins_components_to_merlin_in_k3s_mode(monkeypatch, tmp_path):
|
|
m = _load_render_supabase_module()
|
|
cfg = _minimal_cfg()
|
|
args = SimpleNamespace(output_dir=str(tmp_path), config=str(tmp_path / "knoe.cfg"))
|
|
|
|
monkeypatch.setenv("DB_PASSWORD", "test-db-password")
|
|
monkeypatch.setenv("KNOE_MODE", "k3s")
|
|
monkeypatch.setenv("SUPABASE_PRIMARY_NODE", "merlin.knoe.org")
|
|
|
|
overlay, _meta = m._build_overlay(cfg, args)
|
|
deployment = overlay["deployment"]
|
|
|
|
for component in (
|
|
"analytics",
|
|
"auth",
|
|
"imgproxy",
|
|
"kong",
|
|
"meta",
|
|
"minio",
|
|
"realtime",
|
|
"rest",
|
|
"storage",
|
|
"studio",
|
|
):
|
|
assert component in deployment
|
|
assert (
|
|
deployment[component]["nodeSelector"]["kubernetes.io/hostname"]
|
|
== "merlin.knoe.org"
|
|
)
|
|
|
|
|
|
def test_supabase_overlay_does_not_pin_components_outside_k3s(monkeypatch, tmp_path):
|
|
m = _load_render_supabase_module()
|
|
cfg = _minimal_cfg()
|
|
args = SimpleNamespace(output_dir=str(tmp_path), config=str(tmp_path / "knoe.cfg"))
|
|
|
|
monkeypatch.setenv("DB_PASSWORD", "test-db-password")
|
|
monkeypatch.setenv("KNOE_MODE", "k3d")
|
|
monkeypatch.delenv("SUPABASE_PRIMARY_NODE", raising=False)
|
|
|
|
overlay, _meta = m._build_overlay(cfg, args)
|
|
deployment = overlay["deployment"]
|
|
|
|
# The renderer only injects hostname pinning in k3s mode.
|
|
assert "nodeSelector" not in deployment.get("auth", {})
|
|
assert "nodeSelector" not in deployment.get("analytics", {})
|
|
assert "nodeSelector" not in deployment.get("db", {})
|