@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
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Patching rendered documents (#3566 item 3).
3
+ *
4
+ * A Helm render, a kustomize build root and a `k8sInclude` all hand chant
5
+ * finished manifests. When a chart or an upstream bundle does not expose a
6
+ * field, the alternatives were forking it or running an overlay outside
7
+ * chant. A `RenderedPatch` selects documents by kind and name (namespace and
8
+ * apiVersion optional) and changes them before they become entities, so the
9
+ * patched form is what the serializer emits, what ownership stamping and
10
+ * post-synth checks see, and what `lifecycle diff --live` compares against
11
+ * the cluster.
12
+ *
13
+ * One patch type for all three sources: `HelmRender({ patches })`,
14
+ * `k8sInclude({ patches })`, and `{ path, patches }` entries in
15
+ * `k8s.kustomize.roots`. Each source calls {@link applyRenderedPatches} on
16
+ * its parsed documents.
17
+ *
18
+ * A selector that matches nothing is an error. The common way to get there
19
+ * is a chart upgrade that renamed a resource, and a patch that silently
20
+ * stops applying is the failure this guards against. There is no opt-out:
21
+ * a patch whose target is legitimately absent (a chart value that turns a
22
+ * resource off) belongs behind the same condition in TypeScript that sets
23
+ * the value.
24
+ */
25
+ import type * as Generated from "../generated/index.d";
26
+ import { type JsonPatchOperation } from "./json-patch.js";
27
+ export type { JsonPatchOperation } from "./json-patch.js";
28
+ export { applyJsonPatch, applyMergePatch } from "./json-patch.js";
29
+ /** Which rendered documents a patch applies to. */
30
+ export interface RenderedSelector<K extends string = string> {
31
+ /** The document's `kind`, e.g. `"Deployment"`. */
32
+ kind: K;
33
+ /** The document's `metadata.name`. */
34
+ name: string;
35
+ /** The document's `metadata.namespace`. Omitted, documents in any namespace (or none) match. */
36
+ namespace?: string;
37
+ /** The document's `apiVersion`, for a kind name two API groups share. */
38
+ apiVersion?: string;
39
+ }
40
+ /**
41
+ * The constructor props of the lexicon's generated class named `K`, when
42
+ * there is one; otherwise an open record. Merge patches for known kinds are
43
+ * checked against it.
44
+ */
45
+ export type KindProps<K extends string> = K extends keyof typeof Generated ? (typeof Generated)[K] extends abstract new (props: infer P) => unknown ? P : Record<string, unknown> : Record<string, unknown>;
46
+ /**
47
+ * An RFC 7386 merge patch over `T`: object fields are optional at every
48
+ * depth and may be `null` (which deletes them); arrays replace the target
49
+ * whole, so their elements stay complete.
50
+ */
51
+ export type MergePatchOf<T> = T extends readonly unknown[] ? T : T extends object ? {
52
+ [P in keyof T]?: MergePatchOf<T[P]> | null;
53
+ } : T;
54
+ /** A patch applied as RFC 6902 operations. */
55
+ export interface RenderedJsonPatch<K extends string = string> extends RenderedSelector<K> {
56
+ jsonPatch: JsonPatchOperation[];
57
+ merge?: never;
58
+ }
59
+ /** A patch applied as an RFC 7386 merge. */
60
+ export interface RenderedMergePatch<K extends string = string> extends RenderedSelector<K> {
61
+ merge: MergePatchOf<KindProps<K>>;
62
+ jsonPatch?: never;
63
+ }
64
+ /** One patch on rendered output: a selector plus either `jsonPatch` or `merge`. */
65
+ export type RenderedPatch<K extends string = string> = RenderedJsonPatch<K> | RenderedMergePatch<K>;
66
+ /**
67
+ * Identity helper that infers `kind`, so a `merge` body is checked against
68
+ * that kind's props:
69
+ *
70
+ * ```ts
71
+ * renderedPatch({ kind: "Deployment", name: "web", merge: { spec: { replicas: 3 } } })
72
+ * ```
73
+ *
74
+ * A plain object literal works anywhere a `RenderedPatch` is taken; it just
75
+ * types `merge` as an open record.
76
+ */
77
+ export declare function renderedPatch<K extends string>(patch: RenderedPatch<K>): RenderedPatch;
78
+ /**
79
+ * Apply `patches` in order to `docs` and return the patched documents, in
80
+ * the same order. `source` names where the documents came from (a chart, a
81
+ * file, a URL, an overlay dir) and leads every error message.
82
+ *
83
+ * Each patch applies to every document its selector matches at that point,
84
+ * so a later patch sees an earlier one's changes. Throws when a selector
85
+ * matches nothing, when an operation fails (a `test` included), when a patch
86
+ * carries both or neither of `jsonPatch` and `merge`, and when a patched
87
+ * document no longer has a string `apiVersion` and `kind`.
88
+ */
89
+ export declare function applyRenderedPatches(docs: ReadonlyArray<Record<string, unknown>>, patches: ReadonlyArray<RenderedPatch> | undefined, source: string): Array<Record<string, unknown>>;
90
+ //# sourceMappingURL=rendered-patch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rendered-patch.d.ts","sourceRoot":"","sources":["../../src/patch/rendered-patch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,OAAO,KAAK,KAAK,SAAS,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAmC,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAExF,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D,mDAAmD;AACnD,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACzD,kDAAkD;IAClD,IAAI,EAAE,CAAC,CAAC;IACR,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,OAAO,SAAS,GACtE,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,MAAM,KAAK,EAAE,MAAM,CAAC,KAAK,OAAO,GACpE,CAAC,GACD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5B;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,OAAO,EAAE,GACtD,CAAC,GACD,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;CAAE,GAC9C,CAAC,CAAC;AAER,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IACvF,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,4CAA4C;AAC5C,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IACxF,KAAK,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB;AAED,mFAAmF;AACnF,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAEpG;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAEtF;AAuBD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC5C,OAAO,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,SAAS,EACjD,MAAM,EAAE,MAAM,GACb,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA6ChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAqC,MAAM,0BAA0B,CAAC;AA8BjG,eAAO,MAAM,SAAS,EAAE,aAkuBvB,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAqC,MAAM,0BAA0B,CAAC;AAgCjG,eAAO,MAAM,SAAS,EAAE,aA8uBvB,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Kinds a project generated for itself with `chant generate` from `k8s.crds`
3
+ * (./crd/project-codegen.ts), as opposed to the kinds the lexicon ships in
4
+ * `generated/lexicon-k8s.json`.
5
+ *
6
+ * The serializer's GVK lookup and the CRD spec checks (WK8501/WK8502) consult
7
+ * this registry before the packaged JSON. Entries arrive two ways:
8
+ *
9
+ * - The generated module registers its kinds (type and GVK) when it is
10
+ * imported, so a project's own tests that construct and serialize a
11
+ * resource need nothing else.
12
+ * - A build registers every kind, spec schema included, from the committed
13
+ * `kinds.json` beside the module before it serializes (the plugin's
14
+ * `projectCodegen().load`). That covers a build whose discovery imported the
15
+ * module somewhere else, such as the sandboxed child process.
16
+ *
17
+ * The store hangs off `globalThis` under a registered symbol, so two copies
18
+ * of this module (the plugin the CLI loaded and the one a project's import
19
+ * resolved) share it. No Node imports: the post-synth barrel reaches this
20
+ * through ./lint/post-synth/crd-schema-helpers.ts and must stay edge-safe.
21
+ */
22
+ import type { CrdFieldSchema } from "./spec/parse.js";
23
+ /** One project-generated kind. */
24
+ export interface ProjectKind {
25
+ /** The entity type the generated class constructs, e.g. `K8s::Example::Widget`. */
26
+ resourceType: string;
27
+ /** e.g. `example.com/v1`. */
28
+ apiVersion: string;
29
+ /** e.g. `Widget`. */
30
+ kind: string;
31
+ /** The CRD's `spec` field schema, for the spec checks. */
32
+ specSchema?: CrdFieldSchema;
33
+ }
34
+ /**
35
+ * Register project-generated kinds. A later registration of the same type
36
+ * replaces the earlier one, keeping its spec schema when the new entry has
37
+ * none (the module's import-time registration carries no schema).
38
+ */
39
+ export declare function registerProjectKinds(kinds: readonly ProjectKind[]): void;
40
+ /** The project kind an entity type constructs, if a project registered one. */
41
+ export declare function projectKindForType(resourceType: string): ProjectKind | undefined;
42
+ /** The spec schema a project registered for `apiVersion`/`kind`, if any. */
43
+ export declare function projectSpecSchema(apiVersion: string, kind: string): CrdFieldSchema | undefined;
44
+ /** Test seam: forget every registered kind. */
45
+ export declare function clearProjectKinds(): void;
46
+ //# sourceMappingURL=project-kinds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-kinds.d.ts","sourceRoot":"","sources":["../src/project-kinds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC1B,mFAAmF;IACnF,YAAY,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAUD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAOxE;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAEhF;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAK9F;AAED,+CAA+C;AAC/C,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
@@ -15,6 +15,7 @@ import { createRequire } from "module";
15
15
  import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
16
16
  import type { CrdFieldSchema } from "../../spec/parse";
17
17
  import { docsToManifests, type K8sManifest } from "./k8s-helpers";
18
+ import { projectSpecSchema } from "../../project-kinds";
18
19
 
19
20
  export type { CrdFieldSchema };
20
21
 
@@ -61,10 +62,17 @@ export function setCrdSchemaRegistry(registry: Map<string, CrdFieldSchema> | nul
61
62
  cachedRegistry = registry;
62
63
  }
63
64
 
64
- /** The schema for a manifest's `apiVersion`/`kind`, if the lexicon ships one. */
65
+ /**
66
+ * The schema for a manifest's `apiVersion`/`kind`: one the project generated
67
+ * from its own CRDs (`chant generate`, ../../project-kinds.ts) first, then one
68
+ * the lexicon ships.
69
+ */
65
70
  export function specSchemaFor(manifest: K8sManifest): CrdFieldSchema | undefined {
66
71
  if (typeof manifest.apiVersion !== "string" || typeof manifest.kind !== "string") return undefined;
67
- return getCrdSchemaRegistry().get(registryKey(manifest.apiVersion, manifest.kind));
72
+ return (
73
+ projectSpecSchema(manifest.apiVersion, manifest.kind) ??
74
+ getCrdSchemaRegistry().get(registryKey(manifest.apiVersion, manifest.kind))
75
+ );
68
76
  }
69
77
 
70
78
  /** Every manifest in the build that has a shipped spec schema, with that schema. */
@@ -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
+ }
@@ -15,6 +15,13 @@
15
15
  * When a container passes `--config=<path>`, only keys named by those
