prole/tmp/sim_milestones_ns.py

66 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Simulate exactly what GitOpsMilestone.execute() does for namespace resolution."""
import sys
sys.path.insert(0, "/Users/chrisfu/dev/knoe")
import configparser
CFG = "/Users/chrisfu/dev/knoe/conf/service/knoe.cfg"
# Load config the same way the installer does
parser = configparser.ConfigParser(strict=False)
parser.read(CFG)
# Build state.inputs from [Inputs] section
inputs = dict(parser.items("Inputs")) if parser.has_section("Inputs") else {}
# Build config_data from all sections
config_data = {sec: dict(parser.items(sec)) for sec in parser.sections()}
print("=== state.inputs relevant keys ===")
for k, v in sorted(inputs.items()):
if "gitops" in k or "gitlab" in k or "namespace" in k:
print(f" {k!r} => {v!r}")
print("\n=== config_data[GitOps] ===")
for k, v in config_data.get("GitOps", {}).items():
print(f" {k!r} => {v!r}")
print("\n=== config_data[Global] GITLAB_NAMESPACE ===")
print(f" {config_data.get('Global', {}).get('gitlab_namespace', '<unset>')!r}")
print(f" {config_data.get('global', {}).get('gitlab_namespace', '<unset>')!r}")
# Simulate milestones.py provider detection (lines 945-957)
provider = (
str(inputs.get("gitops.git_provider", "") or "").strip().lower()
or str(
(config_data.get("Optional Features") or {}).get("GITOPS_PROVIDER", "") or ""
).strip().lower()
or "gitea"
)
is_gitlab = provider == "gitlab"
print(f"\n=== Provider: {provider!r} | is_gitlab={is_gitlab} ===")
# Simulate new namespace resolution (lines 965-977)
if is_gitlab:
ns = (
str(inputs.get("gitops.gitlab_namespace", "") or "").strip()
or str(
(config_data.get("Global") or config_data.get("global") or {}).get(
"gitlab_namespace", ""
)
or ""
).strip()
or "gitlab"
)
print(f"\n=== GITLAB ns resolved: {ns!r} ===")
if ns == "gitlab":
print(" ✓ CORRECT — will use 'gitlab' namespace")
else:
print(f" ✗ BUG — got {ns!r}, expected 'gitlab'")
else:
ns = (
inputs.get("gitops.namespace", "")
or "gitea"
).strip()
print(f"\n=== GITEA ns: {ns!r} (is_gitlab=False — BUG if expecting gitlab) ===")