@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,316 @@
1
+ /**
2
+ * WK8701-WK8705: Prometheus Operator selection checks, and WK8606: the PROM
3
+ * rule checks over PrometheusRule groups (chant #3366).
4
+ */
5
+ import { describe, expect, test } from "vitest";
6
+ import { dump } from "js-yaml";
7
+ import { makePostSynthCtx } from "@intentius/chant-test-utils";
8
+ import { wk8606 } from "./wk8606";
9
+ import { wk8701 } from "./wk8701";
10
+ import { wk8702 } from "./wk8702";
11
+ import { wk8703 } from "./wk8703";
12
+ import { wk8704 } from "./wk8704";
13
+ import { wk8705 } from "./wk8705";
14
+
15
+ const yaml = (...docs: object[]) => makePostSynthCtx("k8s", docs.map((d) => dump(d, { lineWidth: -1 })).join("---\n"));
16
+
17
+ const MON = "monitoring.coreos.com/v1";
18
+ const ALPHA = "monitoring.coreos.com/v1alpha1";
19
+
20
+ const meta = (name: string, namespace = "monitoring", labels?: Record<string, string>) => ({
21
+ name,
22
+ namespace,
23
+ ...(labels ? { labels } : {}),
24
+ });
25
+
26
+ const prometheus = (spec: Record<string, unknown>, namespace = "monitoring") => ({
27
+ apiVersion: MON,
28
+ kind: "Prometheus",
29
+ metadata: meta("main", namespace),
30
+ spec,
31
+ });
32
+
33
+ const rule = (labels: Record<string, string> = { role: "alert" }, namespace = "monitoring") => ({
34
+ apiVersion: MON,
35
+ kind: "PrometheusRule",
36
+ metadata: meta("rules", namespace, labels),
37
+ spec: { groups: [{ name: "g", rules: [{ alert: "Down", expr: "up == 0", for: "5m", labels: { severity: "critical" }, annotations: { summary: "Down", runbook_url: "https://runbooks.example.com/down" } }] }] },
38
+ });
39
+
40
+ describe("WK8701: PrometheusRule selected by no Prometheus or ThanosRuler", () => {
41
+ test("a null ruleSelector selects nothing", () => {
42
+ const d = wk8701.check(yaml(prometheus({ ruleSelector: null }), rule()));
43
+ expect(d).toHaveLength(1);
44
+ expect(d[0]).toMatchObject({ checkId: "WK8701", severity: "warning", entity: "rules" });
45
+ expect(d[0].message).toContain("PrometheusRule monitoring/rules");
46
+ });
47
+
48
+ test("an absent ruleSelector counts as null", () => {
49
+ expect(wk8701.check(yaml(prometheus({}), rule()))).toHaveLength(1);
50
+ });
51
+
52
+ test("an empty ruleSelector selects every rule", () => {
53
+ expect(wk8701.check(yaml(prometheus({ ruleSelector: {} }), rule()))).toEqual([]);
54
+ });
55
+
56
+ test("a null ruleNamespaceSelector selects only the Prometheus's own namespace", () => {
57
+ const other = rule({ role: "alert" }, "apps");
58
+ expect(wk8701.check(yaml(prometheus({ ruleSelector: {}, ruleNamespaceSelector: null }), other))).toHaveLength(1);
59
+ expect(wk8701.check(yaml(prometheus({ ruleSelector: {} }), other))).toHaveLength(1);
60
+ expect(wk8701.check(yaml(prometheus({ ruleSelector: {} }), rule()))).toEqual([]);
61
+ });
62
+
63
+ test("an empty ruleNamespaceSelector selects every namespace", () => {
64
+ expect(wk8701.check(yaml(prometheus({ ruleSelector: {}, ruleNamespaceSelector: {} }), rule({ role: "alert" }, "apps")))).toEqual([]);
65
+ });
66
+
67
+ test("matchLabels and matchExpressions pick by the rule's labels", () => {
68
+ const sel = (s: object) => wk8701.check(yaml(prometheus({ ruleSelector: s }), rule({ role: "alert", team: "a" })));
69
+ expect(sel({ matchLabels: { role: "alert" } })).toEqual([]);
70
+ expect(sel({ matchLabels: { role: "other" } })).toHaveLength(1);
71
+ expect(sel({ matchExpressions: [{ key: "team", operator: "In", values: ["a", "b"] }] })).toEqual([]);
72
+ expect(sel({ matchExpressions: [{ key: "team", operator: "NotIn", values: ["a"] }] })).toHaveLength(1);
73
+ expect(sel({ matchExpressions: [{ key: "team", operator: "Exists" }] })).toEqual([]);
74
+ expect(sel({ matchExpressions: [{ key: "team", operator: "DoesNotExist" }] })).toHaveLength(1);
75
+ });
76
+
77
+ test("a namespace label selector matches the name label, and a declared Namespace's labels", () => {
78
+ const p = prometheus({ ruleSelector: {}, ruleNamespaceSelector: { matchLabels: { "kubernetes.io/metadata.name": "apps" } } });
79
+ expect(wk8701.check(yaml(p, rule({ role: "alert" }, "apps")))).toEqual([]);
80
+ expect(wk8701.check(yaml(p, rule({ role: "alert" }, "other")))).toHaveLength(1);
81
+
82
+ const byLabel = prometheus({ ruleSelector: {}, ruleNamespaceSelector: { matchLabels: { tier: "prod" } } });
83
+ const ns = (labels: Record<string, string>) => ({ apiVersion: "v1", kind: "Namespace", metadata: { name: "apps", labels } });
84
+ expect(wk8701.check(yaml(byLabel, ns({ tier: "prod" }), rule({ role: "alert" }, "apps")))).toEqual([]);
85
+ expect(wk8701.check(yaml(byLabel, ns({ tier: "dev" }), rule({ role: "alert" }, "apps")))).toHaveLength(1);
86
+ // The namespace is not declared in the build, so its labels are unknown.
87
+ expect(wk8701.check(yaml(byLabel, rule({ role: "alert" }, "apps")))).toEqual([]);
88
+ });
89
+
90
+ test("one selecting Prometheus is enough, and a ThanosRuler counts", () => {
91
+ const thanos = { apiVersion: MON, kind: "ThanosRuler", metadata: meta("t"), spec: { ruleSelector: {} } };
92
+ expect(wk8701.check(yaml(prometheus({ ruleSelector: null }), thanos, rule()))).toEqual([]);
93
+ expect(wk8701.check(yaml(prometheus({ ruleSelector: null }), prometheus({ ruleSelector: {} }, "monitoring"), rule()))).toEqual([]);
94
+ });
95
+
96
+ test("silent when the build has no Prometheus or ThanosRuler", () => {
97
+ expect(wk8701.check(yaml(rule()))).toEqual([]);
98
+ expect(wk8701.check(yaml(rule(), { apiVersion: MON, kind: "Alertmanager", metadata: meta("am"), spec: {} }))).toEqual([]);
99
+ });
100
+ });
101
+
102
+ describe("WK8702: monitor selected by no Prometheus or PrometheusAgent", () => {
103
+ const monitors = () => [
104
+ { apiVersion: MON, kind: "ServiceMonitor", metadata: meta("sm", "monitoring", { app: "x" }), spec: { selector: {}, endpoints: [] } },
105
+ { apiVersion: MON, kind: "PodMonitor", metadata: meta("pm", "monitoring", { app: "x" }), spec: { selector: {}, podMetricsEndpoints: [] } },
106
+ { apiVersion: MON, kind: "Probe", metadata: meta("pr", "monitoring", { app: "x" }), spec: {} },
107
+ { apiVersion: ALPHA, kind: "ScrapeConfig", metadata: meta("sc", "monitoring", { app: "x" }), spec: {} },
108
+ ];
109
+
110
+ test("all four selectors null: every monitor kind is reported", () => {
111
+ const d = wk8702.check(yaml(prometheus({}), ...monitors()));
112
+ expect(d.map((x) => x.entity).sort()).toEqual(["pm", "pr", "sc", "sm"]);
113
+ expect(d[0]).toMatchObject({ checkId: "WK8702", severity: "warning" });
114
+ });
115
+
116
+ test("explicit null selectors select nothing", () => {
117
+ const spec = { serviceMonitorSelector: null, podMonitorSelector: null, probeSelector: null, scrapeConfigSelector: null };
118
+ expect(wk8702.check(yaml(prometheus(spec), ...monitors()))).toHaveLength(4);
119
+ });
120
+
121
+ test("empty selectors select every monitor of their kind", () => {
122
+ const spec = { serviceMonitorSelector: {}, podMonitorSelector: {}, probeSelector: {}, scrapeConfigSelector: {} };
123
+ expect(wk8702.check(yaml(prometheus(spec), ...monitors()))).toEqual([]);
124
+ });
125
+
126
+ test("each kind reads its own selector", () => {
127
+ const d = wk8702.check(yaml(prometheus({ serviceMonitorSelector: {}, probeSelector: {} }), ...monitors()));
128
+ expect(d.map((x) => x.entity).sort()).toEqual(["pm", "sc"]);
129
+ });
130
+
131
+ test("a null namespace selector leaves out a monitor in another namespace; {} takes it", () => {
132
+ const other = { apiVersion: MON, kind: "ServiceMonitor", metadata: meta("sm", "apps"), spec: { selector: {}, endpoints: [] } };
133
+ expect(wk8702.check(yaml(prometheus({ serviceMonitorSelector: {}, serviceMonitorNamespaceSelector: null }), other))).toHaveLength(1);
134
+ expect(wk8702.check(yaml(prometheus({ serviceMonitorSelector: {}, serviceMonitorNamespaceSelector: {} }), other))).toEqual([]);
135
+ });
136
+
137
+ test("a PrometheusAgent selects too", () => {
138
+ const agent = { apiVersion: ALPHA, kind: "PrometheusAgent", metadata: meta("agent"), spec: { serviceMonitorSelector: {} } };
139
+ expect(wk8702.check(yaml(prometheus({}), agent, monitors()[0]))).toEqual([]);
140
+ expect(wk8702.check(yaml(agent, monitors()[1]))).toHaveLength(1);
141
+ });
142
+
143
+ test("silent when the build has no Prometheus or PrometheusAgent", () => {
144
+ expect(wk8702.check(yaml(...monitors()))).toEqual([]);
145
+ });
146
+ });
147
+
148
+ describe("WK8703: AlertmanagerConfig selected by no Alertmanager", () => {
149
+ const alertmanager = (spec: Record<string, unknown>) => ({ apiVersion: MON, kind: "Alertmanager", metadata: meta("am"), spec });
150
+ const config = (namespace = "monitoring") => ({
151
+ apiVersion: ALPHA,
152
+ kind: "AlertmanagerConfig",
153
+ metadata: meta("cfg", namespace, { team: "a" }),
154
+ spec: { route: { receiver: "r" }, receivers: [{ name: "r" }] },
155
+ });
156
+
157
+ test("a null alertmanagerConfigSelector selects nothing", () => {
158
+ const d = wk8703.check(yaml(alertmanager({ alertmanagerConfigSelector: null }), config()));
159
+ expect(d).toHaveLength(1);
160
+ expect(d[0]).toMatchObject({ checkId: "WK8703", severity: "warning", entity: "cfg" });
161
+ });
162
+
163
+ test("an absent alertmanagerConfigSelector counts as null", () => {
164
+ expect(wk8703.check(yaml(alertmanager({}), config()))).toHaveLength(1);
165
+ });
166
+
167
+ test("an empty alertmanagerConfigSelector selects every config in the namespace", () => {
168
+ expect(wk8703.check(yaml(alertmanager({ alertmanagerConfigSelector: {} }), config()))).toEqual([]);
169
+ });
170
+
171
+ test("a null namespace selector keeps to the Alertmanager's namespace; {} takes every one", () => {
172
+ const am = (ns: unknown) => alertmanager({ alertmanagerConfigSelector: {}, alertmanagerConfigNamespaceSelector: ns });
173
+ expect(wk8703.check(yaml(am(null), config("apps")))).toHaveLength(1);
174
+ expect(wk8703.check(yaml(am({}), config("apps")))).toEqual([]);
175
+ });
176
+
177
+ test("matchLabels picks by the config's labels", () => {
178
+ expect(wk8703.check(yaml(alertmanager({ alertmanagerConfigSelector: { matchLabels: { team: "a" } } }), config()))).toEqual([]);
179
+ expect(wk8703.check(yaml(alertmanager({ alertmanagerConfigSelector: { matchLabels: { team: "b" } } }), config()))).toHaveLength(1);
180
+ });
181
+
182
+ test("silent when the build has no Alertmanager, whatever Prometheus is there", () => {
183
+ expect(wk8703.check(yaml(config()))).toEqual([]);
184
+ expect(wk8703.check(yaml(prometheus({}), config()))).toEqual([]);
185
+ });
186
+ });
187
+
188
+ describe("WK8704: monitor selects no Service or pod, or names a missing port", () => {
189
+ const service = (labels: Record<string, string>, ports: Array<{ name?: string; port: number }>, namespace = "apps") => ({
190
+ apiVersion: "v1",
191
+ kind: "Service",
192
+ metadata: meta("web", namespace, labels),
193
+ spec: { selector: { app: "web" }, ports },
194
+ });
195
+ const sm = (spec: Record<string, unknown>, namespace = "apps") => ({
196
+ apiVersion: MON,
197
+ kind: "ServiceMonitor",
198
+ metadata: meta("web", namespace),
199
+ spec,
200
+ });
201
+
202
+ test("a selector that matches no Service is reported, with no Prometheus in the build", () => {
203
+ const d = wk8704.check(yaml(service({ app: "web" }, [{ name: "http", port: 80 }]), sm({ selector: { matchLabels: { app: "api" } }, endpoints: [{ port: "http" }] })));
204
+ expect(d).toHaveLength(1);
205
+ expect(d[0]).toMatchObject({ checkId: "WK8704", severity: "warning", entity: "web" });
206
+ expect(d[0].message).toContain("matches no Service");
207
+ });
208
+
209
+ test("an empty selector matches every Service in the namespace", () => {
210
+ expect(wk8704.check(yaml(service({ app: "web" }, [{ name: "http", port: 80 }]), sm({ selector: {}, endpoints: [{ port: "http" }] })))).toEqual([]);
211
+ });
212
+
213
+ test("a null or absent selector is read as empty", () => {
214
+ expect(wk8704.check(yaml(service({ app: "web" }, [{ name: "http", port: 80 }]), sm({ selector: null, endpoints: [{ port: "http" }] })))).toEqual([]);
215
+ expect(wk8704.check(yaml(service({ app: "web" }, [{ name: "http", port: 80 }]), sm({ endpoints: [{ port: "http" }] })))).toEqual([]);
216
+ });
217
+
218
+ test("a Service in another namespace is not seen unless namespaceSelector reaches it", () => {
219
+ const svc = service({ app: "web" }, [{ name: "http", port: 80 }], "other");
220
+ expect(wk8704.check(yaml(svc, sm({ selector: {}, endpoints: [] })))).toHaveLength(1);
221
+ expect(wk8704.check(yaml(svc, sm({ selector: {}, namespaceSelector: { matchNames: ["other"] }, endpoints: [] })))).toEqual([]);
222
+ expect(wk8704.check(yaml(svc, sm({ selector: {}, namespaceSelector: { any: true }, endpoints: [] })))).toEqual([]);
223
+ });
224
+
225
+ test("an endpoint port no matched Service names is reported", () => {
226
+ const d = wk8704.check(yaml(service({ app: "web" }, [{ name: "http", port: 80 }]), sm({ selector: {}, endpoints: [{ port: "metrics" }, { port: "http" }] })));
227
+ expect(d).toHaveLength(1);
228
+ expect(d[0].message).toContain('"metrics"');
229
+ expect(d[0].message).toContain("http");
230
+ });
231
+
232
+ test("an endpoint with targetPort only is not checked", () => {
233
+ expect(wk8704.check(yaml(service({ app: "web" }, [{ port: 80 }]), sm({ selector: {}, endpoints: [{ targetPort: 9090 }] })))).toEqual([]);
234
+ });
235
+
236
+ const deployment = (ports: Array<{ name?: string; containerPort: number }>) => ({
237
+ apiVersion: "apps/v1",
238
+ kind: "Deployment",
239
+ metadata: meta("web", "apps"),
240
+ spec: {
241
+ selector: { matchLabels: { app: "web" } },
242
+ template: { metadata: { labels: { app: "web" } }, spec: { containers: [{ name: "c", image: "x:1", ports }] } },
243
+ },
244
+ });
245
+ const pm = (spec: Record<string, unknown>) => ({ apiVersion: MON, kind: "PodMonitor", metadata: meta("web", "apps"), spec });
246
+
247
+ test("PodMonitor: a selector that matches no pod template is reported", () => {
248
+ const d = wk8704.check(yaml(deployment([{ name: "metrics", containerPort: 9090 }]), pm({ selector: { matchLabels: { app: "api" } }, podMetricsEndpoints: [{ port: "metrics" }] })));
249
+ expect(d).toHaveLength(1);
250
+ expect(d[0].message).toContain("matches no pod");
251
+ });
252
+
253
+ test("PodMonitor: an empty selector matches, and a missing container port is reported", () => {
254
+ expect(wk8704.check(yaml(deployment([{ name: "metrics", containerPort: 9090 }]), pm({ selector: {}, podMetricsEndpoints: [{ port: "metrics" }] })))).toEqual([]);
255
+ const d = wk8704.check(yaml(deployment([{ name: "http", containerPort: 80 }]), pm({ selector: {}, podMetricsEndpoints: [{ port: "metrics" }] })));
256
+ expect(d).toHaveLength(1);
257
+ expect(d[0].message).toContain('"metrics"');
258
+ });
259
+ });
260
+
261
+ describe("WK8705: Prometheus whose four monitor selectors are all null", () => {
262
+ test("absent selectors are null", () => {
263
+ const d = wk8705.check(yaml(prometheus({})));
264
+ expect(d).toHaveLength(1);
265
+ expect(d[0]).toMatchObject({ checkId: "WK8705", severity: "warning", entity: "main" });
266
+ expect(d[0].message).toContain("Prometheus monitoring/main");
267
+ });
268
+
269
+ test("explicit nulls report", () => {
270
+ expect(wk8705.check(yaml(prometheus({ serviceMonitorSelector: null, podMonitorSelector: null, probeSelector: null, scrapeConfigSelector: null })))).toHaveLength(1);
271
+ });
272
+
273
+ test("one empty selector is enough to silence it", () => {
274
+ for (const k of ["serviceMonitorSelector", "podMonitorSelector", "probeSelector", "scrapeConfigSelector"]) {
275
+ expect(wk8705.check(yaml(prometheus({ [k]: {} })))).toEqual([]);
276
+ }
277
+ });
278
+
279
+ test("a matchLabels selector counts as set", () => {
280
+ expect(wk8705.check(yaml(prometheus({ serviceMonitorSelector: { matchLabels: { release: "p" } } })))).toEqual([]);
281
+ });
282
+
283
+ test("silent without a Prometheus", () => {
284
+ expect(wk8705.check(yaml(rule()))).toEqual([]);
285
+ });
286
+ });
287
+
288
+ describe("WK8606: PROM checks over PrometheusRule groups", () => {
289
+ test("a duplicate group name is PROM101, naming the PrometheusRule", () => {
290
+ const doc = {
291
+ apiVersion: MON,
292
+ kind: "PrometheusRule",
293
+ metadata: meta("rules", "obs"),
294
+ spec: { groups: [{ name: "g", rules: [{ alert: "A", expr: "up == 0" }] }, { name: "g", rules: [{ alert: "B", expr: "up == 0" }] }] },
295
+ };
296
+ const d = wk8606.check(yaml(doc));
297
+ expect(d.map((x) => x.checkId)).toContain("PROM101");
298
+ const prom101 = d.find((x) => x.checkId === "PROM101")!;
299
+ expect(prom101.message).toContain("PrometheusRule obs/rules");
300
+ });
301
+
302
+ test("a bad duration is reported under its PROM id", () => {
303
+ const doc = {
304
+ apiVersion: MON,
305
+ kind: "PrometheusRule",
306
+ metadata: meta("rules"),
307
+ spec: { groups: [{ name: "g", interval: "soon", rules: [{ alert: "A", expr: "up == 0" }] }] },
308
+ };
309
+ expect(wk8606.check(yaml(doc)).map((x) => x.checkId)).toContain("PROM103");
310
+ });
311
+
312
+ test("a clean PrometheusRule and other kinds are silent", () => {
313
+ expect(wk8606.check(yaml(rule()))).toEqual([]);
314
+ expect(wk8606.check(yaml({ apiVersion: "v1", kind: "ConfigMap", metadata: { name: "c" }, data: { groups: "x" } }))).toEqual([]);
315
+ });
316
+ });
@@ -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
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WK8702: a ServiceMonitor, PodMonitor, Probe or ScrapeConfig that no Prometheus or PrometheusAgent selects
3
+ *
4
+ * A Prometheus or PrometheusAgent scrapes the monitors whose labels match its `serviceMonitorSelector`,
5
+ * `podMonitorSelector`, `probeSelector` or `scrapeConfigSelector`, in the namespaces the matching
6
+ * `*NamespaceSelector` picks. A monitor none selects is accepted and then never scraped.
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 PrometheusAgent, 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 wk8702: PostSynthCheck = {
20
+ id: "WK8702",
21
+ description:
22
+ "A ServiceMonitor, PodMonitor, Probe or ScrapeConfig that no Prometheus or PrometheusAgent in the build selects is never scraped. A null selector matches nothing, {} matches all. Silent when the build has no Prometheus or PrometheusAgent.",
23
+
24
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
25
+ const sc = selectionContext(ctx);
26
+ const selectors = [...monitoringKind(sc.manifests, "Prometheus"), ...monitoringKind(sc.manifests, "PrometheusAgent")];
27
+ const out: PostSynthDiagnostic[] = [];
28
+ for (const [kind, prefix] of [["ServiceMonitor", "serviceMonitor"], ["PodMonitor", "podMonitor"], ["Probe", "probe"], ["ScrapeConfig", "scrapeConfig"]] as const) {
29
+ for (const m of unselected(sc, monitoringKind(sc.manifests, kind), selectors, () => [`${prefix}Selector`, `${prefix}NamespaceSelector`])) {
30
+ out.push({
31
+ checkId: "WK8702",
32
+ severity: "warning",
33
+ message:
34
+ `${describe(m)} is selected by no Prometheus or PrometheusAgent in this build, so it is never scraped. ` +
35
+ `Match its labels (and namespace) with ${prefix}Selector and ${prefix}NamespaceSelector: null selects nothing, {} selects all.`,
36
+ entity: nameOf(m),
37
+ lexicon: "k8s",
38
+ });
39
+ }
40
+ }
41
+ return out;
42
+ },
43
+ };