@intentius/chant-lexicon-k8s 0.106.4 → 0.107.1

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 (116) 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/crd/crd-sources.d.ts.map +1 -1
  10. package/dist/generated/index.d.d.ts +172 -2
  11. package/dist/generated/index.d.ts +301 -0
  12. package/dist/generated/index.d.ts.map +1 -1
  13. package/dist/group-namespace.d.ts.map +1 -1
  14. package/dist/import/embedded.d.ts +3 -0
  15. package/dist/import/embedded.d.ts.map +1 -1
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/integrity.json +16 -9
  19. package/dist/lint/audit-catalog.d.ts.map +1 -1
  20. package/dist/lint/post-synth/index.d.ts.map +1 -1
  21. package/dist/lint/post-synth/monitoring-selection-helpers.d.ts +55 -0
  22. package/dist/lint/post-synth/monitoring-selection-helpers.d.ts.map +1 -0
  23. package/dist/lint/post-synth/otel-placement-helpers.d.ts +16 -0
  24. package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
  25. package/dist/lint/post-synth/wk8604.d.ts +6 -0
  26. package/dist/lint/post-synth/wk8604.d.ts.map +1 -1
  27. package/dist/lint/post-synth/wk8605.d.ts.map +1 -1
  28. package/dist/lint/post-synth/wk8606.d.ts +17 -0
  29. package/dist/lint/post-synth/wk8606.d.ts.map +1 -0
  30. package/dist/lint/post-synth/wk8701.d.ts +17 -0
  31. package/dist/lint/post-synth/wk8701.d.ts.map +1 -0
  32. package/dist/lint/post-synth/wk8702.d.ts +17 -0
  33. package/dist/lint/post-synth/wk8702.d.ts.map +1 -0
  34. package/dist/lint/post-synth/wk8703.d.ts +17 -0
  35. package/dist/lint/post-synth/wk8703.d.ts.map +1 -0
  36. package/dist/lint/post-synth/wk8704.d.ts +21 -0
  37. package/dist/lint/post-synth/wk8704.d.ts.map +1 -0
  38. package/dist/lint/post-synth/wk8705.d.ts +18 -0
  39. package/dist/lint/post-synth/wk8705.d.ts.map +1 -0
  40. package/dist/manifest.json +1 -1
  41. package/dist/meta.json +2284 -370
  42. package/dist/okf/index.md +20 -1
  43. package/dist/okf/rules/WK8604.md +6 -2
  44. package/dist/okf/rules/WK8605.md +4 -0
  45. package/dist/okf/rules/WK8606.md +15 -0
  46. package/dist/okf/rules/WK8701.md +18 -0
  47. package/dist/okf/rules/WK8702.md +20 -0
  48. package/dist/okf/rules/WK8703.md +17 -0
  49. package/dist/okf/rules/WK8704.md +22 -0
  50. package/dist/okf/rules/WK8705.md +18 -0
  51. package/dist/okf/types/Alertmanager.md +18 -0
  52. package/dist/okf/types/AlertmanagerConfig.md +18 -0
  53. package/dist/okf/types/ClusterObservability.md +14 -0
  54. package/dist/okf/types/CronJob.md +1 -0
  55. package/dist/okf/types/DaemonSet.md +1 -0
  56. package/dist/okf/types/Instrumentation.md +14 -0
  57. package/dist/okf/types/MonitoringProbe.md +14 -0
  58. package/dist/okf/types/Namespace.md +3 -0
  59. package/dist/okf/types/OpAMPBridge.md +14 -0
  60. package/dist/okf/types/OpenTelemetryCollector.md +19 -0
  61. package/dist/okf/types/Pod.md +1 -0
  62. package/dist/okf/types/PodMonitor.md +20 -0
  63. package/dist/okf/types/Prometheus.md +21 -0
  64. package/dist/okf/types/PrometheusAgent.md +18 -0
  65. package/dist/okf/types/PrometheusRule.md +6 -1
  66. package/dist/okf/types/ScrapeConfig.md +19 -0
  67. package/dist/okf/types/Service.md +1 -0
  68. package/dist/okf/types/ServiceMonitor.md +7 -1
  69. package/dist/okf/types/StatefulSet.md +1 -0
  70. package/dist/okf/types/TargetAllocator.md +14 -0
  71. package/dist/okf/types/ThanosRuler.md +18 -0
  72. package/dist/rules/monitoring-selection-helpers.ts +185 -0
  73. package/dist/rules/otel-placement-helpers.ts +61 -1
  74. package/dist/rules/wk8601.ts +1 -1
  75. package/dist/rules/wk8603.ts +1 -1
  76. package/dist/rules/wk8604.ts +8 -2
  77. package/dist/rules/wk8605.ts +5 -3
  78. package/dist/rules/wk8606.ts +27 -0
  79. package/dist/rules/wk8701.ts +37 -0
  80. package/dist/rules/wk8702.ts +43 -0
  81. package/dist/rules/wk8703.ts +37 -0
  82. package/dist/rules/wk8704.ts +134 -0
  83. package/dist/rules/wk8705.ts +45 -0
  84. package/dist/types/index.d.ts +172 -2
  85. package/package.json +3 -3
  86. package/src/codegen/naming.ts +15 -1
  87. package/src/composites/catalog.ts +105 -0
  88. package/src/composites/index.ts +2 -0
  89. package/src/composites/otel-collector-shape.ts +2 -0
  90. package/src/composites/otel-operator-collector.test.ts +267 -0
  91. package/src/composites/otel-operator-collector.ts +221 -0
  92. package/src/crd/crd-sources.ts +41 -2
  93. package/src/generated/index.d.ts +172 -2
  94. package/src/generated/index.ts +303 -2
  95. package/src/generated/lexicon-k8s.json +2284 -370
  96. package/src/generated/operations.json +208 -0
  97. package/src/group-namespace.test.ts +4 -0
  98. package/src/group-namespace.ts +4 -0
  99. package/src/import/embedded.ts +26 -0
  100. package/src/import/operator-collector-roundtrip.test.ts +105 -0
  101. package/src/index.ts +2 -2
  102. package/src/lint/audit-catalog.ts +6 -0
  103. package/src/lint/post-synth/index.ts +12 -0
  104. package/src/lint/post-synth/monitoring-selection-helpers.ts +185 -0
  105. package/src/lint/post-synth/monitoring-selection.test.ts +316 -0
  106. package/src/lint/post-synth/otel-placement-helpers.ts +61 -1
  107. package/src/lint/post-synth/wk8601.ts +1 -1
  108. package/src/lint/post-synth/wk8603.ts +1 -1
  109. package/src/lint/post-synth/wk8604.ts +8 -2
  110. package/src/lint/post-synth/wk8605.ts +5 -3
  111. package/src/lint/post-synth/wk8606.ts +27 -0
  112. package/src/lint/post-synth/wk8701.ts +37 -0
  113. package/src/lint/post-synth/wk8702.ts +43 -0
  114. package/src/lint/post-synth/wk8703.ts +37 -0
  115. package/src/lint/post-synth/wk8704.ts +134 -0
  116. package/src/lint/post-synth/wk8705.ts +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
