From 5c33bbcbe81fbdd4aa784bb5a42dd3058cec0578 Mon Sep 17 00:00:00 2001 From: Philippe Merle Date: Thu, 31 Jul 2025 08:49:27 +0300 Subject: [PATCH] Generate more precise paths in messages outputed by add_containers_env_value_from_and_env_from() --- bin/kube-diagrams | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/kube-diagrams b/bin/kube-diagrams index 2b6c319..e57a094 100755 --- a/bin/kube-diagrams +++ b/bin/kube-diagrams @@ -536,8 +536,10 @@ class EdgesContext(list): containers = query_path(self.resource, path) if containers is None: return + target_resources = set() def process_optional_resource( + path, context, kind, name_path, @@ -549,7 +551,7 @@ class EdgesContext(list): if query_path(context, optional_path) is True: if resource_id not in resources: self.info( - path, + f"{path}.{name_path}", f"{kind} '{resource_name}' undefined but optional" ) return @@ -557,17 +559,19 @@ class EdgesContext(list): resource_id ) - for container in containers: + for cidx, container in enumerate(containers): container_env = query_path(container, "env") if isinstance(container_env, list): - for env in container_env: + for eidx, env in enumerate(container_env): process_optional_resource( + f"{path}[{cidx}].env[{eidx}]", env, "ConfigMap", "valueFrom.configMapKeyRef.name", "valueFrom.configMapKeyRef.optional" ) process_optional_resource( + f"{path}[{cidx}].env[{eidx}]", env, "Secret", "valueFrom.secretKeyRef.name", @@ -575,19 +579,22 @@ class EdgesContext(list): ) container_env_from = query_path(container, "envFrom") if isinstance(container_env_from, list): - for env_from in container_env_from: + for eidx, env_from in enumerate(container_env_from): process_optional_resource( + f"{path}[{cidx}].envFrom[{eidx}]", env_from, "ConfigMap", "configMapRef.name", "configMapRef.optional" ) process_optional_resource( + f"{path}[{cidx}].envFrom[{eidx}]", env_from, "Secret", "secretRef.name", "secretRef.optional" ) + for target_resource in target_resources: self.add_edge_to_rid(path, target_resource, "REFERENCE")