@intentius/chant-lexicon-k8s 0.124.96 → 0.124.98

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 (228) hide show
  1. package/dist/application-paths.d.ts +4 -0
  2. package/dist/application-paths.d.ts.map +1 -0
  3. package/dist/application-paths.js +95 -0
  4. package/dist/application-set.d.ts +46 -0
  5. package/dist/application-set.d.ts.map +1 -0
  6. package/dist/application-set.js +303 -0
  7. package/dist/cluster-secret.d.ts +36 -0
  8. package/dist/cluster-secret.d.ts.map +1 -0
  9. package/dist/cluster-secret.js +55 -0
  10. package/dist/components/kustomize-apply.d.ts +6 -0
  11. package/dist/components/kustomize-apply.d.ts.map +1 -1
  12. package/dist/components/kustomize-apply.js +1 -1
  13. package/dist/config-schema.d.ts +8 -0
  14. package/dist/config-schema.d.ts.map +1 -1
  15. package/dist/config-schema.js +6 -2
  16. package/dist/config.d.ts +26 -3
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/helm-references.d.ts +113 -0
  19. package/dist/helm-references.d.ts.map +1 -0
  20. package/dist/helm-references.js +389 -0
  21. package/dist/import/generator.d.ts +11 -2
  22. package/dist/import/generator.d.ts.map +1 -1
  23. package/dist/import/generator.js +37 -55
  24. package/dist/import/parser.d.ts.map +1 -1
  25. package/dist/import/parser.js +34 -5
  26. package/dist/import/typed-classes.d.ts +57 -0
  27. package/dist/import/typed-classes.d.ts.map +1 -0
  28. package/dist/import/typed-classes.js +126 -0
  29. package/dist/integrity.json +41 -41
  30. package/dist/kustomize/render.d.ts +41 -2
  31. package/dist/kustomize/render.d.ts.map +1 -1
  32. package/dist/kustomize/render.js +114 -7
  33. package/dist/kustomize/root.d.ts +3 -3
  34. package/dist/kustomize/root.d.ts.map +1 -1
  35. package/dist/kustomize/root.js +6 -1
  36. package/dist/lint/post-synth/argo-helpers.d.ts +3 -0
  37. package/dist/lint/post-synth/argo-helpers.d.ts.map +1 -1
  38. package/dist/lint/post-synth/argo-helpers.js +8 -2
  39. package/dist/lint/post-synth/argo002.d.ts.map +1 -1
  40. package/dist/lint/post-synth/argo002.js +2 -1
  41. package/dist/lint/post-synth/argo003.d.ts.map +1 -1
  42. package/dist/lint/post-synth/argo003.js +2 -1
  43. package/dist/lint/post-synth/argo005.d.ts.map +1 -1
  44. package/dist/lint/post-synth/argo005.js +36 -9
  45. package/dist/lint/post-synth/crd-schema-helpers.d.ts +1 -1
  46. package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
  47. package/dist/lint/post-synth/crd-schema-helpers.js +3 -3
  48. package/dist/lint/post-synth/flux002.d.ts.map +1 -1
  49. package/dist/lint/post-synth/flux002.js +2 -1
  50. package/dist/lint/post-synth/flux003.d.ts.map +1 -1
  51. package/dist/lint/post-synth/flux003.js +2 -1
  52. package/dist/lint/post-synth/k8s-helpers.d.ts +32 -0
  53. package/dist/lint/post-synth/k8s-helpers.d.ts.map +1 -1
  54. package/dist/lint/post-synth/k8s-helpers.js +57 -10
  55. package/dist/lint/post-synth/wk8005.d.ts +9 -0
  56. package/dist/lint/post-synth/wk8005.d.ts.map +1 -1
  57. package/dist/lint/post-synth/wk8005.js +53 -3
  58. package/dist/lint/post-synth/wk8006.d.ts.map +1 -1
  59. package/dist/lint/post-synth/wk8006.js +4 -2
  60. package/dist/lint/post-synth/wk8041.d.ts.map +1 -1
  61. package/dist/lint/post-synth/wk8041.js +3 -2
  62. package/dist/lint/post-synth/wk8042.js +2 -2
  63. package/dist/lint/post-synth/wk8101.js +2 -2
  64. package/dist/lint/post-synth/wk8102.d.ts.map +1 -1
  65. package/dist/lint/post-synth/wk8102.js +7 -3
  66. package/dist/lint/post-synth/wk8103.d.ts.map +1 -1
  67. package/dist/lint/post-synth/wk8103.js +3 -2
  68. package/dist/lint/post-synth/wk8104.d.ts.map +1 -1
  69. package/dist/lint/post-synth/wk8104.js +3 -2
  70. package/dist/lint/post-synth/wk8105.d.ts.map +1 -1
  71. package/dist/lint/post-synth/wk8105.js +3 -2
  72. package/dist/lint/post-synth/wk8201.d.ts.map +1 -1
  73. package/dist/lint/post-synth/wk8201.js +3 -2
  74. package/dist/lint/post-synth/wk8202.d.ts.map +1 -1
  75. package/dist/lint/post-synth/wk8202.js +3 -2
  76. package/dist/lint/post-synth/wk8203.d.ts.map +1 -1
  77. package/dist/lint/post-synth/wk8203.js +3 -2
  78. package/dist/lint/post-synth/wk8204.d.ts.map +1 -1
  79. package/dist/lint/post-synth/wk8204.js +5 -2
  80. package/dist/lint/post-synth/wk8205.d.ts.map +1 -1
  81. package/dist/lint/post-synth/wk8205.js +3 -2
  82. package/dist/lint/post-synth/wk8207.js +2 -2
  83. package/dist/lint/post-synth/wk8208.js +2 -2
  84. package/dist/lint/post-synth/wk8209.js +2 -2
  85. package/dist/lint/post-synth/wk8301.d.ts.map +1 -1
  86. package/dist/lint/post-synth/wk8301.js +3 -2
  87. package/dist/lint/post-synth/wk8302.js +2 -2
  88. package/dist/lint/post-synth/wk8303.js +2 -2
  89. package/dist/lint/post-synth/wk8304.js +2 -2
  90. package/dist/lint/post-synth/wk8305.js +2 -2
  91. package/dist/lint/post-synth/wk8306.d.ts.map +1 -1
  92. package/dist/lint/post-synth/wk8306.js +3 -2
  93. package/dist/lint/post-synth/wk8401.js +2 -2
  94. package/dist/lint/post-synth/wk8402.js +2 -2
  95. package/dist/lint/post-synth/wk8403.js +2 -2
  96. package/dist/lint/post-synth/wk8404.d.ts.map +1 -1
  97. package/dist/lint/post-synth/wk8404.js +2 -2
  98. package/dist/lint/post-synth/wk8405.js +2 -2
  99. package/dist/lint/post-synth/wk8406.d.ts.map +1 -1
  100. package/dist/lint/post-synth/wk8406.js +3 -2
  101. package/dist/lint/post-synth/wk8407.js +2 -2
  102. package/dist/lint/post-synth/wk8503.js +2 -2
  103. package/dist/manifest.json +1 -1
  104. package/dist/reference-catalog.d.ts +3 -1
  105. package/dist/reference-catalog.d.ts.map +1 -1
  106. package/dist/reference-catalog.js +283 -15
  107. package/dist/rules/argo-helpers.ts +9 -2
  108. package/dist/rules/argo002.ts +2 -1
  109. package/dist/rules/argo003.ts +2 -1
  110. package/dist/rules/argo005.ts +36 -10
  111. package/dist/rules/crd-schema-helpers.ts +3 -3
  112. package/dist/rules/flux002.ts +2 -1
  113. package/dist/rules/flux003.ts +2 -1
  114. package/dist/rules/k8s-helpers.ts +56 -11
  115. package/dist/rules/wk8005.ts +56 -3
  116. package/dist/rules/wk8006.ts +4 -2
  117. package/dist/rules/wk8041.ts +3 -2
  118. package/dist/rules/wk8042.ts +2 -2
  119. package/dist/rules/wk8101.ts +2 -2
  120. package/dist/rules/wk8102.ts +7 -3
  121. package/dist/rules/wk8103.ts +3 -2
  122. package/dist/rules/wk8104.ts +3 -2
  123. package/dist/rules/wk8105.ts +3 -2
  124. package/dist/rules/wk8201.ts +3 -2
  125. package/dist/rules/wk8202.ts +3 -2
  126. package/dist/rules/wk8203.ts +3 -2
  127. package/dist/rules/wk8204.ts +5 -2
  128. package/dist/rules/wk8205.ts +3 -2
  129. package/dist/rules/wk8207.ts +2 -2
  130. package/dist/rules/wk8208.ts +2 -2
  131. package/dist/rules/wk8209.ts +2 -2
  132. package/dist/rules/wk8301.ts +3 -2
  133. package/dist/rules/wk8302.ts +2 -2
  134. package/dist/rules/wk8303.ts +2 -2
  135. package/dist/rules/wk8304.ts +2 -2
  136. package/dist/rules/wk8305.ts +2 -2
  137. package/dist/rules/wk8306.ts +3 -2
  138. package/dist/rules/wk8401.ts +2 -2
  139. package/dist/rules/wk8402.ts +2 -2
  140. package/dist/rules/wk8403.ts +2 -2
  141. package/dist/rules/wk8404.ts +2 -1
  142. package/dist/rules/wk8405.ts +2 -2
  143. package/dist/rules/wk8406.ts +3 -2
  144. package/dist/rules/wk8407.ts +2 -2
  145. package/dist/rules/wk8503.ts +2 -2
  146. package/dist/workspace-member.d.ts +15 -3
  147. package/dist/workspace-member.d.ts.map +1 -1
  148. package/dist/workspace-member.js +151 -21
  149. package/package.json +5 -5
  150. package/src/application-paths.ts +96 -0
  151. package/src/application-set.test.ts +130 -0
  152. package/src/application-set.ts +336 -0
  153. package/src/cluster-secret.test.ts +117 -0
  154. package/src/cluster-secret.ts +76 -0
  155. package/src/components/kustomize-apply.ts +7 -1
  156. package/src/config-schema.ts +6 -2
  157. package/src/config.ts +24 -4
  158. package/src/helm-references.test.ts +149 -0
  159. package/src/helm-references.ts +425 -0
  160. package/src/import/generator.test.ts +57 -0
  161. package/src/import/generator.ts +35 -61
  162. package/src/import/parser.test.ts +59 -0
  163. package/src/import/parser.ts +38 -5
  164. package/src/import/roundtrip-build.test.ts +91 -0
  165. package/src/import/typed-classes.ts +168 -0
  166. package/src/kustomize/helm.test.ts +183 -0
  167. package/src/kustomize/render.ts +142 -6
  168. package/src/kustomize/root.ts +8 -3
  169. package/src/lint/post-synth/argo-helpers.ts +9 -2
  170. package/src/lint/post-synth/argo002.ts +2 -1
  171. package/src/lint/post-synth/argo003.ts +2 -1
  172. package/src/lint/post-synth/argo005.ts +36 -10
  173. package/src/lint/post-synth/audit-identity.test.ts +65 -0
  174. package/src/lint/post-synth/crd-schema-helpers.ts +3 -3
  175. package/src/lint/post-synth/flux002.ts +2 -1
  176. package/src/lint/post-synth/flux003.ts +2 -1
  177. package/src/lint/post-synth/k8s-helpers.ts +56 -11
  178. package/src/lint/post-synth/post-synth.test.ts +144 -0
  179. package/src/lint/post-synth/wk8005.ts +56 -3
  180. package/src/lint/post-synth/wk8006.ts +4 -2
  181. package/src/lint/post-synth/wk8041.ts +3 -2
  182. package/src/lint/post-synth/wk8042.ts +2 -2
  183. package/src/lint/post-synth/wk8101.ts +2 -2
  184. package/src/lint/post-synth/wk8102.ts +7 -3
  185. package/src/lint/post-synth/wk8103.ts +3 -2
  186. package/src/lint/post-synth/wk8104.ts +3 -2
  187. package/src/lint/post-synth/wk8105.ts +3 -2
  188. package/src/lint/post-synth/wk8201.ts +3 -2
  189. package/src/lint/post-synth/wk8202.ts +3 -2
  190. package/src/lint/post-synth/wk8203.ts +3 -2
  191. package/src/lint/post-synth/wk8204.ts +5 -2
  192. package/src/lint/post-synth/wk8205.ts +3 -2
  193. package/src/lint/post-synth/wk8207.ts +2 -2
  194. package/src/lint/post-synth/wk8208.ts +2 -2
  195. package/src/lint/post-synth/wk8209.ts +2 -2
  196. package/src/lint/post-synth/wk8301.ts +3 -2
  197. package/src/lint/post-synth/wk8302.ts +2 -2
  198. package/src/lint/post-synth/wk8303.ts +2 -2
  199. package/src/lint/post-synth/wk8304.ts +2 -2
  200. package/src/lint/post-synth/wk8305.ts +2 -2
  201. package/src/lint/post-synth/wk8306.ts +3 -2
  202. package/src/lint/post-synth/wk8401.ts +2 -2
  203. package/src/lint/post-synth/wk8402.ts +2 -2
  204. package/src/lint/post-synth/wk8403.ts +2 -2
  205. package/src/lint/post-synth/wk8404.ts +2 -1
  206. package/src/lint/post-synth/wk8405.ts +2 -2
  207. package/src/lint/post-synth/wk8406.ts +3 -2
  208. package/src/lint/post-synth/wk8407.ts +2 -2
  209. package/src/lint/post-synth/wk8503.ts +2 -2
  210. package/src/reference-catalog.test.ts +78 -0
  211. package/src/reference-catalog.ts +297 -16
  212. package/src/testdata/helm-chart-missing/kustomization.yaml +8 -0
  213. package/src/testdata/helm-chart-root/charts/webchart/Chart.yaml +3 -0
  214. package/src/testdata/helm-chart-root/charts/webchart/templates/configmap.yaml +6 -0
  215. package/src/testdata/helm-chart-root/charts/webchart/values.yaml +1 -0
  216. package/src/testdata/helm-chart-root/kustomization.yaml +9 -0
  217. package/src/testdata/helm-chart-root/values.yaml +1 -0
  218. package/src/testdata/workspace-members/argo-clusters/clusters.yaml +34 -0
  219. package/src/testdata/workspace-members/argo-set/all.yaml +43 -0
  220. package/src/testdata/workspace-members/plain/deploy.yaml +27 -0
  221. package/src/testdata/workspace-members/plain/es.yaml +15 -0
  222. package/src/testdata/workspace-members/templated/block.yaml +6 -0
  223. package/src/testdata/workspace-members/templated/chart-cm.yaml +4 -0
  224. package/src/testdata/workspace-members/templated/cm.yaml +6 -0
  225. package/src/workspace-kinds.test.ts +9 -1
  226. package/src/workspace-member.test.ts +69 -3
  227. package/src/workspace-member.ts +165 -24
  228. package/workspace-kinds.json +45 -6
