@intentius/chant-lexicon-k8s 0.100.0 → 0.102.0

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 (261) hide show
  1. package/dist/actions/apps.d.ts +4 -4
  2. package/dist/actions/apps.d.ts.map +1 -1
  3. package/dist/actions/core.d.ts +5 -5
  4. package/dist/actions/core.d.ts.map +1 -1
  5. package/dist/actions/networking.d.ts.map +1 -1
  6. package/dist/codegen/generate-typescript.d.ts +2 -2
  7. package/dist/codegen/generate-typescript.d.ts.map +1 -1
  8. package/dist/codegen/generate.d.ts.map +1 -1
  9. package/dist/codegen/naming.d.ts.map +1 -1
  10. package/dist/codegen/versions.d.ts.map +1 -1
  11. package/dist/components/capability-plugin.d.ts.map +1 -1
  12. package/dist/composites/catalog.d.ts.map +1 -1
  13. package/dist/composites/cockroachdb-cluster.d.ts +2 -2
  14. package/dist/composites/gke-otel-collector.d.ts.map +1 -1
  15. package/dist/composites/index.d.ts +1 -0
  16. package/dist/composites/index.d.ts.map +1 -1
  17. package/dist/composites/otel-collector-agent.d.ts +24 -2
  18. package/dist/composites/otel-collector-agent.d.ts.map +1 -1
  19. package/dist/composites/otel-collector-gateway.d.ts +37 -52
  20. package/dist/composites/otel-collector-gateway.d.ts.map +1 -1
  21. package/dist/composites/otel-collector-node.d.ts +88 -0
  22. package/dist/composites/otel-collector-node.d.ts.map +1 -0
  23. package/dist/composites/otel-collector-rbac.d.ts +74 -0
  24. package/dist/composites/otel-collector-rbac.d.ts.map +1 -0
  25. package/dist/composites/otel-collector-shape.d.ts +7 -0
  26. package/dist/composites/otel-collector-shape.d.ts.map +1 -1
  27. package/dist/composites/otel-collector.d.ts +17 -21
  28. package/dist/composites/otel-collector.d.ts.map +1 -1
  29. package/dist/composites/ray-cluster.d.ts +6 -6
  30. package/dist/composites/ray-job.d.ts +5 -5
  31. package/dist/composites/ray-service.d.ts +6 -6
  32. package/dist/crd/crd-sources.d.ts.map +1 -1
  33. package/dist/crd/loader.d.ts.map +1 -1
  34. package/dist/crd/oci-chart.d.ts +50 -0
  35. package/dist/crd/oci-chart.d.ts.map +1 -0
  36. package/dist/crd/types.d.ts +5 -0
  37. package/dist/crd/types.d.ts.map +1 -1
  38. package/dist/effect-receipt-row.d.ts.map +1 -1
  39. package/dist/generated/index.d.ts +752 -729
  40. package/dist/generated/index.d.ts.map +1 -1
  41. package/dist/import/embedded.d.ts +4 -2
  42. package/dist/import/embedded.d.ts.map +1 -1
  43. package/dist/import/generator.d.ts.map +1 -1
  44. package/dist/import/live-export.d.ts +5 -0
  45. package/dist/import/live-export.d.ts.map +1 -1
  46. package/dist/import/parser.d.ts.map +1 -1
  47. package/dist/import/testdata/embedded/fixtures.d.ts +6 -0
  48. package/dist/import/testdata/embedded/fixtures.d.ts.map +1 -1
  49. package/dist/integrity.json +8 -6
  50. package/dist/lint/audit-catalog.d.ts.map +1 -1
  51. package/dist/lint/post-synth/index.d.ts.map +1 -1
  52. package/dist/lint/post-synth/otel-placement-helpers.d.ts +5 -1
  53. package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
  54. package/dist/lint/post-synth/wk8604.d.ts +19 -0
  55. package/dist/lint/post-synth/wk8604.d.ts.map +1 -0
  56. package/dist/lint/post-synth/wk8605.d.ts +23 -0
  57. package/dist/lint/post-synth/wk8605.d.ts.map +1 -0
  58. package/dist/manifest.json +1 -1
  59. package/dist/meta.json +156 -17
  60. package/dist/okf/index.md +5 -0
  61. package/dist/okf/rules/WK8604.md +11 -0
  62. package/dist/okf/rules/WK8605.md +11 -0
  63. package/dist/okf/types/APIGroup.md +3 -3
  64. package/dist/okf/types/APIGroupList.md +1 -1
  65. package/dist/okf/types/APIResourceList.md +1 -1
  66. package/dist/okf/types/APIService.md +1 -1
  67. package/dist/okf/types/APIServiceList.md +2 -2
  68. package/dist/okf/types/APIVersions.md +1 -1
  69. package/dist/okf/types/BatchJob.md +1 -1
  70. package/dist/okf/types/CSIDriver.md +1 -1
  71. package/dist/okf/types/CSIDriverList.md +2 -2
  72. package/dist/okf/types/CSINode.md +1 -1
  73. package/dist/okf/types/CSINodeList.md +2 -2
  74. package/dist/okf/types/CSIStorageCapacity.md +2 -2
  75. package/dist/okf/types/CSIStorageCapacityList.md +2 -2
  76. package/dist/okf/types/CertificateSigningRequest.md +1 -1
  77. package/dist/okf/types/CertificateSigningRequestList.md +2 -2
  78. package/dist/okf/types/ClusterRole.md +1 -1
  79. package/dist/okf/types/ClusterRoleBindingList.md +2 -2
  80. package/dist/okf/types/ClusterRoleList.md +2 -2
  81. package/dist/okf/types/ClusterTrustBundle.md +1 -1
  82. package/dist/okf/types/ClusterTrustBundleList.md +2 -2
  83. package/dist/okf/types/ComponentStatus.md +1 -1
  84. package/dist/okf/types/ComponentStatusList.md +2 -2
  85. package/dist/okf/types/ConfigMapList.md +2 -2
  86. package/dist/okf/types/ControllerRevisionList.md +2 -2
  87. package/dist/okf/types/CoreEventList.md +2 -2
  88. package/dist/okf/types/CronJob.md +1 -1
  89. package/dist/okf/types/CronJobList.md +2 -2
  90. package/dist/okf/types/CustomResourceDefinition.md +1 -1
  91. package/dist/okf/types/CustomResourceDefinitionList.md +2 -2
  92. package/dist/okf/types/DaemonSet.md +1 -1
  93. package/dist/okf/types/DaemonSetList.md +2 -2
  94. package/dist/okf/types/DeleteOptions.md +1 -1
  95. package/dist/okf/types/Deploy.md +1 -1
  96. package/dist/okf/types/DeploymentList.md +2 -2
  97. package/dist/okf/types/DeviceClass.md +1 -1
  98. package/dist/okf/types/DeviceClassList.md +2 -2
  99. package/dist/okf/types/DeviceTaintRule.md +1 -1
  100. package/dist/okf/types/DeviceTaintRuleList.md +2 -2
  101. package/dist/okf/types/EndpointSlice.md +2 -2
  102. package/dist/okf/types/EndpointSliceList.md +2 -2
  103. package/dist/okf/types/Endpoints.md +1 -1
  104. package/dist/okf/types/EndpointsList.md +2 -2
  105. package/dist/okf/types/Event.md +2 -2
  106. package/dist/okf/types/EventsEvent.md +2 -2
  107. package/dist/okf/types/EventsEventList.md +2 -2
  108. package/dist/okf/types/Eviction.md +1 -1
  109. package/dist/okf/types/FlowSchema.md +1 -1
  110. package/dist/okf/types/FlowSchemaList.md +2 -2
  111. package/dist/okf/types/GrafanaDashboard.md +14 -0
  112. package/dist/okf/types/GrafanaDatasource.md +14 -0
  113. package/dist/okf/types/GrafanaFolder.md +14 -0
  114. package/dist/okf/types/HorizontalPodAutoscaler.md +1 -1
  115. package/dist/okf/types/HorizontalPodAutoscalerList.md +2 -2
  116. package/dist/okf/types/IPAddress.md +1 -1
  117. package/dist/okf/types/IPAddressList.md +2 -2
  118. package/dist/okf/types/Ing.md +1 -1
  119. package/dist/okf/types/IngressClass.md +1 -1
  120. package/dist/okf/types/IngressClassList.md +2 -2
  121. package/dist/okf/types/IngressList.md +2 -2
  122. package/dist/okf/types/JobList.md +2 -2
  123. package/dist/okf/types/Lease.md +1 -1
  124. package/dist/okf/types/LeaseCandidate.md +1 -1
  125. package/dist/okf/types/LeaseCandidateList.md +2 -2
  126. package/dist/okf/types/LeaseList.md +2 -2
  127. package/dist/okf/types/LimitRange.md +1 -1
  128. package/dist/okf/types/LimitRangeList.md +2 -2
  129. package/dist/okf/types/LocalSubjectAccessReview.md +1 -1
  130. package/dist/okf/types/MutatingAdmissionPolicy.md +1 -1
  131. package/dist/okf/types/MutatingAdmissionPolicyBinding.md +1 -1
  132. package/dist/okf/types/MutatingAdmissionPolicyBindingList.md +2 -2
  133. package/dist/okf/types/MutatingAdmissionPolicyList.md +2 -2
  134. package/dist/okf/types/MutatingWebhookConfiguration.md +1 -1
  135. package/dist/okf/types/MutatingWebhookConfigurationList.md +2 -2
  136. package/dist/okf/types/Namespace.md +1 -1
  137. package/dist/okf/types/NamespaceList.md +2 -2
  138. package/dist/okf/types/NetPol.md +1 -1
  139. package/dist/okf/types/NetworkPolicyList.md +2 -2
  140. package/dist/okf/types/Node.md +1 -1
  141. package/dist/okf/types/NodeList.md +2 -2
  142. package/dist/okf/types/PersistentVolume.md +1 -1
  143. package/dist/okf/types/PersistentVolumeClaimList.md +2 -2
  144. package/dist/okf/types/PersistentVolumeList.md +2 -2
  145. package/dist/okf/types/PodCertificateRequest.md +1 -1
  146. package/dist/okf/types/PodCertificateRequestList.md +2 -2
  147. package/dist/okf/types/PodDisruptionBudgetList.md +2 -2
  148. package/dist/okf/types/PodList.md +2 -2
  149. package/dist/okf/types/PodTemplateList.md +2 -2
  150. package/dist/okf/types/PriorityClassList.md +2 -2
  151. package/dist/okf/types/PriorityLevelConfiguration.md +1 -1
  152. package/dist/okf/types/PriorityLevelConfigurationList.md +2 -2
  153. package/dist/okf/types/ReplicaSet.md +1 -1
  154. package/dist/okf/types/ReplicaSetList.md +2 -2
  155. package/dist/okf/types/ReplicationController.md +1 -1
  156. package/dist/okf/types/ReplicationControllerList.md +2 -2
  157. package/dist/okf/types/ResourceClaim.md +1 -1
  158. package/dist/okf/types/ResourceClaimList.md +2 -2
  159. package/dist/okf/types/ResourceClaimTemplate.md +1 -1
  160. package/dist/okf/types/ResourceClaimTemplateList.md +2 -2
  161. package/dist/okf/types/ResourceQuota.md +1 -1
  162. package/dist/okf/types/ResourceQuotaList.md +2 -2
  163. package/dist/okf/types/ResourceSlice.md +1 -1
  164. package/dist/okf/types/ResourceSliceList.md +2 -2
  165. package/dist/okf/types/RoleBindingList.md +2 -2
  166. package/dist/okf/types/RoleList.md +2 -2
  167. package/dist/okf/types/RuntimeClass.md +2 -2
  168. package/dist/okf/types/RuntimeClassList.md +2 -2
  169. package/dist/okf/types/Scale.md +1 -1
  170. package/dist/okf/types/SecretList.md +2 -2
  171. package/dist/okf/types/SelfSubjectAccessReview.md +1 -1
  172. package/dist/okf/types/SelfSubjectRulesReview.md +1 -1
  173. package/dist/okf/types/Service.md +1 -1
  174. package/dist/okf/types/ServiceAccountList.md +2 -2
  175. package/dist/okf/types/ServiceCIDR.md +1 -1
  176. package/dist/okf/types/ServiceCIDRList.md +2 -2
  177. package/dist/okf/types/ServiceList.md +2 -2
  178. package/dist/okf/types/StatefulSet.md +1 -1
  179. package/dist/okf/types/StatefulSetList.md +2 -2
  180. package/dist/okf/types/Status.md +2 -2
  181. package/dist/okf/types/StorageClass.md +1 -1
  182. package/dist/okf/types/StorageClassList.md +2 -2
  183. package/dist/okf/types/StorageVersionMigration.md +1 -1
  184. package/dist/okf/types/StorageVersionMigrationList.md +2 -2
  185. package/dist/okf/types/SubjectAccessReview.md +1 -1
  186. package/dist/okf/types/TokenRequest.md +1 -1
  187. package/dist/okf/types/TokenReview.md +1 -1
  188. package/dist/okf/types/ValidatingAdmissionPolicy.md +1 -1
  189. package/dist/okf/types/ValidatingAdmissionPolicyBinding.md +1 -1
  190. package/dist/okf/types/ValidatingAdmissionPolicyBindingList.md +2 -2
  191. package/dist/okf/types/ValidatingAdmissionPolicyList.md +2 -2
  192. package/dist/okf/types/ValidatingWebhookConfiguration.md +1 -1
  193. package/dist/okf/types/ValidatingWebhookConfigurationList.md +2 -2
  194. package/dist/okf/types/VolumeAttachment.md +1 -1
  195. package/dist/okf/types/VolumeAttachmentList.md +2 -2
  196. package/dist/okf/types/VolumeAttributesClassList.md +2 -2
  197. package/dist/op/activities/argo.d.ts.map +1 -1
  198. package/dist/op/activities/index.d.ts +3 -3
  199. package/dist/op/activities/index.d.ts.map +1 -1
  200. package/dist/op/activities/wait-for-ready.d.ts.map +1 -1
  201. package/dist/op/builders.d.ts.map +1 -1
  202. package/dist/rules/otel-placement-helpers.ts +7 -11
  203. package/dist/rules/wk8604.ts +29 -0
  204. package/dist/rules/wk8605.ts +131 -0
  205. package/dist/skills/chant-k8s.md +1 -1
  206. package/dist/spec/parse.d.ts +27 -0
  207. package/dist/spec/parse.d.ts.map +1 -1
  208. package/dist/types/index.d.ts +5360 -972
  209. package/dist/variables.d.ts.map +1 -1
  210. package/package.json +4 -4
  211. package/src/codegen/declarations.test.ts +118 -0
  212. package/src/codegen/generate-typescript.ts +69 -4
  213. package/src/codegen/generate.ts +15 -6
  214. package/src/composites/__snapshots__/gke-otel-collector.snapshot.test.ts.snap +2 -68
  215. package/src/composites/catalog.ts +12 -0
  216. package/src/composites/gke-otel-collector.snapshot.test.ts +3 -1
  217. package/src/composites/gke-otel-collector.ts +13 -2
  218. package/src/composites/index.ts +1 -0
  219. package/src/composites/otel-collector-agent.ts +45 -11
  220. package/src/composites/otel-collector-gateway.test.ts +102 -5
  221. package/src/composites/otel-collector-gateway.ts +96 -18
  222. package/src/composites/otel-collector-node.test.ts +174 -0
  223. package/src/composites/otel-collector-node.ts +213 -0
  224. package/src/composites/otel-collector-rbac.test.ts +114 -0
  225. package/src/composites/otel-collector-rbac.ts +144 -0
  226. package/src/composites/otel-collector-shape.ts +19 -0
  227. package/src/composites/otel-collector.ts +40 -35
  228. package/src/crd/crd-sources.ts +26 -0
  229. package/src/crd/loader.test.ts +9 -1
  230. package/src/crd/loader.ts +26 -3
  231. package/src/crd/oci-chart.test.ts +149 -0
  232. package/src/crd/oci-chart.ts +178 -0
  233. package/src/crd/types.ts +5 -0
  234. package/src/generated/index.d.ts +5360 -972
  235. package/src/generated/index.ts +23 -0
  236. package/src/generated/lexicon-k8s.json +156 -17
  237. package/src/generated/operations.json +48 -0
  238. package/src/import/embedded-live.test.ts +180 -0
  239. package/src/import/embedded-roundtrip.test.ts +73 -7
  240. package/src/import/embedded-types.e2e.test.ts +3 -1
  241. package/src/import/embedded.test.ts +64 -0
  242. package/src/import/embedded.ts +31 -2
  243. package/src/import/generator.test.ts +19 -0
  244. package/src/import/generator.ts +20 -2
  245. package/src/import/live-export.ts +10 -2
  246. package/src/import/testdata/embedded/README.md +4 -1
  247. package/src/import/testdata/embedded/alertmanager-configmap.yaml +91 -0
  248. package/src/import/testdata/embedded/fixtures.ts +18 -0
  249. package/src/import/testdata/embedded/grafana-operator-dashboard.yaml +363 -0
  250. package/src/import/testdata/embedded/grafana-v2-dashboard-configmap.yaml +851 -0
  251. package/src/lint/audit-catalog.ts +2 -0
  252. package/src/lint/post-synth/index.ts +4 -0
  253. package/src/lint/post-synth/otel-placement-helpers.ts +7 -11
  254. package/src/lint/post-synth/otel-placement.test.ts +35 -0
  255. package/src/lint/post-synth/post-synth.test.ts +3 -3
  256. package/src/lint/post-synth/wk8604.ts +29 -0
  257. package/src/lint/post-synth/wk8605.test.ts +141 -0
  258. package/src/lint/post-synth/wk8605.ts +131 -0
  259. package/src/skills/chant-k8s.md +1 -1
  260. package/src/spec/parse.test.ts +118 -0
  261. package/src/spec/parse.ts +250 -29