16
16
  * paths count.
17
17
  *
18
+ * 3. An OpenTelemetry Operator `OpenTelemetryCollector` carries its config in
19
+ * `spec.config` (an object in v1beta1, a YAML string in v1alpha1) and its
20
+ * placement in `spec.mode` and `spec.replicas`; it is its own workload. A
21
+ * `sidecar` runs inside other pods and is left out. The Services the
22
+ * operator makes (`<name>-collector`, `<name>-collector-headless`) are not
23
+ * in the build, so \`servicesSelecting\` names them from the CR.
24
+ *
18
25
  * Anything this can't resolve (a ConfigMap or workload outside the build, a
19
26
  * replica count that isn't a number) is left out, so the checks stay silent
20
27
  * rather than guess. Like every bundle-join check they see one build root at
@@ -33,6 +40,7 @@ export const PLACEMENT_ANNOTATIONS = {
33
40
  workload: "otel.chant.dev/workload",
34
41
  config: "otel.chant.dev/config",
35
42
  gateways: "otel.chant.dev/gateways",
43
+ header: "otel.chant.dev/header",
36
44
  } as const;
37
45
 
38
46
  /** The part of a collector config the placement checks read. */
@@ -59,13 +67,51 @@ export interface CollectorPlacement {
59
67
  * Undefined for a DaemonSet, or when the count isn't a number.
60
68
  */
61
69
  replicas: number | undefined;
70
+ /** The ConfigMap holding the config; the CR's own name for an `OpenTelemetryCollector`. */
62
71
  configMap: string;
72
+ /** The data key holding the config; `spec.config` for an `OpenTelemetryCollector`. */
63
73
  key: string;
64
74
  config: CollectorConfigShape;
75
+ /** Where the config is, for messages: `ConfigMap observability/x, config.yaml` or `spec.config`. */
76
+ where: string;
77
+ /** The workload is an OpenTelemetry Operator `OpenTelemetryCollector`, which the operator turns into the pods. */
78
+ operatorCR?: true;
65
79
  }
66
80
 
67
81
  const PLACED_KINDS = new Set(["DaemonSet", "Deployment", "StatefulSet"]);
68
82
 
83
+ const OTEL_OPERATOR_KINDS = { daemonset: "DaemonSet", deployment: "Deployment", statefulset: "StatefulSet" } as const;
84
+
85
+ /** An OpenTelemetry Operator `OpenTelemetryCollector` (any version of `opentelemetry.io`). */
86
+ export function isOperatorCollector(m: K8sManifest): boolean {
87
+ return m.kind === "OpenTelemetryCollector" && typeof m.apiVersion === "string" && m.apiVersion.startsWith("opentelemetry.io/");
88
+ }
89
+
90
+ /** The placement of one `OpenTelemetryCollector`, or undefined for a sidecar, a missing name or a config that isn't one. */
91
+ function operatorPlacement(cr: K8sManifest): CollectorPlacement | undefined {
92
+ const name = cr.metadata?.name;
93
+ if (typeof name !== "string") return undefined;
94
+ const mode = cr.spec?.mode === undefined || cr.spec.mode === null ? "deployment" : cr.spec.mode;
95
+ if (typeof mode !== "string" || !(mode in OTEL_OPERATOR_KINDS)) return undefined;
96
+ const kind = OTEL_OPERATOR_KINDS[mode as keyof typeof OTEL_OPERATOR_KINDS];
97
+
98
+ // v1beta1 holds the config as an object, v1alpha1 as YAML text.
99
+ const raw = cr.spec?.config;
100
+ const config = isRecord(raw)
101
+ ? (parseCollectorConfig(JSON.stringify(raw)) as CollectorConfigShape | undefined)
102
+ : parseCollectorConfig(raw);
103
+ if (!config) return undefined;
104
+
105
+ let replicas: number | undefined;
106
+ if (kind !== "DaemonSet") {
107
+ const r = cr.spec?.replicas;
108
+ const base = r === undefined || r === null ? 1 : typeof r === "number" ? r : undefined;
109
+ const auto = isRecord(cr.spec?.autoscaler) ? cr.spec.autoscaler.maxReplicas : undefined;
110
+ replicas = base === undefined ? undefined : Math.max(base, typeof auto === "number" ? auto : 0);
111
+ }
112
+ return { workload: cr, kind, name, namespace: ns(cr), replicas, configMap: name, key: "spec.config", config, where: "spec.config", operatorCR: true };
113
+ }
114
+
69
115
  function ns(m: K8sManifest): string {
70
116
  const n = m.metadata?.namespace;
71
117
  return typeof n === "string" && n.length > 0 ? n : "default";
@@ -212,15 +258,21 @@ export function collectorPlacements(manifests: K8sManifest[]): CollectorPlacemen
212
258
  }
213
259
  const named = parsed.filter(([key]) => argNames.includes(key));
214
260
  for (const [key, config] of named.length > 0 ? named : parsed) {
215
- out.push({ workload, kind, name, namespace, replicas, configMap, key, config });
261
+ out.push({ workload, kind, name, namespace, replicas, configMap, key, config, where: `ConfigMap ${configMap}, ${key}` });
216
262
  }
217
263
  }
218
264
  }
265
+ for (const m of manifests) {
266
+ if (!isOperatorCollector(m)) continue;
267
+ const p = operatorPlacement(m);
268
+ if (p) out.push(p);
269
+ }
219
270
  return out;
220
271
  }
221
272
 
222
273
  /** How a placement is described in a message: `DaemonSet observability/otel-agent`. */
223
274
  export function describePlacement(p: CollectorPlacement): string {
275
+ if (p.operatorCR) return `OpenTelemetryCollector ${p.namespace}/${p.name} (mode ${p.kind.toLowerCase()})`;
224
276
  return `${p.kind} ${p.namespace}/${p.name}`;
225
277
  }
226
278
 
@@ -235,6 +287,14 @@ export interface SelectingService {
235
287
 
236
288
  /** The Services in a workload's namespace whose selector matches its pod template labels. */
237
289
  export function servicesSelecting(manifests: K8sManifest[], workload: K8sManifest): SelectingService[] {
290
+ // The operator's Services for a CR are not in the build; their names are fixed by the operator.
291
+ if (isOperatorCollector(workload) && typeof workload.metadata?.name === "string") {
292
+ const name = workload.metadata.name;
293
+ return [
294
+ { name: `${name}-collector`, namespace: ns(workload), headless: false },
295
+ { name: `${name}-collector-headless`, namespace: ns(workload), headless: true },
296
+ ];
297
+ }
238
298
  const template = isRecord(workload.spec?.template) ? workload.spec.template : undefined;
239
299
  const labels = isRecord(template?.metadata) && isRecord(template.metadata.labels) ? template.metadata.labels : {};
240
300
  const out: SelectingService[] = [];
@@ -32,7 +32,7 @@ export const wk8601: PostSynthCheck = {
32
32
  checkId: "WK8601",
33
33
  severity: "warning",
34
34
  message:
35
- `${describePlacement(p)} runs ${ids.join(", ")} (ConfigMap ${p.configMap}, ${p.key}) on every node. ` +
35
+ `${describePlacement(p)} runs ${ids.join(", ")} (${p.where}) on every node. ` +
36
36
  `Each agent sees only its own node's spans, so sampling decisions are made on partial traces. ` +