@@ -21,8 +21,11 @@
21
21
  * megabytes.
22
22
  */
23
23
  import { exec } from "node:child_process";
24
+ import { existsSync, statSync } from "node:fs";
25
+ import { isAbsolute, join, relative, resolve } from "node:path";
24
26
  import { promisify } from "node:util";
25
27
  import { loadAll } from "js-yaml";
28
+ import { readKustomizationFile } from "../helm-references.js";
26
29
  const execAsync = promisify(exec);
27
30
  export const defaultKustomizeRunner = (command) => execAsync(command, { maxBuffer: 64 * 1024 * 1024 });
28
31
  /** Single-quote shell escaping, as helm-upgrade quotes its argv. */
@@ -30,8 +33,91 @@ function q(v) {
30
33
  return `'${v.replace(/'/g, "'\\''")}'`;
31
34
  }
32
35
  /** The exact render command, standalone binary first. Pure; exported for tests. */
33
- export function renderCommand(dir, tool = "kustomize") {
34
- return tool === "kustomize" ? `kustomize build ${q(dir)}` : `kubectl kustomize ${q(dir)}`;
36
+ export function renderCommand(dir, tool = "kustomize", helm = {}) {
37
+ const flags = helm.enableHelm ? ` --enable-helm${helm.helmCommand ? ` --helm-command ${q(helm.helmCommand)}` : ""}` : "";
38
+ return tool === "kustomize" ? `kustomize build${flags} ${q(dir)}` : `kubectl kustomize${flags} ${q(dir)}`;
39
+ }
40
+ /**
41
+ * A kustomization names a chart and the render was not allowed to inflate it
42
+ * (`enableHelm` unset). A class of its own so the workspace graph reader tells
43
+ * it from a render the binary ran and refused.
44
+ */
45
+ export class KustomizeHelmDisabledError extends Error {
46
+ constructor(message) {
47
+ super(message);
48
+ this.name = "KustomizeHelmDisabledError";
49
+ }
50
+ }
51
+ /**
52
+ * Helm inflation was asked for and a chart could not be had: it is not in the
53
+ * chart home and `fetchCharts` is off, or helm failed on it. The member reader
54
+ * keeps the Helm nodes it read as data when it sees this.
55
+ */
56
+ export class KustomizeHelmRenderError extends Error {
57
+ constructor(message) {
58
+ super(message);
59
+ this.name = "KustomizeHelmRenderError";
60
+ }
61
+ }
62
+ /** Every `helmCharts` entry of the kustomization at `dir` and of the local directories it lists in `resources`, `bases` and `components`. */
63
+ function helmChartEntries(dir, seen = new Set()) {
64
+ const root = resolve(dir);
65
+ if (seen.has(root))
66
+ return [];
67
+ seen.add(root);
68
+ const read = readKustomizationFile(root);
69
+ if (!read)
70
+ return [];
71
+ const { doc } = read;
72
+ const entries = [];
73
+ const globals = doc.helmGlobals && typeof doc.helmGlobals === "object" && !Array.isArray(doc.helmGlobals) ? doc.helmGlobals : {};
74
+ const home = typeof globals.chartHome === "string" && globals.chartHome !== "" ? globals.chartHome : "charts";
75
+ for (const c of Array.isArray(doc.helmCharts) ? doc.helmCharts : []) {
76
+ if (!c || typeof c !== "object" || Array.isArray(c))
77
+ continue;
78
+ const e = c;
79
+ if (typeof e.name !== "string" || e.name === "")
80
+ continue;
81
+ entries.push({ dir: root, name: e.name, version: typeof e.version === "string" ? e.version : "", chartHome: isAbsolute(home) ? home : join(root, home) });
82
+ }
83
+ for (const key of ["resources", "bases", "components"]) {
84
+ for (const item of Array.isArray(doc[key]) ? doc[key] : []) {
85
+ if (typeof item !== "string" || /^[a-z][a-z0-9+.-]*:\/\//i.test(item) || item.includes("::") || item.startsWith("git@"))
86
+ continue;
87
+ const child = resolve(root, item);
88
+ if (existsSync(child) && statSync(child).isDirectory())
89
+ entries.push(...helmChartEntries(child, seen));
90
+ }
91
+ }
92
+ return entries;
93
+ }
94
+ const chartLabel = (c) => `"${c.name}"${c.version ? ` ${c.version}` : ""}`;
95
+ /**
96
+ * Check a render's Helm settings before any subprocess runs. With inflation
97
+ * off, a kustomization that has `helmCharts` is refused here, naming the
98
+ * charts and the option. With it on and `fetchCharts` off, a chart that is
99
+ * not in its chart home is refused naming the chart and the directory it is
100
+ * expected in, so a render with no network says what is missing and never
101
+ * starts a pull. Kustomizations the root lists are checked too.
102
+ */
103
+ export function checkHelmOptions(dir, helm = {}) {
104
+ const charts = helmChartEntries(dir);
105
+ if (charts.length === 0)
106
+ return;
107
+ if (!helm.enableHelm) {
108
+ throw new KustomizeHelmDisabledError(`Kustomization "${dir}" names Helm charts (${charts.map(chartLabel).join(", ")}), which kustomize renders only with --enable-helm. ` +
109
+ `Set enableHelm: true on the entry (k8s.kustomize.roots, or the member's k8s.member) to allow it; kustomize pulls a chart that is not in its chart home, so also set fetchCharts: true to allow the network.`);
110
+ }
111
+ if (helm.fetchCharts)
112
+ return;
113
+ // kustomize uses `<chartHome>/<name>`, and puts a chart it pulled at `<chartHome>/<name>-<version>/<name>`.
114
+ const missing = charts.filter((c) => !existsSync(join(c.chartHome, c.name)) && !(c.version && existsSync(join(c.chartHome, `${c.name}-${c.version}`, c.name))));
115
+ if (missing.length > 0) {
116
+ const first = missing[0];
117
+ throw new KustomizeHelmRenderError(`Kustomization "${dir}" names Helm chart ${chartLabel(first)}${missing.length > 1 ? ` and ${missing.length - 1} more (${missing.slice(1).map(chartLabel).join(", ")})` : ""}, ` +
118
+ `which is not in the chart home (${relative(resolve(dir), join(first.chartHome, first.name)) || "."} was expected), and fetching charts is off, so no network is used. ` +
119
+ `Put the chart there, or set fetchCharts: true to let kustomize pull it from its repository.`);
120
+ }
35
121
  }
36
122
  /**
37
123
  * Neither `kustomize` nor `kubectl` is installed. A class of its own so a
@@ -47,24 +133,45 @@ export class KustomizeBinaryMissingError extends Error {
47
133
  /** Does this error mean "the binary is not installed" (vs "the render failed")? */
48
134
  function isMissingBinary(err) {
49
135
  const message = err instanceof Error ? err.message : String(err);
136
+ // Go's "exec: \"helm\": executable file not found" is kustomize reporting a missing helm, not a missing kustomize.
137
+ if (/executable file not found/.test(message))
138
+ return false;
50
139
  return /ENOENT|not found|command not found|127/.test(message);
51
140
  }
141
+ /**
142
+ * A failure from the binary that is about Helm gets a message that names the
143
+ * option or the chart; any other failure is kustomize's own and passes through.
144
+ * The pre-check reads the root and the directories it lists, so this catches
145
+ * what it cannot see: a base that is a remote reference, or a chart helm
146
+ * itself refuses.
147
+ */
148
+ function refineHelmFailure(dir, err, helm) {
149
+ const text = err instanceof Error ? err.message : String(err);
150
+ if (!helm.enableHelm && /must specify --enable-helm/.test(text)) {
151
+ return new KustomizeHelmDisabledError(`Kustomization "${dir}" names Helm charts, which kustomize renders only with --enable-helm. Set enableHelm: true on the entry to allow it. kustomize said: ${text}`);
152
+ }
153
+ if (helm.enableHelm && /helm|chart/i.test(text) && helmChartEntries(dir).length > 0) {
154
+ return new KustomizeHelmRenderError(`Kustomization "${dir}" has Helm charts and helm failed on them${helm.fetchCharts ? "" : " (fetching charts is off)"}. kustomize said: ${text}`);
155
+ }
156
+ return err;
157
+ }
52
158
  /**
53
159
  * Render the kustomization at `dir` and parse the emitted YAML into document
54
160
  * objects. Falls back to kubectl's vendored kustomize when the standalone
55
161
  * binary is missing; when both binaries are missing, fails with a message
56
162
  * naming them.
57
163
  */
58
- export async function renderKustomizeDocuments(dir, run = defaultKustomizeRunner) {
164
+ export async function renderKustomizeDocuments(dir, run = defaultKustomizeRunner, helm = {}) {
165
+ checkHelmOptions(dir, helm);
59
166
  let stdout;
60
167
  try {
61
- ({ stdout } = await run(renderCommand(dir, "kustomize")));
168
+ ({ stdout } = await run(renderCommand(dir, "kustomize", helm)));
62
169
  }
63
170
  catch (err) {
64
171
  if (!isMissingBinary(err))
65
- throw err;
172
+ throw refineHelmFailure(dir, err, helm);
66
173
  try {
67
- ({ stdout } = await run(renderCommand(dir, "kubectl")));
174
+ ({ stdout } = await run(renderCommand(dir, "kubectl", helm)));
68
175
  }
69
176
  catch (err2) {
70
177
  if (isMissingBinary(err2)) {
@@ -72,7 +179,7 @@ export async function renderKustomizeDocuments(dir, run = defaultKustomizeRunner
72
179
  `(whose vendored \`kubectl kustomize\` is the fallback) was found on PATH. ` +
73
180
  `Install kustomize or kubectl and retry.`);
74
181
  }
75
- throw err2;
182
+ throw refineHelmFailure(dir, err2, helm);
76
183
  }
77
184
  }
78
185
  const documents = [];
@@ -1,14 +1,14 @@
1
1
  import type { Declarable } from "@intentius/chant/declarable";
2
- import { type KustomizeRunner } from "./render.js";
2
+ import { type KustomizeHelmOptions, type KustomizeRunner } from "./render.js";
3
3
  import { type RenderedPatch } from "../patch/rendered-patch.js";
4
4
  /**
5
5
  * One `k8s.kustomize.roots` entry: a directory, or a directory plus patches
6
6
  * applied to its rendered documents (#3566).
7
7
  */
8
- export type KustomizeRootEntry = string | {
8
+ export type KustomizeRootEntry = string | ({
9
9
  path: string;
10
10
  patches?: RenderedPatch[];
11
- };
11
+ } & KustomizeHelmOptions);
12
12
  export interface KustomizeRootsResult {
13
13
  entities: Map<string, Declarable>;
14
14
  warnings: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../src/kustomize/root.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAoD,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAElG,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEnF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC;AAItF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,uFAAuF;IACvF,WAAW,EAAE,MAAM,CAAC;IACpB,6FAA6F;IAC7F,KAAK,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACrC,2EAA2E;IAC3E,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAoChC"}
1
+ {"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../src/kustomize/root.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAoD,KAAK,oBAAoB,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAE7H,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEnF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAA;CAAE,GAAG,oBAAoB,CAAC,CAAC;AAI/G,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,uFAAuF;IACvF,WAAW,EAAE,MAAM,CAAC;IACpB,6FAA6F;IAC7F,KAAK,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACrC,2EAA2E;IAC3E,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqChC"}
@@ -20,6 +20,10 @@
20
20
  * - **Deterministic**: entity names derive from the root dir plus each
21
21
  * document's kind/name/namespace, disambiguated in render order — the same
22
22
  * overlay renders the same entity set every build.
23
+ * - **Helm is opt-in** (#5112): a root with `helmCharts` renders only with
24
+ * `enableHelm: true` on its entry, and a chart that is not already in the
25
+ * chart home is pulled only with `fetchCharts: true` (the one setting that
26
+ * reaches the network).
23
27
  * - **Fail loudly, not weirdly**: a root that doesn't exist, or a dir with no
24
28
  * kustomization file, refuses with the path in the message before any
25
29
  * subprocess runs — offline, the failure mode is a sentence, never a
@@ -42,6 +46,7 @@ export async function renderKustomizeRoots(opts) {
42
46
  for (const entry of opts.roots) {
43
47
  const root = typeof entry === "string" ? entry : entry.path;
44
48
  const patches = typeof entry === "string" ? undefined : entry.patches;
49
+ const helm = typeof entry === "string" ? {} : { enableHelm: entry.enableHelm, helmCommand: entry.helmCommand, fetchCharts: entry.fetchCharts };
45
50
  const rootDir = isAbsolute(root) ? root : resolve(opts.projectRoot, root);
46
51
  // The label rendered docs carry as provenance: the declared (relative)
47
52
  // form when possible, so it names the overlay the way the config does.
@@ -53,7 +58,7 @@ export async function renderKustomizeRoots(opts) {
53
58
  throw new Error(`k8s.kustomize.roots entry "${root}": ${rootDir} contains no kustomization file ` +
54
59
  `(expected one of ${KUSTOMIZATION_FILES.join(", ")})`);
55
60
  }
56
- const rendered = await renderKustomizeDocuments(rootDir, run);
61
+ const rendered = await renderKustomizeDocuments(rootDir, run, helm);
57
62
  const documents = applyRenderedPatches(rendered, patches, `kustomize root "${rootLabel}"`);
58
63
  for (const doc of documents) {
59
64
  const entity = renderedManifestEntity(doc, rootLabel);
@@ -19,6 +19,9 @@ export declare function manifestsOfKind(manifests: K8sManifest[], kind: string):
19
19
  /**
20
20
  * Read a string field from a Secret's stringData or data block.
21
21
  * (Argo cluster Secrets conventionally use stringData.)
22
+ *
23
+ * A value the live reader masked is not a value: it reads as absent, so a
24
+ * masked `name` or `server` never registers a cluster called "<masked>" or "[REDACTED]".
22
25
  */
23
26
  export declare function secretField(manifest: K8sManifest, key: string): string | undefined;
24
27
  /** True if the Secret is labelled as an Argo cluster registration. */
@@ -1 +1 @@
1
- {"version":3,"file":"argo-helpers.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/argo-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAElE,uDAAuD;AACvD,eAAO,MAAM,iBAAiB,mCAAmC,CAAC;AAClE,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,6EAA6E;A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KED } from "@intentius/chant/deep-observation";
1
2
  import { docsToManifests } from "./k8s-helpers.js";
3
+ /** What the live lister (`<masked>`) and the deep observation (`[REDACTED]`) leave where a value was. */
4
+ const MASKED_VALUES = new Set([MASKED, "<masked>"]);
2
5
  /** The always-present, in-cluster Argo destination. */
3
6
  export const IN_CLUSTER_SERVER = "https://kubernetes.default.svc";
4
7
  export const IN_CLUSTER_NAME = "in-cluster";
@@ -15,15 +18,18 @@ export function manifestsOfKind(manifests, kind) {
15
18
  /**
16
19
  * Read a string field from a Secret's stringData or data block.
17
20
  * (Argo cluster Secrets conventionally use stringData.)
21
+ *
22
+ * A value the live reader masked is not a value: it reads as absent, so a
23
+ * masked `name` or `server` never registers a cluster called "<masked>" or "[REDACTED]".
18
24
  */
19
25
  export function secretField(manifest, key) {
20
26
  const stringData = manifest.stringData;
21
27
  const data = manifest.data;
22
28
  const fromStringData = stringData?.[key];
23
- if (typeof fromStringData === "string")
29
+ if (typeof fromStringData === "string" && !MASKED_VALUES.has(fromStringData))
24
30
  return fromStringData;
25
31
  const fromData = data?.[key];
26
- if (typeof fromData === "string")
32
+ if (typeof fromData === "string" && !MASKED_VALUES.has(fromData))
27
33
  return fromData;
28
34
  return undefined;
29
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"argo002.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/argo002.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAG9G,eAAO,MAAM,OAAO,EAAE,cAkCrB,CAAC"}
1
+ {"version":3,"file":"argo002.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/argo002.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAI9G,eAAO,MAAM,OAAO,EAAE,cAkCrB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { allManifests, manifestsOfKind } from "./argo-helpers.js";
2
+ import { nameOf } from "./k8s-helpers.js";
2
3
  export const argo002 = {
3
4
  id: "ARGO002",
4
5
  description: "Application.spec.project must reference a declared AppProject (or the built-in default)",
@@ -12,7 +13,7 @@ export const argo002 = {
12
13
  declaredProjects.add("default");
13
14
  for (const app of manifestsOfKind(manifests, "Application")) {
14
15
  const project = app.spec?.project;
15
- const name = app.metadata?.name ?? "Application";
16
+ const name = nameOf(app, "Application");
16
17
  // No project set → defaults to `default` at sync time; not this check's job.
17
18
  if (typeof project !== "string" || project === "")
18
19
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"argo003.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/argo003.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAU9G,eAAO,MAAM,OAAO,EAAE,cA0DrB,CAAC"}
1
+ {"version":3,"file":"argo003.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/argo003.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAW9G,eAAO,MAAM,OAAO,EAAE,cA0DrB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { allManifests, manifestsOfKind, isClusterSecret, secretField, IN_CLUSTER_SERVER, IN_CLUSTER_NAME, } from "./argo-helpers.js";
2
+ import { nameOf } from "./k8s-helpers.js";
2
3
  export const argo003 = {
3
4
  id: "ARGO003",
4
5
  description: "Application.spec.destination must reference a registered cluster or the in-cluster target",
@@ -16,7 +17,7 @@ export const argo003 = {
16
17
  registeredNames.add(name);
17
18
  }
18
19
  for (const app of manifestsOfKind(manifests, "Application")) {
19
- const name = app.metadata?.name ?? "Application";
20
+ const name = nameOf(app, "Application");
20
21
  const destination = app.spec?.destination;
21
22
  if (!destination || (destination.server === undefined && destination.name === undefined)) {
22
23
  diagnostics.push({
@@ -1 +1 @@
1
- {"version":3,"file":"argo005.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/argo005.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAY9G,eAAO,MAAM,OAAO,EAAE,cA+BrB,CAAC"}
1
+ {"version":3,"file":"argo005.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/argo005.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAc9G,eAAO,MAAM,OAAO,EAAE,cA0CrB,CAAC"}
@@ -2,10 +2,23 @@
2
2
  * ARGO005: Application source.path should point at an existing directory (warn)
3
3
  *
4
4
  * When an Argo `Application` syncs from a git source it names a `source.path`
5
- * inside the repo. In the common monorepo layout — Argo watches the same repo
6
- * Chant builds — that path is relative to the build root, so a typo'd or moved
7
- * path surfaces as a sync error only after deploy. This check warns when the
8
- * path doesn't resolve to a directory under the build root.
5
+ * inside the repository `source.repoURL` names. This check warns when the path
6
+ * does not resolve to a directory in the tree being read.
7
+ *
8
+ * Which tree depends on the command:
9
+ *
10
+ * - `chant build` and `chant lint` read the project, so a relative path
11
+ * resolves against the project root (the directory of the project config).
12
+ * The common monorepo layout, where Argo watches the same repo Chant builds,
13
+ * is the one this assumes.
14
+ * - `chant audit <dir>` reads a tree that need not be the working directory.
15
+ * The path resolves against the root of the checkout the audited directory
16
+ * is in, never the working directory, and only when that checkout's `origin`
17
+ * remote is the repository `repoURL` names. When the remote names another
18
+ * repository the path lives in a tree that is not on disk and the check is
19
+ * silent. A tree with no `origin` (an extracted archive) resolves against
20
+ * the audited directory. A remote tree fetch has nothing on disk and gets no
21
+ * findings. The resolution is `resolveRepoPath` in core.
9
22
  *
10
23
  * It is a warning, not an error: Applications that sync from a *different*
11
24
  * remote repo legitimately reference paths that don't exist locally. Helm chart
@@ -13,10 +26,12 @@
13
26
  */
14
27
  import { existsSync, statSync } from "fs";
15
28
  import { isAbsolute, resolve } from "path";
29
+ import { resolveRepoPath } from "@intentius/chant/repo-path";
16
30
  import { allManifests, manifestsOfKind } from "./argo-helpers.js";
17
- function dirExists(path) {
31
+ import { nameOf } from "./k8s-helpers.js";
32
+ function dirExists(base, path) {
18
33
  try {
19
- const full = isAbsolute(path) ? path : resolve(process.cwd(), path);
34
+ const full = isAbsolute(path) ? path : resolve(base, path);
20
35
  return existsSync(full) && statSync(full).isDirectory();
21
36
  }
22
37
  catch {
@@ -29,7 +44,7 @@ export const argo005 = {
29
44
  check(ctx) {
30
45
  const diagnostics = [];
31
46
  for (const app of manifestsOfKind(allManifests(ctx), "Application")) {
32
- const name = app.metadata?.name ?? "Application";
47
+ const name = nameOf(app, "Application");
33
48
  const source = app.spec?.source;
34
49
  if (!source)
35
50
  continue;
@@ -39,12 +54,24 @@ export const argo005 = {
39
54
  const path = source.path;
40
55
  if (typeof path !== "string" || path === "")
41
56
  continue;
42
- if (dirExists(path))
57
+ let where = "under the build root";
58
+ if (ctx.audit) {
59
+ // No tree on disk (a remote fetch): nothing to resolve against.
60
+ if (ctx.audit.root === undefined)
61
+ continue;
62
+ const repoURL = typeof source.repoURL === "string" ? source.repoURL : undefined;
63
+ const found = resolveRepoPath(ctx.audit.root, repoURL, path);
64
+ if (found.status !== "missing")
65
+ continue;
66
+ where = found.path === path ? "in the audited repository" : `in the audited repository (looked for "${found.path}" from its root)`;
67
+ }
68
+ else if (dirExists(ctx.projectDir ?? process.cwd(), path)) {
43
69
  continue;
70
+ }
44
71
  diagnostics.push({
45
72
  checkId: "ARGO005",
46
73
  severity: "warning",
47
- message: `Application "${name}" source.path "${path}" does not resolve to a directory under the build root. Confirm the path (or ignore if it lives in a different repo).`,
74
+ message: `Application "${name}" source.path "${path}" does not resolve to a directory ${where}. Confirm the path (or ignore if it lives in a different repo).`,
48
75
  entity: name,
49
76
  lexicon: "k8s",
50
77
  });
@@ -48,6 +48,6 @@ export declare function validateSpec(value: unknown, schema: CrdFieldSchema, pat
48
48
  export declare function levenshtein(a: string, b: string): number;
49
49
  /** Closest known field within Levenshtein distance 3 (case-insensitive), if any. */
50
50
  export declare function suggestField(unknown: string, known: string[]): string | undefined;
51
- /** `metadata.name` or the kind, for diagnostics. */
51
+ /** `metadata.name` when it is a string, else the kind, for diagnostics. */
52
52
  export declare function resourceLabel(manifest: K8sManifest): string;
53
53
  //# sourceMappingURL=crd-schema-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crd-schema-helpers.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/crd-schema-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAGlE,YAAY,EAAE,cAAc,EAAE,CAAC;AAgB/B;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAkBlE;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI,GAAG,IAAI,CAEvF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,GAAG,cAAc,GAAG,SAAS,CAM/E;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,GAAG,EAAE,gBAAgB,GAAG,KAAK,CAAC;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC,CAO/G;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,GAAG,eAAe,CAAC;IACxC,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH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AI,EAAE,eAAe,GAAG,eAAe,CAAC;IACxC,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,SAAS,GAAG,WAAW,EAAE,CAIjG;AAgGD,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAcxD;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAWjF;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAE3D"}
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import { createRequire } from "module";
14
14
  import { moduleSourceUrl } from "@intentius/chant/module-source";
15
- import { docsToManifests } from "./k8s-helpers.js";
15
+ import { docsToManifests, nameOf } from "./k8s-helpers.js";
16
16
  import { projectSpecSchema } from "../../project-kinds.js";
17
17
  let cachedRegistry = null;
18
18
  /** Registry key: `<apiVersion>/<kind>`, the pair a manifest carries verbatim. */
@@ -208,7 +208,7 @@ export function suggestField(unknown, known) {
208
208
  }
209
209
  return best;
210
210
  }
211
- /** `metadata.name` or the kind, for diagnostics. */
211
+ /** `metadata.name` when it is a string, else the kind, for diagnostics. */
212
212
  export function resourceLabel(manifest) {
213
- return manifest.metadata?.name ?? manifest.kind ?? "resource";
213
+ return nameOf(manifest, manifest.kind ?? "resource");
214
214
  }
@@ -1 +1 @@
1
- {"version":3,"file":"flux002.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/flux002.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAS9G,eAAO,MAAM,OAAO,EAAE,cAwDrB,CAAC"}
1
+ {"version":3,"file":"flux002.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/flux002.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAU9G,eAAO,MAAM,OAAO,EAAE,cAwDrB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { allManifests, manifestsOfKind } from "./argo-helpers.js";
2
+ import { nameOf } from "./k8s-helpers.js";
2
3
  /** Source kinds the kustomize-controller can reconcile from. */
3
4
  const SOURCE_KINDS = ["GitRepository", "OCIRepository", "Bucket"];
4
5
  /** The GitRepository `flux bootstrap` creates alongside the controllers. */
@@ -26,7 +27,7 @@ export const flux002 = {
26
27
  const apiVersion = kustomization.apiVersion;
27
28
  if (typeof apiVersion === "string" && !apiVersion.startsWith("kustomize.toolkit.fluxcd.io/"))
28
29
  continue;
29
- const name = kustomization.metadata?.name ?? "Kustomization";
30
+ const name = nameOf(kustomization, "Kustomization");
30
31
  const sourceRef = kustomization.spec?.sourceRef;
31
32
  if (!sourceRef || typeof sourceRef.name !== "string" || sourceRef.name === "") {
32
33
  diagnostics.push({
@@ -1 +1 @@
1
- {"version":3,"file":"flux003.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/flux003.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAY9G,eAAO,MAAM,OAAO,EAAE,cAgDrB,CAAC"}
1
+ {"version":3,"file":"flux003.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/flux003.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,kCAAkC,CAAC;AAa9G,eAAO,MAAM,OAAO,EAAE,cAgDrB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { allManifests, manifestsOfKind } from "./argo-helpers.js";
2
+ import { nameOf } from "./k8s-helpers.js";
2
3
  /** Flux Kustomizations only — the kustomize.config.k8s.io kind shares the name. */
3
4
  function fluxKustomizations(manifests) {
4
5
  return manifestsOfKind(manifests, "Kustomization").filter((m) => {
@@ -16,7 +17,7 @@ export const flux003 = {
16
17
  .map((k) => k.metadata?.name)
17
18
  .filter((n) => typeof n === "string"));
18
19
  for (const kustomization of kustomizations) {
19
- const name = kustomization.metadata?.name ?? "Kustomization";
20
+ const name = nameOf(kustomization, "Kustomization");
20
21
  const dependsOn = kustomization.spec?.dependsOn;
21
22
  if (!Array.isArray(dependsOn))
22
23
  continue;
@@ -75,6 +75,31 @@ export interface K8sContainer {
75
75
  * rather than silently returning no manifests.
76
76
  */
77
77
  export declare function docsToManifests(ctx: PostSynthContext): K8sManifest[];
78
+ /**
79
+ * What a `metadata.name` that is not a string is, in words a finding can use.
80
+ * Undefined when the name is absent or a string.
81
+ *
82
+ * The usual cause is a template placeholder: `name: {{name}}` is a YAML flow
83
+ * mapping whose key is another mapping, so the parser hands back a map whose
84
+ * only key is the stringified inner map. A shell script or a templating step
85
+ * fills those files in; the file is not a manifest until it has run.
86
+ */
87
+ export declare function describeNonStringName(manifest: {
88
+ metadata?: {
89
+ name?: unknown;
90
+ };
91
+ }): string | undefined;
92
+ /**
93
+ * The name a diagnostic prints and uses as its `entity`: `metadata.name` when
94
+ * it is a string, otherwise `fallback`. A name that is a map or a list would
95
+ * print as `[object Object]` and break the report's string `entity`, so it
96
+ * never gets through; {@link describeNonStringName} says what it was.
97
+ */
98
+ export declare function nameOf<F extends string | undefined>(manifest: {
99
+ metadata?: {
100
+ name?: unknown;
101
+ };
102
+ }, fallback: F): string | F;
78
103
  /**
79
104
  * Extract the pod spec from any workload manifest.
80
105
  *
@@ -89,6 +114,13 @@ export declare function extractPodSpec(manifest: K8sManifest): Record<string, un
89
114
  * Extract all containers (including init containers) from a workload manifest.
90
115
  */
91
116
  export declare function extractContainers(manifest: K8sManifest): K8sContainer[];
117
+ /**
118
+ * The place of a container in its workload, `<kind>/<field>[<index>]`, for a
119
+ * diagnostic's `locator`. It names the position, not the container, so a
120
+ * finding keeps its audit identity when the container is renamed. Pass a
121
+ * container that {@link extractContainers} returned.
122
+ */
123
+ export declare function containerLocator(manifest: K8sManifest, container: K8sContainer): string;
92
124
  /**
93
125
  * Workload kinds that contain pod templates.
94
126
  */
@@ -1 +1 @@
1
- {"version":3,"file":"k8s-helpers.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/k8s-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO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filter((d) => !d.error && !d.file)
39
39
  .map((d) => d.value);
40
40
  }
41
+ /**
42
+ * What a `metadata.name` that is not a string is, in words a finding can use.
43
+ * Undefined when the name is absent or a string.
44
+ *
45
+ * The usual cause is a template placeholder: `name: {{name}}` is a YAML flow
46
+ * mapping whose key is another mapping, so the parser hands back a map whose
47
+ * only key is the stringified inner map. A shell script or a templating step
48
+ * fills those files in; the file is not a manifest until it has run.
49
+ */
50
+ export function describeNonStringName(manifest) {
51
+ const name = manifest.metadata?.name;
52
+ if (name === undefined || name === null || typeof name === "string")
53
+ return undefined;
54
+ if (Array.isArray(name))
55
+ return "a list";
56
+ if (typeof name === "object") {
57
+ const keys = Object.keys(name);
58
+ if (keys.length === 1 && keys[0] === "[object Object]") {
59
+ return "a map, which is what YAML makes of a {{placeholder}}";
60
+ }
61
+ const shown = keys.slice(0, 3).map((k) => JSON.stringify(k)).join(", ");
62
+ return keys.length === 0 ? "an empty map" : `a map with the key${keys.length > 1 ? "s" : ""} ${shown}${keys.length > 3 ? ", ..." : ""}`;
63
+ }
64
+ return `${typeof name} ${String(name)}`;
65
+ }
66
+ /**
67
+ * The name a diagnostic prints and uses as its `entity`: `metadata.name` when
68
+ * it is a string, otherwise `fallback`. A name that is a map or a list would
69
+ * print as `[object Object]` and break the report's string `entity`, so it
70
+ * never gets through; {@link describeNonStringName} says what it was.
71
+ */
72
+ export function nameOf(manifest, fallback) {
73
+ const name = manifest.metadata?.name;
74
+ if (typeof name === "string")
75
+ return name;
76
+ if (typeof name === "number" || typeof name === "boolean")
77
+ return String(name);
78
+ return fallback;
79
+ }
41
80
  /**
42
81
  * Extract the pod spec from any workload manifest.
43
82
  *
@@ -78,6 +117,8 @@ export function extractPodSpec(manifest) {
78
117
  return null;
79
118
  }
80
119
  }
120
+ /** Where each container extracted by {@link extractContainers} sits in its pod spec, e.g. `containers[1]`. */
121
+ const containerPaths = new WeakMap();
81
122
  /**
82
123
  * Extract all containers (including init containers) from a workload manifest.
83
124
  */
@@ -86,22 +127,28 @@ export function extractContainers(manifest) {
86
127
  if (!podSpec)
87
128
  return [];
88
129
  const containers = [];
89
- if (Array.isArray(podSpec.containers)) {
90
- for (const c of podSpec.containers) {
130
+ for (const field of ["containers", "initContainers"]) {
131
+ const list = podSpec[field];
132
+ if (!Array.isArray(list))
133
+ continue;
134
+ list.forEach((c, i) => {
91
135
  if (typeof c === "object" && c !== null) {
136
+ containerPaths.set(c, `${field}[${i}]`);
92
137
  containers.push(c);
93
138
  }
94
- }
95
- }
96
- if (Array.isArray(podSpec.initContainers)) {
97
- for (const c of podSpec.initContainers) {
98
- if (typeof c === "object" && c !== null) {
99
- containers.push(c);
100
- }
101
- }
139
+ });
102
140
  }
103
141
  return containers;
104
142
  }
143
+ /**
144
+ * The place of a container in its workload, `<kind>/<field>[<index>]`, for a
145
+ * diagnostic's `locator`. It names the position, not the container, so a
146
+ * finding keeps its audit identity when the container is renamed. Pass a
147
+ * container that {@link extractContainers} returned.
148
+ */
149
+ export function containerLocator(manifest, container) {
150
+ return `${manifest.kind ?? ""}/${containerPaths.get(container) ?? "containers"}`;
151
+ }
105
152
  /**
106
153
  * Workload kinds that contain pod templates.
107
154
  */