@@ -1 +1 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS;IACpB,6BAA6B;;IAE7B,iCAAiC;;IAEjC,gCAAgC;;IAEhC,kCAAkC;;IAElC,gCAAgC;;IAEhC,mCAAmC;;CAE3B,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB,iCAAiC;;IAEjC,gCAAgC;;CAExB,CAAC"}
1
+ {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS;IACpB,6BAA6B;aAC7B,OAAO,EAAE,wBAAwB;IACjC,iCAAiC;aACjC,WAAW,EAAE,4BAA4B;IACzC,gCAAgC;aAChC,UAAU,EAAE,2BAA2B;IACvC,kCAAkC;aAClC,YAAY,EAAE,6BAA6B;IAC3C,gCAAgC;aAChC,SAAS,EAAE,2BAA2B;IACtC,mCAAmC;aACnC,YAAY,EAAE,8BAA8B;CACpC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB,iCAAiC;aACjC,WAAW,EAAE,4BAA4B;IACzC,gCAAgC;aAChC,WAAW,EAAE,2BAA2B;CAChC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-k8s",
3
- "version": "0.100.0",
3
+ "version": "0.102.0",
4
4
  "description": "Kubernetes lexicon for chant — declarative IaC in TypeScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -69,7 +69,7 @@
69
69
  "validate": "tsx src/validate-cli.ts",
70
70
  "docs": "tsx src/codegen/docs-cli.ts",
71
71
  "prepack": "npm run generate && npm run bundle && npm run validate && npm run build",
72
- "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && find dist -type f \\( -name \"*.js\" -o -name \"*.js.map\" \\) -delete"
72
+ "build": "../../scripts/tsc7.sh -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && find dist -type f \\( -name \"*.js\" -o -name \"*.js.map\" \\) -delete"
73
73
  },
