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
feat(k8s): exposed routes and policy selectors
Martin Vogel0e75e31e9cb0
diff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.hindex 6be7102d5..4cef7f0f5 100644--- a/internal/cbm/cbm.h+++ b/internal/cbm/cbm.h@@ -608,8 +608,16 @@ typedef struct {* CBM_K8S_FACT_CRD: the CRD def_index declares kind `kind` in group `name`.* CBM_K8S_FACT_DEPLOY: object def_index (a Flux Kustomization, an Argo* Application) deploys the repository directory `name` into namespace- * `ns` (NULL: the objects' own); via "flux" / "argo". */-typedef enum { CBM_K8S_FACT_REF = 0, CBM_K8S_FACT_CRD, CBM_K8S_FACT_DEPLOY } CBMK8sFactKind;+ * `ns` (NULL: the objects' own); via "flux" / "argo".+ * CBM_K8S_FACT_ROUTE: object def_index (an Ingress, an HTTPRoute) exposes+ * `route` ("<host or *><path>") and sends it to the kind/ns/name backend+ * (name NULL: none); via "ingress" / "httproute". */+typedef enum {+ CBM_K8S_FACT_REF = 0,+ CBM_K8S_FACT_CRD,+ CBM_K8S_FACT_DEPLOY,+ CBM_K8S_FACT_ROUTE+} CBMK8sFactKind;typedef struct {CBMK8sFactKind fact;int def_index;@@ -618,6 +626,7 @@ typedef struct {const char *name;const char *via;const char *edge;+ const char *route;} CBMK8sFact;typedef struct {diff --git a/internal/cbm/extract_k8s.c b/internal/cbm/extract_k8s.cindex 6d5df5565..5c8394055 100644--- a/internal/cbm/extract_k8s.c+++ b/internal/cbm/extract_k8s.c@@ -798,6 +798,144 @@ static const char *k8s_field(k8s_walk_t *w, TSNode mapping, const char *field) {return NULL;}+// The content node of `field` in a mapping (null when absent or not a mapping).+static TSNode k8s_child(k8s_walk_t *w, TSNode mapping, const char *field) {+ TSNode none = {0};+ if (ts_node_is_null(mapping) || !k8s_is_mapping(mapping)) {+ return none;+ }+ uint32_t n = ts_node_named_child_count(mapping);+ for (uint32_t i = 0; i < n; i++) {+ TSNode pair = ts_node_named_child(mapping, i);+ if (!k8s_is_pair(pair)) {+ continue;+ }+ TSNode key = ts_node_named_child(pair, 0);+ const char *k =+ ts_node_is_null(key) ? NULL : get_scalar_text(w->ctx->arena, key, w->ctx->source);+ if (k && strcmp(k, field) == 0) {+ TSNode v = unwrap_pair_value(pair);+ return ts_node_is_null(v) ? none : k8s_unwrap(v);+ }+ }+ return none;+}++// The items of a sequence node, unwrapped, comments skipped.+typedef struct {+ TSNode seq;+ uint32_t i;+ uint32_t n;+} k8s_iter_t;++static k8s_iter_t k8s_iter(TSNode seq) {+ k8s_iter_t it = {.seq = seq};+ if (!ts_node_is_null(seq) && (strcmp(ts_node_type(seq), "block_sequence") == 0 ||+ strcmp(ts_node_type(seq), "flow_sequence") == 0)) {+ it.n = ts_node_named_child_count(seq);+ }+ return it;+}++static bool k8s_next(k8s_iter_t *it, TSNode *out) {+ while (it->i < it->n) {+ TSNode item = ts_node_named_child(it->seq, it->i++);+ if (strcmp(ts_node_type(item), "block_sequence_item") == 0) {+ item = first_content_child(item);+ }+ if (!ts_node_is_null(item) && strcmp(ts_node_type(item), "comment") != 0) {+ *out = k8s_unwrap(item);+ return true;+ }+ }+ return false;+}++// A scalar field of a node (NULL unless a mapping holding a scalar there).+static const char *k8s_text(k8s_walk_t *w, TSNode mapping, const char *field) {+ TSNode v = k8s_child(w, mapping, field);+ return ts_node_is_null(v) ? NULL : get_scalar_text(w->ctx->arena, v, w->ctx->source);+}++// An exposed route "<host or *><path>" to backend `name` (NULL: none).+static void k8s_emit_route(k8s_walk_t *w, const char *host, const char *path, const char *ns,+ const char *name, const char *via) {+ host = host && host[0] ? host : "*";+ path = path && path[0] ? path : "/";+ if (strstr(host, "{{") || strstr(path, "{{") || strchr(host, '/')) {+ return;+ }+ CBMArena *a = w->ctx->arena;+ CBMK8sFact f = {.fact = CBM_K8S_FACT_ROUTE,+ .def_index = w->def_index,+ .kind = name ? "Service" : NULL,+ .ns = ns && ns[0] && !strstr(ns, "{{") ? cbm_arena_strdup(a, ns) : NULL,+ .name = name && !strstr(name, "{{") ? cbm_arena_strdup(a, name) : NULL,+ .via = via,+ .edge = "INFRA_MAPS",+ .route = cbm_arena_sprintf(a, "%s%s%s", host, path[0] == '/' ? "" : "/", path)};+ cbm_k8sfact_push(&w->ctx->result->k8s_facts, a, f);+}++// The routes an Ingress rule (spec.rules[] item) exposes: its host and each+// http path, sent to the path's backend Service.+static void k8s_ingress_rule(k8s_walk_t *w, TSNode rule) {+ const char *host = k8s_text(w, rule, "host");+ k8s_iter_t paths = k8s_iter(k8s_child(w, k8s_child(w, rule, "http"), "paths"));+ TSNode p;+ while (k8s_next(&paths, &p)) {+ TSNode backend = k8s_child(w, p, "backend");+ const char *svc = k8s_text(w, k8s_child(w, backend, "service"), "name");+ svc = svc ? svc : k8s_text(w, backend, "serviceName");+ k8s_emit_route(w, host, k8s_text(w, p, "path"), NULL, svc, "ingress");+ }+}++// One HTTPRoute host x path: to each Service backend of the rule, else none.+static void k8s_httproute_target(k8s_walk_t *w, TSNode rule, const char *host, const char *path) {+ k8s_iter_t backs = k8s_iter(k8s_child(w, rule, "backendRefs"));+ TSNode b;+ bool any = false;+ while (k8s_next(&backs, &b)) {+ const char *kind = k8s_text(w, b, "kind");+ if (kind && strcmp(kind, "Service") != 0) {+ continue;+ }+ k8s_emit_route(w, host, path, k8s_text(w, b, "namespace"), k8s_text(w, b, "name"),+ "httproute");+ any = true;+ }+ if (!any) {+ k8s_emit_route(w, host, path, NULL, NULL, "httproute");+ }+}++// The routes an HTTPRoute spec exposes: every hostname (else any) with+// every path match of a rule (else `/`), sent to the rule's Service backends.+static void k8s_httproute_spec(k8s_walk_t *w, TSNode spec) {+ TSNode hostnames = k8s_child(w, spec, "hostnames");+ k8s_iter_t rules = k8s_iter(k8s_child(w, spec, "rules"));+ TSNode rule;+ while (k8s_next(&rules, &rule)) {+ k8s_iter_t hosts = k8s_iter(hostnames);+ TSNode h;+ bool any_host = k8s_next(&hosts, &h);+ do {+ const char *host = any_host ? get_scalar_text(w->ctx->arena, h, w->ctx->source) : NULL;+ k8s_iter_t matches = k8s_iter(k8s_child(w, rule, "matches"));+ TSNode m;+ bool any_match = false;+ while (k8s_next(&matches, &m)) {+ k8s_httproute_target(w, rule, host, k8s_text(w, k8s_child(w, m, "path"), "value"));+ any_match = true;+ }+ if (!any_match) {+ k8s_httproute_target(w, rule, host, NULL);+ }+ } while (any_host && k8s_next(&hosts, &h));+ }+}+// The reference a mapping holds in its kind/name/namespace: to `kind`, or// (NULL) to its own `kind` field, one of `allowed` (NULL: any), `dflt`// when absent.@@ -828,6 +966,14 @@ static void k8s_mapping(k8s_walk_t *w, const char *path, TSNode mapping) {k8s_mapping_ref(w, mapping, r->kind, r->allowed, r->dflt, r->via, r->edge);}}+ if (k8s_source_is(w, "|networking.k8s.io|extensions|", "|Ingress|") &&+ strcmp(path, "spec.rules[]") == 0) {+ k8s_ingress_rule(w, mapping);+ }+ if (k8s_source_is(w, "|gateway.networking.k8s.io|", "|HTTPRoute|") &&+ strcmp(path, "spec") == 0) {+ k8s_httproute_spec(w, mapping);+ }}// Walk `node` (reached at `path`) for references.diff --git a/src/pipeline/pass_k8s.c b/src/pipeline/pass_k8s.cindex 674eabdd4..ca466b0ba 100644--- a/src/pipeline/pass_k8s.c+++ b/src/pipeline/pass_k8s.c@@ -104,6 +104,8 @@ typedef enum {K8S_REC_SERVICE, /* pairs = spec.selector */K8S_REC_WORKLOAD, /* pairs = pod-template labels */K8S_REC_POD, /* pairs = metadata.labels */+ K8S_REC_PDB, /* pairs = spec.selector.matchLabels */+ K8S_REC_NETPOL, /* pairs = spec.podSelector.matchLabels */} k8s_rec_kind_t;typedef struct {@@ -113,6 +115,7 @@ typedef struct {k8s_rec_kind_t kind;int pair_off; /* this record's pairs: pairs[pair_off .. pair_off + pair_n) */int pair_n;+ bool has_expr; /* its label selector also has matchExpressions */} k8s_record_t;typedef struct {@@ -179,12 +182,20 @@ typedef enum {K8S_PAIR_SELECTOR, /* spec.selector (a Service's selector is a flat map) */K8S_PAIR_TEMPLATE_LABEL, /* spec.template.metadata.labels, also under a CronJob's jobTemplate */K8S_PAIR_META_LABEL, /* metadata.labels */+ K8S_PAIR_MATCH_LABELS, /* spec.selector.matchLabels (a PodDisruptionBudget's) */+ K8S_PAIR_POD_SELECTOR, /* spec.podSelector.matchLabels (a NetworkPolicy's) */} k8s_pair_block_t;static k8s_pair_block_t k8s_pair_block(const char *parent_path) {if (strcmp(parent_path, "spec.selector") == 0) {return K8S_PAIR_SELECTOR;}+ if (strcmp(parent_path, "spec.selector.matchLabels") == 0) {+ return K8S_PAIR_MATCH_LABELS;+ }+ if (strcmp(parent_path, "spec.podSelector.matchLabels") == 0) {+ return K8S_PAIR_POD_SELECTOR;+ }if (strcmp(parent_path, "spec.template.metadata.labels") == 0 ||strcmp(parent_path, "spec.jobTemplate.spec.template.metadata.labels") == 0) {return K8S_PAIR_TEMPLATE_LABEL;@@ -198,10 +209,16 @@ static k8s_pair_block_t k8s_pair_block(const char *parent_path) {static k8s_rec_kind_t k8s_rec_kind(const char *kind) {static const char *const workloads[] = {"Deployment", "StatefulSet", "DaemonSet", "ReplicaSet", "ReplicationController",- "Job", "CronJob", NULL};+ "Job", "CronJob", "Rollout", NULL};if (strcmp(kind, "Service") == 0) {return K8S_REC_SERVICE;}+ if (strcmp(kind, "PodDisruptionBudget") == 0) {+ return K8S_REC_PDB;+ }+ if (strcmp(kind, "NetworkPolicy") == 0) {+ return K8S_REC_NETPOL;+ }if (strcmp(kind, "Pod") == 0) {return K8S_REC_POD;}@@ -222,6 +239,10 @@ static k8s_pair_block_t k8s_kind_block(k8s_rec_kind_t kind) {return K8S_PAIR_TEMPLATE_LABEL;case K8S_REC_POD:return K8S_PAIR_META_LABEL;+ case K8S_REC_PDB:+ return K8S_PAIR_MATCH_LABELS;+ case K8S_REC_NETPOL:+ return K8S_PAIR_POD_SELECTOR;case K8S_REC_OTHER:default:return K8S_PAIR_NONE;@@ -371,6 +392,12 @@ static void k8s_scan_labels(const char *source, k8s_record_t *rec, k8s_scanned_tchar key[64];char val[CBM_SZ_512]; /* a whole flow map fits: the line is the limit */if (k8s_split_kv(trimmed, key, sizeof(key), val, sizeof(val))) {+ if (strcmp(key, "matchExpressions") == 0) {+ char parent[CBM_SZ_512];+ k8s_parent_path(parent, sizeof(parent), (const char (*)[64])keys, depth);+ rec->has_expr = rec->has_expr || strcmp(parent, "spec.selector") == 0 ||+ strcmp(parent, "spec.podSelector") == 0;+ }if (val[0] == '\0') {/* Block-opening key: push onto the path stack. */if (depth < K8S_PATH_DEPTH) {@@ -1085,6 +1112,7 @@ typedef struct {char *name; /* target metadata.name */const char *via; /* static: the extractor's table */const char *edge; /* static: "USAGE", "INFRA_MAPS" or "DEPENDS_ON" */+ char *route; /* an exposed route "<host><path>" the edge leaves from, NULL = src */} k8s_ref_t;/* A CRD and the group/kind it declares. */@@ -1119,6 +1147,7 @@ static void k8s_facts_free(k8s_facts_t *f) {cbm_free(CBM_MEM_CLASS_OTHER, f->refs[i].kind);cbm_free(CBM_MEM_CLASS_OTHER, f->refs[i].ns);cbm_free(CBM_MEM_CLASS_OTHER, f->refs[i].name);+ cbm_free(CBM_MEM_CLASS_OTHER, f->refs[i].route);}for (int i = 0; i < f->crd_n; i++) {cbm_free(CBM_MEM_CLASS_OTHER, f->crds[i].group);@@ -1201,13 +1230,15 @@ static void k8s_facts_keep(k8s_facts_t *f, const CBMFileResult *res, const int64cbm_mem_strdup(CBM_MEM_CLASS_OTHER, x->kind)};}} else if (k8s_grow((void **)&f->refs, &f->ref_cap, f->ref_n, sizeof(*f->refs))) {+ bool route = x->fact == CBM_K8S_FACT_ROUTE && x->route;f->refs[f->ref_n++] =(k8s_ref_t){.src = node,- .kind = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, x->kind),+ .kind = x->kind ? cbm_mem_strdup(CBM_MEM_CLASS_OTHER, x->kind) : NULL,.ns = x->ns ? cbm_mem_strdup(CBM_MEM_CLASS_OTHER, x->ns) : NULL,- .name = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, x->name),+ .name = x->name ? cbm_mem_strdup(CBM_MEM_CLASS_OTHER, x->name) : NULL,.via = x->via,- .edge = x->edge};+ .edge = x->edge,+ .route = route ? cbm_mem_strdup(CBM_MEM_CLASS_OTHER, x->route) : NULL};}}}@@ -1557,14 +1588,52 @@ static bool k8s_ref_meets(k8s_bundles_t *b, const k8s_ref_t *ref, const cbm_gbufreturn false;}+/* The Route node of a route `src` (an Ingress, an HTTPRoute) exposes, which+ * `src` DEFINES; 0 on failure. Its QN is the route itself, so every object+ * exposing one host and path shares it. */+static int64_t k8s_route_node(cbm_pipeline_ctx_t *ctx, const cbm_gbuf_node_t *src,+ const k8s_ref_t *ref) {+ enum { K8S_ROUTE_ESC = 6 * CBM_SZ_256 };+ const char *slash = strchr(ref->route, '/');+ if (!slash) {+ return 0;+ }+ char qn[CBM_SZ_1K];+ char host[CBM_SZ_256];+ char esc_host[K8S_ROUTE_ESC];+ char esc_path[K8S_ROUTE_ESC];+ snprintf(qn, sizeof(qn), "__route__ingress__%s", ref->route);+ snprintf(host, sizeof(host), "%.*s", (int)(slash - ref->route), ref->route);+ cbm_json_escape(esc_host, sizeof(esc_host), host);+ cbm_json_escape(esc_path, sizeof(esc_path), slash);+ char props[2 * K8S_ROUTE_ESC + CBM_SZ_256];+ snprintf(props, sizeof(props),+ "{\"source\":\"k8s\",\"via\":\"%s\",\"host\":\"%s\",\"path\":\"%s\"}", ref->via,+ esc_host, esc_path);+ int64_t id = cbm_gbuf_upsert_node(ctx->gbuf, "Route", ref->route, qn, src->file_path,+ src->start_line, src->end_line, props);+ if (id > 0) {+ cbm_gbuf_insert_edge(ctx->gbuf, src->id, id, "DEFINES", "{}");+ }+ return id;+}+/* Draw every reference to the object(s) it names inside its bundle;- * an unresolved reference draws nothing. */+ * an unresolved reference draws nothing. An exposed route's reference+ * leaves from its Route node. */static void k8s_resolve_refs(cbm_pipeline_ctx_t *ctx, k8s_bundles_t *b, const k8s_facts_t *f) {int edges = 0;int unresolved = 0;for (int i = 0; i < f->ref_n; i++) {const k8s_ref_t *ref = &f->refs[i];const cbm_gbuf_node_t *src = cbm_gbuf_find_by_id(ctx->gbuf, ref->src);+ int64_t from = src ? src->id : 0;+ if (ref->route) {+ from = src && src->file_path ? k8s_route_node(ctx, src, ref) : 0;+ if (from <= 0 || !ref->kind || !ref->name) {+ continue;+ }+ }char name[CBM_SZ_1K];snprintf(name, sizeof(name), "%s/%s", ref->kind, ref->name);const cbm_gbuf_node_t **cands = NULL;@@ -1596,7 +1665,7 @@ static void k8s_resolve_refs(cbm_pipeline_ctx_t *ctx, k8s_bundles_t *b, const k8!k8s_ref_meets(b, ref, src, t)) {continue;}- cbm_gbuf_insert_edge(ctx->gbuf, src->id, t->id, ref->edge, props);+ cbm_gbuf_insert_edge(ctx->gbuf, from, t->id, ref->edge, props);hits++;}edges += hits;@@ -1745,14 +1814,72 @@ static void k8s_link_crds(cbm_pipeline_ctx_t *ctx, k8s_bundles_t *b, const k8s_f}}+/* A workload a selector matched: its object name, declaring file and+ * whether that is the selector's file. */+typedef struct {+ const char *name; /* "Kind/name" (graph-owned) */+ const char *ns;+ bool own;+ int rec;+} k8s_match_t;++static int k8s_cmp_match(const void *a, const void *b) {+ const k8s_match_t *x = a;+ const k8s_match_t *y = b;+ int c = strcmp(x->name, y->name);+ c = c ? c : strcmp(x->ns, y->ns);+ return c ? c : (x->rec > y->rec) - (x->rec < y->rec);+}++/* Draw the selector's edge to each match. A name is one object per kind and+ * namespace, so matches declaring one name in several files are alternatives+ * (versioned manifests side by side): the one in the selector's file, when+ * there is one, is the one it selects. */+static int k8s_draw_matches(cbm_pipeline_ctx_t *ctx, const k8s_record_array_t *recs,+ const k8s_record_t *svc, k8s_match_t *m, int n) {+ qsort(m, (size_t)n, sizeof(*m), k8s_cmp_match);+ int edges = 0;+ for (int g = 0; g < n;) {+ int end = g;+ bool own = false;+ while (end < n && strcmp(m[end].name, m[g].name) == 0 && strcmp(m[end].ns, m[g].ns) == 0) {+ own = own || m[end].own;+ end++;+ }+ for (int i = g; i < end; i++) {+ if (own && !m[i].own) {+ continue;+ }+ const k8s_record_t *wl = &recs->items[m[i].rec];+ if (svc->kind == K8S_REC_SERVICE) {+ char props[CBM_SZ_256];+ snprintf(props, sizeof(props),+ "{\"kind\":\"selector\",\"service\":\"%s\",\"workload\":\"%s\"}",+ svc->name, wl->name);+ cbm_gbuf_insert_edge(ctx->gbuf, svc->node_id, wl->node_id, "INFRA_MAPS", props);+ } else {+ cbm_gbuf_insert_edge(ctx->gbuf, svc->node_id, wl->node_id, "USAGE",+ svc->kind == K8S_REC_PDB ? "{\"ref\":\"selector\"}"+ : "{\"ref\":\"podSelector\"}");+ }+ edges++;+ }+ g = end;+ }+ return edges;+}+/* Connect each Service to the workloads its selector targets via an INFRA_MAPS- * edge (Service Resource → workload Resource), inside a shared bundle. */+ * edge (Service Resource → workload Resource), inside a shared bundle; a+ * PodDisruptionBudget or NetworkPolicy to the workloads it selects (USAGE). */static void k8s_link_selectors(cbm_pipeline_ctx_t *ctx, const k8s_record_array_t *recs,k8s_bundles_t *bundles) {CBMHashTable *index = cbm_ht_create(0);if (!index) {return;}+ k8s_match_t *matches = NULL;+ int match_cap = 0;for (int i = 0; i < recs->count; i++) {const k8s_record_t *wl = &recs->items[i];if (wl->kind == K8S_REC_WORKLOAD || wl->kind == K8S_REC_POD) {@@ -1763,8 +1890,13 @@ static void k8s_link_selectors(cbm_pipeline_ctx_t *ctx, const k8s_record_array_t}int edges = 0;for (int i = 0; i < recs->count; i++) {+ /* a Service, PodDisruptionBudget or NetworkPolicy selector; one with+ * matchExpressions selects fewer pods than its matchLabels, and an+ * empty one every pod of the namespace: neither is drawn */const k8s_record_t *svc = &recs->items[i];- if (svc->kind != K8S_REC_SERVICE || svc->pair_n == 0) {+ if ((svc->kind != K8S_REC_SERVICE && svc->kind != K8S_REC_PDB &&+ svc->kind != K8S_REC_NETPOL) ||+ svc->pair_n == 0 || svc->has_expr) {continue;}/* Candidates: the workloads carrying the Service's rarest pair. */@@ -1779,22 +1911,25 @@ static void k8s_link_selectors(cbm_pipeline_ctx_t *ctx, const k8s_record_array_trarest = posting;}}- for (int c = 0; rarest && c < rarest->count; c++) {+ const cbm_gbuf_node_t *sn = cbm_gbuf_find_by_id(ctx->gbuf, svc->node_id);+ int n = 0;+ for (int c = 0; sn && rarest && c < rarest->count; c++) {const k8s_record_t *wl = &recs->items[rarest->items[c]];bool all = k8s_share_bundle(bundles, ctx, svc, wl);for (int p = 0; all && p < svc->pair_n; p++) {all = k8s_has_pair(recs, wl, recs->pairs[svc->pair_off + p]);}- if (all) {- char props[CBM_SZ_256];- snprintf(props, sizeof(props),- "{\"kind\":\"selector\",\"service\":\"%s\",\"workload\":\"%s\"}",- svc->name, wl->name);- cbm_gbuf_insert_edge(ctx->gbuf, svc->node_id, wl->node_id, "INFRA_MAPS", props);- edges++;+ const cbm_gbuf_node_t *wn = all ? cbm_gbuf_find_by_id(ctx->gbuf, wl->node_id) : NULL;+ if (wn && wn->name && wn->file_path &&+ k8s_grow((void **)&matches, &match_cap, n, sizeof(*matches))) {+ matches[n++] = (k8s_match_t){+ wn->name, wl->ns, sn->file_path && strcmp(wn->file_path, sn->file_path) == 0,+ rarest->items[c]};}}+ edges += k8s_draw_matches(ctx, recs, svc, matches, n);}+ cbm_free(CBM_MEM_CLASS_OTHER, matches);cbm_ht_foreach(index, k8s_posting_free, NULL);cbm_ht_free(index);if (edges > 0) {diff --git a/src/pipeline/pass_route_nodes.c b/src/pipeline/pass_route_nodes.cindex 11fe8c7d7..78775b779 100644--- a/src/pipeline/pass_route_nodes.c+++ b/src/pipeline/pass_route_nodes.c@@ -346,7 +346,7 @@ static bool is_broker_route(const char *qn) {static const char *const prefixes[] = {"__route__infra__", "__route__pubsub__", "__route__cloud_tasks__","__route__async__", "__route__cloud_scheduler__", "__route__kafka__",- "__route__sqs__"};+ "__route__sqs__", "__route__ingress__"};if (!qn) {return false;}diff --git a/tests/test_grammar_probe_f.c b/tests/test_grammar_probe_f.cindex 812a6f16c..ec87497fd 100644--- a/tests/test_grammar_probe_f.c+++ b/tests/test_grammar_probe_f.c@@ -1482,6 +1482,85 @@ TEST(probe_argo_application_and_rollout_refs) {PASS();}+/* ── Exposed routes + policy selectors (P1.4) ───────────────────────── */++/* A PodDisruptionBudget's selector and a NetworkPolicy's podSelector pick+ * workloads by their pod labels; an empty podSelector (every pod of the+ * namespace) and a selector with matchExpressions draw nothing. */+TEST(probe_k8s_pdb_and_networkpolicy_select_workloads) {+ static const char doc[] =+ "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: web\nspec:\n template:\n"+ " metadata:\n labels:\n app: web\n---\n"+ "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: api\nspec:\n template:\n"+ " metadata:\n labels:\n app: api\n---\n"+ "apiVersion: policy/v1\nkind: PodDisruptionBudget\nmetadata:\n name: web\nspec:\n"+ " minAvailable: 1\n selector:\n matchLabels:\n app: web\n---\n"+ "apiVersion: policy/v1\nkind: PodDisruptionBudget\nmetadata:\n name: narrowed\nspec:\n"+ " selector:\n matchLabels:\n app: web\n matchExpressions:\n"+ " - key: track\n operator: In\n values: [canary]\n---\n"+ "apiVersion: networking.k8s.io/v1\nkind: NetworkPolicy\nmetadata:\n name: api\nspec:\n"+ " podSelector:\n matchLabels:\n app: api\n---\n"+ "apiVersion: networking.k8s.io/v1\nkind: NetworkPolicy\nmetadata:\n name: deny-all\n"+ "spec:\n podSelector: {}\n";+ static const GpfFile files[] = {{"k8s/app.yaml", doc}};+ ASSERT_EQ(gpf_typed_edges(files, 1, "USAGE", "Resource", "Resource", "\"ref\":\"selector\""),+ 1);+ ASSERT_EQ(gpf_typed_edges(files, 1, "USAGE", "Resource", "Resource",+ "\"ref\":\"podSelector\""),+ 1);+ PASS();+}++/* Versioned manifests side by side (kubermatic addons/canal/canal_v3.2x):+ * each declares the same Deployment; a selector picks the copy in its own+ * file, not every version's. */+TEST(probe_k8s_selectors_pick_their_own_version) {+ static const char v1[] =+ "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: kube-controllers\nspec:\n"+ " template:\n metadata:\n labels:\n app: kube-controllers\n---\n"+ "apiVersion: policy/v1\nkind: PodDisruptionBudget\nmetadata:\n"+ " name: kube-controllers\nspec:\n selector:\n matchLabels:\n"+ " app: kube-controllers\n---\n"+ "apiVersion: v1\nkind: Service\nmetadata:\n name: metrics\nspec:\n selector:\n"+ " app: kube-controllers\n";+ static const GpfFile files[] = {{"addons/canal/canal_v1.yaml", v1},+ {"addons/canal/canal_v2.yaml", v1}};+ ASSERT_EQ(gpf_typed_edges(files, 2, "USAGE", "Resource", "Resource", "\"ref\":\"selector\""),+ 2);+ ASSERT_EQ(gpf_typed_edges(files, 2, "INFRA_MAPS", "Resource", "Resource",+ "\"kind\":\"selector\""),+ 2);+ PASS();+}++/* An Ingress rule's host and paths and an HTTPRoute's hostnames and path+ * matches are routes the cluster exposes: the object DEFINES each, and the+ * route maps to the Service it is sent to. */+TEST(probe_k8s_ingress_and_httproute_expose_routes) {+ static const char doc[] =+ "apiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n name: shop\nspec:\n"+ " rules:\n - host: shop.example.com\n http:\n paths:\n"+ " - path: /api\n pathType: Prefix\n backend:\n"+ " service:\n name: api\n port:\n"+ " number: 80\n"+ " - path: /\n pathType: Prefix\n backend:\n"+ " service:\n name: web\n port:\n"+ " number: 80\n---\n"+ "apiVersion: gateway.networking.k8s.io/v1\nkind: HTTPRoute\nmetadata:\n name: api\n"+ "spec:\n hostnames:\n - api.example.com\n rules:\n - matches:\n"+ " - path:\n type: PathPrefix\n value: /v1\n"+ " backendRefs:\n - name: api\n port: 80\n---\n"+ "apiVersion: v1\nkind: Service\nmetadata:\n name: api\n---\n"+ "apiVersion: v1\nkind: Service\nmetadata:\n name: web\n";+ static const GpfFile files[] = {{"k8s/edge.yaml", doc}};+ ASSERT_EQ(gpf_typed_edges(files, 1, "DEFINES", "Resource", "Route", "{"), 3);+ ASSERT_EQ(gpf_typed_edges(files, 1, "INFRA_MAPS", "Route", "Resource", "\"kind\":\"ingress\""),+ 2);+ ASSERT_EQ(+ gpf_typed_edges(files, 1, "INFRA_MAPS", "Route", "Resource", "\"kind\":\"httproute\""), 1);+ PASS();+}+/* A CRD vendored twice (gardener: example/seed-crds and a chart): a custom* resource is an instance of the copy deployed with it; only when no copy* shares its bundle does it stand for all of them. */@@ -3090,6 +3169,9 @@ SUITE(grammar_probe_f) {RUN_TEST(probe_capi_refs_follow_the_api_group);RUN_TEST(probe_cert_manager_and_kkp_refs);RUN_TEST(probe_argo_application_and_rollout_refs);+ RUN_TEST(probe_k8s_pdb_and_networkpolicy_select_workloads);+ RUN_TEST(probe_k8s_selectors_pick_their_own_version);+ RUN_TEST(probe_k8s_ingress_and_httproute_expose_routes);RUN_TEST(probe_k8s_selector_stays_in_its_directory);RUN_TEST(probe_k8s_selector_within_kustomize_build);RUN_TEST(probe_k8s_kustomize_namespace_is_effective);