@intentius/chant 0.124.100 → 0.124.102

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/dist/action-pins.d.ts +2 -0
  2. package/dist/action-pins.js +3 -0
  3. package/dist/ci-detect.d.ts +13 -0
  4. package/dist/ci-detect.js +12 -0
  5. package/dist/ci-evidence-claims.d.ts +12 -0
  6. package/dist/ci-evidence-claims.js +12 -0
  7. package/dist/ci-system.d.ts +66 -0
  8. package/dist/ci-system.js +61 -0
  9. package/dist/cli/handlers/build.js +27 -0
  10. package/dist/cli/handlers/release-doctor.d.ts +12 -0
  11. package/dist/cli/handlers/release-doctor.js +118 -0
  12. package/dist/cli/handlers/release-init.d.ts +10 -0
  13. package/dist/cli/handlers/release-init.js +374 -0
  14. package/dist/cli/handlers/release.d.ts +43 -2
  15. package/dist/cli/handlers/release.js +667 -39
  16. package/dist/cli/handlers/run-generate.js +11 -0
  17. package/dist/cli/main.d.ts +2 -0
  18. package/dist/cli/main.js +44 -101
  19. package/dist/cli/parse-args.js +48 -0
  20. package/dist/cli/registry.d.ts +16 -0
  21. package/dist/cli/release-commands/artifacts.d.ts +3 -0
  22. package/dist/cli/release-commands/artifacts.js +14 -0
  23. package/dist/cli/release-commands/candidates.d.ts +3 -0
  24. package/dist/cli/release-commands/candidates.js +16 -0
  25. package/dist/cli/release-commands/changed.d.ts +3 -0
  26. package/dist/cli/release-commands/changed.js +14 -0
  27. package/dist/cli/release-commands/compose.d.ts +3 -0
  28. package/dist/cli/release-commands/compose.js +16 -0
  29. package/dist/cli/release-commands/cut.d.ts +3 -0
  30. package/dist/cli/release-commands/cut.js +50 -0
  31. package/dist/cli/release-commands/doctor.d.ts +3 -0
  32. package/dist/cli/release-commands/doctor.js +14 -0
  33. package/dist/cli/release-commands/export.d.ts +3 -0
  34. package/dist/cli/release-commands/export.js +12 -0
  35. package/dist/cli/release-commands/images.d.ts +3 -0
  36. package/dist/cli/release-commands/images.js +13 -0
  37. package/dist/cli/release-commands/index.d.ts +8 -0
  38. package/dist/cli/release-commands/index.js +52 -0
  39. package/dist/cli/release-commands/init.d.ts +3 -0
  40. package/dist/cli/release-commands/init.js +19 -0
  41. package/dist/cli/release-commands/list.d.ts +3 -0
  42. package/dist/cli/release-commands/list.js +10 -0
  43. package/dist/cli/release-commands/next.d.ts +3 -0
  44. package/dist/cli/release-commands/next.js +13 -0
  45. package/dist/cli/release-commands/publish.d.ts +3 -0
  46. package/dist/cli/release-commands/publish.js +22 -0
  47. package/dist/cli/release-commands/stamp.d.ts +3 -0
  48. package/dist/cli/release-commands/stamp.js +15 -0
  49. package/dist/cli/release-commands/status.d.ts +3 -0
  50. package/dist/cli/release-commands/status.js +17 -0
  51. package/dist/cli/release-commands/tag.d.ts +3 -0
  52. package/dist/cli/release-commands/tag.js +12 -0
  53. package/dist/cli/release-commands/types.d.ts +20 -0
  54. package/dist/cli/release-commands/types.js +1 -0
  55. package/dist/cli/release-commands/verify.d.ts +3 -0
  56. package/dist/cli/release-commands/verify.js +15 -0
  57. package/dist/cli/release-commands/workflow.d.ts +3 -0
  58. package/dist/cli/release-commands/workflow.js +15 -0
  59. package/dist/cloud-lister/index.d.ts +4 -1
  60. package/dist/cloud-lister/index.js +2 -1
  61. package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
  62. package/dist/cloud-lister/kubernetes-components.js +642 -0
  63. package/dist/cloud-lister/kubernetes.d.ts +18 -0
  64. package/dist/cloud-lister/kubernetes.js +26 -1
  65. package/dist/cloud-lister/mask.d.ts +5 -1
  66. package/dist/cloud-lister/mask.js +14 -5
  67. package/dist/components/cli-support.d.ts +1 -1
  68. package/dist/components/cli-support.js +1 -1
  69. package/dist/config-environments.d.ts +8 -1
  70. package/dist/config-environments.js +2 -0
  71. package/dist/config-import.d.ts +1 -1
  72. package/dist/config-import.js +6 -2
  73. package/dist/config-sandbox.d.ts +1 -1
  74. package/dist/config-sandbox.js +3 -3
  75. package/dist/config.d.ts +369 -10
  76. package/dist/config.js +127 -7
  77. package/dist/deep-observation.js +9 -3
  78. package/dist/floor-table.data.js +21 -1
  79. package/dist/forge-remote.d.ts +13 -0
  80. package/dist/forge-remote.js +15 -0
  81. package/dist/lexicon.d.ts +45 -4
  82. package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
  83. package/dist/lifecycle/__fixtures__/package-files.js +72 -0
  84. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
  85. package/dist/lifecycle/__fixtures__/publish-fakes.js +275 -3
  86. package/dist/lifecycle/publish-attachments.d.ts +2 -1
  87. package/dist/lifecycle/publish-attachments.js +19 -2
  88. package/dist/lifecycle/publish-cargo.d.ts +99 -0
  89. package/dist/lifecycle/publish-cargo.js +412 -0
  90. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  91. package/dist/lifecycle/publish-credentials.js +13 -0
  92. package/dist/lifecycle/publish-declaration.d.ts +322 -4
  93. package/dist/lifecycle/publish-declaration.js +340 -9
  94. package/dist/lifecycle/publish-forge.d.ts +45 -2
  95. package/dist/lifecycle/publish-forge.js +434 -34
  96. package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
  97. package/dist/lifecycle/publish-git-ssh.js +30 -4
  98. package/dist/lifecycle/publish-github.d.ts +40 -2
  99. package/dist/lifecycle/publish-github.js +100 -3
  100. package/dist/lifecycle/publish-helm.d.ts +83 -0
  101. package/dist/lifecycle/publish-helm.js +452 -0
  102. package/dist/lifecycle/publish-homebrew.d.ts +7 -9
  103. package/dist/lifecycle/publish-homebrew.js +34 -197
  104. package/dist/lifecycle/publish-index.d.ts +141 -0
  105. package/dist/lifecycle/publish-index.js +719 -0
  106. package/dist/lifecycle/publish-marketplace.js +77 -0
  107. package/dist/lifecycle/publish-maven.d.ts +79 -0
  108. package/dist/lifecycle/publish-maven.js +364 -0
  109. package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
  110. package/dist/lifecycle/publish-mcp-registry.js +305 -0
  111. package/dist/lifecycle/publish-npm.d.ts +27 -1
  112. package/dist/lifecycle/publish-npm.js +216 -3
  113. package/dist/lifecycle/publish-nuget.d.ts +93 -0
  114. package/dist/lifecycle/publish-nuget.js +377 -0
  115. package/dist/lifecycle/publish-oci.d.ts +91 -2
  116. package/dist/lifecycle/publish-oci.js +247 -8
  117. package/dist/lifecycle/publish-package-files.d.ts +16 -0
  118. package/dist/lifecycle/publish-package-files.js +39 -0
  119. package/dist/lifecycle/publish-pypi.d.ts +138 -0
  120. package/dist/lifecycle/publish-pypi.js +657 -0
  121. package/dist/lifecycle/publish-record.d.ts +6 -3
  122. package/dist/lifecycle/publish-record.js +6 -3
  123. package/dist/lifecycle/publish-rubygems.d.ts +84 -0
  124. package/dist/lifecycle/publish-rubygems.js +366 -0
  125. package/dist/lifecycle/publish-signing.d.ts +147 -0
  126. package/dist/lifecycle/publish-signing.js +257 -0
  127. package/dist/lifecycle/publish-targets.d.ts +37 -1
  128. package/dist/lifecycle/publish-targets.js +102 -0
  129. package/dist/lifecycle/publish-tauri.js +43 -0
  130. package/dist/lifecycle/publish-train-names.d.ts +57 -0
  131. package/dist/lifecycle/publish-train-names.js +123 -0
  132. package/dist/lifecycle/publish-verify.d.ts +121 -0
  133. package/dist/lifecycle/publish-verify.js +130 -0
  134. package/dist/lifecycle/query.js +8 -0
  135. package/dist/lifecycle/release-artifacts.d.ts +290 -0
  136. package/dist/lifecycle/release-artifacts.js +808 -0
  137. package/dist/lifecycle/release-changelog.d.ts +13 -1
  138. package/dist/lifecycle/release-changelog.js +35 -2
  139. package/dist/lifecycle/release-cut.d.ts +64 -4
  140. package/dist/lifecycle/release-cut.js +147 -34
  141. package/dist/lifecycle/release-doctor.d.ts +113 -0
  142. package/dist/lifecycle/release-doctor.js +1198 -0
  143. package/dist/lifecycle/release-green.d.ts +86 -0
  144. package/dist/lifecycle/release-green.js +286 -0
  145. package/dist/lifecycle/release-init-registries.d.ts +48 -0
  146. package/dist/lifecycle/release-init-registries.js +97 -0
  147. package/dist/lifecycle/release-init.d.ts +275 -0
  148. package/dist/lifecycle/release-init.js +984 -0
  149. package/dist/lifecycle/release-intents.d.ts +73 -0
  150. package/dist/lifecycle/release-intents.js +128 -0
  151. package/dist/lifecycle/release-next.d.ts +111 -0
  152. package/dist/lifecycle/release-next.js +251 -0
  153. package/dist/lifecycle/release-prerelease.d.ts +19 -0
  154. package/dist/lifecycle/release-prerelease.js +30 -0
  155. package/dist/lifecycle/release-publish.d.ts +256 -10
  156. package/dist/lifecycle/release-publish.js +247 -35
  157. package/dist/lifecycle/release-status-change.d.ts +226 -0
  158. package/dist/lifecycle/release-status-change.js +478 -0
  159. package/dist/lifecycle/release-status.d.ts +11 -0
  160. package/dist/lifecycle/release-status.js +1 -1
  161. package/dist/lifecycle/release-store.d.ts +73 -2
  162. package/dist/lifecycle/release-store.js +32 -1
  163. package/dist/lifecycle/release-tag.d.ts +142 -0
  164. package/dist/lifecycle/release-tag.js +322 -0
  165. package/dist/lifecycle/release-verify.d.ts +73 -1
  166. package/dist/lifecycle/release-verify.js +117 -2
  167. package/dist/lifecycle/release-version-formats.d.ts +73 -0
  168. package/dist/lifecycle/release-version-formats.js +570 -0
  169. package/dist/lifecycle/release-version.d.ts +58 -10
  170. package/dist/lifecycle/release-version.js +164 -36
  171. package/dist/lifecycle/release-workstation.d.ts +3 -2
  172. package/dist/lifecycle/release-workstation.js +3 -2
  173. package/dist/op/generate-pipeline.js +1 -1
  174. package/dist/op/local-executor.d.ts +1 -1
  175. package/dist/op/local-executor.js +2 -2
  176. package/dist/op/op-waves-evidence.js +9 -2
  177. package/dist/pr-forge-base.js +4 -2
  178. package/dist/pr-forge.d.ts +20 -2
  179. package/dist/pr-forge.js +46 -10
  180. package/dist/release-floors.d.ts +8 -1
  181. package/dist/release-floors.js +9 -2
  182. package/dist/sensitive-key.d.ts +12 -0
  183. package/dist/sensitive-key.js +52 -0
  184. package/dist/tool-pins.d.ts +40 -0
  185. package/dist/tool-pins.js +66 -0
  186. package/dist/ts-loader.d.ts +8 -0
  187. package/dist/ts-loader.js +19 -0
  188. package/dist/wave-runtime.mjs +345 -342
  189. package/dist/workspace/ci-forge.d.ts +17 -0
  190. package/dist/workspace/ci-forge.js +17 -0
  191. package/dist/workspace/ci-init.js +1 -1
  192. package/dist/workspace/composites.schema.json +1 -0
  193. package/dist/workspace/declaration.d.ts +8 -0
  194. package/dist/workspace/declaration.js +12 -0
  195. package/dist/workspace/declaration.schema.json +8 -0
  196. package/dist/workspace/environments.d.ts +2 -0
  197. package/dist/workspace/environments.js +1 -1
  198. package/dist/workspace/identity-gate-rule.d.ts +61 -5
  199. package/dist/workspace/identity-gate-rule.js +81 -12
  200. package/dist/workspace/lexicon-outputs.d.ts +1 -1
  201. package/dist/workspace/lexicon-outputs.js +1 -1
  202. package/dist/workspace/member-pipeline.d.ts +2 -1
  203. package/dist/workspace/member-pipeline.js +5 -2
  204. package/dist/workspace/reason-codes.d.ts +2 -0
  205. package/dist/workspace/reason-codes.js +3 -1
  206. package/dist/workspace/release-changed.d.ts +75 -4
  207. package/dist/workspace/release-changed.js +205 -34
  208. package/dist/workspace/release-changed.schema.json +20 -2
  209. package/dist/workspace/release-steps/artifacts.d.ts +7 -0
  210. package/dist/workspace/release-steps/artifacts.js +45 -0
  211. package/dist/workspace/release-steps/builds.d.ts +12 -0
  212. package/dist/workspace/release-steps/builds.js +38 -0
  213. package/dist/workspace/release-steps/doctor.d.ts +8 -0
  214. package/dist/workspace/release-steps/doctor.js +14 -0
  215. package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
  216. package/dist/workspace/release-steps/goreleaser.js +36 -0
  217. package/dist/workspace/release-steps/green.d.ts +3 -0
  218. package/dist/workspace/release-steps/green.js +6 -0
  219. package/dist/workspace/release-steps/images.d.ts +22 -0
  220. package/dist/workspace/release-steps/images.js +59 -0
  221. package/dist/workspace/release-steps/index.d.ts +9 -0
  222. package/dist/workspace/release-steps/index.js +50 -0
  223. package/dist/workspace/release-steps/nfpm.d.ts +13 -0
  224. package/dist/workspace/release-steps/nfpm.js +29 -0
  225. package/dist/workspace/release-steps/nuget.d.ts +14 -0
  226. package/dist/workspace/release-steps/nuget.js +16 -0
  227. package/dist/workspace/release-steps/pypi.d.ts +15 -0
  228. package/dist/workspace/release-steps/pypi.js +21 -0
  229. package/dist/workspace/release-steps/qemu.d.ts +21 -0
  230. package/dist/workspace/release-steps/qemu.js +35 -0
  231. package/dist/workspace/release-steps/signing.d.ts +18 -0
  232. package/dist/workspace/release-steps/signing.js +30 -0
  233. package/dist/workspace/release-steps/stamp.d.ts +3 -0
  234. package/dist/workspace/release-steps/stamp.js +4 -0
  235. package/dist/workspace/release-steps/targets.d.ts +31 -0
  236. package/dist/workspace/release-steps/targets.js +40 -0
  237. package/dist/workspace/release-steps/types.d.ts +104 -0
  238. package/dist/workspace/release-steps/types.js +2 -0
  239. package/dist/workspace/release-steps/verify.d.ts +3 -0
  240. package/dist/workspace/release-steps/verify.js +4 -0
  241. package/dist/workspace/release-toolchains.d.ts +59 -0
  242. package/dist/workspace/release-toolchains.js +133 -0
  243. package/dist/workspace/release-train-workflow.d.ts +36 -0
  244. package/dist/workspace/release-train-workflow.js +121 -0
  245. package/dist/workspace/release-train.d.ts +3 -1
  246. package/dist/workspace/release-train.js +20 -3
  247. package/dist/workspace/release-workflow.d.ts +183 -59
  248. package/dist/workspace/release-workflow.js +570 -201
  249. package/dist/workspace/releases.schema.json +70 -1
  250. package/dist/workspace/search-contract.d.ts +1 -1
  251. package/dist/workspace/security.js +9 -2
  252. package/dist/workspace/train-cut.d.ts +182 -0
  253. package/dist/workspace/train-cut.js +504 -0
  254. package/dist/workspace/train-prepare.d.ts +64 -0
  255. package/dist/workspace/train-prepare.js +313 -0
  256. package/dist/workspace/train-publish.d.ts +177 -0
  257. package/dist/workspace/train-publish.js +574 -0
  258. package/dist/workspace/train-range-labels.d.ts +33 -0
  259. package/dist/workspace/train-range-labels.js +109 -0
  260. package/dist/workspace/train-shell.d.ts +5 -0
  261. package/dist/workspace/train-shell.js +17 -0
  262. package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
  263. package/dist/workspace/trust/check-evidence-report.js +3 -7
  264. package/dist/workspace/trust/seal.d.ts +13 -3
  265. package/dist/workspace/trust/seal.js +14 -4
  266. package/dist/workspace/work-cli.d.ts +3 -2
  267. package/dist/workspace/work-cli.js +3 -2
  268. package/dist/workspace/workspace-ledger.d.ts +14 -1
  269. package/dist/workspace/workspace-ledger.js +33 -7
  270. package/package.json +1 -1
