A scalar at `path`: a leaf reference, or a CRD's group / kind.
| 1155 | |
| 1156 | // A scalar at `path`: a leaf reference, or a CRD's group / kind. |
| 1157 | static void k8s_leaf(k8s_walk_t *w, const char *path, const char *value) { |
| 1158 | const char *pod = k8s_pod_prefix(w->kind); |
| 1159 | size_t pl = strlen(pod); |
| 1160 | if (pl && strncmp(path, pod, pl) == 0 && path[pl] == '.') { |
| 1161 | const char *rel = path + pl + SKIP_ONE; |
| 1162 | for (size_t i = 0; i < sizeof(k8s_pod_refs) / sizeof(k8s_pod_refs[0]); i++) { |
| 1163 | if (strcmp(rel, k8s_pod_refs[i].path) == 0) { |
| 1164 | k8s_emit_ref(w, k8s_pod_refs[i].kind, NULL, value, k8s_pod_refs[i].via, "USAGE"); |
| 1165 | } |
| 1166 | } |
| 1167 | static const char *const holders[] = {"containers[].", "initContainers[].", |
| 1168 | "ephemeralContainers[]."}; |
| 1169 | for (size_t h = 0; h < sizeof(holders) / sizeof(holders[0]); h++) { |
| 1170 | size_t hl = strlen(holders[h]); |
| 1171 | if (strncmp(rel, holders[h], hl) != 0) { |
| 1172 | continue; |
| 1173 | } |
| 1174 | for (size_t i = 0; i < sizeof(k8s_container_refs) / sizeof(k8s_container_refs[0]); |
| 1175 | i++) { |
| 1176 | if (strcmp(rel + hl, k8s_container_refs[i].path) == 0) { |
| 1177 | k8s_emit_ref(w, k8s_container_refs[i].kind, NULL, value, |
| 1178 | k8s_container_refs[i].via, "USAGE"); |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | for (size_t i = 0; i < sizeof(k8s_object_refs) / sizeof(k8s_object_refs[0]); i++) { |
| 1184 | const k8s_object_ref_t *r = &k8s_object_refs[i]; |
| 1185 | if (k8s_kind_in(r->kinds, w->kind) && strcmp(path, r->path) == 0) { |
| 1186 | k8s_emit_ref(w, r->kind, NULL, value, r->via, r->edge); |
| 1187 | } |
| 1188 | } |
| 1189 | for (size_t i = 0; i < sizeof(k8s_crd_leaf_refs) / sizeof(k8s_crd_leaf_refs[0]); i++) { |
| 1190 | const k8s_crd_leaf_ref_t *r = &k8s_crd_leaf_refs[i]; |
| 1191 | if (k8s_source_is(w, r->groups, r->kinds) && k8s_path_match(r->path, path)) { |
| 1192 | k8s_emit_ref(w, r->kind, NULL, value, r->via, r->edge); |
| 1193 | } |
| 1194 | } |
| 1195 | k8s_deploy_leaf(w, path, value); |
| 1196 | if (strcmp(w->kind, "CustomResourceDefinition") == 0) { |
| 1197 | if (strcmp(path, "spec.group") == 0) { |
| 1198 | snprintf(w->crd_group, sizeof(w->crd_group), "%s", value); |
| 1199 | } else if (strcmp(path, "spec.names.kind") == 0) { |
| 1200 | snprintf(w->crd_kind, sizeof(w->crd_kind), "%s", value); |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | // Through block_node / flow_node wrappers to the content node. |
| 1206 | static TSNode k8s_unwrap(TSNode node) { |
no test coverage detected