@intentius/chant-lexicon-k8s 0.106.4 → 0.108.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 (167) hide show
  1. package/dist/codegen/naming.d.ts.map +1 -1
  2. package/dist/composites/catalog.d.ts.map +1 -1
  3. package/dist/composites/index.d.ts +2 -0
  4. package/dist/composites/index.d.ts.map +1 -1
  5. package/dist/composites/otel-collector-shape.d.ts +2 -0
  6. package/dist/composites/otel-collector-shape.d.ts.map +1 -1
  7. package/dist/composites/otel-operator-collector.d.ts +101 -0
  8. package/dist/composites/otel-operator-collector.d.ts.map +1 -0
  9. package/dist/config-schema.d.ts +115 -1
  10. package/dist/config-schema.d.ts.map +1 -1
  11. package/dist/config.d.ts +58 -3
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/crd/crd-sources.d.ts.map +1 -1
  14. package/dist/crd/loader.d.ts +4 -0
  15. package/dist/crd/loader.d.ts.map +1 -1
  16. package/dist/crd/parser.d.ts +5 -0
  17. package/dist/crd/parser.d.ts.map +1 -1
  18. package/dist/crd/project-codegen.d.ts +33 -0
  19. package/dist/crd/project-codegen.d.ts.map +1 -0
  20. package/dist/generated/index.d.d.ts +172 -2
  21. package/dist/generated/index.d.ts +301 -0
  22. package/dist/generated/index.d.ts.map +1 -1
  23. package/dist/group-namespace.d.ts.map +1 -1
  24. package/dist/import/embedded.d.ts +3 -0
  25. package/dist/import/embedded.d.ts.map +1 -1
  26. package/dist/include/entity.d.ts +73 -0
  27. package/dist/include/entity.d.ts.map +1 -0
  28. package/dist/include/resolve.d.ts +29 -0
  29. package/dist/include/resolve.d.ts.map +1 -0
  30. package/dist/index.d.ts +9 -2
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/integrity.json +17 -10
  33. package/dist/kustomize/rendered-entity.d.ts +15 -1
  34. package/dist/kustomize/rendered-entity.d.ts.map +1 -1
  35. package/dist/kustomize/root.d.ts +11 -2
  36. package/dist/kustomize/root.d.ts.map +1 -1
  37. package/dist/lint/audit-catalog.d.ts.map +1 -1
  38. package/dist/lint/post-synth/crd-schema-helpers.d.ts +5 -1
  39. package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
  40. package/dist/lint/post-synth/index.d.ts.map +1 -1
  41. package/dist/lint/post-synth/monitoring-selection-helpers.d.ts +55 -0
  42. package/dist/lint/post-synth/monitoring-selection-helpers.d.ts.map +1 -0
  43. package/dist/lint/post-synth/otel-placement-helpers.d.ts +16 -0
  44. package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
  45. package/dist/lint/post-synth/wk8604.d.ts +6 -0
  46. package/dist/lint/post-synth/wk8604.d.ts.map +1 -1
  47. package/dist/lint/post-synth/wk8605.d.ts.map +1 -1
  48. package/dist/lint/post-synth/wk8606.d.ts +17 -0
  49. package/dist/lint/post-synth/wk8606.d.ts.map +1 -0
  50. package/dist/lint/post-synth/wk8701.d.ts +17 -0
  51. package/dist/lint/post-synth/wk8701.d.ts.map +1 -0
  52. package/dist/lint/post-synth/wk8702.d.ts +17 -0
  53. package/dist/lint/post-synth/wk8702.d.ts.map +1 -0
  54. package/dist/lint/post-synth/wk8703.d.ts +17 -0
  55. package/dist/lint/post-synth/wk8703.d.ts.map +1 -0
  56. package/dist/lint/post-synth/wk8704.d.ts +21 -0
  57. package/dist/lint/post-synth/wk8704.d.ts.map +1 -0
  58. package/dist/lint/post-synth/wk8705.d.ts +18 -0
  59. package/dist/lint/post-synth/wk8705.d.ts.map +1 -0
  60. package/dist/manifest.json +1 -1
  61. package/dist/meta.json +2284 -370
  62. package/dist/okf/index.md +20 -1
  63. package/dist/okf/rules/WK8604.md +6 -2
  64. package/dist/okf/rules/WK8605.md +4 -0
  65. package/dist/okf/rules/WK8606.md +15 -0
  66. package/dist/okf/rules/WK8701.md +18 -0
  67. package/dist/okf/rules/WK8702.md +20 -0
  68. package/dist/okf/rules/WK8703.md +17 -0
  69. package/dist/okf/rules/WK8704.md +22 -0
  70. package/dist/okf/rules/WK8705.md +18 -0
  71. package/dist/okf/types/Alertmanager.md +18 -0
  72. package/dist/okf/types/AlertmanagerConfig.md +18 -0
  73. package/dist/okf/types/ClusterObservability.md +14 -0
  74. package/dist/okf/types/CronJob.md +1 -0
  75. package/dist/okf/types/DaemonSet.md +1 -0
  76. package/dist/okf/types/Instrumentation.md +14 -0
  77. package/dist/okf/types/MonitoringProbe.md +14 -0
  78. package/dist/okf/types/Namespace.md +3 -0
  79. package/dist/okf/types/OpAMPBridge.md +14 -0
  80. package/dist/okf/types/OpenTelemetryCollector.md +19 -0
  81. package/dist/okf/types/Pod.md +1 -0
  82. package/dist/okf/types/PodMonitor.md +20 -0
  83. package/dist/okf/types/Prometheus.md +21 -0
  84. package/dist/okf/types/PrometheusAgent.md +18 -0
  85. package/dist/okf/types/PrometheusRule.md +6 -1
  86. package/dist/okf/types/ScrapeConfig.md +19 -0
  87. package/dist/okf/types/Service.md +1 -0
  88. package/dist/okf/types/ServiceMonitor.md +7 -1
  89. package/dist/okf/types/StatefulSet.md +1 -0
  90. package/dist/okf/types/TargetAllocator.md +14 -0
  91. package/dist/okf/types/ThanosRuler.md +18 -0
  92. package/dist/patch/json-patch.d.ts +51 -0
  93. package/dist/patch/json-patch.d.ts.map +1 -0
  94. package/dist/patch/rendered-patch.d.ts +90 -0
  95. package/dist/patch/rendered-patch.d.ts.map +1 -0
  96. package/dist/plugin.d.ts.map +1 -1
  97. package/dist/project-kinds.d.ts +46 -0
  98. package/dist/project-kinds.d.ts.map +1 -0
  99. package/dist/rules/crd-schema-helpers.ts +10 -2
  100. package/dist/rules/monitoring-selection-helpers.ts +185 -0
  101. package/dist/rules/otel-placement-helpers.ts +61 -1
  102. package/dist/rules/wk8601.ts +1 -1
  103. package/dist/rules/wk8603.ts +1 -1
  104. package/dist/rules/wk8604.ts +8 -2
  105. package/dist/rules/wk8605.ts +5 -3
  106. package/dist/rules/wk8606.ts +27 -0
  107. package/dist/rules/wk8701.ts +37 -0
  108. package/dist/rules/wk8702.ts +43 -0
  109. package/dist/rules/wk8703.ts +37 -0
  110. package/dist/rules/wk8704.ts +134 -0
  111. package/dist/rules/wk8705.ts +45 -0
  112. package/dist/serializer.d.ts.map +1 -1
  113. package/dist/types/index.d.ts +172 -2
  114. package/package.json +3 -3
  115. package/src/codegen/naming.ts +15 -1
  116. package/src/composites/catalog.ts +105 -0
  117. package/src/composites/index.ts +2 -0
  118. package/src/composites/otel-collector-shape.ts +2 -0
  119. package/src/composites/otel-operator-collector.test.ts +267 -0
  120. package/src/composites/otel-operator-collector.ts +221 -0
  121. package/src/config-augmentation.test.ts +28 -0
  122. package/src/config-schema.ts +47 -1
  123. package/src/config.ts +44 -3
  124. package/src/crd/crd-sources.ts +41 -2
  125. package/src/crd/loader.ts +1 -1
  126. package/src/crd/parser.ts +9 -5
  127. package/src/crd/project-codegen.test.ts +239 -0
  128. package/src/crd/project-codegen.ts +327 -0
  129. package/src/generated/index.d.ts +172 -2
  130. package/src/generated/index.ts +303 -2
  131. package/src/generated/lexicon-k8s.json +2284 -370
  132. package/src/generated/operations.json +208 -0
  133. package/src/group-namespace.test.ts +4 -0
  134. package/src/group-namespace.ts +4 -0
  135. package/src/import/embedded.ts +26 -0
  136. package/src/import/operator-collector-roundtrip.test.ts +105 -0
  137. package/src/include/entity.ts +119 -0
  138. package/src/include/include.test.ts +345 -0
  139. package/src/include/resolve.ts +204 -0
  140. package/src/index.ts +25 -2
  141. package/src/kustomize/rendered-entity.ts +43 -1
  142. package/src/kustomize/root.test.ts +39 -0
  143. package/src/kustomize/root.ts +16 -30
  144. package/src/lint/audit-catalog.ts +6 -0
  145. package/src/lint/post-synth/crd-schema-helpers.ts +10 -2
  146. package/src/lint/post-synth/index.ts +12 -0
  147. package/src/lint/post-synth/monitoring-selection-helpers.ts +185 -0
  148. package/src/lint/post-synth/monitoring-selection.test.ts +316 -0
  149. package/src/lint/post-synth/otel-placement-helpers.ts +61 -1
  150. package/src/lint/post-synth/wk8601.ts +1 -1
  151. package/src/lint/post-synth/wk8603.ts +1 -1
  152. package/src/lint/post-synth/wk8604.ts +8 -2
  153. package/src/lint/post-synth/wk8605.ts +5 -3
  154. package/src/lint/post-synth/wk8606.ts +27 -0
  155. package/src/lint/post-synth/wk8701.ts +37 -0
  156. package/src/lint/post-synth/wk8702.ts +43 -0
  157. package/src/lint/post-synth/wk8703.ts +37 -0
  158. package/src/lint/post-synth/wk8704.ts +134 -0
  159. package/src/lint/post-synth/wk8705.ts +45 -0
  160. package/src/patch/json-patch.test.ts +91 -0
  161. package/src/patch/json-patch.ts +189 -0
  162. package/src/patch/rendered-patch.test.ts +143 -0
  163. package/src/patch/rendered-patch.ts +180 -0
  164. package/src/plugin.ts +16 -2
  165. package/src/project-kinds.ts +75 -0
  166. package/src/serializer.ts +10 -0
  167. package/src/testdata/include/bundle.yaml +45 -0
