@intentius/chant-lexicon-k8s 0.124.97 → 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
package/dist/config.d.ts CHANGED
@@ -101,6 +101,17 @@ export interface K8sChantConfig {
101
101
  * An entry may also be `{ path, patches }`: the patches apply to the
102
102
  * rendered documents before they become entities (see `RenderedPatch`).
103
103
  *
104
+ * A kustomization with `helmCharts` renders only when asked (#5112).
105
+ * `enableHelm: true` passes `--enable-helm` to kustomize (and to `kubectl
106
+ * kustomize`), and `helmCommand` names the `helm` binary for
107
+ * `--helm-command`. Without `enableHelm` the root fails with a message that
108
+ * names the charts and this option. kustomize pulls a chart that is not
109
+ * already in the root's chart home (`helmGlobals.chartHome`, default
110
+ * `charts/`), which reaches the network, so that is its own switch:
111
+ * `fetchCharts: true` allows the pull, and without it a chart that is not in
112
+ * the chart home fails naming the chart, with no network used. A pull writes
113
+ * the chart into the root's directory.
114
+ *
104
115
  * ```ts
105
116
  * k8s: {
106
117
  * kustomize: {
@@ -117,12 +128,15 @@ export interface K8sChantConfig {
117
128
  roots?: Array<string | {
118
129
  path: string;
119
130
  patches?: RenderedPatch[];
131
+ enableHelm?: boolean;
132
+ helmCommand?: string;
133
+ fetchCharts?: boolean;
120
134
  }>;
121
135
  };
122
136
  /**
123
137
  * One workspace member read into the graph (#3179). `chant workspace graph`
124
138
  * writes this into the reader project it makes for a member of kind
125
- * `kustomize`, `argo-app` or `flux-kustomization`; it is not meant to be
139
+ * `kustomize`, `argo-app`, `flux-kustomization` or `manifests`; it is not meant to be
126
140
  * written by hand. `dir` is the member's directory, absolute; `label` names
127
141
  * the entities (`<label>/deploymentWeb`), the member's name.
128
142
  *
@@ -130,12 +144,21 @@ export interface K8sChantConfig {
130
144
  * neither installed the graph carries no objects for it and says why on
131
145
  * `meta.k8sMember` (`rendered: false`, `reason`); a render the binary ran
132
146
  * and refused still fails. An Argo or Flux member is read from its manifests
133
- * and needs no binary.
147
+ * and needs no binary. A `manifests` member keeps every document with an
148
+ * `apiVersion` and a `kind`.
134
149
  */
135
150
  member?: {
136
- kind: "kustomize" | "argo-app" | "flux-kustomization";
151
+ kind: "kustomize" | "argo-app" | "flux-kustomization" | "manifests";
137
152
  dir: string;
138
153
  label?: string;
154
+ /** Kustomize only: pass `--enable-helm` (#5112). Also read from the environment as `CHANT_K8S_ENABLE_HELM=1`, which is how `chant workspace graph` is told, since it writes this config itself. */
155
+ enableHelm?: boolean;
156
+ /** Kustomize only: the `helm` binary for `--helm-command`. Environment: `CHANT_K8S_HELM_COMMAND`. */
157
+ helmCommand?: string;
158
+ /** Kustomize only: let kustomize pull a chart that is not in the chart home, which uses the network. Environment: `CHANT_K8S_FETCH_CHARTS=1`. */
159
+ fetchCharts?: boolean;
160
+ /** The workspace root, absolute. A `manifests` member leaves out a directory a kustomization under it lists in `resources`. */
161
+ workspace?: string;
139
162
  };
140
163
  /**
141
164
  * Effect receipt settings (#2074, epic #1703).
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC7C;;;;;;;;;;;;;;;OAeG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,SAAS,CAAC,EAAE;QACV,mFAAmF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AW,CAAC,EAAE,OAAO,CAAC;QACtB,+HAA+H;QAC/H,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CAAC,EAAE;QACT,uEAAuE;QACvE,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAC9B;AAED,wEAAwE;AACxE,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE9G,OAAO,QAAQ,yBAAyB,CAAC;IACvC,UAAU,WAAW;QACnB,GAAG,CAAC,EAAE,cAAc,CAAC;KACtB;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,113 @@
1
+ import type { Declarable } from "@intentius/chant/declarable";
2
+ import type { IRNode } from "@intentius/chant/graph-ir";
3
+ import type { FileNode } from "@intentius/chant/graph-refs";
4
+ /** The key the stamp is written under on the object that names a chart. */
5
+ export declare const HELM_REFERENCES_KEY = "helmReferences";
6
+ /** Annotation on an object read out of a values file's `extraObjects`, valued with the file's workspace-relative path. */
7
+ export declare const HELM_VALUES_ANNOTATION = "chant.intentius.io/helm-values";
8
+ /** Node kind of a values file. The helm lexicon's `Helm::Values` type. */
9
+ export declare const HELM_VALUES_KIND = "Helm::Values";
10
+ /** One chart a repository serves at one version: what a chart node stands for. */
11
+ export interface HelmChartRef {
12
+ /** The chart repository URL without a trailing slash, or `flux:<namespace>/<name>` for a Flux `sourceRef` the catalog resolves to the repository's URL. */
13
+ repo: string;
14
+ chart: string;
15
+ /** As written; empty when the reference names no version. */
16
+ version: string;
17
+ }
18
+ /** What the reader leaves on an object that names a chart. */
19
+ export interface HelmReferences {
20
+ charts: Array<HelmChartRef & {
21
+ valuesFiles?: string[];
22
+ }>;
23
+ /** Workspace-relative, `/` separated: every values file the object names, resolved. */
24
+ valuesFiles: string[];
25
+ }
26
+ type Doc = Record<string, unknown>;
27
+ /** A repository URL as chart references compare it: no trailing slash. */
28
+ export declare function normalizeChartRepo(url: string): string;
29
+ /** `<repo without scheme>/<chart>@<version>`: the id suffix of a chart node, and what two references share when they name the same chart. */
30
+ export declare function helmChartKey(ref: HelmChartRef): string;
31
+ export interface HelmReadContext {
32
+ /** The workspace root, absolute. */
33
+ workspace: string;
34
+ /** The member's directory, absolute. */
35
+ dir: string;
36
+ }
37
+ /** The first kustomization file in `dir`, parsed, or undefined. */
38
+ export declare function readKustomizationFile(dir: string): {
39
+ file: string;
40
+ doc: Doc;
41
+ } | undefined;
42
+ /** Whether a kustomization names a chart: a non-empty `helmCharts` with a mapping in it. */
43
+ export declare function hasHelmCharts(doc: Doc): boolean;
44
+ /**
45
+ * The kustomization as a manifest document, for a directory whose
46
+ * kustomization names a chart, or undefined when it names none. The file has
47
+ * no `apiVersion` or `kind` of its own to require, so they are given their
48
+ * kustomize defaults, and the member's label names it.
49
+ */
50
+ export declare function kustomizationDocument(dir: string, label: string): Doc | undefined;
51
+ /**
52
+ * The document with `helmReferences` on it, when it names a chart or a values
53
+ * file. A document that names neither is returned as it is.
54
+ */
55
+ export declare function stampHelmReferences(doc: Doc, ctx: HelmReadContext): {
56
+ doc: Doc;
57
+ references?: HelmReferences;
58
+ };
59
+ /** A values file read as data. */
60
+ export interface HelmValuesRead {
61
+ /** Workspace-relative. */
62
+ path: string;
63
+ values: Doc;
64
+ }
65
+ /**
66
+ * Read a workspace-relative values file as YAML. Returns undefined, with a
67
+ * warning naming the file, when it is not a file, does not parse, or is not a
68
+ * mapping; a file that does not exist is not a warning, the reference to it is
69
+ * the dangling entry.
70
+ */
71
+ export declare function readValuesFile(workspace: string, path: string, warn: (message: string) => void): HelmValuesRead | undefined;
72
+ /** A values file's text read as YAML, as {@link readValuesFile} reads it: undefined, with a warning, when it does not parse or is not a mapping. */
73
+ export declare function parseValuesFile(path: string, text: string, warn: (message: string) => void): HelmValuesRead | undefined;
74
+ /**
75
+ * A values file as a node: the helm lexicon's `Helm::Values`, its `path`
76
+ * (workspace-relative, the name catalog rules join on), the charts that name
77
+ * it, and the values, as the file has them.
78
+ */
79
+ export declare function helmValuesEntity(read: HelmValuesRead, charts: HelmChartRef[]): Declarable;
80
+ /**
81
+ * Everything one member's documents say about charts: stamp each holder, and
82
+ * add a values node for each file a holder names that exists, and a manifest
83
+ * node for each object in those files' `extraObjects`. Returns the stamped
84
+ * documents, in order; the nodes go into `entities`.
85
+ */
86
+ export declare function readHelmReferences(opts: {
87
+ documents: Doc[];
88
+ ctx: HelmReadContext;
89
+ label: string;
90
+ entities: Map<string, Declarable>;
91
+ warnings: string[];
92
+ memberKind: string;
93
+ }): Doc[];
94
+ /**
95
+ * A generated Application (./application-set.ts) with the `helmReferences`
96
+ * stamp the reader gives one written by hand (#5094): the charts its
97
+ * sources name and its `$<ref>/` and source-relative values files, as
98
+ * workspace-relative paths. The graph makes it after every member is read,
99
+ * so the stamp is made here. Pure.
100
+ */
101
+ export declare function stampGeneratedApplication(doc: Doc): Doc;
102
+ /**
103
+ * The nodes the values files of a stamped generated Application make
104
+ * (#5094), as the reader makes them for one written by hand: a
105
+ * `Helm::Values` node for each file that exists and parses, keyed
106
+ * `values/<path>`, and a manifest node for each of its `extraObjects`,
107
+ * keyed `values/<path>/<kindName>`. A file a `Helm::Values` node of the
108
+ * Application's member already holds is not read again. `readFile` returns
109
+ * a workspace-relative file's text, or undefined when it is not there.
110
+ */
111
+ export declare function generatedValuesNodes(node: IRNode, readFile: (path: string) => string | undefined, nodes: readonly IRNode[]): FileNode[];
112
+ export {};
113
+ //# sourceMappingURL=helm-references.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helm-references.d.ts","sourceRoot":"","sources":["../src/helm-references.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAK5D,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AAEpD,0HAA0H;AAC1H,eAAO,MAAM,sBAAsB,mCAAmC,CAAC;AAEvE,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,2JAA2J;IAC3J,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,KAAK,CAAC,YAAY,GAAG;QAAE,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACzD,uFAAuF;IACvF,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAMnC,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,GA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B,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,CAQzF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,GAAG,EAAE,eAAe,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,GAAG,EAAE,CAuBR;AAsBD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAEvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,EAAE,CAiCvI"}
@@ -0,0 +1,389 @@
1
+ /**
2
+ * Helm charts and values files, read from manifests as data (#5100).
3
+ *
4
+ * Four places name a chart: a kustomization's `helmCharts`, an Argo CD
5
+ * Application or ApplicationSet source, a Flux `HelmRelease`, and a Terraform
6
+ * `helm_release`. Nothing here fetches a chart, renders one or runs a binary;
7
+ * it reads what the files say.
8
+ *
9
+ * ## What the reader leaves on a node
10
+ *
11
+ * {@link stampHelmReferences} puts a `helmReferences` key on the object that
12
+ * names a chart: the chart references it names ({@link HelmChartRef}), and the
13
+ * workspace-relative path of every values file it names. A kustomization with
14
+ * `helmCharts` is itself a node ({@link kustomizationDocument}), since the
15
+ * file is no manifest and no rendered object stands for it. The values files
16
+ * that exist and parse become `Helm::Values` nodes ({@link helmValuesEntity}),
17
+ * and a values file's `extraObjects` become manifest nodes of the same member,
18
+ * so the objects a chart is told to create are in the graph with the rest.
19
+ *
20
+ * The edges are the catalog's. A holder's `helmReferences.valuesFiles[]`
21
+ * names a `Helm::Values` node by its `path` (rules in ./reference-catalog.ts),
22
+ * so a file that does not exist is a dangling reference with its path. The
23
+ * chart nodes are shared by every member that names the chart, and are made
24
+ * by the helm lexicon's catalog from the stamps (`sharedNodes`,
25
+ * `@intentius/chant-lexicon-helm`), which can see every member at once.
26
+ *
27
+ * ## How a path resolves
28
+ *
29
+ * - A kustomization's `valuesFile` and `additionalValuesFiles` are relative to
30
+ * the kustomization's directory.
31
+ * - An Argo `$<ref>/path` in `helm.valueFiles` names a file in the repository
32
+ * of the source whose `ref` is `<ref>`. The checkout is one repository, so
33
+ * the path is read from the workspace root, whatever that source's
34
+ * `repoURL` says. If the repository is another one, the file is not there
35
+ * and the reference is dangling, with the path as written.
36
+ * - A relative `valueFiles` entry of a source with a git `path` is relative to
37
+ * that path, read from the workspace root. On a source with a `chart` it is
38
+ * inside the chart's package, which is not in the checkout, and is not read.
39
+ * - A path with template syntax (`{{ ... }}`) is not read: an ApplicationSet's
40
+ * templated paths are expanded by the generator issue, not here.
41
+ * - A path that leaves the workspace is not read, and is dangling.
42
+ */
43
+ import { existsSync, readFileSync, statSync } from "node:fs";
44
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
45
+ import { loadAll } from "js-yaml";
46
+ import { DECLARABLE_MARKER } from "@intentius/chant/declarable";
47
+ import { addRenderedEntity, renderedLogicalId, renderedManifestEntity } from "./kustomize/rendered-entity.js";
48
+ /** The key the stamp is written under on the object that names a chart. */
49
+ export const HELM_REFERENCES_KEY = "helmReferences";
50
+ /** Annotation on an object read out of a values file's `extraObjects`, valued with the file's workspace-relative path. */
51
+ export const HELM_VALUES_ANNOTATION = "chant.intentius.io/helm-values";
52
+ /** Node kind of a values file. The helm lexicon's `Helm::Values` type. */
53
+ export const HELM_VALUES_KIND = "Helm::Values";
54
+ const isMap = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
55
+ const str = (v) => (typeof v === "string" && v !== "" ? v : undefined);
56
+ const templated = (s) => s.includes("{{");
57
+ /** A repository URL as chart references compare it: no trailing slash. */
58
+ export function normalizeChartRepo(url) {
59
+ return url.trim().replace(/\/+$/, "");
60
+ }
61
+ /** `<repo without scheme>/<chart>@<version>`: the id suffix of a chart node, and what two references share when they name the same chart. */
62
+ export function helmChartKey(ref) {
63
+ return `${ref.repo.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "")}/${ref.chart}@${ref.version}`;
64
+ }
65
+ /** The values file a reference names, as the workspace names it, or undefined when it is not read (templated, outside the workspace). */
66
+ function workspacePath(workspace, abs) {
67
+ const rel = relative(workspace, abs);
68
+ if (rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel))
69
+ return undefined;
70
+ return rel.split(sep).join("/");
71
+ }
72
+ function chartOrNone(repo, chart, version) {
73
+ const r = str(repo);
74
+ const c = str(chart);
75
+ if (!r || !c || templated(r) || templated(c))
76
+ return undefined;
77
+ const v = typeof version === "string" ? version : typeof version === "number" ? String(version) : "";
78
+ return { repo: normalizeChartRepo(r), chart: c, version: templated(v) ? "" : v };
79
+ }
80
+ /** The sources of an Argo CD Application, or of an ApplicationSet's template. */
81
+ function argoSources(doc) {
82
+ const spec = isMap(doc.spec) ? doc.spec : {};
83
+ const holder = doc.kind === "ApplicationSet" ? (isMap(spec.template) && isMap(spec.template.spec) ? spec.template.spec : {}) : spec;
84
+ const list = Array.isArray(holder.sources) ? holder.sources : holder.source !== undefined ? [holder.source] : [];
85
+ return list.filter(isMap);
86
+ }
87
+ function argoFound(doc, ctx) {
88
+ const found = { charts: [], loose: [], outside: [] };
89
+ const sources = argoSources(doc);
90
+ const refs = new Set(sources.map((s) => str(s.ref)).filter((r) => r !== undefined));
91
+ for (const source of sources) {
92
+ const ref = chartOrNone(source.repoURL, source.chart, source.targetRevision);
93
+ const helm = isMap(source.helm) ? source.helm : {};
94
+ const files = [];
95
+ for (const entry of Array.isArray(helm.valueFiles) ? helm.valueFiles : []) {
96
+ const file = str(entry);
97
+ if (!file || templated(file) || /^[a-z][a-z0-9+.-]*:\/\//i.test(file))
98
+ continue;
99
+ let abs;
100
+ if (file.startsWith("$")) {
101
+ const slash = file.indexOf("/");
102
+ if (slash === -1 || !refs.has(file.slice(1, slash)))
103
+ continue;
104
+ abs = resolve(ctx.workspace, file.slice(slash + 1));
105
+ }
106
+ else if (str(source.path) && !str(source.chart) && !templated(String(source.path))) {
107
+ abs = resolve(ctx.workspace, String(source.path), file);
108
+ }
109
+ else {
110
+ continue;
111
+ }
112
+ const rel = workspacePath(ctx.workspace, abs);
113
+ if (rel === undefined)
114
+ found.outside.push(file);
115
+ else
116
+ files.push(rel);
117
+ }
118
+ if (ref)
119
+ found.charts.push({ ...ref, valuesFiles: files });
120
+ else
121
+ found.loose.push(...files);
122
+ }
123
+ return found;
124
+ }
125
+ function fluxFound(doc) {
126
+ const found = { charts: [], loose: [], outside: [] };
127
+ const spec = isMap(doc.spec) ? doc.spec : {};
128
+ const chartSpec = isMap(spec.chart) && isMap(spec.chart.spec) ? spec.chart.spec : {};
129
+ const chart = str(chartSpec.chart);
130
+ const source = isMap(chartSpec.sourceRef) ? chartSpec.sourceRef : {};
131
+ const name = str(source.name);
132
+ if (!chart || !name || source.kind !== "HelmRepository" || templated(chart) || templated(name))
133
+ return found;
134
+ const metadata = isMap(doc.metadata) ? doc.metadata : {};
135
+ const namespace = str(source.namespace) ?? str(metadata.namespace) ?? "default";
136
+ const version = typeof chartSpec.version === "string" && !templated(chartSpec.version) ? chartSpec.version : "";
137
+ found.charts.push({ repo: `flux:${namespace}/${name}`, chart, version, valuesFiles: [] });
138
+ return found;
139
+ }
140
+ /** The first kustomization file in `dir`, parsed, or undefined. */
141
+ export function readKustomizationFile(dir) {
142
+ for (const name of ["kustomization.yaml", "kustomization.yml", "Kustomization"]) {
143
+ const file = join(dir, name);
144
+ if (!existsSync(file) || !statSync(file).isFile())
145
+ continue;
146
+ try {
147
+ const doc = loadAll(readFileSync(file, "utf-8"))[0];
148
+ if (isMap(doc))
149
+ return { file, doc };
150
+ }
151
+ catch {
152
+ // A kustomization that does not parse is the render's to report.
153
+ }
154
+ }
155
+ return undefined;
156
+ }
157
+ /** Whether a kustomization names a chart: a non-empty `helmCharts` with a mapping in it. */
158
+ export function hasHelmCharts(doc) {
159
+ return Array.isArray(doc.helmCharts) && doc.helmCharts.some(isMap);
160
+ }
161
+ /**
162
+ * The kustomization as a manifest document, for a directory whose
163
+ * kustomization names a chart, or undefined when it names none. The file has
164
+ * no `apiVersion` or `kind` of its own to require, so they are given their
165
+ * kustomize defaults, and the member's label names it.
166
+ */
167
+ export function kustomizationDocument(dir, label) {
168
+ const read = readKustomizationFile(dir);
169
+ if (!read || !hasHelmCharts(read.doc))
170
+ return undefined;
171
+ const { apiVersion, kind, metadata, ...rest } = read.doc;
172
+ return {
173
+ apiVersion: str(apiVersion) ?? "kustomize.config.k8s.io/v1beta1",
174
+ kind: str(kind) ?? "Kustomization",
175
+ metadata: { ...(isMap(metadata) ? metadata : {}), name: label },
176
+ ...rest,
177
+ };
178
+ }
179
+ function kustomizationFound(doc, ctx) {
180
+ const found = { charts: [], loose: [], outside: [] };
181
+ for (const entry of Array.isArray(doc.helmCharts) ? doc.helmCharts : []) {
182
+ if (!isMap(entry))
183
+ continue;
184
+ const ref = chartOrNone(entry.repo, entry.name, entry.version);
185
+ const named = [entry.valuesFile, ...(Array.isArray(entry.additionalValuesFiles) ? entry.additionalValuesFiles : [])];
186
+ const files = [];
187
+ for (const f of named) {
188
+ const file = str(f);
189
+ if (!file || templated(file))
190
+ continue;
191
+ const rel = workspacePath(ctx.workspace, resolve(ctx.dir, file));
192
+ if (rel === undefined)
193
+ found.outside.push(file);
194
+ else
195
+ files.push(rel);
196
+ }
197
+ if (ref)
198
+ found.charts.push({ ...ref, valuesFiles: files });
199
+ else
200
+ found.loose.push(...files);
201
+ }
202
+ return found;
203
+ }
204
+ /** Whether a document is an object that can name a chart. */
205
+ function holderKind(doc) {
206
+ const api = str(doc.apiVersion) ?? "";
207
+ if (api.startsWith("argoproj.io/") && (doc.kind === "Application" || doc.kind === "ApplicationSet"))
208
+ return "argo";
209
+ if (api.startsWith("helm.toolkit.fluxcd.io/") && doc.kind === "HelmRelease")
210
+ return "flux";
211
+ if (api.startsWith("kustomize.config.k8s.io/") && doc.kind === "Kustomization")
212
+ return "kustomize";
213
+ return undefined;
214
+ }
215
+ /**
216
+ * The document with `helmReferences` on it, when it names a chart or a values
217
+ * file. A document that names neither is returned as it is.
218
+ */
219
+ export function stampHelmReferences(doc, ctx) {
220
+ const kind = holderKind(doc);
221
+ if (!kind)
222
+ return { doc };
223
+ const found = kind === "argo" ? argoFound(doc, ctx) : kind === "flux" ? fluxFound(doc) : kustomizationFound(doc, ctx);
224
+ const valuesFiles = [...new Set([...found.charts.flatMap((c) => c.valuesFiles), ...found.loose])].sort();
225
+ const lone = found.outside;
226
+ if (found.charts.length === 0 && valuesFiles.length === 0 && lone.length === 0)
227
+ return { doc };
228
+ const references = {
229
+ charts: found.charts.map((c) => ({ repo: c.repo, chart: c.chart, version: c.version, ...(c.valuesFiles.length > 0 ? { valuesFiles: c.valuesFiles } : {}) })),
230
+ valuesFiles: [...valuesFiles, ...lone],
231
+ };
232
+ return { doc: { ...doc, [HELM_REFERENCES_KEY]: references }, references };
233
+ }
234
+ /**
235
+ * Read a workspace-relative values file as YAML. Returns undefined, with a
236
+ * warning naming the file, when it is not a file, does not parse, or is not a
237
+ * mapping; a file that does not exist is not a warning, the reference to it is
238
+ * the dangling entry.
239
+ */
240
+ export function readValuesFile(workspace, path, warn) {
241
+ const abs = resolve(workspace, path);
242
+ if (!existsSync(abs) || !statSync(abs).isFile())
243
+ return undefined;
244
+ return parseValuesFile(path, readFileSync(abs, "utf-8"), warn);
245
+ }
246
+ /** A values file's text read as YAML, as {@link readValuesFile} reads it: undefined, with a warning, when it does not parse or is not a mapping. */
247
+ export function parseValuesFile(path, text, warn) {
248
+ try {
249
+ const doc = loadAll(text)[0];
250
+ if (doc === undefined || doc === null)
251
+ return { path, values: {} };
252
+ if (!isMap(doc)) {
253
+ warn(`values file ${path} is not a mapping and was skipped`);
254
+ return undefined;
255
+ }
256
+ return { path, values: doc };
257
+ }
258
+ catch (err) {
259
+ warn(`values file ${path} is not valid YAML and was skipped (${(err instanceof Error ? err.message : String(err)).split("\n")[0]})`);
260
+ return undefined;
261
+ }
262
+ }
263
+ /**
264
+ * A values file as a node: the helm lexicon's `Helm::Values`, its `path`
265
+ * (workspace-relative, the name catalog rules join on), the charts that name
266
+ * it, and the values, as the file has them.
267
+ */
268
+ export function helmValuesEntity(read, charts) {
269
+ return {
270
+ lexicon: "helm",
271
+ entityType: HELM_VALUES_KIND,
272
+ kind: "resource",
273
+ props: { path: read.path, ...(charts.length > 0 ? { charts } : {}), values: read.values },
274
+ [DECLARABLE_MARKER]: true,
275
+ };
276
+ }
277
+ /**
278
+ * Everything one member's documents say about charts: stamp each holder, and
279
+ * add a values node for each file a holder names that exists, and a manifest
280
+ * node for each object in those files' `extraObjects`. Returns the stamped
281
+ * documents, in order; the nodes go into `entities`.
282
+ */
283
+ export function readHelmReferences(opts) {
284
+ const { ctx, label, entities, warnings } = opts;
285
+ const files = new Map();
286
+ const stamped = opts.documents.map((document) => {
287
+ const { doc, references } = stampHelmReferences(document, ctx);
288
+ if (!references)
289
+ return doc;
290
+ for (const path of references.valuesFiles)
291
+ if (!files.has(path))
292
+ files.set(path, []);
293
+ for (const chart of references.charts) {
294
+ for (const path of chart.valuesFiles ?? []) {
295
+ const have = files.get(path);
296
+ if (!have.some((c) => helmChartKey(c) === helmChartKey(chart)))
297
+ have.push({ repo: chart.repo, chart: chart.chart, version: chart.version });
298
+ }
299
+ }
300
+ return doc;
301
+ });
302
+ for (const path of [...files.keys()].sort()) {
303
+ const read = readValuesFile(ctx.workspace, path, (m) => warnings.push(`${opts.memberKind} member "${label}": ${m}`));
304
+ if (!read)
305
+ continue;
306
+ entities.set(`${label}/values/${path}`, helmValuesEntity(read, files.get(path)));
307
+ for (const entity of extraObjectEntities(read))
308
+ addRenderedEntity(entities, label, entity);
309
+ }
310
+ return stamped;
311
+ }
312
+ /** The manifest entities of a values file's `extraObjects`, each annotated with the file's path. */
313
+ function extraObjectEntities(read) {
314
+ const extra = read.values.extraObjects;
315
+ const out = [];
316
+ for (const object of Array.isArray(extra) ? extra : []) {
317
+ if (!isMap(object))
318
+ continue;
319
+ if (typeof object.apiVersion !== "string" || typeof object.kind !== "string")
320
+ continue;
321
+ const entity = renderedManifestEntity(object, read.path, HELM_VALUES_ANNOTATION);
322
+ if (entity)
323
+ out.push(entity);
324
+ }
325
+ return out;
326
+ }
327
+ /**
328
+ * The root a generated Application's stamp is resolved against (#5094). The
329
+ * stamp holds workspace-relative paths, and resolving under a fixed root
330
+ * gives the same paths the reader gives, with no directory read.
331
+ */
332
+ const GENERATED_ROOT = resolve(sep, "chant-workspace");
333
+ /**
334
+ * A generated Application (./application-set.ts) with the `helmReferences`
335
+ * stamp the reader gives one written by hand (#5094): the charts its
336
+ * sources name and its `$<ref>/` and source-relative values files, as
337
+ * workspace-relative paths. The graph makes it after every member is read,
338
+ * so the stamp is made here. Pure.
339
+ */
340
+ export function stampGeneratedApplication(doc) {
341
+ return stampHelmReferences(doc, { workspace: GENERATED_ROOT, dir: GENERATED_ROOT }).doc;
342
+ }
343
+ /**
344
+ * The nodes the values files of a stamped generated Application make
345
+ * (#5094), as the reader makes them for one written by hand: a
346
+ * `Helm::Values` node for each file that exists and parses, keyed
347
+ * `values/<path>`, and a manifest node for each of its `extraObjects`,
348
+ * keyed `values/<path>/<kindName>`. A file a `Helm::Values` node of the
349
+ * Application's member already holds is not read again. `readFile` returns
350
+ * a workspace-relative file's text, or undefined when it is not there.
351
+ */
352
+ export function generatedValuesNodes(node, readFile, nodes) {
353
+ const refs = node.attrs[HELM_REFERENCES_KEY];
354
+ if (!isMap(refs) || !Array.isArray(refs.valuesFiles))
355
+ return [];
356
+ const member = node.member;
357
+ const held = new Set(nodes
358
+ .filter((n) => n.kind === HELM_VALUES_KIND && n.member === member)
359
+ .map((n) => n.attrs.path)
360
+ .filter((p) => typeof p === "string"));
361
+ const charts = Array.isArray(refs.charts) ? refs.charts : [];
362
+ const out = [];
363
+ for (const path of refs.valuesFiles) {
364
+ // A path that left the workspace stays in the stamp as written, to be dangling, and is not read.
365
+ if (typeof path !== "string" || held.has(path) || path.startsWith("$") || path.startsWith("/") || path.split("/").includes(".."))
366
+ continue;
367
+ const text = readFile(path);
368
+ if (text === undefined)
369
+ continue;
370
+ const read = parseValuesFile(path, text, () => { });
371
+ if (!read)
372
+ continue;
373
+ const named = charts.filter((c) => c.valuesFiles?.includes(path)).map((c) => ({ repo: c.repo, chart: c.chart, version: c.version }));
374
+ out.push({ key: `values/${path}`, kind: HELM_VALUES_KIND, lexicon: "helm", attrs: { path, ...(named.length > 0 ? { charts: named } : {}), values: read.values } });
375
+ const keys = new Set();
376
+ for (const entity of extraObjectEntities(read)) {
377
+ const metadata = entity.props.metadata;
378
+ const base = `values/${path}/${renderedLogicalId(entity.props.kind, str(metadata.name))}`;
379
+ let key = base;
380
+ if (keys.has(key) && str(metadata.namespace))
381
+ key = `${base}.${str(metadata.namespace)}`;
382
+ for (let n = 2; keys.has(key); n++)
383
+ key = `${base}~${n}`;
384
+ keys.add(key);
385
+ out.push({ key, kind: entity.entityType, lexicon: "k8s", attrs: entity.props });
386
+ }
387
+ }
388
+ return out;
389
+ }
@@ -21,10 +21,19 @@ export declare class K8sGenerator implements TypeScriptGenerator {
21
21
  */
22
22
  private maskedValueHelper;
23
23
  /**
24
- * Resolve a K8s type name to a constructor class name.
25
- * Falls back to extracting the last segment of the type.
24
+ * Resolve a resource to a constructor class name, or undefined when the
25
+ * lexicon exports none or the class builds another apiVersion than the
26
+ * resource has (the resource is written as a `k8sManifest`, see
27
+ * `importClassFor`).
26
28
  */
27
29
  private resolveClass;
30
+ /**
31
+ * An untyped resource: the whole manifest handed to `k8sManifest`, which
32
+ * the serializer writes as given. Property constructors do not apply, the
33
+ * kind's schema is unknown. Undefined when the apiVersion or kind cannot
34
+ * be found.
35
+ */
36
+ private emitManifest;
28
37
  private collectNestedConstructors;
29
38
  private emitProps;
30
39
  private emitValue;
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/import/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,gCAAgC,CAAC;AAwH7E;;GAEG;AACH,qBAAa,YAAa,YAAW,mBAAmB;IACtD,yFAAyF;IACzF,OAAO,CAAC,KAAK,CAA+B;IAE5C,sGAAsG;IACtG,OAAO,CAAC,eAAe,CAAS;IAEhC,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,aAAa,EAAE,CAqExC;IAED;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,yBAAyB;IAmCjC,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,SAAS;IA2BjB,OAAO,CAAC,oBAAoB;IAwB5B,OAAO,CAAC,WAAW;CAiCpB"}
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/import/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,gCAAgC,CAAC;AAyE7E;;GAEG;AACH,qBAAa,YAAa,YAAW,mBAAmB;IACtD,yFAAyF;IACzF,OAAO,CAAC,KAAK,CAA+B;IAE5C,sGAAsG;IACtG,OAAO,CAAC,eAAe,CAAS;IAEhC,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,aAAa,EAAE,CA8ExC;IAED;;;OAGG;IACH,OAAO,CAAC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