| 84 | /* ── Kustomize handler ───────────────────────────────────────────── */ |
| 85 | |
| 86 | static void handle_kustomize(cbm_pipeline_ctx_t *ctx, const char *path, const char *rel_path, |
| 87 | CBMFileResult *result) { |
| 88 | /* Emit Module node for this kustomize overlay file */ |
| 89 | char *mod_qn = cbm_infra_qn(ctx->project_name, rel_path, "kustomize", NULL); |
| 90 | if (!mod_qn) { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | int64_t mod_id = cbm_gbuf_upsert_node(ctx->gbuf, "Module", k8s_basename(rel_path), mod_qn, |
| 95 | rel_path, SKIP_ONE, 0, "{\"source\":\"kustomize\"}"); |
| 96 | free(mod_qn); |
| 97 | |
| 98 | if (mod_id <= 0) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | /* If we have a cached extraction result, emit IMPORTS edges for |
| 103 | * resources/bases/patches/components entries */ |
| 104 | int import_count = 0; |
| 105 | CBMFileResult *res = result; |
| 106 | bool allocated = false; |
| 107 | |
| 108 | if (!res) { |
| 109 | /* Fall back to re-extraction */ |
| 110 | int src_len = 0; |
| 111 | char *source = k8s_read_file(path, &src_len); |
| 112 | if (source) { |
| 113 | res = cbm_extract_file(source, src_len, CBM_LANG_KUSTOMIZE, ctx->project_name, rel_path, |
| 114 | CBM_EXTRACT_BUDGET, NULL, NULL); |
| 115 | free(source); |
| 116 | allocated = true; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (res) { |
| 121 | for (int j = 0; j < res->imports.count; j++) { |
| 122 | CBMImport *imp = &res->imports.items[j]; |
| 123 | if (!imp->module_path) { |
| 124 | continue; |
| 125 | } |
| 126 | |
| 127 | /* Compute target file QN */ |
| 128 | char *target_qn = |
| 129 | cbm_pipeline_fqn_compute(ctx->project_name, imp->module_path, "__file__"); |
| 130 | if (!target_qn) { |
| 131 | continue; |
| 132 | } |
| 133 | |
| 134 | const cbm_gbuf_node_t *target = cbm_gbuf_find_by_qn(ctx->gbuf, target_qn); |
| 135 | free(target_qn); |
| 136 | |
| 137 | if (target) { |
| 138 | cbm_gbuf_insert_edge(ctx->gbuf, mod_id, target->id, "IMPORTS", |
| 139 | "{\"via\":\"kustomize\"}"); |
| 140 | import_count++; |
| 141 | } |
| 142 | } |
| 143 |
no test coverage detected