@@ -0,0 +1,642 @@
1
+ /**
2
+ * chant#5252: the applications in a live Kubernetes read, inferred from the
3
+ * objects and drawn as chant components.
4
+ *
5
+ * A cluster read (`listCloud` through `indexCloud`, ../lifecycle/cloud-index.ts)
6
+ * gives every object and the references between them, and nothing declares
7
+ * an application. {@link inferK8sComponents} draws one from each top-level
8
+ * workload and what it reaches, and writes them in the shape `chant graph
9
+ * --components --format ir` writes (../cli/handlers/graph.ts): one
10
+ * `Component` node per application with `attrs.wave` and `attrs.liveNames`,
11
+ * a `dependsOn` edge from consumer to producer, and `groups.byWave`. A reader
12
+ * of the declared component graph reads this one with no new code.
13
+ *
14
+ * Seeds. A workload (Deployment, StatefulSet, DaemonSet, CronJob, Job,
15
+ * ReplicaSet, Pod) that no other workload controls, so a Job, ReplicaSet or
16
+ * Pod with no workload owner seeds as well and nothing running is left out.
17
+ * Owner references are followed by uid, and by kind and name in the
18
+ * namespace when the uid is not in the read.
19
+ *
20
+ * Boundaries. The first of these on a seed's own labels and annotations
21
+ * names its unit, and seeds of one namespace with the same unit are one
22
+ * application: `app.kubernetes.io/part-of`, `argocd.argoproj.io/instance`,
23
+ * the `meta.helm.sh/release-name` annotation, `app.kubernetes.io/instance`,
24
+ * and `app.kubernetes.io/name` on an object a k8s composite made
25
+ * (`app.kubernetes.io/managed-by: chant`). A seed with none stands alone.
26
+ * An Argo CD instance is one application across every namespace it deploys
27
+ * into, since one Application can name several.
28
+ *
29
+ * Names. An application is named by its unit's value, or by its workload's
30
+ * name when it has no unit. Inside one namespace a second unit with a taken
31
+ * name is told apart by its kind (`cronjob-web`) or its label
32
+ * (`instance-web`). When two namespaces in one read give the same name, each
33
+ * is written `<namespace>/<name>`; an Argo CD instance keeps its plain name.
34
+ * A read of one namespace never qualifies a name.
35
+ *
36
+ * Membership. An application takes in its seeds' runtime children, the
37
+ * Services that select their pods (with those Services' Endpoints and
38
+ * EndpointSlices), the Ingresses and HTTPRoutes that reach those Services,
39
+ * the autoscalers, disruption budgets and network policies that target them,
40
+ * and the ConfigMaps, Secrets, claims and ServiceAccount the pod template
41
+ * and the running Pods name, with any ExternalSecret that writes one of those
42
+ * Secrets. An object two or more applications take in is shared: it is in no
43
+ * application's members, and {@link InferredK8sComponents.shared} lists it.
44
+ *
45
+ * dependsOn. An env value in a seed's pod template, or a value in a
46
+ * ConfigMap the application uses, that names another application's Service
47
+ * by its cluster DNS name (`svc.ns.svc`, `svc.ns.svc.cluster.local`), or by
48
+ * its bare name inside the reader's namespace when that is the whole value or
49
+ * a URL's host.
50
+ *
51
+ * Health. Each application's `attrs.status` sums the lister's
52
+ * `workloadStatus` views (./kubernetes.ts): ready over desired replicas for
53
+ * its workloads, and the restarts of every Pod they run.
54
+ *
55
+ * Secrets. The lister keeps a pod spec's Secret names readable and masks the
56
+ * rest (`podSecretNameView`, ../sensitive-key.ts), so a mounted Secret is
57
+ * taken in. A reference that still reads as masked (a read by an older
58
+ * lister) is left out, and a note says so. Pure, and it reads only
59
+ * each node's listed type, location, native id, attributes and uid, so a
60
+ * graph typed without the k8s lexicon gives the same answer.
61
+ */
62
+ import { MASKED as TYPED_MASKED } from "../deep-observation.js";
63
+ import { NEXT_RELEASE } from "../release-floors.js";
64
+ import { MASKED as LISTED_MASKED } from "./mask.js";
65
+ /** The first chant with `inferK8sComponents`, the applications of a live Kubernetes read as a component graph (#5252). */
66
+ export const K8S_COMPONENTS_FLOOR = NEXT_RELEASE;
67
+ const WORKLOAD_KINDS = new Set(["Deployment", "StatefulSet", "DaemonSet", "CronJob", "Job", "ReplicaSet", "Pod"]);
68
+ const WORKLOAD_GROUPS = new Set(["", "apps", "batch"]);
69
+ const ROLE_OF_KIND = {
70
+ Service: "service",
71
+ Endpoints: "bookkeeping",
72
+ EndpointSlice: "bookkeeping",
73
+ Ingress: "route",
74
+ HTTPRoute: "route",
75
+ HorizontalPodAutoscaler: "policy",
76
+ PodDisruptionBudget: "policy",
77
+ NetworkPolicy: "policy",
78
+ ConfigMap: "config",
79
+ Secret: "config",
80
+ ExternalSecret: "config",
81
+ PersistentVolumeClaim: "storage",
82
+ ServiceAccount: "identity",
83
+ };
84
+ const OUTSIDE_ANNOTATIONS = ["eks.amazonaws.com/role-arn", "iam.gke.io/gcp-service-account", "azure.workload.identity/client-id"];
85
+ const SERVICE_NAME_LABEL = "kubernetes.io/service-name";
86
+ const HELM_RELEASE = "meta.helm.sh/release-name";
87
+ const isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
88
+ const rec = (v) => (isRec(v) ? v : {});
89
+ const arr = (v) => (Array.isArray(v) ? v : []);
90
+ const str = (v) => (typeof v === "string" && v.length > 0 ? v : undefined);
91
+ const isMasked = (v) => v === LISTED_MASKED || v === TYPED_MASKED;
92
+ const byString = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
93
+ function readObj(n) {
94
+ const type = (n.listedType ?? "").split("/");
95
+ if (type.length < 2)
96
+ return undefined;
97
+ const kind = type[type.length - 1];
98
+ const group = type.length === 3 ? type[0] : "";
99
+ const attrs = rec(n.attrs);
100
+ const meta = rec(attrs.metadata);
101
+ const native = n.nativeId ?? "";
102
+ const name = str(meta.name) ?? native.split("/").pop() ?? "";
103
+ if (!name)
104
+ return undefined;
105
+ const ns = n.location && n.location !== "cluster" ? n.location : "";
106
+ const labels = {};
107
+ for (const [k, v] of Object.entries({ ...rec(meta.labels), ...(n.tags ?? {}) }))
108
+ if (typeof v === "string")
109
+ labels[k] = v;
110
+ const annotations = {};
111
+ for (const [k, v] of Object.entries(rec(meta.annotations)))
112
+ if (typeof v === "string")
113
+ annotations[k] = v;
114
+ const uid = n.facts?.cloudIds?.find((c) => c.kind === "k8s-uid")?.value ?? str(meta.uid);
115
+ return { id: n.id, kind, group, ns, name, attrs, labels, annotations, ...(uid ? { uid } : {}) };
116
+ }
117
+ const isWorkload = (o) => WORKLOAD_KINDS.has(o.kind) && WORKLOAD_GROUPS.has(o.group);
118
+ /** The pod template of a workload (the Pod itself for a Pod): its labels and its pod spec. */
119
+ function podTemplate(o) {
120
+ if (o.kind === "Pod")
121
+ return { labels: o.labels, spec: rec(o.attrs.spec) };
122
+ const spec = rec(o.attrs.spec);
123
+ const template = o.kind === "CronJob" ? rec(rec(rec(spec.jobTemplate).spec).template) : rec(spec.template);
124
+ if (!isRec(spec.template) && !isRec(rec(spec.jobTemplate).spec))
125
+ return undefined;
126
+ const labels = {};
127
+ for (const [k, v] of Object.entries(rec(rec(template.metadata).labels)))
128
+ if (typeof v === "string")
129
+ labels[k] = v;
130
+ return { labels, spec: rec(template.spec) };
131
+ }
132
+ /** A label selector (`matchLabels`, `matchExpressions`) against a label set. `plain` is a Service's map selector. */
133
+ function selects(selector, labels, opts = {}) {
134
+ const sel = rec(selector);
135
+ if (opts.plain) {
136
+ const pairs = Object.entries(sel).filter(([, v]) => typeof v === "string");
137
+ return pairs.length > 0 && pairs.every(([k, v]) => labels[k] === v);
138
+ }
139
+ const matchLabels = Object.entries(rec(sel.matchLabels)).filter(([, v]) => typeof v === "string");
140
+ const expressions = arr(sel.matchExpressions).filter(isRec);
141
+ if (matchLabels.length === 0 && expressions.length === 0)
142
+ return opts.emptyMatchesAll === true;
143
+ if (!matchLabels.every(([k, v]) => labels[k] === v))
144
+ return false;
145
+ return expressions.every((e) => {
146
+ const key = str(e.key);
147
+ if (!key)
148
+ return false;
149
+ const values = arr(e.values).filter((v) => typeof v === "string");
150
+ switch (e.operator) {
151
+ case "In":
152
+ return key in labels && values.includes(labels[key]);
153
+ case "NotIn":
154
+ return !(key in labels) || !values.includes(labels[key]);
155
+ case "Exists":
156
+ return key in labels;
157
+ case "DoesNotExist":
158
+ return !(key in labels);
159
+ default:
160
+ return false;
161
+ }
162
+ });
163
+ }
164
+ /** The objects a pod spec names, and how many references the read masked. */
165
+ function podRefs(spec, into) {
166
+ const out = into ?? { configMaps: new Set(), secrets: new Set(), claims: new Set(), serviceAccount: "", masked: new Set() };
167
+ const name = (at, v, field = "name") => {
168
+ const n = isMasked(v) ? v : rec(v)[field];
169
+ if (isMasked(n)) {
170
+ out.masked.add(at);
171
+ return undefined;
172
+ }
173
+ return str(n);
174
+ };
175
+ const add = (set, n) => n && set.add(n);
176
+ const sa = str(spec.serviceAccountName) ?? str(spec.serviceAccount);
177
+ if (!out.serviceAccount)
178
+ out.serviceAccount = sa ?? "default";
179
+ for (const v of arr(spec.volumes).filter(isRec)) {
180
+ const at = `volume ${String(v.name)}`;
181
+ if ("configMap" in v)
182
+ add(out.configMaps, name(at, v.configMap));
183
+ if ("secret" in v)
184
+ add(out.secrets, name(at, v.secret, "secretName"));
185
+ if ("persistentVolumeClaim" in v)
186
+ add(out.claims, name(at, v.persistentVolumeClaim, "claimName"));
187
+ arr(rec(v.projected).sources).filter(isRec).forEach((s, i) => {
188
+ if ("configMap" in s)
189
+ add(out.configMaps, name(`${at} ${i}`, s.configMap));
190
+ if ("secret" in s)
191
+ add(out.secrets, name(`${at} ${i}`, s.secret));
192
+ });
193
+ }
194
+ const ips = spec.imagePullSecrets;
195
+ if (isMasked(ips))
196
+ out.masked.add("imagePullSecrets");
197
+ arr(ips).forEach((p, i) => add(out.secrets, name(`imagePullSecrets ${i}`, p)));
198
+ for (const c of [...arr(spec.containers), ...arr(spec.initContainers)].filter(isRec)) {
199
+ for (const e of arr(c.env).filter(isRec)) {
200
+ const from = rec(e.valueFrom);
201
+ const at = `env ${String(c.name)} ${String(e.name)}`;
202
+ if ("configMapKeyRef" in from)
203
+ add(out.configMaps, name(at, from.configMapKeyRef));
204
+ if ("secretKeyRef" in from)
205
+ add(out.secrets, name(at, from.secretKeyRef));
206
+ }
207
+ arr(c.envFrom).filter(isRec).forEach((e, i) => {
208
+ const at = `envFrom ${String(c.name)} ${i}`;
209
+ if ("configMapRef" in e)
210
+ add(out.configMaps, name(at, e.configMapRef));
211
+ if ("secretRef" in e)
212
+ add(out.secrets, name(at, e.secretRef));
213
+ });
214
+ }
215
+ return out;
216
+ }
217
+ /** `(name, value)` for each plain env value in a pod spec's containers. */
218
+ function envValues(spec) {
219
+ const out = [];
220
+ for (const c of [...arr(spec.containers), ...arr(spec.initContainers)].filter(isRec)) {
221
+ for (const e of arr(c.env).filter(isRec)) {
222
+ const n = str(e.name);
223
+ const v = e.value;
224
+ if (n && typeof v === "string" && !isMasked(v))
225
+ out.push([n, v]);
226
+ }
227
+ }
228
+ return out;
229
+ }
230
+ const DNS_NAME = /(?:^|[^a-z0-9.-])([a-z0-9](?:[-a-z0-9]*[a-z0-9])?)\.([a-z0-9](?:[-a-z0-9]*[a-z0-9])?)\.svc(?:\.cluster\.local)?(?!\.?[a-z0-9-])/g;
231
+ const BARE_NAME = /^(?:[a-z][a-z0-9+.-]*:\/\/)?([a-z0-9](?:[-a-z0-9]*[a-z0-9])?)(?::\d+)?(?:\/\S*)?$/;
232
+ /**
233
+ * The Services a string names: `[namespace, name]` for each cluster DNS name
234
+ * in it, and the bare name in `ns` when the whole string is a name, a
235
+ * `name:port` or a URL whose host is the name. Exported for tests.
236
+ */
237
+ export function serviceNamesIn(value, ns) {
238
+ const v = value.trim().toLowerCase();
239
+ const out = [];
240
+ for (const m of v.matchAll(DNS_NAME))
241
+ out.push([m[2], m[1]]);
242
+ if (out.length === 0) {
243
+ const bare = BARE_NAME.exec(v);
244
+ if (bare)
245
+ out.push([ns, bare[1]]);
246
+ }
247
+ return out;
248
+ }
249
+ function unitOf(o) {
250
+ const l = o.labels;
251
+ if (l["app.kubernetes.io/part-of"])
252
+ return { by: "part-of", value: l["app.kubernetes.io/part-of"] };
253
+ if (l["argocd.argoproj.io/instance"])
254
+ return { by: "argocd", value: l["argocd.argoproj.io/instance"] };
255
+ if (o.annotations[HELM_RELEASE])
256
+ return { by: "helm", value: o.annotations[HELM_RELEASE] };
257
+ if (l["app.kubernetes.io/instance"])
258
+ return { by: "instance", value: l["app.kubernetes.io/instance"] };
259
+ if (l["app.kubernetes.io/managed-by"] === "chant" && l["app.kubernetes.io/name"])
260
+ return { by: "chant", value: l["app.kubernetes.io/name"] };
261
+ return { by: "workload", value: o.name };
262
+ }
263
+ /** Infer the applications of a live Kubernetes read (an `IndexDocument`'s `graph`). */
264
+ export function inferK8sComponents(graph) {
265
+ const notes = [];
266
+ const objs = graph.nodes.map(readObj).filter((o) => o !== undefined);
267
+ const byId = new Map(objs.map((o) => [o.id, o]));
268
+ const byUid = new Map();
269
+ for (const o of objs)
270
+ if (o.uid)
271
+ byUid.set(o.uid, o);
272
+ const keyOf = (ns, kind, name) => `${ns}\u0000${kind}\u0000${name}`;
273
+ const byKey = new Map();
274
+ for (const o of objs) {
275
+ const k = keyOf(o.ns, o.kind, o.name);
276
+ if (!byKey.has(k) || o.group === "" || WORKLOAD_GROUPS.has(o.group))
277
+ byKey.set(k, o);
278
+ }
279
+ const find = (ns, kind, name) => (name ? byKey.get(keyOf(ns, kind, name)) : undefined);
280
+ // The controlling owner of each object, when the read holds it.
281
+ const ownerOf = (o) => {
282
+ const refs = arr(rec(o.attrs.metadata).ownerReferences).filter(isRec);
283
+ const ref = refs.find((r) => r.controller === true) ?? refs[0];
284
+ if (!ref)
285
+ return undefined;
286
+ const uid = str(ref.uid);
287
+ return (uid ? byUid.get(uid) : undefined) ?? find(o.ns, String(ref.kind ?? ""), str(ref.name));
288
+ };
289
+ // Seeds: workloads no workload controls.
290
+ const seeds = objs.filter((o) => {
291
+ if (!isWorkload(o) || !o.ns)
292
+ return false;
293
+ const owner = ownerOf(o);
294
+ return !owner || !isWorkload(owner);
295
+ });
296
+ // Units, then their names. An Argo CD instance is one unit whatever namespaces it deploys into.
297
+ const units = new Map();
298
+ for (const s of seeds) {
299
+ const boundary = unitOf(s);
300
+ const key = boundary.by === "workload"
301
+ ? `${s.ns}\u0000workload\u0000${s.kind}\u0000${s.name}`
302
+ : boundary.by === "argocd"
303
+ ? `\u0000argocd\u0000${boundary.value}`
304
+ : `${s.ns}\u0000${boundary.by}\u0000${boundary.value}`;
305
+ const u = units.get(key) ?? { key, ns: s.ns, namespaces: [], boundary, seeds: [], name: "" };
306
+ u.seeds.push(s);
307
+ if (!u.namespaces.includes(s.ns))
308
+ u.namespaces = [...u.namespaces, s.ns].sort(byString);
309
+ u.ns = u.namespaces[0];
310
+ units.set(key, u);
311
+ }
312
+ const ordered = [...units.values()].sort((a, b) => {
313
+ const wa = a.boundary.by === "workload" ? 1 : 0;
314
+ const wb = b.boundary.by === "workload" ? 1 : 0;
315
+ return wa - wb || byString(a.ns, b.ns) || byString(a.key, b.key);
316
+ });
317
+ // Inside one namespace a second unit with a taken name is told apart by its kind or its label.
318
+ const taken = new Set();
319
+ for (const u of ordered) {
320
+ const plain = u.boundary.value;
321
+ const clash = u.namespaces.some((ns) => taken.has(`${ns}\u0000${plain}`));
322
+ u.name = clash ? (u.boundary.by === "workload" ? `${u.seeds[0].kind.toLowerCase()}-${plain}` : `${u.boundary.by}-${plain}`) : plain;
323
+ for (const ns of u.namespaces)
324
+ taken.add(`${ns}\u0000${u.name}`);
325
+ }
326
+ // Across namespaces a name two units give is written <namespace>/<name>; an Argo CD instance keeps its plain name.
327
+ const unitsOfName = new Map();
328
+ for (const u of ordered)
329
+ (unitsOfName.get(u.name) ?? unitsOfName.set(u.name, []).get(u.name)).push(u);
330
+ for (const group of unitsOfName.values()) {
331
+ if (group.length < 2)
332
+ continue;
333
+ for (const u of group)
334
+ if (u.namespaces.length === 1)
335
+ u.name = `${u.ns}/${u.name}`;
336
+ }
337
+ const unitOfSeed = new Map();
338
+ for (const u of ordered)
339
+ for (const s of u.seeds)
340
+ unitOfSeed.set(s.id, u);
341
+ // What each application takes in: object id -> the applications and the role.
342
+ const usedBy = new Map();
343
+ const roleOf = new Map();
344
+ const take = (o, component, role) => {
345
+ if (!o)
346
+ return;
347
+ (usedBy.get(o.id) ?? usedBy.set(o.id, new Set()).get(o.id)).add(component);
348
+ if (!roleOf.has(o.id))
349
+ roleOf.set(o.id, role ?? ROLE_OF_KIND[o.kind] ?? "config");
350
+ };
351
+ const users = (o) => usedBy.get(o.id) ?? new Set();
352
+ for (const s of seeds)
353
+ take(s, unitOfSeed.get(s.id).name, "workload");
354
+ // Runtime children: an owner chain that ends at a seed.
355
+ const seedIds = new Set(seeds.map((s) => s.id));
356
+ const seedOfChain = (o) => {
357
+ const seen = new Set();
358
+ let cur = o;
359
+ while (cur && !seen.has(cur.id)) {
360
+ seen.add(cur.id);
361
+ if (seedIds.has(cur.id))
362
+ return cur;
363
+ cur = ownerOf(cur);
364
+ }
365
+ return undefined;
366
+ };
367
+ const runtimePods = new Map();
368
+ for (const o of objs) {
369
+ if (seedIds.has(o.id))
370
+ continue;
371
+ const seed = seedOfChain(o);
372
+ if (!seed)
373
+ continue;
374
+ take(o, unitOfSeed.get(seed.id).name, "runtime");
375
+ if (o.kind === "Pod")
376
+ (runtimePods.get(seed.id) ?? runtimePods.set(seed.id, []).get(seed.id)).push(o);
377
+ }
378
+ const templates = new Map();
379
+ for (const s of seeds) {
380
+ const t = podTemplate(s);
381
+ if (t)
382
+ templates.set(s.id, t);
383
+ }
384
+ const ofKind = (kind) => objs.filter((o) => o.kind === kind && o.ns);
385
+ // Services that select a seed's pods, and their bookkeeping.
386
+ const services = ofKind("Service");
387
+ for (const svc of services) {
388
+ for (const s of seeds) {
389
+ const t = templates.get(s.id);
390
+ if (s.ns === svc.ns && t && selects(rec(svc.attrs.spec).selector, t.labels, { plain: true }))
391
+ take(svc, unitOfSeed.get(s.id).name);
392
+ }
393
+ }
394
+ for (const svc of services) {
395
+ for (const c of users(svc)) {
396
+ take(find(svc.ns, "Endpoints", svc.name), c);
397
+ for (const es of ofKind("EndpointSlice"))
398
+ if (es.ns === svc.ns && es.labels[SERVICE_NAME_LABEL] === svc.name)
399
+ take(es, c);
400
+ }
401
+ }
402
+ // Routes to those Services.
403
+ for (const ing of ofKind("Ingress")) {
404
+ const spec = rec(ing.attrs.spec);
405
+ const names = new Set();
406
+ const backend = (b) => {
407
+ const n = str(rec(rec(b).service).name) ?? str(rec(b).serviceName);
408
+ if (n)
409
+ names.add(n);
410
+ };
411
+ backend(spec.defaultBackend ?? spec.backend);
412
+ for (const r of arr(spec.rules).filter(isRec))
413
+ for (const p of arr(rec(r.http).paths).filter(isRec))
414
+ backend(p.backend);
415
+ for (const n of names) {
416
+ const svc = find(ing.ns, "Service", n);
417
+ if (svc)
418
+ for (const c of users(svc))
419
+ take(ing, c);
420
+ }
421
+ }
422
+ for (const route of ofKind("HTTPRoute")) {
423
+ for (const r of arr(rec(route.attrs.spec).rules).filter(isRec)) {
424
+ for (const b of arr(r.backendRefs).filter(isRec)) {
425
+ if (b.kind !== undefined && b.kind !== "Service")
426
+ continue;
427
+ const svc = find(str(b.namespace) ?? route.ns, "Service", str(b.name));
428
+ if (svc)
429
+ for (const c of users(svc))
430
+ take(route, c);
431
+ }
432
+ }
433
+ }
434
+ // Policies that target the seeds.
435
+ for (const hpa of ofKind("HorizontalPodAutoscaler")) {
436
+ const ref = rec(rec(hpa.attrs.spec).scaleTargetRef);
437
+ const target = find(hpa.ns, String(ref.kind ?? ""), str(ref.name));
438
+ if (target && unitOfSeed.has(target.id))
439
+ take(hpa, unitOfSeed.get(target.id).name);
440
+ }
441
+ for (const [kind, field, all] of [["PodDisruptionBudget", "selector", false], ["NetworkPolicy", "podSelector", true]]) {
442
+ for (const p of ofKind(kind)) {
443
+ for (const s of seeds) {
444
+ const t = templates.get(s.id);
445
+ if (s.ns === p.ns && t && selects(rec(p.attrs.spec)[field], t.labels, { emptyMatchesAll: all }))
446
+ take(p, unitOfSeed.get(s.id).name);
447
+ }
448
+ }
449
+ }
450
+ // What the pod template and the running Pods name.
451
+ const maskedBy = new Map();
452
+ for (const s of seeds) {
453
+ const c = unitOfSeed.get(s.id).name;
454
+ const t = templates.get(s.id);
455
+ const refs = podRefs(t?.spec ?? {});
456
+ for (const pod of runtimePods.get(s.id) ?? [])
457
+ podRefs(rec(pod.attrs.spec), refs);
458
+ for (const n of refs.configMaps)
459
+ take(find(s.ns, "ConfigMap", n), c);
460
+ for (const n of refs.secrets)
461
+ take(find(s.ns, "Secret", n), c);
462
+ for (const n of refs.claims)
463
+ take(find(s.ns, "PersistentVolumeClaim", n), c);
464
+ take(find(s.ns, "ServiceAccount", refs.serviceAccount), c);
465
+ if (refs.masked.size > 0)
466
+ maskedBy.set(c, (maskedBy.get(c) ?? 0) + refs.masked.size);
467
+ }
468
+ for (const es of objs.filter((o) => o.kind === "ExternalSecret" && o.ns)) {
469
+ const target = find(es.ns, "Secret", str(rec(rec(es.attrs.spec).target).name) ?? es.name);
470
+ if (target)
471
+ for (const c of users(target))
472
+ take(es, c);
473
+ }
474
+ // Bookkeeping roles, and what members name outside the cluster.
475
+ for (const [id] of usedBy) {
476
+ const o = byId.get(id);
477
+ if ((o.kind === "ConfigMap" && o.name === "kube-root-ca.crt") || (o.kind === "ServiceAccount" && o.name === "default"))
478
+ roleOf.set(id, "bookkeeping");
479
+ }
480
+ const outsideOf = (o) => {
481
+ const out = [];
482
+ if (o.kind === "ServiceAccount") {
483
+ for (const key of OUTSIDE_ANNOTATIONS)
484
+ if (o.annotations[key] && !isMasked(o.annotations[key]))
485
+ out.push({ from: o.id, key, value: o.annotations[key] });
486
+ }
487
+ if (o.kind === "ExternalSecret") {
488
+ const spec = rec(o.attrs.spec);
489
+ for (const d of arr(spec.data).filter(isRec)) {
490
+ const k = str(rec(d.remoteRef).key);
491
+ if (k && !isMasked(k))
492
+ out.push({ from: o.id, key: "remoteRef.key", value: k });
493
+ }
494
+ for (const d of arr(spec.dataFrom).filter(isRec)) {
495
+ const k = str(rec(d.extract).key);
496
+ if (k && !isMasked(k))
497
+ out.push({ from: o.id, key: "remoteRef.key", value: k });
498
+ }
499
+ }
500
+ return out;
501
+ };
502
+ // Members and shared objects.
503
+ const members = new Map();
504
+ const shares = new Map();
505
+ const outside = new Map();
506
+ const shared = [];
507
+ for (const [id, set] of [...usedBy.entries()].sort(([a], [b]) => byString(a, b))) {
508
+ const role = roleOf.get(id);
509
+ const o = byId.get(id);
510
+ const names = outsideOf(o);
511
+ if (set.size === 1) {
512
+ const c = [...set][0];
513
+ (members.get(c) ?? members.set(c, []).get(c)).push({ id, role });
514
+ if (names.length)
515
+ (outside.get(c) ?? outside.set(c, []).get(c)).push(...names);
516
+ }
517
+ else {
518
+ const usedByList = [...set].sort(byString);
519
+ shared.push({ id, role, usedBy: usedByList, ...(names.length ? { outside: names } : {}) });
520
+ for (const c of usedByList)
521
+ (shares.get(c) ?? shares.set(c, []).get(c)).push(id);
522
+ }
523
+ }
524
+ // dependsOn from Service names in env values and ConfigMap data.
525
+ const serviceOwner = (ns, name) => {
526
+ const svc = find(ns, "Service", name);
527
+ const set = svc ? users(svc) : undefined;
528
+ return set && set.size === 1 ? [...set][0] : undefined;
529
+ };
530
+ const deps = new Map();
531
+ const depend = (from, ns, value, via) => {
532
+ for (const [tns, tname] of serviceNamesIn(value, ns)) {
533
+ const to = serviceOwner(tns, tname);
534
+ if (!to || to === from)
535
+ continue;
536
+ const m = deps.get(from) ?? deps.set(from, new Map()).get(from);
537
+ const list = m.get(to) ?? m.set(to, []).get(to);
538
+ if (!list.includes(via))
539
+ list.push(via);
540
+ }
541
+ };
542
+ for (const s of seeds) {
543
+ const c = unitOfSeed.get(s.id).name;
544
+ for (const [n, v] of envValues(templates.get(s.id)?.spec ?? {}))
545
+ depend(c, s.ns, v, `${s.kind} ${s.name} env ${n}`);
546
+ }
547
+ for (const [id, set] of usedBy) {
548
+ const o = byId.get(id);
549
+ if (o.kind !== "ConfigMap")
550
+ continue;
551
+ for (const [k, v] of Object.entries(rec(o.attrs.data))) {
552
+ if (typeof v !== "string" || isMasked(v))
553
+ continue;
554
+ for (const c of set)
555
+ depend(c, o.ns, v, `ConfigMap ${o.name} data.${k}`);
556
+ }
557
+ }
558
+ // Waves: Kahn layers, with any cycle in one last wave.
559
+ const names = ordered.map((u) => u.name);
560
+ const remaining = new Set(names);
561
+ const waves = [];
562
+ while (remaining.size > 0) {
563
+ let wave = [...remaining].filter((n) => [...(deps.get(n)?.keys() ?? [])].every((d) => !remaining.has(d))).sort(byString);
564
+ if (wave.length === 0) {
565
+ wave = [...remaining].sort(byString);
566
+ notes.push(`these applications name each other's Services in a cycle and share the last wave: ${wave.join(", ")}`);
567
+ }
568
+ for (const n of wave)
569
+ remaining.delete(n);
570
+ waves.push(wave);
571
+ }
572
+ const waveOf = new Map();
573
+ waves.forEach((w, i) => w.forEach((n) => waveOf.set(n, i + 1)));
574
+ for (const [c, n] of [...maskedBy.entries()].sort(([a], [b]) => byString(a, b))) {
575
+ notes.push(`${c}: ${n} Secret reference${n === 1 ? " is" : "s are"} masked by the live read, so ${n === 1 ? "that Secret is" : "those Secrets are"} not taken in`);
576
+ }
577
+ // Health: ready over desired for the workloads, and restarts over every Pod they run.
578
+ const statusOf = (u) => {
579
+ let ready = 0;
580
+ let desired = 0;
581
+ let counted = false;
582
+ let restarts = 0;
583
+ let pods = 0;
584
+ for (const seed of u.seeds) {
585
+ const view = rec(seed.attrs.workloadStatus);
586
+ if (typeof view.desiredReplicas === "number") {
587
+ ready += typeof view.readyReplicas === "number" ? view.readyReplicas : 0;
588
+ desired += view.desiredReplicas;
589
+ counted = true;
590
+ }
591
+ else if (seed.kind === "Pod" && typeof view.ready === "boolean") {
592
+ ready += view.ready ? 1 : 0;
593
+ desired += 1;
594
+ counted = true;
595
+ }
596
+ for (const pod of [...(seed.kind === "Pod" ? [seed] : []), ...(runtimePods.get(seed.id) ?? [])]) {
597
+ const pv = rec(pod.attrs.workloadStatus);
598
+ if (typeof pv.restarts === "number") {
599
+ restarts += pv.restarts;
600
+ pods++;
601
+ }
602
+ }
603
+ }
604
+ if (!counted && pods === 0)
605
+ return undefined;
606
+ return { ...(counted ? { readyReplicas: ready, desiredReplicas: desired } : {}), restarts };
607
+ };
608
+ const unitByName = new Map(ordered.map((u) => [u.name, u]));
609
+ const nodes = waves.flat().map((name) => {
610
+ const u = unitByName.get(name);
611
+ const mine = members.get(name) ?? [];
612
+ return {
613
+ id: name,
614
+ kind: "Component",
615
+ lexicon: "chant",
616
+ attrs: {
617
+ wave: waveOf.get(name) ?? null,
618
+ liveNames: mine.map((m) => m.id),
619
+ members: mine,
620
+ ...(u.namespaces.length === 1 ? { namespace: u.ns } : { namespaces: u.namespaces }),
621
+ boundary: u.boundary,
622
+ ...(statusOf(u) ? { status: statusOf(u) } : {}),
623
+ inferredFrom: "kubernetes",
624
+ ...(shares.get(name)?.length ? { shares: shares.get(name) } : {}),
625
+ ...(outside.get(name)?.length ? { outside: outside.get(name) } : {}),
626
+ },
627
+ };
628
+ });
629
+ const edges = [];
630
+ for (const from of [...deps.keys()].sort(byString)) {
631
+ for (const [to, via] of [...deps.get(from).entries()].sort(([a], [b]) => byString(a, b))) {
632
+ edges.push({ from, to, kind: "ref", origin: "derived", rule: "k8s:service-dns", viaAttr: via.sort(byString).join("; ") });
633
+ }
634
+ }
635
+ const ir = {
636
+ version: 1,
637
+ nodes,
638
+ edges,
639
+ groups: { byWave: Object.fromEntries(waves.map((w, i) => [`wave-${i + 1}`, [...w]])) },
640
+ };
641
+ return { ir, shared, notes };
642
+ }
@@ -48,6 +48,24 @@ export declare function discover(ctx: ListerContext, target: KubernetesTarget, r
48
48
  /** `labelSelector` for a tag filter, or undefined. Exported for tests. */
49
49
  export declare function labelSelector(filter: Readonly<Record<string, string>> | undefined): string | undefined;
50
50
  export declare function listKubernetes(ctx: ListerContext, target: KubernetesTarget, retryDelays?: readonly number[]): Promise<void>;
51
+ /**
52
+ * What a workload's or a Pod's `status` says about its health (chant#5252),
53
+ * kept beside the object as `workloadStatus` because typing prunes `status`
54
+ * whole. A Deployment, StatefulSet or ReplicaSet gives ready and desired
55
+ * replicas (desired is `spec.replicas`, 1 when absent); a DaemonSet its ready
56
+ * and desired scheduled pods; a Pod its phase, the restarts summed over its
57
+ * containers, and whether its `Ready` condition is true. Other kinds, and an
58
+ * object with no `status`, get none.
59
+ */
60
+ export type WorkloadStatus = {
61
+ readyReplicas: number;
62
+ desiredReplicas: number;
63
+ } | {
64
+ phase?: string;
65
+ restarts: number;
66
+ ready: boolean;
67
+ };
68
+ export declare function workloadStatusView(obj: Record<string, unknown>, group: string, kind: string): WorkloadStatus | undefined;
51
69
  /**
52
70
  * A {@link KubernetesTarget} from a kubeconfig the caller names (its text,
53
71
  * and the directory relative file paths resolve against). Static credentials