@@ -2193,6 +2193,102 @@
2193
2193
  "watch"
2194
2194
  ]
2195
2195
  },
2196
+ "K8s::Monitoring::Alertmanager": {
2197
+ "entityType": "K8s::Monitoring::Alertmanager",
2198
+ "apiVersion": "monitoring.coreos.com/v1",
2199
+ "kind": "Alertmanager",
2200
+ "plural": "alertmanagers",
2201
+ "scope": "Namespaced",
2202
+ "verbs": [
2203
+ "delete",
2204
+ "get",
2205
+ "list",
2206
+ "patch",
2207
+ "post",
2208
+ "put",
2209
+ "watch"
2210
+ ]
2211
+ },
2212
+ "K8s::Monitoring::AlertmanagerConfig": {
2213
+ "entityType": "K8s::Monitoring::AlertmanagerConfig",
2214
+ "apiVersion": "monitoring.coreos.com/v1alpha1",
2215
+ "kind": "AlertmanagerConfig",
2216
+ "plural": "alertmanagerconfigs",
2217
+ "scope": "Namespaced",
2218
+ "verbs": [
2219
+ "delete",
2220
+ "get",
2221
+ "list",
2222
+ "patch",
2223
+ "post",
2224
+ "put",
2225
+ "watch"
2226
+ ]
2227
+ },
2228
+ "K8s::Monitoring::PodMonitor": {
2229
+ "entityType": "K8s::Monitoring::PodMonitor",
2230
+ "apiVersion": "monitoring.coreos.com/v1",
2231
+ "kind": "PodMonitor",
2232
+ "plural": "podmonitors",
2233
+ "scope": "Namespaced",
2234
+ "verbs": [
2235
+ "delete",
2236
+ "get",
2237
+ "list",
2238
+ "patch",
2239
+ "post",
2240
+ "put",
2241
+ "watch"
2242
+ ]
2243
+ },
2244
+ "K8s::Monitoring::Probe": {
2245
+ "entityType": "K8s::Monitoring::Probe",
2246
+ "apiVersion": "monitoring.coreos.com/v1",
2247
+ "kind": "Probe",
2248
+ "plural": "probes",
2249
+ "scope": "Namespaced",
2250
+ "verbs": [
2251
+ "delete",
2252
+ "get",
2253
+ "list",
2254
+ "patch",
2255
+ "post",
2256
+ "put",
2257
+ "watch"
2258
+ ]
2259
+ },
2260
+ "K8s::Monitoring::Prometheus": {
2261
+ "entityType": "K8s::Monitoring::Prometheus",
2262
+ "apiVersion": "monitoring.coreos.com/v1",
2263
+ "kind": "Prometheus",
2264
+ "plural": "prometheuses",
2265
+ "scope": "Namespaced",
2266
+ "verbs": [
2267
+ "delete",
2268
+ "get",
2269
+ "list",
2270
+ "patch",
2271
+ "post",
2272
+ "put",
2273
+ "watch"
2274
+ ]
2275
+ },
2276
+ "K8s::Monitoring::PrometheusAgent": {
2277
+ "entityType": "K8s::Monitoring::PrometheusAgent",
2278
+ "apiVersion": "monitoring.coreos.com/v1alpha1",
2279
+ "kind": "PrometheusAgent",
2280
+ "plural": "prometheusagents",
2281
+ "scope": "Namespaced",
2282
+ "verbs": [
2283
+ "delete",
2284
+ "get",
2285
+ "list",
2286
+ "patch",
2287
+ "post",
2288
+ "put",
2289
+ "watch"
2290
+ ]
2291
+ },
2196
2292
  "K8s::Monitoring::PrometheusRule": {
2197
2293
  "entityType": "K8s::Monitoring::PrometheusRule",
2198
2294
  "apiVersion": "monitoring.coreos.com/v1",
@@ -2209,6 +2305,22 @@
2209
2305
  "watch"
2210
2306
  ]