37
37
  `Move tail sampling to a gateway (OtelCollectorGateway) and send traces to it through a loadbalancing exporter routed by traceID.`,
38
38
  entity: p.name,
@@ -54,7 +54,7 @@ export const wk8603: PostSynthCheck = {
54
54
  checkId: "WK8603",
55
55
  severity: "warning",
56
56
  message:
57
- `${describePlacement(p)} runs the k8s_cluster receiver on ${copies} (ConfigMap ${p.configMap}, ${p.key}): ${reasons.join("; ")}. ` +
57
+ `${describePlacement(p)} runs the k8s_cluster receiver on ${copies} (${p.where}): ${reasons.join("; ")}. ` +
58
58
  `Each copy reports every cluster object, duplicating series and API server watches. ` +
59
59
  `Run it in a single-replica Deployment, or reference a k8s_leader_elector extension from the receiver and enable it in service.extensions.`,
60
60
  entity: p.name,
@@ -10,6 +10,12 @@
10
10
  * otel lexicon's `validateCollectorConfig`, and through `attributionIssues`
11
11
  * (OTEL118) when the build stamps telemetry attribution.
12
12
  *
13
+ * An OpenTelemetry Operator `OpenTelemetryCollector` carries its config in
14
+ * `spec.config` (an object in v1beta1, YAML text in v1alpha1), and goes
15
+ * through the same checks; its findings name `OpenTelemetryCollector
16
+ * <namespace>/<name>, spec.config` where a ConfigMap's name the ConfigMap and
17
+ * key (#3367).
18
+ *
13
19
  * Findings keep the otel rule ids (OTEL101-OTEL106, OTEL112-OTEL127, and any config
14
20
  * check the otel lexicon adds later), so `lint.rules` and suppressions name
15
21
  * one id wherever the config lives. Each message names the ConfigMap's
@@ -22,9 +28,9 @@ import { collectorConfigDiagnostics } from "@intentius/chant-lexicon-otel/lint/p
22
28
  export const wk8604: PostSynthCheck = {
23
29
  id: "WK8604",
24
30
  description:
25
- "OpenTelemetry Collector config in a ConfigMap fails the otel lexicon's config checks; findings are reported under their OTEL1xx ids, naming the ConfigMap and key.",
31
+ "OpenTelemetry Collector config in a ConfigMap or an OpenTelemetryCollector's spec.config fails the otel lexicon's config checks; findings are reported under their OTEL1xx ids, naming the ConfigMap and key, or the OpenTelemetryCollector.",
26
32
 
27
33
  check(ctx: PostSynthContext): PostSynthDiagnostic[] {
28
- return collectorConfigDiagnostics(ctx, { configMapsOnly: true });
34
+ return collectorConfigDiagnostics(ctx, { hostedOnly: true });
29
35
  },
30
36
  };
@@ -21,7 +21,7 @@
21
21
 
22
22
  import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
23
23
  import { docsToManifests, extractContainers, extractPodSpec, type K8sContainer, type K8sManifest } from "./k8s-helpers";
24
- import { collectorPlacements, describePlacement } from "./otel-placement-helpers";
24
+ import { collectorPlacements, describePlacement, isOperatorCollector } from "./otel-placement-helpers";
25
25
  import { collectorNodeAccess, type NodeHostMount } from "../../composites/otel-collector-node";
26
26
 
27
27
  function isRecord(v: unknown): v is Record<string, unknown> {
@@ -38,6 +38,8 @@ function within(path: string, dir: string): boolean {
38
38
  * container when none does. A sidecar's variables and mounts don't count.
39
39
  */
40
40
  function collectorContainers(workload: K8sManifest): K8sContainer[] {
41
+ // An OpenTelemetryCollector's `spec.env` and `spec.volumeMounts` are the collector container's own.
42
+ if (isOperatorCollector(workload)) return [{ env: workload.spec?.env as K8sContainer["env"], volumeMounts: workload.spec?.volumeMounts }];
41
43
  const all = extractContainers(workload);
42
44
  const withConfig = all.filter((c) =>
43
45
  [...(Array.isArray(c.command) ? c.command : []), ...(Array.isArray(c.args) ? c.args : [])].some(
@@ -49,7 +51,7 @@ function collectorContainers(workload: K8sManifest): K8sContainer[] {
49
51
 
50
52
  /** Each container mount backed by a hostPath volume, as [host path, container path]. */
51
53
  function hostMounts(workload: K8sManifest, containers: K8sContainer[]): Array<[string, string]> {
52
- const pod = extractPodSpec(workload);
54
+ const pod = isOperatorCollector(workload) ? workload.spec : extractPodSpec(workload);
53
55
  const hostPaths = new Map<string, string>();
54
56
  for (const v of Array.isArray(pod?.volumes) ? pod.volumes : []) {
55
57
  if (isRecord(v) && typeof v.name === "string" && isRecord(v.hostPath) && typeof v.hostPath.path === "string") {
@@ -119,7 +121,7 @@ export const wk8605: PostSynthCheck = {
119
121
  checkId: "WK8605",
120
122
  severity: "warning",
121
123
  message:
122
- `${describePlacement(p)} runs a collector config that reads the node (ConfigMap ${p.configMap}, ${p.key}), but: ${gaps.join("; ")}. ` +
124
+ `${describePlacement(p)} runs a collector config that reads the node (${p.where}), but: ${gaps.join("; ")}. ` +
123
125
  `Without them the collector reports on its own container, or nothing. OtelCollector adds these from the config; ` +
124
126
  `in a hand-written workload, add them read-only.`,
125
127
  entity: p.name,
@@ -0,0 +1,27 @@
1
+ /**
2
+ * WK8606: the prometheus rule checks over PrometheusRule groups
3
+ *
4
+ * `PrometheusRule.spec.groups` is a rule file's `groups`. `chant build` gives
5
+ * each lexicon's checks only that lexicon's output, so the prometheus
6
+ * lexicon's PROM checks never see a rule that lives in the k8s output. This
7
+ * check runs them there: every PrometheusRule's groups go through the
8
+ * prometheus lexicon's rule-file checks (PROM101-PROM107, PROM211,
9
+ * PROM213-PROM219; PROM212 stays opt-in).
10
+ *
11
+ * Findings keep the PROM ids, so `lint.rules` and suppressions name one id
12
+ * wherever the rules live. Each message names the PrometheusRule's namespace
13
+ * and name. Needs only the k8s lexicon in the project.
14
+ */
15
+
16
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
17
+ import { prometheusRuleDiagnostics } from "@intentius/chant-lexicon-prometheus/lint/post-synth/prom-helpers";
18
+
19
+ export const wk8606: PostSynthCheck = {
20
+ id: "WK8606",
21
+ description:
22
+ "A PrometheusRule's groups fail the prometheus lexicon's rule-file checks; findings are reported under their PROM ids, naming the PrometheusRule.",
23
+
24
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
25
+ return prometheusRuleDiagnostics(ctx);
26
+ },
27
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * WK8701: a PrometheusRule that no Prometheus or ThanosRuler selects
3
+ *
4
+ * A Prometheus or ThanosRuler runs the rules whose labels match its `ruleSelector` in the namespaces its
5
+ * `ruleNamespaceSelector` picks. A PrometheusRule neither selects is accepted by the API server and then
6
+ * never evaluated: no error, no alert.
7
+ *
8
+ * Selection is worked out from the manifests in one build root (chant #1939),
9
+ * by the operator's rules: a null object selector matches nothing, `{}`
10
+ * matches all; a null namespace selector matches only the selecting resource's
11
+ * own namespace, `{}` every namespace. Silent when the build has no Prometheus or ThanosRuler, since the
12
+ * stack is often installed separately. A selector on a namespace label the
13
+ * build cannot read (the Namespace is not declared in it) counts as selecting.
14
+ */
15
+
16
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
17
+ import { describe, monitoringKind, nameOf, selectionContext, unselected } from "./monitoring-selection-helpers";
18
+
19
+ export const wk8701: PostSynthCheck = {
20
+ id: "WK8701",
21
+ description:
22
+ "A PrometheusRule that no Prometheus or ThanosRuler in the build selects through ruleSelector and ruleNamespaceSelector is never evaluated. A null selector matches nothing, {} matches all. Silent when the build has no Prometheus or ThanosRuler.",
23
+
24
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
25
+ const sc = selectionContext(ctx);
26
+ const selectors = [...monitoringKind(sc.manifests, "Prometheus"), ...monitoringKind(sc.manifests, "ThanosRuler")];
27
+ return unselected(sc, monitoringKind(sc.manifests, "PrometheusRule"), selectors, () => ["ruleSelector", "ruleNamespaceSelector"]).map((r) => ({
28
+ checkId: "WK8701",
29
+ severity: "warning",
30
+ message:
31
+ `${describe(r)} is selected by no Prometheus or ThanosRuler in this build, so the operator never loads it and its rules are never evaluated. ` +
32
+ `Match its labels (and namespace) with ruleSelector and ruleNamespaceSelector: null selects nothing, {} selects all.`,
33
+ entity: nameOf(r),
34
+ lexicon: "k8s",
35
+ }));
36
+ },
37
+ };