+ });
package/src/index.ts CHANGED
@@ -70,7 +70,7 @@ export {
70
70
  WebApp, StatefulApp, CronWorkload, AutoscaledService, WorkerPool, NamespaceEnv, NodeAgent,
71
71
  BatchJob, SecureIngress, ConfiguredApp, SidecarApp, MonitoredService, NetworkIsolatedApp,
72
72
  IrsaServiceAccount, AlbIngress, EbsStorageClass, EfsStorageClass, FluentBitAgent, ExternalDnsAgent, AdotCollector, OtelCollector,
73
- OtelCollectorGateway, gatewayExporter, OTEL_COLLECTOR_ANNOTATIONS,
73
+ OtelCollectorGateway, gatewayExporter, OTEL_COLLECTOR_ANNOTATIONS, OtelOperatorCollector,
74
74
  MetricsServer, WorkloadIdentityServiceAccount, GcePdStorageClass, FilestoreStorageClass, GkeGateway, ConfigConnectorContext,
75
75
  GceIngress, CockroachDbCluster, CockroachDbRegionStack,
76
76
  RayCluster, RayJob, RayService,
@@ -93,7 +93,7 @@ export type {
93
93
  EbsStorageClassProps, EbsStorageClassResult, EfsStorageClassProps, EfsStorageClassResult,
94
94
  FluentBitAgentProps, FluentBitAgentResult, ExternalDnsAgentProps, ExternalDnsAgentResult,
95
95
  AdotCollectorProps, AdotCollectorResult,
96
- OtelCollectorProps, OtelCollectorResult,
96
+ OtelCollectorProps, OtelCollectorResult, OtelOperatorCollectorProps, OtelOperatorCollectorResult, OtelOperatorMode,
97
97
  OtelCollectorGatewayProps, OtelCollectorGatewayResult, GatewayExporterOptions, CollectorPolicyRule,
98
98
  CollectorRole, GatewayRouting,
99
99
  MetricsServerProps, MetricsServerResult,
@@ -51,6 +51,12 @@ export const k8sAuditCatalog: Record<string, RuleMeta> = {
51
51
  WK8603: auditRule("WK8603", "merge-worthy", "guidance", "k8s_cluster receiver runs in every collector copy", "Run the k8s_cluster receiver in a single-replica Deployment, or set its k8s_leader_elector to a k8s_leader_elector extension enabled in service.extensions.", { category: "correctness" }),
52
52
  WK8604: auditRule("WK8604", "merge-worthy", "guidance", "Collector config in a ConfigMap fails the otel config checks", "Fix the collector config the ConfigMap carries: each finding keeps its OTEL1xx id and names the ConfigMap and key. Change the declared components and pipelines, not the rendered YAML.", { category: "correctness" }),
53
53
  WK8605: auditRule("WK8605", "merge-worthy", "guidance", "Collector config reads the node but its workload lacks the node name or host mounts", "Set the node name variable from spec.nodeName with the downward API and mount the host paths hostmetrics and filelog read, read-only; OtelCollector adds them from the config.", { category: "correctness" }),
54
+ WK8606: auditRule("WK8606", "merge-worthy", "guidance", "PrometheusRule groups fail the prometheus rule-file checks", "Fix the rule group the PrometheusRule carries: each finding keeps its PROM1xx or PROM2xx id and names the PrometheusRule. Change the declared RuleGroup, not the rendered YAML.", { category: "correctness" }),
55
+ WK8701: auditRule("WK8701", "merge-worthy", "guidance", "PrometheusRule selected by no Prometheus or ThanosRuler", "Match the rule's labels and namespace with ruleSelector and ruleNamespaceSelector; null selects nothing, {} selects all.", { category: "correctness" }),
56
+ WK8702: auditRule("WK8702", "merge-worthy", "guidance", "Monitor selected by no Prometheus or PrometheusAgent", "Match the ServiceMonitor, PodMonitor, Probe or ScrapeConfig with the selector and namespace selector for its kind; null selects nothing, {} selects all.", { category: "correctness" }),
57
+ WK8703: auditRule("WK8703", "merge-worthy", "guidance", "AlertmanagerConfig selected by no Alertmanager", "Match the config's labels and namespace with alertmanagerConfigSelector and alertmanagerConfigNamespaceSelector; null selects nothing, {} selects all.", { category: "correctness" }),
58
+ WK8704: auditRule("WK8704", "merge-worthy", "guidance", "Monitor selects no Service or pod, or names a port that is not there", "Make the monitor's selector match the labels on the Service or pod template, and name a port the Service or container declares.", { category: "correctness" }),
59
+ WK8705: auditRule("WK8705", "merge-worthy", "guidance", "Prometheus selects no monitor at all", "Set serviceMonitorSelector, podMonitorSelector, probeSelector and scrapeConfigSelector for the monitor kinds it should scrape; {} selects all in the selected namespaces.", { category: "correctness" }),
54
60
  };
55
61
 
56
62
  // Prior art credits live beside the rules in ./audit-lineage.ts (see core audit/prior-art.ts).
@@ -45,6 +45,12 @@ import { wk8602 } from "./wk8602";
45
45
  import { wk8603 } from "./wk8603";
46
46
  import { wk8604 } from "./wk8604";
47
47
  import { wk8605 } from "./wk8605";
48
+ import { wk8606 } from "./wk8606";
49
+ import { wk8701 } from "./wk8701";
50
+ import { wk8702 } from "./wk8702";
51
+ import { wk8703 } from "./wk8703";
52
+ import { wk8704 } from "./wk8704";
53
+ import { wk8705 } from "./wk8705";
48
54
 
49
55
  export const postSynthChecks: PostSynthCheck[] = [
50
56
  argo002,
@@ -92,4 +98,10 @@ export const postSynthChecks: PostSynthCheck[] = [
92
98
  wk8603,
93
99
  wk8604,
94
100
  wk8605,
101
+ wk8606,
102
+ wk8701,
103
+ wk8702,
104
+ wk8703,
105
+ wk8704,
106
+ wk8705,
95
107
  ];
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Shared plumbing for the Prometheus Operator selection checks (WK8701-WK8705).
3
+ *
4
+ * An operator accepts a PrometheusRule, monitor or AlertmanagerConfig that no
5
+ * Prometheus or Alertmanager selects and then ignores it without an error.
6
+ * These helpers decide, from the manifests in one build, whether a selector
7
+ * picks an object, following the operator's rules for a label selector:
8
+ *
9
+ * - an object selector that is null (or absent) matches nothing, `{}` matches all;
10
+ * - a namespace selector that is null (or absent) matches only the selecting
11
+ * resource's own namespace, `{}` matches every namespace.
12
+ *
13
+ * Namespace labels come from the Namespace manifests in the build, plus the
14
+ * `kubernetes.io/metadata.name` label every namespace carries. A selector on a
15
+ * label the build cannot know (the namespace is not declared in it) answers
16
+ * "unknown", and the checks stay silent on "unknown".
17
+ */
18
+
19
+ import { docsToManifests, type K8sManifest } from "./k8s-helpers";
20
+ import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
21
+
22
+ export const MONITORING_GROUP = "monitoring.coreos.com/";
23
+
24
+ export type Match = "yes" | "no" | "unknown";
25
+
26
+ function isRecord(v: unknown): v is Record<string, unknown> {
27
+ return typeof v === "object" && v !== null && !Array.isArray(v);
28
+ }
29
+
30
+ /** A manifest of a monitoring.coreos.com kind, whatever the version. */
31
+ export function ofMonitoringKind(m: K8sManifest, kind: string): boolean {
32
+ return m.kind === kind && typeof m.apiVersion === "string" && m.apiVersion.startsWith(MONITORING_GROUP);
33
+ }
34
+
35
+ export function monitoringKind(manifests: K8sManifest[], kind: string): K8sManifest[] {
36
+ return manifests.filter((m) => ofMonitoringKind(m, kind));
37
+ }
38
+
39
+ export function namespaceOf(m: K8sManifest): string {
40
+ return typeof m.metadata?.namespace === "string" && m.metadata.namespace !== "" ? m.metadata.namespace : "default";
41
+ }
42
+
43
+ export function nameOf(m: K8sManifest): string {
44
+ return typeof m.metadata?.name === "string" ? m.metadata.name : "";
45
+ }
46
+
47
+ export function describe(m: K8sManifest): string {
48
+ return `${m.kind} ${namespaceOf(m)}/${nameOf(m)}`;
49
+ }
50
+
51
+ /**
52
+ * Whether a label selector matches a label set. Null, undefined and anything
53
+ * that is not an object match nothing; `{}` matches everything.
54
+ * `unknownKeys` are label keys the caller cannot read (a namespace the build
55
+ * does not declare); a requirement on one answers "unknown".
56
+ */
57
+ export function matchLabelSelector(selector: unknown, labels: Record<string, string>, unknownKeys: ReadonlySet<string> = new Set()): Match {
58
+ if (!isRecord(selector)) return "no";
59
+ let unknown = false;
60
+ const matchLabels = isRecord(selector.matchLabels) ? selector.matchLabels : {};
61
+ for (const [k, v] of Object.entries(matchLabels)) {
62
+ if (unknownKeys.has(k)) {
63
+ unknown = true;
64
+ } else if (labels[k] !== String(v)) {
65
+ return "no";
66
+ }
67
+ }
68
+ const exprs = Array.isArray(selector.matchExpressions) ? selector.matchExpressions : [];
69
+ for (const e of exprs) {
70
+ if (!isRecord(e) || typeof e.key !== "string") continue;
71
+ if (unknownKeys.has(e.key)) {
72
+ unknown = true;
73
+ continue;
74
+ }
75
+ const values = Array.isArray(e.values) ? e.values.map(String) : [];
76
+ const has = Object.prototype.hasOwnProperty.call(labels, e.key);
77
+ switch (e.operator) {
78
+ case "In":
79
+ if (!has || !values.includes(labels[e.key])) return "no";
80
+ break;
81
+ case "NotIn":
82
+ if (has && values.includes(labels[e.key])) return "no";
83
+ break;
84
+ case "Exists":
85
+ if (!has) return "no";
86
+ break;
87
+ case "DoesNotExist":
88
+ if (has) return "no";
89
+ break;
90
+ }
91
+ }
92
+ return unknown ? "unknown" : "yes";
93
+ }
94
+
95
+ export function labelsOf(m: K8sManifest): Record<string, string> {
96
+ const out: Record<string, string> = {};
97
+ const labels = m.metadata?.labels;
98
+ if (isRecord(labels)) for (const [k, v] of Object.entries(labels)) out[k] = String(v);
99
+ return out;
100
+ }
101
+
102
+ /** The namespaces a build declares, with their labels. */
103
+ function declaredNamespaces(manifests: K8sManifest[]): Map<string, Record<string, string>> {
104
+ const out = new Map<string, Record<string, string>>();
105
+ for (const m of manifests) {
106
+ if (m.kind === "Namespace" && (m.apiVersion === "v1" || m.apiVersion === undefined) && nameOf(m)) {
107
+ out.set(nameOf(m), { ...labelsOf(m), "kubernetes.io/metadata.name": nameOf(m) });
108
+ }
109
+ }
110
+ return out;
111
+ }
112
+
113
+ /**
114
+ * Whether a selecting resource's namespace selector picks `targetNamespace`.
115
+ * Null or absent: the selecting resource's own namespace only.
116
+ */
117
+ export function matchNamespaceSelector(
118
+ selector: unknown,
119
+ ownNamespace: string,
120
+ targetNamespace: string,
121
+ namespaces: Map<string, Record<string, string>>,
122
+ ): Match {
123
+ if (!isRecord(selector)) return ownNamespace === targetNamespace ? "yes" : "no";
124
+ const declared = namespaces.get(targetNamespace);
125
+ const labels = declared ?? { "kubernetes.io/metadata.name": targetNamespace };
126
+ // A namespace the build does not declare has labels the build cannot know, except the name label.
127
+ const unknownKeys = new Set<string>();
128
+ if (!declared) {
129
+ const keys = [
130
+ ...Object.keys(isRecord(selector.matchLabels) ? selector.matchLabels : {}),
131
+ ...(Array.isArray(selector.matchExpressions) ? selector.matchExpressions : []).map((e) => (isRecord(e) ? String(e.key) : "")),
132
+ ];
133
+ for (const k of keys) if (k !== "kubernetes.io/metadata.name") unknownKeys.add(k);
134
+ }
135
+ return matchLabelSelector(selector, labels, unknownKeys);
136
+ }
137
+
138
+ /** A selecting resource's reach over one object: its object selector, then its namespace selector. */
139
+ export function selects(
140
+ selector: unknown,
141
+ namespaceSelector: unknown,
142
+ selecting: K8sManifest,
143
+ object: K8sManifest,
144
+ namespaces: Map<string, Record<string, string>>,
145
+ ): Match {
146
+ const ns = matchNamespaceSelector(namespaceSelector, namespaceOf(selecting), namespaceOf(object), namespaces);
147
+ if (ns === "no") return "no";
148
+ const obj = matchLabelSelector(selector, labelsOf(object));
149
+ if (obj === "no") return "no";
150
+ return ns === "unknown" || obj === "unknown" ? "unknown" : "yes";
151
+ }
152
+
153
+ export interface SelectionContext {
154
+ manifests: K8sManifest[];
155
+ namespaces: Map<string, Record<string, string>>;
156
+ }
157
+
158
+ export function selectionContext(ctx: PostSynthContext): SelectionContext {
159
+ const manifests = docsToManifests(ctx);
160
+ return { manifests, namespaces: declaredNamespaces(manifests) };
161
+ }
162
+
163
+ /**
164
+ * Objects of `kinds` that no resource in `selectors` selects, by the named
165
+ * object selector and namespace selector fields of each selector's spec.
166
+ * Silent (empty) when `selectors` is empty, since the stack is often installed
167
+ * separately. A selector that answers "unknown" counts as selecting.
168
+ */
169
+ export function unselected(
170
+ sc: SelectionContext,
171
+ objects: K8sManifest[],
172
+ selectors: K8sManifest[],
173
+ fields: (selecting: K8sManifest, object: K8sManifest) => [string, string] | null,
174
+ ): K8sManifest[] {
175
+ if (selectors.length === 0) return [];
176
+ return objects.filter((object) => {
177
+ for (const sel of selectors) {
178
+ const f = fields(sel, object);
179
+ if (!f) continue;
180
+ const spec = (sel.spec ?? {}) as Record<string, unknown>;
181
+ if (selects(spec[f[0]], spec[f[1]], sel, object, sc.namespaces) !== "no") return false;
182
+ }
183
+ return true;
184
+ });
185
+ }