workaround
All checks were successful
cloudmon GitOps Deploy / build-and-deploy (push) Successful in 22s

This commit is contained in:
Bast 2026-11-02 12:24:53 -06:00
parent 9e616b1a65
commit 576448a486
2 changed files with 2 additions and 8 deletions

View file

@ -12,7 +12,8 @@ class ClusterGraphDataView(View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
try: try:
repo_name = request.GET.get("repo", "boday_tf") repo_name = request.GET.get("repo", "boday_tf")
consul_url = f"http://consul:8500/v1/kv/terraform/states/{repo_name}" # DIE RETTUNG: Nutzt das Docker-Host-Gateway, damit der K3s-Pod Consul auf dem Host erreicht!
consul_url = f"http://172.17.0{repo_name}"
response = requests.get(consul_url, timeout=5) response = requests.get(consul_url, timeout=5)
if response.status_code == 404: if response.status_code == 404:
@ -21,7 +22,6 @@ class ClusterGraphDataView(View):
consul_data = response.json() consul_data = response.json()
raw_value = None raw_value = None
# DIE ABSOLUTE RETTUNG: Greift sicher auf das erste Element der Consul-Liste zu!
if isinstance(consul_data, list) and len(consul_data) > 0: if isinstance(consul_data, list) and len(consul_data) > 0:
first_item = consul_data[0] first_item = consul_data[0]
if isinstance(first_item, dict): if isinstance(first_item, dict):
@ -32,7 +32,6 @@ class ClusterGraphDataView(View):
if not raw_value: if not raw_value:
return JsonResponse({"name": f"Key '{repo_name}' geladen, aber Value ist leer.", "type": "Root", "children": []}) return JsonResponse({"name": f"Key '{repo_name}' geladen, aber Value ist leer.", "type": "Root", "children": []})
# Base64 decodieren
state_json = json.loads(base64.b64decode(raw_value).decode('utf-8')) state_json = json.loads(base64.b64decode(raw_value).decode('utf-8'))
resources = state_json.get("resources", []) resources = state_json.get("resources", [])
@ -40,7 +39,6 @@ class ClusterGraphDataView(View):
services = {} services = {}
deployments = {} deployments = {}
# Extrahiere Ressourcen aus dem geladenen JSON
for res in resources: for res in resources:
res_type = res.get("type") res_type = res.get("type")
res_name = res.get("name") res_name = res.get("name")
@ -64,7 +62,6 @@ class ClusterGraphDataView(View):
rules = spec[0].get("rule", []) if isinstance(spec, list) and len(spec) > 0 else spec.get("rule", []) if hasattr(spec, "get") else [] rules = spec[0].get("rule", []) if isinstance(spec, list) and len(spec) > 0 else spec.get("rule", []) if hasattr(spec, "get") else []
ingresses.append({"name": actual_name, "rules": rules}) ingresses.append({"name": actual_name, "rules": rules})
elif res_type in ["kubernetes_service", "kubernetes_service_v1", "helm_release"]: elif res_type in ["kubernetes_service", "kubernetes_service_v1", "helm_release"]:
# Da boday_tf aktuell nur ein helm_release deklariert, mappen wir es als Service/Knoten ein!
services[actual_name] = {"name": actual_name, "type": "Helm-Chart" if res_type == "helm_release" else "Service"} services[actual_name] = {"name": actual_name, "type": "Helm-Chart" if res_type == "helm_release" else "Service"}
elif res_type in ["kubernetes_deployment", "kubernetes_deployment_v1"]: elif res_type in ["kubernetes_deployment", "kubernetes_deployment_v1"]:
deployments[actual_name] = {"name": actual_name, "type": "Deployment"} deployments[actual_name] = {"name": actual_name, "type": "Deployment"}
@ -75,13 +72,10 @@ class ClusterGraphDataView(View):
"children": [] "children": []
} }
# Falls Ingresses da sind, Baum bauen
for ing in ingresses: for ing in ingresses:
ing_node = {"name": ing["name"], "type": "Ingress", "children": []} ing_node = {"name": ing["name"], "type": "Ingress", "children": []}
root_node["children"].append(ing_node) root_node["children"].append(ing_node)
# Falls keine Ingress-Objekte direkt im State liegen (wie bei boday_tf rein via Helm),
# hängen wir alle gefundenen Haupt-Komponenten/Charts direkt an die Wurzel!
if not root_node["children"]: if not root_node["children"]:
for s_name, s_obj in services.items(): for s_name, s_obj in services.items():
root_node["children"].append({"name": s_name, "type": s_obj["type"], "children": []}) root_node["children"].append({"name": s_name, "type": s_obj["type"], "children": []})

0
showlogs.sh Normal file → Executable file
View file