@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.
- package/dist/codegen/naming.d.ts.map +1 -1
- package/dist/composites/catalog.d.ts.map +1 -1
- package/dist/composites/index.d.ts +2 -0
- package/dist/composites/index.d.ts.map +1 -1
- package/dist/composites/otel-collector-shape.d.ts +2 -0
- package/dist/composites/otel-collector-shape.d.ts.map +1 -1
- package/dist/composites/otel-operator-collector.d.ts +101 -0
- package/dist/composites/otel-operator-collector.d.ts.map +1 -0
- package/dist/crd/crd-sources.d.ts.map +1 -1
- package/dist/generated/index.d.d.ts +172 -2
- package/dist/generated/index.d.ts +301 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/group-namespace.d.ts.map +1 -1
- package/dist/import/embedded.d.ts +3 -0
- package/dist/import/embedded.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/integrity.json +16 -9
- package/dist/lint/audit-catalog.d.ts.map +1 -1
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/lint/post-synth/monitoring-selection-helpers.d.ts +55 -0
- package/dist/lint/post-synth/monitoring-selection-helpers.d.ts.map +1 -0
- package/dist/lint/post-synth/otel-placement-helpers.d.ts +16 -0
- package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8604.d.ts +6 -0
- package/dist/lint/post-synth/wk8604.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8605.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8606.d.ts +17 -0
- package/dist/lint/post-synth/wk8606.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8701.d.ts +17 -0
- package/dist/lint/post-synth/wk8701.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8702.d.ts +17 -0
- package/dist/lint/post-synth/wk8702.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8703.d.ts +17 -0
- package/dist/lint/post-synth/wk8703.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8704.d.ts +21 -0
- package/dist/lint/post-synth/wk8704.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8705.d.ts +18 -0
- package/dist/lint/post-synth/wk8705.d.ts.map +1 -0
- package/dist/manifest.json +1 -1
- package/dist/meta.json +2284 -370
- package/dist/okf/index.md +20 -1
- package/dist/okf/rules/WK8604.md +6 -2
- package/dist/okf/rules/WK8605.md +4 -0
- package/dist/okf/rules/WK8606.md +15 -0
- package/dist/okf/rules/WK8701.md +18 -0
- package/dist/okf/rules/WK8702.md +20 -0
- package/dist/okf/rules/WK8703.md +17 -0
- package/dist/okf/rules/WK8704.md +22 -0
- package/dist/okf/rules/WK8705.md +18 -0
- package/dist/okf/types/Alertmanager.md +18 -0
- package/dist/okf/types/AlertmanagerConfig.md +18 -0
- package/dist/okf/types/ClusterObservability.md +14 -0
- package/dist/okf/types/CronJob.md +1 -0
- package/dist/okf/types/DaemonSet.md +1 -0
- package/dist/okf/types/Instrumentation.md +14 -0
- package/dist/okf/types/MonitoringProbe.md +14 -0
- package/dist/okf/types/Namespace.md +3 -0
- package/dist/okf/types/OpAMPBridge.md +14 -0
- package/dist/okf/types/OpenTelemetryCollector.md +19 -0
- package/dist/okf/types/Pod.md +1 -0
- package/dist/okf/types/PodMonitor.md +20 -0
- package/dist/okf/types/Prometheus.md +21 -0
- package/dist/okf/types/PrometheusAgent.md +18 -0
- package/dist/okf/types/PrometheusRule.md +6 -1
- package/dist/okf/types/ScrapeConfig.md +19 -0
- package/dist/okf/types/Service.md +1 -0
- package/dist/okf/types/ServiceMonitor.md +7 -1
- package/dist/okf/types/StatefulSet.md +1 -0
- package/dist/okf/types/TargetAllocator.md +14 -0
- package/dist/okf/types/ThanosRuler.md +18 -0
- package/dist/rules/monitoring-selection-helpers.ts +185 -0
- package/dist/rules/otel-placement-helpers.ts +61 -1
- package/dist/rules/wk8601.ts +1 -1
- package/dist/rules/wk8603.ts +1 -1
- package/dist/rules/wk8604.ts +8 -2
- package/dist/rules/wk8605.ts +5 -3
- package/dist/rules/wk8606.ts +27 -0
- package/dist/rules/wk8701.ts +37 -0
- package/dist/rules/wk8702.ts +43 -0
- package/dist/rules/wk8703.ts +37 -0
- package/dist/rules/wk8704.ts +134 -0
- package/dist/rules/wk8705.ts +45 -0
- package/dist/types/index.d.ts +172 -2
- package/package.json +3 -3
- package/src/codegen/naming.ts +15 -1
- package/src/composites/catalog.ts +105 -0
- package/src/composites/index.ts +2 -0
- package/src/composites/otel-collector-shape.ts +2 -0
- package/src/composites/otel-operator-collector.test.ts +267 -0
- package/src/composites/otel-operator-collector.ts +221 -0
- package/src/crd/crd-sources.ts +41 -2
- package/src/generated/index.d.ts +172 -2
- package/src/generated/index.ts +303 -2
- package/src/generated/lexicon-k8s.json +2284 -370
- package/src/generated/operations.json +208 -0
- package/src/group-namespace.test.ts +4 -0
- package/src/group-namespace.ts +4 -0
- package/src/import/embedded.ts +26 -0
- package/src/import/operator-collector-roundtrip.test.ts +105 -0
- package/src/index.ts +2 -2
- package/src/lint/audit-catalog.ts +6 -0
- package/src/lint/post-synth/index.ts +12 -0
- package/src/lint/post-synth/monitoring-selection-helpers.ts +185 -0
- package/src/lint/post-synth/monitoring-selection.test.ts +316 -0
- package/src/lint/post-synth/otel-placement-helpers.ts +61 -1
- package/src/lint/post-synth/wk8601.ts +1 -1
- package/src/lint/post-synth/wk8603.ts +1 -1
- package/src/lint/post-synth/wk8604.ts +8 -2
- package/src/lint/post-synth/wk8605.ts +5 -3
- package/src/lint/post-synth/wk8606.ts +27 -0
- package/src/lint/post-synth/wk8701.ts +37 -0
- package/src/lint/post-synth/wk8702.ts +43 -0
- package/src/lint/post-synth/wk8703.ts +37 -0
- package/src/lint/post-synth/wk8704.ts +134 -0
- package/src/lint/post-synth/wk8705.ts +45 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WK8703: an AlertmanagerConfig that no Alertmanager selects
|
|
3
|
+
*
|
|
4
|
+
* An Alertmanager merges the AlertmanagerConfigs whose labels match its `alertmanagerConfigSelector` in the
|
|
5
|
+
* namespaces its `alertmanagerConfigNamespaceSelector` picks. One neither selects is accepted and then
|
|
6
|
+
* never routes an 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 Alertmanager, 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 wk8703: PostSynthCheck = {
|
|
20
|
+
id: "WK8703",
|
|
21
|
+
description:
|
|
22
|
+
"An AlertmanagerConfig that no Alertmanager in the build selects through alertmanagerConfigSelector and alertmanagerConfigNamespaceSelector never routes an alert. A null selector matches nothing, {} matches all. Silent when the build has no Alertmanager.",
|
|
23
|
+
|
|
24
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
25
|
+
const sc = selectionContext(ctx);
|
|
26
|
+
const configs = monitoringKind(sc.manifests, "AlertmanagerConfig");
|
|
27
|
+
return unselected(sc, configs, monitoringKind(sc.manifests, "Alertmanager"), () => ["alertmanagerConfigSelector", "alertmanagerConfigNamespaceSelector"]).map((c) => ({
|
|
28
|
+
checkId: "WK8703",
|
|
29
|
+
severity: "warning",
|
|
30
|
+
message:
|
|
31
|
+
`${describe(c)} is selected by no Alertmanager in this build, so its routes and receivers are never used. ` +
|
|
32
|
+
`Match its labels (and namespace) with alertmanagerConfigSelector and alertmanagerConfigNamespaceSelector: null selects nothing, {} selects all.`,
|
|
33
|
+
entity: nameOf(c),
|
|
34
|
+
lexicon: "k8s",
|
|
35
|
+
}));
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WK8704: a ServiceMonitor or PodMonitor that selects no Service or pod, or names a port that is not there
|
|
3
|
+
*
|
|
4
|
+
* A ServiceMonitor's `selector` picks Services (in its own namespace, the
|
|
5
|
+
* `namespaceSelector.matchNames` ones, or every namespace with `any: true`),
|
|
6
|
+
* and each `endpoints[].port` names a port on them. A PodMonitor's `selector`
|
|
7
|
+
* picks pods, and each `podMetricsEndpoints[].port` names a container port.
|
|
8
|
+
* When nothing matches, or the port name is on none of the matches, Prometheus
|
|
9
|
+
* scrapes nothing and says nothing. This check needs no Prometheus in the
|
|
10
|
+
* build: it reads the monitor against the Services and workloads declared
|
|
11
|
+
* beside it.
|
|
12
|
+
*
|
|
13
|
+
* Pods come from the pod templates of Deployment, StatefulSet, DaemonSet, Job
|
|
14
|
+
* and CronJob, and from Pods themselves. An empty `selector` ({}) matches
|
|
15
|
+
* everything, as the operator does. Only a port given by name is checked;
|
|
16
|
+
* `targetPort` and `portNumber` are left alone. One build root at a time
|
|
17
|
+
* (chant #1939): a Service or workload installed from another root is not seen.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
21
|
+
import { extractContainers, type K8sManifest } from "./k8s-helpers";
|
|
22
|
+
import { describe, labelsOf, matchLabelSelector, monitoringKind, nameOf, namespaceOf, selectionContext } from "./monitoring-selection-helpers";
|
|
23
|
+
|
|
24
|
+
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
25
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Whether a monitor looks in this namespace: its own, `matchNames`, or all of them with `any`. */
|
|
29
|
+
function reaches(monitor: K8sManifest, namespace: string): boolean {
|
|
30
|
+
const ns = (monitor.spec as Record<string, unknown> | undefined)?.namespaceSelector;
|
|
31
|
+
if (isRecord(ns)) {
|
|
32
|
+
if (ns.any === true) return true;
|
|
33
|
+
if (Array.isArray(ns.matchNames) && ns.matchNames.length > 0) return ns.matchNames.includes(namespace);
|
|
34
|
+
}
|
|
35
|
+
return namespaceOf(monitor) === namespace;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The labels a pod from this workload carries, and its manifest to read ports from. */
|
|
39
|
+
function podsOf(manifests: K8sManifest[]): Array<{ manifest: K8sManifest; labels: Record<string, string> }> {
|
|
40
|
+
const out: Array<{ manifest: K8sManifest; labels: Record<string, string> }> = [];
|
|
41
|
+
for (const m of manifests) {
|
|
42
|
+
const spec = (m.spec ?? {}) as Record<string, any>;
|
|
43
|
+
if (m.kind === "Pod") {
|
|
44
|
+
out.push({ manifest: m, labels: labelsOf(m) });
|
|
45
|
+
} else if (m.kind === "Deployment" || m.kind === "StatefulSet" || m.kind === "DaemonSet" || m.kind === "Job") {
|
|
46
|
+
out.push({ manifest: m, labels: labelsOf({ metadata: spec.template?.metadata } as K8sManifest) });
|
|
47
|
+
} else if (m.kind === "CronJob") {
|
|
48
|
+
out.push({ manifest: m, labels: labelsOf({ metadata: spec.jobTemplate?.spec?.template?.metadata } as K8sManifest) });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function containerPortNames(workload: K8sManifest): Set<string> {
|
|
55
|
+
const names = new Set<string>();
|
|
56
|
+
for (const c of extractContainers(workload)) {
|
|
57
|
+
for (const p of Array.isArray(c.ports) ? c.ports : []) {
|
|
58
|
+
if (isRecord(p) && typeof p.name === "string") names.add(p.name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return names;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function servicePortNames(service: K8sManifest): Set<string> {
|
|
65
|
+
const names = new Set<string>();
|
|
66
|
+
const ports = (service.spec as Record<string, unknown> | undefined)?.ports;
|
|
67
|
+
for (const p of Array.isArray(ports) ? ports : []) {
|
|
68
|
+
if (isRecord(p) && typeof p.name === "string") names.add(p.name);
|
|
69
|
+
}
|
|
70
|
+
return names;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const wk8704: PostSynthCheck = {
|
|
74
|
+
id: "WK8704",
|
|
75
|
+
description:
|
|
76
|
+
"A ServiceMonitor whose selector matches no Service in the build, or whose endpoints[].port names no port on the matched Services; the same for a PodMonitor against pod container ports. Needs no Prometheus in the build. Sees one build root at a time (chant #1939).",
|
|
77
|
+
|
|
78
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
79
|
+
const { manifests } = selectionContext(ctx);
|
|
80
|
+
const out: PostSynthDiagnostic[] = [];
|
|
81
|
+
const diag = (m: K8sManifest, message: string): PostSynthDiagnostic => ({
|
|
82
|
+
checkId: "WK8704",
|
|
83
|
+
severity: "warning",
|
|
84
|
+
message,
|
|
85
|
+
entity: nameOf(m),
|
|
86
|
+
lexicon: "k8s",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const services = manifests.filter((m) => m.kind === "Service" && (m.apiVersion === "v1" || m.apiVersion === undefined));
|
|
90
|
+
for (const sm of monitoringKind(manifests, "ServiceMonitor")) {
|
|
91
|
+
const spec = (sm.spec ?? {}) as Record<string, unknown>;
|
|
92
|
+
// A ServiceMonitor's selector is required; treat a missing one like {}.
|
|
93
|
+
const selector = isRecord(spec.selector) ? spec.selector : {};
|
|
94
|
+
const matched = services.filter((s) => reaches(sm, namespaceOf(s)) && matchLabelSelector(selector, labelsOf(s)) !== "no");
|
|
95
|
+
if (matched.length === 0) {
|
|
96
|
+
out.push(diag(sm, `${describe(sm)} has a selector that matches no Service in this build (looking in ${where(sm)}), so Prometheus scrapes nothing for it. Make spec.selector match the labels on the Service, or fix namespaceSelector.`));
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const known = new Set<string>();
|
|
100
|
+
for (const s of matched) for (const n of servicePortNames(s)) known.add(n);
|
|
101
|
+
for (const e of Array.isArray(spec.endpoints) ? spec.endpoints : []) {
|
|
102
|
+
if (!isRecord(e) || typeof e.port !== "string" || known.has(e.port)) continue;
|
|
103
|
+
out.push(diag(sm, `${describe(sm)} scrapes endpoint port "${e.port}", but the Service(s) it selects (${matched.map(nameOf).join(", ")}) declare no port with that name${known.size > 0 ? ` (they have: ${[...known].join(", ")})` : ""}. Name the Service port, or point the endpoint at an existing one.`));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const pods = podsOf(manifests);
|
|
108
|
+
for (const pm of monitoringKind(manifests, "PodMonitor")) {
|
|
109
|
+
const spec = (pm.spec ?? {}) as Record<string, unknown>;
|
|
110
|
+
const selector = isRecord(spec.selector) ? spec.selector : {};
|
|
111
|
+
const matched = pods.filter((p) => reaches(pm, namespaceOf(p.manifest)) && matchLabelSelector(selector, p.labels) !== "no");
|
|
112
|
+
if (matched.length === 0) {
|
|
113
|
+
out.push(diag(pm, `${describe(pm)} has a selector that matches no pod in this build (looking in ${where(pm)}), so Prometheus scrapes nothing for it. Make spec.selector match the pod template labels, or fix namespaceSelector.`));
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const known = new Set<string>();
|
|
117
|
+
for (const p of matched) for (const n of containerPortNames(p.manifest)) known.add(n);
|
|
118
|
+
for (const e of Array.isArray(spec.podMetricsEndpoints) ? spec.podMetricsEndpoints : []) {
|
|
119
|
+
if (!isRecord(e) || typeof e.port !== "string" || known.has(e.port)) continue;
|
|
120
|
+
out.push(diag(pm, `${describe(pm)} scrapes container port "${e.port}", but the pods it selects (${matched.map((p) => nameOf(p.manifest)).join(", ")}) declare no container port with that name${known.size > 0 ? ` (they have: ${[...known].join(", ")})` : ""}. Name the container port, or point the endpoint at an existing one.`));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function where(m: K8sManifest): string {
|
|
128
|
+
const ns = (m.spec as Record<string, unknown> | undefined)?.namespaceSelector;
|
|
129
|
+
if (isRecord(ns)) {
|
|
130
|
+
if (ns.any === true) return "every namespace";
|
|
131
|
+
if (Array.isArray(ns.matchNames) && ns.matchNames.length > 0) return `namespace ${ns.matchNames.join(", ")}`;
|
|
132
|
+
}
|
|
133
|
+
return `namespace ${namespaceOf(m)}`;
|
|
134
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WK8705: a Prometheus whose four monitor selectors are all null
|
|
3
|
+
*
|
|
4
|
+
* A Prometheus picks the ServiceMonitors, PodMonitors, Probes and
|
|
5
|
+
* ScrapeConfigs to scrape with `serviceMonitorSelector`, `podMonitorSelector`,
|
|
6
|
+
* `probeSelector` and `scrapeConfigSelector`. A null selector (absent counts
|
|
7
|
+
* as null) matches nothing, so a Prometheus with all four null selects no
|
|
8
|
+
* monitor at all and scrapes only what `additionalScrapeConfigs` and its own
|
|
9
|
+
* config hold. `{}` matches every monitor in the selected namespaces. This is
|
|
10
|
+
* the usual way a fresh Prometheus ends up scraping nothing.
|
|
11
|
+
*
|
|
12
|
+
* A Prometheus with `additionalScrapeConfigs` set still reports: that
|
|
13
|
+
* is a deliberate setup the finding names, not one it hides. The message says
|
|
14
|
+
* so, and a suppression is the way to accept it.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
18
|
+
import { describe, monitoringKind, nameOf, selectionContext } from "./monitoring-selection-helpers";
|
|
19
|
+
|
|
20
|
+
const SELECTORS = ["serviceMonitorSelector", "podMonitorSelector", "probeSelector", "scrapeConfigSelector"] as const;
|
|
21
|
+
|
|
22
|
+
export const wk8705: PostSynthCheck = {
|
|
23
|
+
id: "WK8705",
|
|
24
|
+
description:
|
|
25
|
+
"A Prometheus whose serviceMonitorSelector, podMonitorSelector, probeSelector and scrapeConfigSelector are all null selects no monitor, so the operator scrapes nothing from ServiceMonitors, PodMonitors, Probes or ScrapeConfigs.",
|
|
26
|
+
|
|
27
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
28
|
+
const { manifests } = selectionContext(ctx);
|
|
29
|
+
return monitoringKind(manifests, "Prometheus")
|
|
30
|
+
.filter((p) => {
|
|
31
|
+
const spec = (p.spec ?? {}) as Record<string, unknown>;
|
|
32
|
+
return SELECTORS.every((k) => spec[k] === null || spec[k] === undefined);
|
|
33
|
+
})
|
|
34
|
+
.map((p) => ({
|
|
35
|
+
checkId: "WK8705",
|
|
36
|
+
severity: "warning" as const,
|
|
37
|
+
message:
|
|
38
|
+
`${describe(p)} has ${SELECTORS.join(", ")} all null, so it selects no ServiceMonitor, PodMonitor, Probe or ScrapeConfig and scrapes only its own config` +
|
|
39
|
+
`${(p.spec as Record<string, unknown> | undefined)?.additionalScrapeConfigs ? " and additionalScrapeConfigs" : ""}. ` +
|
|
40
|
+
`Set the selector for each monitor kind it should pick up ({} selects all in the selected namespaces).`,
|
|
41
|
+
entity: nameOf(p),
|
|
42
|
+
lexicon: "k8s",
|
|
43
|
+
}));
|
|
44
|
+
},
|
|
45
|
+
};
|