Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(k8s): stop minting an edgeless second Module per kustomization
Martin Vogel2929afa60b1f
diff --git a/src/pipeline/pass_k8s.c b/src/pipeline/pass_k8s.cindex 4bc665309..aa09748ee 100644--- a/src/pipeline/pass_k8s.c+++ b/src/pipeline/pass_k8s.c@@ -1,14 +1,12 @@/*- * pass_k8s.c — Pipeline pass for Kubernetes manifest and Kustomize overlay processing.+ * pass_k8s.c — Pipeline pass for Kubernetes manifests, Helm charts and dependency manifests.*- * For each discovered YAML file:- * 1. Check if it is a kustomize overlay (kustomization.yaml / kustomization.yml)- * → emit a Module node and IMPORTS edges for each resources/bases/patches entry- * 2. Else if it is a generic k8s manifest (apiVersion: detected)- * → emit one Resource node per file (first document only — multi-document YAML is not yet- * supported)+ * For each discovered YAML file that is a generic k8s manifest (apiVersion: detected)+ * → emit one Resource node per file (first document only — multi-document YAML is not yet+ * supported). Kustomizations are not handled here: their entries are IMPORTS of the+ * file itself, resolved by the import resolver (resolve_kustomize_entry).*- * Depends on: pass_infrascan.c (cbm_is_kustomize_file, cbm_is_k8s_manifest, cbm_infra_qn),+ * Depends on: pass_infrascan.c (cbm_is_k8s_manifest, cbm_infra_qn),* extraction layer (cbm.h), graph_buffer, pipeline internals.*/#include "foundation/constants.h"@@ -86,59 +84,6 @@ static const char *k8s_basename(const char *path) {return p ? p + SKIP_ONE : path;}-/* ── Kustomize handler ───────────────────────────────────────────── */--/* `result` is the cached parallel-pass result or, for an uncached file, the- * re-extraction the preparation step made; the caller owns it. */-static void handle_kustomize(cbm_pipeline_ctx_t *ctx, const char *rel_path,- const CBMFileResult *result) {- /* Emit Module node for this kustomize overlay file */- char *mod_qn = cbm_infra_qn(ctx->project_name, rel_path, "kustomize", NULL);- if (!mod_qn) {- return;- }-- int64_t mod_id = cbm_gbuf_upsert_node(ctx->gbuf, "Module", k8s_basename(rel_path), mod_qn,- rel_path, SKIP_ONE, 0, "{\"source\":\"kustomize\"}");- free(mod_qn);-- if (mod_id <= 0) {- return;- }-- /* With an extraction result, emit IMPORTS edges for- * resources/bases/patches/components entries */- int import_count = 0;- const CBMFileResult *res = result;-- if (res) {- for (int j = 0; j < res->imports.count; j++) {- CBMImport *imp = &res->imports.items[j];- if (!imp->module_path) {- continue;- }-- /* Compute target file QN */- char *target_qn =- cbm_pipeline_fqn_compute(ctx->project_name, imp->module_path, "__file__");- if (!target_qn) {- continue;- }-- const cbm_gbuf_node_t *target = cbm_gbuf_find_by_qn(ctx->gbuf, target_qn);- free(target_qn);-- if (target) {- cbm_gbuf_insert_edge(ctx->gbuf, mod_id, target->id, "IMPORTS",- "{\"via\":\"kustomize\"}");- import_count++;- }- }- }-- cbm_log_info("pass.k8s.kustomize", "file", rel_path, "imports", itoa_k8s(import_count));-}-/* ── K8s cross-manifest label-selector matching ──────────────────────* A Service routes traffic to the workload Pods whose labels match the* Service's spec.selector. We record, per manifest, the Resource node id plus@@ -623,13 +568,13 @@ static void handle_dep_manifest(cbm_pipeline_ctx_t *ctx, const char *rel_path, c* the sequential loop did. Sequentially the pass re-read and re-parsed every* YAML manifest on one thread -- 1.1 s of the Go corpus (6,275 manifests;* profile + waste sanitizer, 2026-09-17). */-typedef enum { K8S_SKIP = 0, K8S_DEP, K8S_KUSTOMIZE, K8S_HELM, K8S_MANIFEST } k8s_kind_t;+typedef enum { K8S_SKIP = 0, K8S_DEP, K8S_HELM, K8S_MANIFEST } k8s_kind_t;typedef struct {k8s_kind_t kind;char *source; /* DEP, HELM, MANIFEST */int src_len;- CBMFileResult *res; /* MANIFEST, or KUSTOMIZE without a cached result */+ CBMFileResult *res; /* MANIFEST */} k8s_prep_t;typedef struct {@@ -653,19 +598,6 @@ static void k8s_prep_file(const k8s_prep_job_t *job, int i, k8s_prep_t *out) {if (is_gomod_file(base) || lang == CBM_LANG_GOMOD || is_requirements_file(base)) {out->source = k8s_read_file(path, &out->src_len);out->kind = out->source ? K8S_DEP : K8S_SKIP;- } else if (cbm_is_kustomize_file(base)) {- out->kind = K8S_KUSTOMIZE;- bool cached = ctx->result_cache && ctx->result_cache[i];- if (!cached) {- /* Fall back to re-extraction */- int src_len = 0;- char *source = k8s_read_file(path, &src_len);- if (source) {- out->res = cbm_extract_file(source, src_len, CBM_LANG_KUSTOMIZE, ctx->project_name,- rel, CBM_EXTRACT_BUDGET, NULL, NULL);- cbm_free(CBM_MEM_CLASS_OTHER, source);- }- }} else if (lang == CBM_LANG_YAML || lang == CBM_LANG_K8S) {/* Read source once to classify (and reuse for uncached extraction). */out->source = k8s_read_file(path, &out->src_len);@@ -711,7 +643,6 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,cbm_init();- int kustomize_count = 0;int manifest_count = 0;int helm_count = 0;@@ -750,17 +681,11 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,if (!cancelled) {const char *rel = files[i].rel_path;const char *base = k8s_basename(rel);- CBMFileResult *cached =- (ctx->result_cache && ctx->result_cache[i]) ? ctx->result_cache[i] : NULL;switch (p->kind) {case K8S_DEP:handle_dep_manifest(ctx, rel, p->source,is_requirements_file(base) ? "pypi" : "gomod");break;- case K8S_KUSTOMIZE:- handle_kustomize(ctx, rel, cached ? cached : p->res);- kustomize_count++;- break;case K8S_HELM:handle_helm_chart(ctx, rel, p->source);helm_count++;@@ -796,8 +721,7 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,k8s_link_selectors(ctx, &recs);cbm_free(CBM_MEM_CLASS_OTHER, recs.items);- cbm_log_info("pass.done", "pass", "k8s", "kustomize", itoa_k8s(kustomize_count), "manifests",- itoa_k8s(manifest_count));+ cbm_log_info("pass.done", "pass", "k8s", "manifests", itoa_k8s(manifest_count));(void)helm_count;return 0;}diff --git a/tests/test_grammar_probe_f.c b/tests/test_grammar_probe_f.cindex e5e5314c8..c619e68d7 100644--- a/tests/test_grammar_probe_f.c+++ b/tests/test_grammar_probe_f.c@@ -564,6 +564,20 @@ TEST(probe_kustomize_remote_base_names_no_symbol) {PASS();}+/* The k8s pass minted a second, edgeless Module per kustomization next to+ * the file's own Module: its import lookup took entries as repo-root paths+ * and resolved none of them in any of 17 infra repositories. */+TEST(probe_kustomize_single_module) {+ GpfMetrics m = gpf_metrics("kustomization.yaml",+ "apiVersion: kustomize.config.k8s.io/v1beta1\n"+ "kind: Kustomization\n"+ "resources:\n"+ " - deploy.yaml\n");+ ASSERT_TRUE(m.ok);+ ASSERT_EQ(m.modules, 1);+ PASS();+}+/* Entries are relative to the kustomization's own directory; in a nested* overlay they resolve through the sibling lookup, not the repo root. */TEST(probe_kustomize_nested_sibling_entries) {@@ -1725,6 +1739,7 @@ SUITE(grammar_probe_f) {RUN_TEST(probe_kustomize_extensionless_file);RUN_TEST(probe_kustomize_remote_base_names_no_symbol);RUN_TEST(probe_kustomize_nested_sibling_entries);+ RUN_TEST(probe_kustomize_single_module);/* Nix */RUN_TEST(probe_nix_attrset_node);diff --git a/tests/test_pipeline.c b/tests/test_pipeline.cindex 77647762e..68166f0c4 100644--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@ -16992,9 +16992,10 @@ TEST(incremental_k8s_manifest_indexed) {PASS();}-TEST(incremental_kustomize_module_indexed) {+TEST(incremental_kustomize_entries_indexed) {/* Verifies that a kustomization.yaml added after the initial full index- * gets a Module node via the incremental k8s pass. */+ * is indexed incrementally: its entry becomes an IMPORTS edge to the+ * manifest it names. */char tmpdir[256];snprintf(tmpdir, sizeof(tmpdir), "/tmp/cbm_kust_incr_XXXXXX");if (!cbm_mkdtemp(tmpdir)) {@@ -17035,20 +17036,27 @@ TEST(incremental_kustomize_module_indexed) {ASSERT_EQ(cbm_pipeline_run(p), 0);cbm_pipeline_free(p);- /* Verify Module node created for the kustomization overlay */+ /* Verify the overlay's entry was resolved: kustomization.yaml IMPORTS deploy.yaml */cbm_store_t *s = cbm_store_open_path(dbpath);ASSERT_NOT_NULL(s);- cbm_node_t *nodes = NULL;- int count = 0;- cbm_store_find_nodes_by_label(s, project, "Module", &nodes, &count);+ cbm_edge_t *edges = NULL;+ int edge_count = 0;+ cbm_store_find_edges_by_type(s, project, "IMPORTS", &edges, &edge_count);bool found_kust = false;- for (int i = 0; i < count; i++) {- if (nodes[i].properties_json && strstr(nodes[i].properties_json, "kustomize")) {- found_kust = true;- break;+ for (int i = 0; i < edge_count && !found_kust; i++) {+ cbm_node_t src = {0};+ cbm_node_t tgt = {0};+ if (cbm_store_find_node_by_id(s, edges[i].source_id, &src) == CBM_STORE_OK &&+ cbm_store_find_node_by_id(s, edges[i].target_id, &tgt) == CBM_STORE_OK) {+ found_kust = src.file_path && strcmp(src.file_path, "kustomization.yaml") == 0 &&+ tgt.file_path && strcmp(tgt.file_path, "deploy.yaml") == 0;}+ cbm_node_free_fields(&src);+ cbm_node_free_fields(&tgt);+ }+ if (edges) {+ cbm_store_free_edges(edges, edge_count);}- cbm_store_free_nodes(nodes, count);cbm_store_close(s);ASSERT_TRUE(found_kust);@@ -19783,7 +19791,7 @@ SUITE(pipeline) {#endifRUN_TEST(incremental_fast_preserves_mode_skipped_tools_dir);RUN_TEST(incremental_k8s_manifest_indexed);- RUN_TEST(incremental_kustomize_module_indexed);+ RUN_TEST(incremental_kustomize_entries_indexed);/* Resource management & internal helper tests */RUN_TEST(pipeline_empty_path);RUN_TEST(pipeline_project_name_content);