74
74
  "dependencies": {
75
75
  "@intentius/chant-lexicon-otel": "*",
@@ -78,7 +78,7 @@
78
78
  "@types/js-yaml": "^4.0.9"
79
79
  },
80
80
  "optionalDependencies": {
81
- "@intentius/chant-k8s-client": "^0.100.0"
81
+ "@intentius/chant-k8s-client": "^0.102.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@intentius/chant": "*",
@@ -86,7 +86,7 @@
86
86
  },
87
87
  "peerDependencies": {
88
88
  "zod": "^4.3.6",
89
- "@intentius/chant": "^0.100.0",
89
+ "@intentius/chant": "^0.102.0",
90
90
  "typescript": "^5.9.3"
91
91
  }
92
92
  }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * The generated declarations check nested objects (chant #3093). Before,
3
+ * `Deployment.spec` was `Record<string, unknown>` and the property classes
4
+ * had no members, so a wrong type or an unknown key below a resource's top
5
+ * level type-checked.
6
+ *
7
+ * Compiled against `src/generated/index.d.ts`, the file the package ships as
8
+ * `@intentius/chant-lexicon-k8s/types` (which entry consumers get is #2224).
9
+ */
10
+ import { describe, expect, test } from "vitest";
11
+ import { copyFileSync, existsSync, mkdtempSync, rmSync, writeFileSync } from "fs";
12
+ import { tmpdir } from "os";
13
+ import { dirname, join } from "path";
14
+ import { fileURLToPath } from "url";
15
+ import * as ts from "typescript";
16
+
17
+ const pkgDir = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
18
+ const dts = join(pkgDir, "src", "generated", "index.d.ts");
19
+
20
+ /** Type errors in each probe, by probe name, compiled against the generated declarations. */
21
+ function typeErrors(probes: Record<string, string>): Record<string, string[]> {
22
+ const dir = mkdtempSync(join(tmpdir(), "chant-k8s-dts-"));
23
+ try {
24
+ copyFileSync(dts, join(dir, "k8s.d.ts"));
25
+ const files = Object.entries(probes).map(([name, body]) => {
26
+ const file = join(dir, `${name}.ts`);
27
+ writeFileSync(file, body);
28
+ return file;
29
+ });
30
+ const program = ts.createProgram(files, {
31
+ strict: true,
32
+ noEmit: true,
33
+ target: ts.ScriptTarget.ES2022,
34
+ module: ts.ModuleKind.ESNext,
35
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
36
+ types: [],
37
+ });
38
+ const out: Record<string, string[]> = Object.fromEntries(Object.keys(probes).map((n) => [n, []]));
39
+ for (const d of ts.getPreEmitDiagnostics(program)) {
40
+ const name = d.file ? d.file.fileName.split("/").pop()!.replace(/(\.d)?\.ts$/, "") : "global";
41
+ (out[name] ??= []).push(`TS${d.code}: ${ts.flattenDiagnosticMessageText(d.messageText, " ")}`);
42
+ }
43
+ return out;
44
+ } finally {
45
+ rmSync(dir, { recursive: true, force: true });
46
+ }
47
+ }
48
+
49
+ const IMPORT = `import { ConfigMap, Container, ControllerRevision, CustomResourceDefinition, Deployment, Probe, Role, StatefulSet } from "./k8s";\n`;
50
+
51
+ describe.skipIf(!existsSync(dts))("the generated declarations type nested objects", () => {
52
+ test("nested mistakes are errors, valid manifests are not", () => {
53
+ const errors = typeErrors({
54
+ replicasString: `${IMPORT}new Deployment({ spec: { replicas: "three", selector: {}, template: {} } });`,
55
+ unknownSpecKey: `${IMPORT}new Deployment({ spec: { bogusField: true, selector: {}, template: {} } });`,
56
+ unknownContainerKey: `${IMPORT}new Deployment({ spec: { selector: {}, template: { spec: { containers: [{ name: "a", imag: "b" }] } } } });`,
57
+ wrongProbeField: `${IMPORT}new Container({ name: "a", livenessProbe: new Probe({ httpGet: { path: "/", port: 80, verb: "GET" } }) });`,
58
+ missingSelector: `${IMPORT}new Deployment({ spec: { template: {} } });`,
59
+ valid: `${IMPORT}
60
+ export const deployment = new Deployment({
61
+ metadata: { name: "app", labels: { app: "app" } },
62
+ spec: {
63
+ replicas: 2,
64
+ selector: { matchLabels: { app: "app" } },
65
+ strategy: { type: "RollingUpdate", rollingUpdate: { maxSurge: "25%", maxUnavailable: 0 } },
66
+ template: {
67
+ metadata: { labels: { app: "app" } },
68
+ spec: {
69
+ securityContext: { runAsNonRoot: true, fsGroup: 1000 },
70
+ containers: [
71
+ new Container({
72
+ name: "app",
73
+ image: "app:1.0",
74
+ ports: [{ containerPort: 8080, name: "http" }],
75
+ resources: { limits: { cpu: 1, memory: "256Mi" }, requests: { cpu: "100m" } },
76
+ readinessProbe: new Probe({ httpGet: { path: "/readyz", port: "http" } }),
77
+ }),
78
+ ],
79
+ },
80
+ },
81
+ },
82
+ });
83
+ export const sts = new StatefulSet({
84
+ spec: {
85
+ serviceName: "db",
86
+ selector: { matchLabels: { app: "db" } },
87
+ template: { spec: { containers: [{ name: "db", image: "postgres:16" }] } },
88
+ volumeClaimTemplates: [{ metadata: { name: "data" }, spec: { accessModes: ["ReadWriteOnce"], resources: { requests: { storage: "1Gi" } } } }],
89
+ },
90
+ });
91
+ export const role = new Role({ rules: [{ apiGroups: [""], resources: ["pods"], verbs: ["get"] }] });
92
+ export const cm = new ConfigMap({ data: { key: "value" } });
93
+ // RawExtension stays open.
94
+ export const rev = new ControllerRevision({ revision: 1, data: { anything: { goes: true } } });
95
+ // JSONSchemaProps refers to itself.
96
+ export const crd = new CustomResourceDefinition({
97
+ spec: {
98
+ group: "example.com",
99
+ names: { kind: "Widget", plural: "widgets" },
100
+ scope: "Namespaced",
101
+ versions: [{
102
+ name: "v1", served: true, storage: true,
103
+ schema: { openAPIV3Schema: { type: "object", properties: { spec: { type: "object", properties: { size: { type: "integer" } } } } } },
104
+ }],
105
+ },
106
+ });
107
+ `,
108
+ });
109
+
110
+ expect(errors.global ?? []).toEqual([]);
111
+ expect(errors.valid).toEqual([]);
112
+ expect(errors.replicasString).toEqual(["TS2322: Type 'string' is not assignable to type 'number'."]);
113
+ expect(errors.unknownSpecKey.join("\n")).toMatch(/TS2353: .*'bogusField' does not exist in type 'DeploymentSpec'/);
114
+ expect(errors.unknownContainerKey.join("\n")).toMatch(/TS2561: .*'imag' does not exist in type 'Container'/);
115
+ expect(errors.wrongProbeField.join("\n")).toMatch(/'verb' does not exist in type 'HTTPGetAction'/);
116
+ expect(errors.missingSelector.join("\n")).toMatch(/TS2741: Property 'selector' is missing/);
117
+ });
118
+ });
@@ -3,14 +3,13 @@
3
3
  * Kubernetes resource and property type classes.
4
4
  */
5
5
 
6
- import type { K8sParseResult } from "../spec/parse";
6
+ import type { K8sParseResult, ParsedDefinitionType } from "../spec/parse";
7
7
  import { k8sShortName } from "../spec/parse";
8
8
  import type { NamingStrategy } from "./naming";
9
9
  import { propertyTypeName, extractDefName } from "./naming";
10
10
  import {
11
11
  writeResourceClass,
12
- writePropertyClass,
13
- writeEnumType,
12
+ resolveConstructorType,
14
13
  type DtsProperty,
15
14
  type DtsAttribute,
16
15
  } from "@intentius/chant/codegen/generate-typescript";
@@ -29,6 +28,7 @@ interface ResourceEntry {
29
28
  export function generateTypeScriptDeclarations(
30
29
  results: K8sParseResult[],
31
30
  naming: NamingStrategy,
31
+ definitionTypes: ParsedDefinitionType[] = [],
32
32
  ): string {
33
33
  const lines: string[] = [];
34
34
  lines.push("// Code generated by chant k8s generate. DO NOT EDIT.");
@@ -88,10 +88,75 @@ export function generateTypeScriptDeclarations(
88
88
  lines.push("");
89
89
  lines.push("// --- Property type classes ---");
90
90
  for (const pe of propertyEntries) {
91
- writePropertyClass(lines, pe.tsName, pe.properties, pe.remap);
91
+ writeMembersInterface(lines, pe.tsName, undefined, pe.properties, pe.remap);
92
+ lines.push(`export declare class ${pe.tsName} {`);
93
+ lines.push(` constructor(props: ${pe.tsName});`);
94
+ lines.push("}");
95
+ }
96
+ }
97
+
98
+ // chant #3093 — every other object definition a resource reaches. Declared
99
+ // as interfaces: nothing constructs them at runtime, an author writes them
100
+ // as object literals.
101
+ if (definitionTypes.length > 0) {
102
+ const classNames = new Set(resources.map((r) => r.tsName));
103
+ lines.push("");
104
+ lines.push("// --- Definition interfaces ---");
105
+ for (const dt of definitionTypes) {
106
+ if (classNames.has(dt.name)) {
107
+ throw new Error(`k8s codegen: definition ${dt.defKey} would be declared as ${dt.name}, which is already a class`);
108
+ }
109
+ const props: DtsProperty[] = dt.properties.map((p) => ({
110
+ name: p.name,
111
+ type: p.tsType,
112
+ required: p.required,
113
+ description: p.description,
114
+ }));
115
+ writeMembersInterface(lines, dt.name, dt.description, props, undefined);
92
116
  }
93
117
  }
94
118
 
95
119
  lines.push("");
96
120
  return lines.join("\n");
97
121
  }
122
+
123
+ const IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
124
+
125
+ /**
126
+ * Write the members of a property type or definition as an interface. For a
127
+ * property type the interface merges with its class, so `new Container({...})`
128
+ * and a `{...}` literal both check against the same members, and so does a
129
+ * field typed `Container`. A class with only a constructor has no members, and
130
+ * an empty instance type accepts any object (chant #3093).
131
+ */
132
+ function writeMembersInterface(
133
+ lines: string[],
134
+ tsName: string,
135
+ description: string | undefined,
136
+ props: DtsProperty[],
137
+ remap: Map<string, string> | undefined,
138
+ ): void {
139
+ lines.push("");
140
+ if (description) lines.push(`/** ${jsdoc(description)} */`);
141
+ if (props.length === 0) {
142
+ lines.push(`export interface ${tsName} {}`);
143
+ return;
144
+ }
145
+ // Required first, then optional, each alphabetical — the constructor order.
146
+ const sorted = [...props].sort((a, b) => {
147
+ if (a.required !== b.required) return a.required ? -1 : 1;
148
+ return a.name.localeCompare(b.name);
149
+ });
150
+ lines.push(`export interface ${tsName} {`);
151
+ for (const p of sorted) {
152
+ if (p.description) lines.push(` /** ${jsdoc(p.description)} */`);
153
+ const key = IDENT.test(p.name) ? p.name : JSON.stringify(p.name);
154
+ lines.push(` ${key}${p.required ? "" : "?"}: ${resolveConstructorType(p.type, remap)};`);
155
+ }
156
+ lines.push("}");
157
+ }
158
+
159
+ /** A description made safe for a one-line JSDoc comment. */
160
+ function jsdoc(text: string): string {
161
+ return text.replace(/\*\//g, "*\\/");
162
+ }
@@ -12,7 +12,13 @@ import {
12
12
  type GeneratePipelineConfig,
13
13
  } from "@intentius/chant/codegen/generate";
14
14
  import { fetchSchemas } from "../spec/fetch";
15
- import { parseK8sSwagger, specListMapKeyPairs, k8sShortName, type K8sParseResult } from "../spec/parse";
15
+ import {
16
+ parseK8sSwaggerTypes,
17
+ specListMapKeyPairs,
18
+ k8sShortName,
19
+ type K8sParseResult,
20
+ type ParsedDefinitionType,
21
+ } from "../spec/parse";
16
22
  import { loadMultipleCRDs } from "../crd/loader";
17
23
  import { CRD_SOURCES } from "../crd/crd-sources";
18
24
  import { NamingStrategy, propertyTypeName, extractDefName } from "./naming";
@@ -42,6 +48,8 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
42
48
  // chant #1441 — read off the raw document in `parseSchema`, since the
43
49
  // result set covers only the definitions chant emits types for.
44
50
  let specPairs: Array<[string, string[]]> = [];
51
+ // chant #3093 — the declaration-only interfaces, which only the `.d.ts` emits.
52
+ let definitionTypes: ParsedDefinitionType[] = [];
45
53
 
46
54
  const config: GeneratePipelineConfig<K8sParseResult> = {
47
55
  fetchSchemas: async (fetchOpts) => {
@@ -49,10 +57,11 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
49
57
  },
50
58
 
51
59
  parseSchema: (_typeName, data) => {
52
- // The K8s schema is a single document — parseK8sSwagger returns multiple results.
60
+ // The K8s schema is a single document — parseK8sSwaggerTypes returns multiple results.
53
61
  // The pipeline calls this once per schema entry. We return the first result
54
62
  // and use augmentResults to inject the rest.
55
- const results = parseK8sSwagger(data);
63
+ const { results, definitionTypes: defs } = parseK8sSwaggerTypes(data);
64
+ definitionTypes = defs;
56
65
  specPairs = specListMapKeyPairs(data);
57
66
  if (results.length === 0) return null;
58
67
  // Return the first result; stash the rest for augmentResults
@@ -71,10 +80,10 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
71
80
  try {
72
81
  const parsed = await loadMultipleCRDs([source]);
73
82
  crdResults.push(...parsed);
74
- log(`Loaded ${parsed.length} CRD type(s) from ${source.url ?? source.path ?? "cluster"}`);
83
+ log(`Loaded ${parsed.length} CRD type(s) from ${source.url ?? source.path ?? source.chart ?? "cluster"}`);
75
84
  } catch (err) {
76
85
  const msg = err instanceof Error ? err.message : String(err);
77
- warnings.push({ file: source.url ?? source.path ?? "cluster", error: msg });
86
+ warnings.push({ file: source.url ?? source.path ?? source.chart ?? "cluster", error: msg });
78
87
  log(`Warning: failed to load CRD: ${msg}`);
79
88
  }
80
89
  }
@@ -98,7 +107,7 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
98
107
  },
99
108
 
100
109
  generateTypes: (results, naming) => {
101
- return generateTypeScriptDeclarations(results, naming as NamingStrategy);
110
+ return generateTypeScriptDeclarations(results, naming as NamingStrategy, definitionTypes);
102
111
  },
103
112
 
104
113
  generateRuntimeIndex: (results, naming) => {
@@ -80,8 +80,8 @@ rules:
80
80
  - ''
81
81
  resources:
82
82
  - pods
83
+ - namespaces
83
84
  - nodes
84
- - endpoints
85
85
  verbs:
86
86
  - get
87
87
  - list
@@ -94,39 +94,6 @@ rules:
94
94
  - get
95
95
  - list
96
96
  - watch
97
- - apiGroups:
98
- - batch
99
- resources:
100
- - jobs
101
- verbs:
102
- - get
103
- - list
104
- - watch
105
- - apiGroups:
106
- - ''
107
- resources:
108
- - nodes/proxy
109
- verbs:
110
- - get
111
- - apiGroups:
112
- - ''
113
- resources:
114
- - nodes/stats
115
- - configmaps
116
- - events
117
- verbs:
118
- - create
119
- - get
120
- - apiGroups:
121
- - ''
122
- resources:
123
- - configmaps
124
- verbs:
125
- - get
126
- - update
127
- - create
128
- resourceNames:
129
- - otel-container-insight-clusterleader
130
97
 
131
98
  ---
132
99
  apiVersion: rbac.authorization.k8s.io/v1
@@ -281,8 +248,8 @@ rules:
281
248
  - ''
282
249
  resources:
283
250
  - pods
251
+ - namespaces
284
252
  - nodes
285
- - endpoints
286
253
  verbs:
287
254
  - get
288
255
  - list
@@ -295,39 +262,6 @@ rules:
295
262
  - get
296
263
  - list
297
264
  - watch
298
- - apiGroups:
299
- - batch
300
- resources:
301
- - jobs
302
- verbs:
303
- - get
304
- - list
305
- - watch
306
- - apiGroups:
307
- - ''
308
- resources:
309
- - nodes/proxy
310
- verbs:
311
- - get
312
- - apiGroups:
313
- - ''
314
- resources:
315
- - nodes/stats
316
- - configmaps
317
- - events
318
- verbs:
319
- - create
320
- - get
321
- - apiGroups:
322
- - ''
323
- resources:
324
- - configmaps
325
- verbs:
326
- - get
327
- - update
328
- - create
329
- resourceNames:
330
- - otel-container-insight-clusterleader
331
265
 
332
266
  ---
333
267
  apiVersion: rbac.authorization.k8s.io/v1
@@ -2149,11 +2149,15 @@ export const compositeCatalog: CompositeEntry[] = [
2149
2149
  "lexicon": "k8s",
2150
2150
  "description": "Create a GkeOtelCollector composite — returns prop objects for a DaemonSet, ServiceAccount, ClusterRole, ClusterRoleBinding, and ConfigMap.",
2151
2151
  "bundles": [
2152
+ "BatchProcessor",
2152
2153
  "ClusterRole",
2153
2154
  "ClusterRoleBinding",
2154
2155
  "ConfigMap",
2155
2156
  "DaemonSet",
2157
+ "GoogleCloudExporter",
2158
+ "OtlpReceiver",
2156
2159
  "Pipeline",
2160
+ "ResourceDetectionProcessor",
2157
2161
  "ServiceAccount"
2158
2162
  ],
2159
2163
  "params": [
@@ -2949,6 +2953,12 @@ export const compositeCatalog: CompositeEntry[] = [
2949
2953
  "required": false,
2950
2954
  "description": "Additional labels."
2951
2955
  },
2956
+ {
2957
+ "name": "logAccess",
2958
+ "type": "CollectorLogAccess",
2959
+ "required": false,
2960
+ "description": "How a config with a `filelog` receiver reads the node's container logs, which are root's."
2961
+ },
2952
2962
  {
2953
2963
  "name": "cpuRequest",
2954
2964
  "type": "string",
@@ -2991,6 +3001,8 @@ export const compositeCatalog: CompositeEntry[] = [
2991
3001
  "ConfigMap",
2992
3002
  "Deployment",
2993
3003
  "PodDisruptionBudget",
3004
+ "Role",
3005
+ "RoleBinding",
2994
3006
  "Service",
2995
3007
  "ServiceAccount"
2996
3008
  ],
@@ -4,7 +4,9 @@
4
4
  * `OtelCollector`, `OtelCollectorGateway` and `GkeOtelCollector` share the
5
5
  * collector resources in `otel-collector-agent.ts`. The snapshot was recorded
6
6
  * before the gateway work touched that file, so any change to the GKE output
7
- * made through the shared code fails here.
7
+ * made through the shared code fails here. #2923 changed it on purpose: the
8
+ * shared ClusterRole was narrowed to what k8sattributes and the config's
9
+ * receivers need (see `agentClusterRules`).
8
10
  */
9
11
  import { describe, expect, test } from "vitest";
10
12
  import { expandComposite } from "@intentius/chant";
@@ -16,9 +16,12 @@ import {
16
16
  ResourceDetectionProcessor,
17
17
  GoogleCloudExporter,
18
18
  Pipeline,
19
+ buildCollectorConfig,
19
20
  collectorYaml,
20
21
  } from "@intentius/chant-lexicon-otel";
21
22
  import { collectorAgentResources, type CollectorAgentResources } from "./otel-collector-agent";
23
+ import { agentClusterRules } from "./otel-collector-rbac";
24
+ import { collectorNodeAccess } from "./otel-collector-node";
22
25
 
23
26
  export interface GkeOtelCollectorProps {
24
27
  /** GKE cluster name. */
@@ -110,14 +113,16 @@ export const GkeOtelCollector = Composite((props: GkeOtelCollectorProps) => {
110
113
  attribute_mappings: [{ key: "service.name", replacement: "g.co/r/service/name" }],
111
114
  },
112
115
  });
113
- const otelConfig = collectorYaml([
116
+ const entities = [
114
117
  otlp,
115
118
  batch,
116
119
  resourceDetection,
117
120
  googleCloud,
118
121
  new Pipeline({ signal: "metrics", receivers: [otlp], processors: [batch, resourceDetection], exporters: [googleCloud] }),
119
122
  new Pipeline({ signal: "traces", receivers: [otlp], processors: [batch, resourceDetection], exporters: [googleCloud] }),
120
- ]);
123
+ ];
124
+ const otelConfig = collectorYaml(entities);
125
+ const built = buildCollectorConfig(entities).config;
121
126
 
122
127
  // The DaemonSet, RBAC and ConfigMap are the ones OtelCollector builds too.
123
128
  return collectorAgentResources({
@@ -128,6 +133,12 @@ export const GkeOtelCollector = Composite((props: GkeOtelCollectorProps) => {
128
133
  extraLabels,
129
134
  configYaml: otelConfig,
130
135
  configDir: "/etc/otel",
136
+ // The ClusterRole OtelCollector shares: k8sattributes' rules, and none
137
+ // for receivers, since the config's only receiver is otlp (#2923).
138
+ clusterRules: agentClusterRules(built),
139
+ // Derived like OtelCollector's (#3103). The config reads nothing from the
140
+ // node, so this adds no variable or mount and the output is unchanged.
141
+ nodeAccess: collectorNodeAccess(built, "/etc/otel"),
131
142
  ports: [
132
143
  { containerPort: 4317, name: "otlp-grpc" },
133
144
  { containerPort: 4318, name: "otlp-http" },
@@ -67,6 +67,7 @@ export { GkeFluentBitAgent } from "./gke-fluent-bit-agent";
67
67
  export type { GkeFluentBitAgentProps, GkeFluentBitAgentResult } from "./gke-fluent-bit-agent";
68
68
  export { OtelCollector } from "./otel-collector";
69
69
  export type { OtelCollectorProps, OtelCollectorResult } from "./otel-collector";
70
+ export type { CollectorLogAccess } from "./otel-collector-agent";
70
71
  export { OtelCollectorGateway, gatewayExporter } from "./otel-collector-gateway";
71
72
  export type {
72
73
  OtelCollectorGatewayProps,
@@ -2,7 +2,8 @@
2
2
  * The Kubernetes resources an OpenTelemetry Collector agent needs, shared by
3
3
  * `OtelCollector` and `GkeOtelCollector`: a DaemonSet running the collector
4
4
  * with its config mounted from a ConfigMap, and a ServiceAccount bound to a
5
- * ClusterRole that reads pods, nodes and workloads.
5
+ * ClusterRole with the rules the caller works out from its config (see
6
+ * `agentClusterRules` in `otel-collector-rbac.ts`).
6
7
  *
7
8
  * The caller renders the collector config (with the otel lexicon's
8
9
  * `collectorYaml`) and says which ports the container exposes. Everything
@@ -15,6 +16,17 @@
15
16
 
16
17
  import { mergeDefaults } from "@intentius/chant";
17
18
  import { DaemonSet, ServiceAccount, ClusterRole, ClusterRoleBinding, ConfigMap } from "../generated";
19
+ import type { CollectorPolicyRule } from "./otel-collector-rbac";
20
+ import { nodeVolumeMounts, nodeVolumes, type CollectorNodeAccess } from "./otel-collector-node";
21
+
22
+ /**
23
+ * How a collector that reads the kubelet's container logs gets past their
24
+ * owner. The files are root's, readable by group root (containerd writes
25
+ * them mode 0640), so `group` keeps user 10001 and adds the pod to group 0
26
+ * with `supplementalGroups`. `root` runs the container as user 0 instead,
27
+ * for a runtime that writes the logs readable by their owner only.
28
+ */
29
+ export type CollectorLogAccess = "group" | "root";
18
30
 
19
31
  export interface CollectorAgentOptions {
20
32
  name: string;
@@ -29,6 +41,8 @@ export interface CollectorAgentOptions {
29
41
  /** Directory the config is mounted in. The file is `<dir>/config.yaml`. */
30
42
  configDir: string;
31
43
  ports: Array<{ containerPort: number; name: string }>;
44
+ /** The ClusterRole's rules, from `agentClusterRules`. */
45
+ clusterRules: CollectorPolicyRule[];
32
46
  cpuRequest: string;
33
47
  memoryRequest: string;
34
48
  cpuLimit: string;
@@ -41,6 +55,10 @@ export interface CollectorAgentOptions {
41
55
  workloadAnnotations?: Record<string, string>;
42
56
  /** Annotations on the ConfigMap. */
43
57
  configMapAnnotations?: Record<string, string>;
58
+ /** What the config reads from the node, from `collectorNodeAccess`: the node name variables and host mounts. */
59
+ nodeAccess?: CollectorNodeAccess;
60
+ /** How a config that reads container logs gets read access to them (default `group`). */
61
+ logAccess?: CollectorLogAccess;
44
62
  defaults?: {
45
63
  daemonSet?: Partial<Record<string, unknown>>;
46
64
  serviceAccount?: Partial<Record<string, unknown>>;
@@ -65,7 +83,15 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
65
83
  const bindingName = `${name}-binding`;
66
84
  const configMapName = `${name}-config`;
67
85
 
68
- const container = collectorContainer(opts);
86
+ const access = opts.nodeAccess;
87
+ const asRoot = access?.readsLogs === true && opts.logAccess === "root";
88
+ const baseContainer = collectorContainer({
89
+ ...opts,
90
+ env: access?.env,
91
+ extraVolumeMounts: access ? nodeVolumeMounts(access.mounts) : undefined,
92
+ });
93
+ const container = asRoot ? runAsRoot(baseContainer) : baseContainer;
94
+ const podSecurity = access?.readsLogs && !asRoot ? { securityContext: { supplementalGroups: [0] } } : {};
69
95
 
70
96
  const daemonSet = new DaemonSet(mergeDefaults({
71
97
  metadata: {
@@ -83,8 +109,10 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
83
109
  containers: [container],
84
110
  volumes: [
85
111
  { name: "config", configMap: { name: configMapName } },
112
+ ...(access ? nodeVolumes(access.mounts) : []),
86
113
  ],
87
114
  tolerations: [{ operator: "Exists" }],
115
+ ...podSecurity,
88
116
  },
89
117
  },
90
118
  },
@@ -104,14 +132,7 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
104
132
  name: clusterRoleName,
105
133
  labels: { ...commonLabels, "app.kubernetes.io/component": "rbac" },
106
134
  },
107
- rules: [
108
- { apiGroups: [""], resources: ["pods", "nodes", "endpoints"], verbs: ["get", "list", "watch"] },
109
- { apiGroups: ["apps"], resources: ["replicasets"], verbs: ["get", "list", "watch"] },
110
- { apiGroups: ["batch"], resources: ["jobs"], verbs: ["get", "list", "watch"] },
111
- { apiGroups: [""], resources: ["nodes/proxy"], verbs: ["get"] },
112
- { apiGroups: [""], resources: ["nodes/stats", "configmaps", "events"], verbs: ["create", "get"] },
113
- { apiGroups: [""], resources: ["configmaps"], verbs: ["get", "update", "create"], resourceNames: ["otel-container-insight-clusterleader"] },
114
- ],
135
+ rules: opts.clusterRules,
115
136
  }, defs?.clusterRole));
116
137
 
117
138
  const clusterRoleBinding = new ClusterRoleBinding(mergeDefaults({
@@ -142,7 +163,12 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
142
163
  export type CollectorContainerOptions = Pick<
143
164
  CollectorAgentOptions,
144
165
  "name" | "image" | "configDir" | "ports" | "cpuRequest" | "memoryRequest" | "cpuLimit" | "memoryLimit" | "containerExtra"
145
- >;
166
+ > & {
167
+ /** Environment variables, such as the node name from the downward API. Left out when empty. */
168
+ env?: Array<Record<string, unknown>>;
169
+ /** Mounts after the config mount, such as read-only host directories. */
170
+ extraVolumeMounts?: Array<Record<string, unknown>>;
171
+ };
146
172
 
147
173
  /**
148
174
  * The collector container: the image, the config file argument, the ports,
@@ -155,6 +181,7 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
155
181
  name: opts.name,
156
182
  image: opts.image,
157
183
  args: [`--config=${opts.configDir}/config.yaml`],
184
+ ...(opts.env?.length ? { env: opts.env } : {}),
158
185
  ports: opts.ports,
159
186
  resources: {
160
187
  requests: { cpu: opts.cpuRequest, memory: opts.memoryRequest },
@@ -162,6 +189,7 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
162
189
  },
163
190
  volumeMounts: [
164
191
  { name: "config", mountPath: opts.configDir, readOnly: true },
192
+ ...(opts.extraVolumeMounts ?? []),
165
193
  ],
166
194
  securityContext: {
167
195
  runAsNonRoot: true,
@@ -173,6 +201,12 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
173
201
  };
174
202
  }
175
203
 
204
+ /** The container run as user 0, for `logAccess: "root"`; the rest of its security context is kept. */
205
+ function runAsRoot(container: Record<string, unknown>): Record<string, unknown> {
206
+ const sc = (container.securityContext ?? {}) as Record<string, unknown>;
207
+ return { ...container, securityContext: { ...sc, runAsNonRoot: false, runAsUser: 0 } };
208
+ }
209
+
176
210
  /** The ConfigMap holding the rendered collector config under `config.yaml`. */
177
211
  export function collectorConfigMap(
178
212
  opts: Pick<CollectorAgentOptions, "namespace" | "commonLabels" | "configYaml"> & {