2211
2307
  },
2308
+ "K8s::Monitoring::ScrapeConfig": {
2309
+ "entityType": "K8s::Monitoring::ScrapeConfig",
2310
+ "apiVersion": "monitoring.coreos.com/v1alpha1",
2311
+ "kind": "ScrapeConfig",
2312
+ "plural": "scrapeconfigs",
2313
+ "scope": "Namespaced",
2314
+ "verbs": [
2315
+ "delete",
2316
+ "get",
2317
+ "list",
2318
+ "patch",
2319
+ "post",
2320
+ "put",
2321
+ "watch"
2322
+ ]
2323
+ },
2212
2324
  "K8s::Monitoring::ServiceMonitor": {
2213
2325
  "entityType": "K8s::Monitoring::ServiceMonitor",
2214
2326
  "apiVersion": "monitoring.coreos.com/v1",
@@ -2225,6 +2337,22 @@
2225
2337
  "watch"
2226
2338
  ]
2227
2339
  },
2340
+ "K8s::Monitoring::ThanosRuler": {
2341
+ "entityType": "K8s::Monitoring::ThanosRuler",
2342
+ "apiVersion": "monitoring.coreos.com/v1",
2343
+ "kind": "ThanosRuler",
2344
+ "plural": "thanosrulers",
2345
+ "scope": "Namespaced",
2346
+ "verbs": [
2347
+ "delete",
2348
+ "get",
2349
+ "list",
2350
+ "patch",
2351
+ "post",
2352
+ "put",
2353
+ "watch"
2354
+ ]
2355
+ },
2228
2356
  "K8s::Networking::IPAddress": {
2229
2357
  "entityType": "K8s::Networking::IPAddress",
2230
2358
  "apiVersion": "networking.k8s.io/v1",
@@ -2357,6 +2485,86 @@
2357
2485
  "scope": "Namespaced",
2358
2486
  "verbs": []
2359
2487
  },
2488
+ "K8s::OpenTelemetry::ClusterObservability": {
2489
+ "entityType": "K8s::OpenTelemetry::ClusterObservability",
2490
+ "apiVersion": "opentelemetry.io/v1alpha1",
2491
+ "kind": "ClusterObservability",
2492
+ "plural": "clusterobservabilities",
2493
+ "scope": "Namespaced",
2494
+ "verbs": [
2495
+ "delete",
2496
+ "get",
2497
+ "list",
2498
+ "patch",
2499
+ "post",
2500
+ "put",
2501
+ "watch"
2502
+ ]
2503
+ },
2504
+ "K8s::OpenTelemetry::Instrumentation": {
2505
+ "entityType": "K8s::OpenTelemetry::Instrumentation",
2506
+ "apiVersion": "opentelemetry.io/v1alpha1",
2507
+ "kind": "Instrumentation",
2508
+ "plural": "instrumentations",
2509
+ "scope": "Namespaced",
2510
+ "verbs": [
2511
+ "delete",
2512
+ "get",
2513
+ "list",
2514
+ "patch",
2515
+ "post",
2516
+ "put",
2517
+ "watch"
2518
+ ]
2519
+ },
2520
+ "K8s::OpenTelemetry::OpAMPBridge": {
2521
+ "entityType": "K8s::OpenTelemetry::OpAMPBridge",
2522
+ "apiVersion": "opentelemetry.io/v1alpha1",
2523
+ "kind": "OpAMPBridge",
2524
+ "plural": "opampbridges",
2525
+ "scope": "Namespaced",
2526
+ "verbs": [
2527
+ "delete",
2528
+ "get",
2529
+ "list",
2530
+ "patch",
2531
+ "post",
2532
+ "put",
2533
+ "watch"
2534
+ ]
2535
+ },
2536
+ "K8s::OpenTelemetry::OpenTelemetryCollector": {
2537
+ "entityType": "K8s::OpenTelemetry::OpenTelemetryCollector",
2538
+ "apiVersion": "opentelemetry.io/v1beta1",
2539
+ "kind": "OpenTelemetryCollector",
2540
+ "plural": "opentelemetrycollectors",
2541
+ "scope": "Namespaced",
2542
+ "verbs": [
2543
+ "delete",
2544
+ "get",
2545
+ "list",
2546
+ "patch",
2547
+ "post",
2548
+ "put",
2549
+ "watch"
2550
+ ]
2551
+ },
2552
+ "K8s::OpenTelemetry::TargetAllocator": {
2553
+ "entityType": "K8s::OpenTelemetry::TargetAllocator",
2554
+ "apiVersion": "opentelemetry.io/v1alpha1",
2555
+ "kind": "TargetAllocator",
2556
+ "plural": "targetallocators",
2557
+ "scope": "Namespaced",
2558
+ "verbs": [
2559
+ "delete",
2560
+ "get",
2561
+ "list",
2562
+ "patch",
2563
+ "post",
2564
+ "put",
2565
+ "watch"
2566
+ ]
2567
+ },
2360
2568
  "K8s::Policy::Eviction": {
2361
2569
  "entityType": "K8s::Policy::Eviction",
2362
2570
  "apiVersion": "policy/v1",
@@ -32,6 +32,10 @@ describe("namespaceSegmentForGroup", () => {
32
32
  expect(namespaceSegmentForGroup("serving.kserve.io")).toBe("KServe");
33
33
  });
34
34
 
35
+ test("opentelemetry.io takes the OpenTelemetry override, not the misspelt first segment", () => {
36
+ expect(namespaceSegmentForGroup("opentelemetry.io")).toBe("OpenTelemetry");
37
+ });
38
+
35
39
  test("cluster.x-k8s.io takes the CAPI override, avoiding the Cluster::Cluster stutter", () => {
36
40
  expect(namespaceSegmentForGroup("cluster.x-k8s.io")).toBe("CAPI");
37
41
  });
@@ -72,6 +72,10 @@ export const GROUP_NAMESPACE_OVERRIDES: Record<string, string> = {
72
72
  // don't need the same rescue. `addons.cluster.x-k8s.io` (CAAPH's HelmChartProxy,
73
73
  // core CAPI's ClusterResourceSet) likewise stays `Addons`.
74
74
  "cluster.x-k8s.io": "CAPI",
75
+ // The first-segment rule would give `Opentelemetry`, which misspells the
76
+ // product (OpenTelemetry is one word with two capitals) and leaves the
77
+ // operator's kinds as `K8s::Opentelemetry::OpenTelemetryCollector`.
78
+ "opentelemetry.io": "OpenTelemetry",
75
79
  };
76
80
 
77
81
  /**
@@ -9,6 +9,9 @@
9
9
  * JSON);
10
10
  * - a `monitoring.coreos.com` PrometheusRule's `spec.groups`, as the rule file
11
11
  * `{ groups }` those groups would make;
12
+ * - an OpenTelemetry Operator `OpenTelemetryCollector`'s `spec.config` (v1beta1,
13
+ * a structured object), offered as `{ config, header }` with the `# chant:`
14
+ * header lines kept in the `otel.chant.dev/header` annotation (#3367);
12
15
  * - a Grafana Operator `GrafanaDashboard`'s `spec.json`, as text (#3015);
13
16
  * - the alerting content of the Grafana Operator's `GrafanaAlertRuleGroup`
14
17
  * (`spec.rules`), `GrafanaContactPoint` (`spec.receivers`),
@@ -31,6 +34,9 @@ function isObject(v: unknown): v is Record<string, unknown> {
31
34
  return typeof v === "object" && v !== null && !Array.isArray(v);
32
35
  }
33
36
 
37
+ /** The annotation `OtelCollectorCR` keeps the collector config's `# chant:` header lines in (see OTEL_COLLECTOR_ANNOTATIONS). */
38
+ const OTEL_HEADER_ANNOTATION = "otel.chant.dev/header";
39
+
34
40
  /** The `grafana_dashboard` label the Grafana dashboard sidecar looks for (kube-prometheus-stack, the Grafana Helm chart). */
35
41
  export const GRAFANA_DASHBOARD_LABEL = "grafana_dashboard";
36
42
 
@@ -165,6 +171,26 @@ export function delegateEmbedded(
165
171
  return;
166
172
  }
167
173
 
174
+ // The CR holds the config as an object, so the owner is asked for an object (`select: "config"`,
175
+ // answered with `collectorConfig([...])`) rather than for text, which would put a string where the CRD wants a map.
176
+ if (type === "K8s::OpenTelemetry::OpenTelemetryCollector" && isObject(properties.spec) && isObject(properties.spec.config)) {
177
+ const spec = properties.spec;
178
+ const raw = isObject(metadata) && isObject(metadata.annotations) ? metadata.annotations[OTEL_HEADER_ANNOTATION] : undefined;
179
+ const header = typeof raw === "string" ? raw.split("\n").filter((l) => l.length > 0) : [];
180
+ const ref = embedded.resolve({
181
+ host: "k8s",
182
+ hostType: type,
183
+ location: `OpenTelemetryCollector ${name} spec.config`,
184
+ directory: name,
185
+ document: { config: spec.config, header },
186
+ select: "config",
187
+ labels,
188
+ expectedOwner: { lexicon: "otel", what: "an OpenTelemetry Collector config" },
189
+ });
190
+ if (ref) properties.spec = { ...spec, config: ref };
191
+ return;
192
+ }
193
+
168
194
  if (type === "K8s::Monitoring::PrometheusRule" && isObject(properties.spec) && Array.isArray(properties.spec.groups)) {
169
195
  const groups = properties.spec.groups;
170
196
  const ref = embedded.resolve({
@@ -0,0 +1,105 @@
1
+ /**
2
+ * An OpenTelemetryCollector through `chant import` (#3367): the CR
3
+ * `OtelOperatorCollector` writes imports as otel declarations, `spec.config`
4
+ * becomes `collectorConfig([...])` (an object, not the text `collectorYaml`
5
+ * makes), and `chant build` gives back the same resource.
6
+ *
7
+ * The CR is written by `OtelOperatorCollector` itself, so the test holds the
8
+ * writer and the reader to each other. The custom component's pin travels in
9
+ * the `otel.chant.dev/header` annotation and comes back as the pin in the
10
+ * imported `custom-components.ts`.
11
+ */
12
+
13
+ import { describe, expect, test } from "vitest";
14
+ import { loadAll } from "js-yaml";
15
+ import { build } from "@intentius/chant/build";
16
+ import { expandComposite } from "@intentius/chant/composite";
17
+ import type { SerializerResult } from "@intentius/chant/serializer";
18
+ import {
19
+ DebugExporter,
20
+ LoadBalancingExporter,
21
+ OtlpReceiver,
22
+ Pipeline,
23
+ TailSamplingProcessor,
24
+ defineComponent,
25
+ otelSerializer,
26
+ } from "@intentius/chant-lexicon-otel";
27
+ import { k8sSerializer } from "../serializer";
28
+ import { OtelOperatorCollector } from "../composites/otel-operator-collector";
29
+ import { importManifest, removeDir } from "./testdata/embedded/fixtures";
30
+
31
+ type Json = Record<string, unknown>;
32
+
33
+ function primary(out: string | SerializerResult | undefined): string {
34
+ if (out === undefined) return "";
35
+ return typeof out === "string" ? out : out.primary;
36
+ }
37
+
38
+ const Mycorp = defineComponent<{ endpoint: string }>()({
39
+ kind: "receiver",
40
+ type: "mycorp",
41
+ pin: { source: "github.com/mycorp/otel", version: "v1.2.3" },
42
+ });
43
+
44
+ function manifest(): string {
45
+ const config = [
46
+ new Pipeline({
47
+ signal: "traces",
48
+ receivers: [new OtlpReceiver({ protocols: { grpc: { endpoint: "0.0.0.0:4317" } } }), new Mycorp({ endpoint: "0.0.0.0:9999" })],
49
+ processors: [
50
+ new TailSamplingProcessor({
51
+ decision_wait: "5s",
52
+ policies: [{ name: "errors", type: "status_code", status_code: { status_codes: ["ERROR"] } }],
53
+ }),
54
+ ],
55
+ exporters: [
56
+ new DebugExporter({}),
57
+ new LoadBalancingExporter({
58
+ routing_key: "traceID",
59
+ protocol: { otlp: { tls: { insecure: true } } },
60
+ resolver: { dns: { hostname: "gw-headless.observability.svc" } },
61
+ }),
62
+ ],
63
+ }),
64
+ ];
65
+ const instance = OtelOperatorCollector({ name: "gw", mode: "deployment", replicas: 2, config });
66
+ return primary(k8sSerializer.serialize(new Map(expandComposite("gw", instance as never))));
67
+ }
68
+
69
+ function find(docs: Json[], kind: string): Json {
70
+ const doc = docs.find((d) => d.kind === kind);
71
+ if (!doc) throw new Error(`no ${kind}`);
72
+ return doc;
73
+ }
74
+
75
+ describe("OtelOperatorCollector -> chant import -> chant build", () => {
76
+ test("spec.config is imported as otel declarations and builds back to the same resource", async () => {
77
+ const yaml = manifest();
78
+ const input = (loadAll(yaml) as Json[]).filter((d) => d);
79
+ expect(((find(input, "OpenTelemetryCollector").spec as Json).config as Json).service).toBeDefined();
80
+
81
+ const imported = await importManifest(yaml);
82
+ try {
83
+ expect(imported.result.error).toBeUndefined();
84
+ expect(imported.result.success).toBe(true);
85
+
86
+ // An object, so `collectorConfig`; `collectorYaml` would put text in a field the CRD types as a map.
87
+ const sources = Object.values(imported.files).join("\n");
88
+ expect(sources).toContain("collectorConfig(");
89
+ expect(sources).not.toContain("collectorYaml(");
90
+ expect(sources).toContain("new OtlpReceiver(");
91
+ expect(sources).toContain("new TailSamplingProcessor(");
92
+ expect(sources).toContain("new Pipeline(");
93
+ // The pin the annotation carried is back on the custom component.
94
+ expect(sources).toContain("github.com/mycorp/otel");
95
+
96
+ const result = await build(imported.srcDir, [k8sSerializer, otelSerializer]);
97
+ expect(result.errors).toEqual([]);
98
+ const output = (loadAll(primary(result.outputs.get("k8s"))) as Json[]).filter((d) => d);
99
+ expect(find(output, "OpenTelemetryCollector")).toEqual(find(input, "OpenTelemetryCollector"));
100
+ for (const kind of ["ServiceAccount", "ClusterRole", "ClusterRoleBinding"]) expect(find(output, kind)).toEqual(find(input, kind));
101
+ } finally {
102
+ removeDir(imported.dir);
103
+ }
104
+ });
105
+ });
@@ -0,0 +1,119 @@
1
+ /**
2
+ * `k8sInclude`: bring a plain multi-document YAML file or pinned URL into a
3
+ * build as it is (#3566 item 4).
4
+ *
5
+ * Before this, the way to ship a vendored manifest bundle (an operator's
6
+ * install.yaml, a CRD bundle) through chant was a kustomization directory
7
+ * listing it as its only resource. `k8sInclude` declares the file or URL
8
+ * directly. Its documents become the same verbatim manifest entities a
9
+ * kustomize build root produces (`../manifest-entity.ts`), so they get
10
+ * default labels and ownership stamping, post-synth checks, and
11
+ * `lifecycle diff --live` like any declared resource.
12
+ *
13
+ * This module is the declaration only, with no filesystem or network access,
14
+ * so the factory stays pure and folds under `--sandbox`. The bytes are read
15
+ * at `buildRoots()`, the build's one impure seam, in `./resolve.ts`, the same
16
+ * split `declareSecret({ provenance: "committed-encrypted" })` uses.
17
+ *
18
+ * The declaration itself never reaches the output: the serializer skips it,
19
+ * and it carries no `props`, so the live read paths never ask a cluster
20
+ * about it.
21
+ */
22
+ import { DECLARABLE_MARKER, type Declarable } from "@intentius/chant/declarable";
23
+ import type { RenderedPatch } from "../patch/rendered-patch";
24
+
25
+ /** Marks a `k8sInclude` declaration. */
26
+ export const K8S_INCLUDE_MARKER = Symbol.for("chant.k8s.include");
27
+
28
+ export const K8S_INCLUDE_ENTITY_TYPE = "chant:k8s:include";
29
+
30
+ /** Annotation stamped on every included document, valued with its source. */
31
+ export const INCLUDE_SOURCE_ANNOTATION = "chant.intentius.io/include-source";
32
+
33
+ const DIGEST_RE = /^sha256:[0-9a-f]{64}$/;
34
+
35
+ export interface K8sIncludeProps {
36
+ /**
37
+ * A local file path, relative to the project root (the directory holding
38
+ * `chant.config.*`), or an `https://` / `http://` URL.
39
+ */
40
+ source: string;
41
+ /**
42
+ * `sha256:<64 hex>` digest of the source's bytes. Required for a URL: the
43
+ * fetched bytes must match it, and the digest keys the local cache, so
44
+ * only the first build needs the network. Optional for a local file; when
45
+ * set, the file must match it too.
46
+ */
47
+ digest?: string;
48
+ /** Patches applied to the documents before they become entities. */
49
+ patches?: RenderedPatch[];
50
+ }
51
+
52
+ export interface K8sIncludeDeclaration extends Declarable {
53
+ readonly lexicon: "k8s";
54
+ readonly entityType: typeof K8S_INCLUDE_ENTITY_TYPE;
55
+ readonly [K8S_INCLUDE_MARKER]: true;
56
+ readonly source: string;
57
+ readonly digest?: string;
58
+ readonly patches?: RenderedPatch[];
59
+ }
60
+
61
+ export function isK8sInclude(value: unknown): value is K8sIncludeDeclaration {
62
+ return (
63
+ typeof value === "object" &&
64
+ value !== null &&
65
+ (value as Record<symbol, unknown>)[K8S_INCLUDE_MARKER] === true
66
+ );
67
+ }
68
+
69
+ /** True for an `http://` or `https://` source. */
70
+ export function isRemoteSource(source: string): boolean {
71
+ return /^https?:\/\//i.test(source);
72
+ }
73
+
74
+ /**
75
+ * Declare a local or pinned remote multi-document YAML to include in the
76
+ * build.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { k8sInclude } from "@intentius/chant-lexicon-k8s";
81
+ *
82
+ * export const certManager = k8sInclude({
83
+ * source: "https://github.com/cert-manager/cert-manager/releases/download/v1.16.2/cert-manager.yaml",
84
+ * digest: "sha256:...",
85
+ * });
86
+ *
87
+ * export const legacy = k8sInclude({ source: "manifests/legacy.yaml" });
88
+ * ```
89
+ */
90
+ export function k8sInclude(props: K8sIncludeProps): K8sIncludeDeclaration {
91
+ const source = props?.source;
92
+ if (typeof source !== "string" || source.length === 0) {
93
+ throw new Error("k8sInclude: `source` must be a non-empty path or URL");
94
+ }
95
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(source) && !isRemoteSource(source)) {
96
+ throw new Error(`k8sInclude("${source}"): only local paths and http(s) URLs are supported`);
97
+ }
98
+ if (props.digest !== undefined && !DIGEST_RE.test(props.digest)) {
99
+ throw new Error(
100
+ `k8sInclude("${source}"): digest ${JSON.stringify(props.digest)} is not of the form "sha256:<64 lowercase hex>"`,
101
+ );
102
+ }
103
+ if (isRemoteSource(source) && props.digest === undefined) {
104
+ throw new Error(
105
+ `k8sInclude("${source}"): a URL source must be pinned with \`digest: "sha256:<hex>"\`. ` +
106
+ `Compute it from a copy you have reviewed, e.g. \`curl -sL <url> | shasum -a 256\`.`,
107
+ );
108
+ }
109
+
110
+ return {
111
+ lexicon: "k8s",
112
+ entityType: K8S_INCLUDE_ENTITY_TYPE,
113
+ source,
114
+ ...(props.digest !== undefined ? { digest: props.digest } : {}),
115
+ ...(props.patches !== undefined ? { patches: JSON.parse(JSON.stringify(props.patches)) as RenderedPatch[] } : {}),
116
+ [DECLARABLE_MARKER]: true,
117
+ [K8S_INCLUDE_MARKER]: true,
118
+ };
119
+ }