@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.
- 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/config-schema.d.ts +115 -1
- package/dist/config-schema.d.ts.map +1 -1
- package/dist/config.d.ts +58 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/crd/crd-sources.d.ts.map +1 -1
- package/dist/crd/loader.d.ts +4 -0
- package/dist/crd/loader.d.ts.map +1 -1
- package/dist/crd/parser.d.ts +5 -0
- package/dist/crd/parser.d.ts.map +1 -1
- package/dist/crd/project-codegen.d.ts +33 -0
- package/dist/crd/project-codegen.d.ts.map +1 -0
- 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/include/entity.d.ts +73 -0
- package/dist/include/entity.d.ts.map +1 -0
- package/dist/include/resolve.d.ts +29 -0
- package/dist/include/resolve.d.ts.map +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/integrity.json +17 -10
- package/dist/kustomize/rendered-entity.d.ts +15 -1
- package/dist/kustomize/rendered-entity.d.ts.map +1 -1
- package/dist/kustomize/root.d.ts +11 -2
- package/dist/kustomize/root.d.ts.map +1 -1
- package/dist/lint/audit-catalog.d.ts.map +1 -1
- package/dist/lint/post-synth/crd-schema-helpers.d.ts +5 -1
- package/dist/lint/post-synth/crd-schema-helpers.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/patch/json-patch.d.ts +51 -0
- package/dist/patch/json-patch.d.ts.map +1 -0
- package/dist/patch/rendered-patch.d.ts +90 -0
- package/dist/patch/rendered-patch.d.ts.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/project-kinds.d.ts +46 -0
- package/dist/project-kinds.d.ts.map +1 -0
- package/dist/rules/crd-schema-helpers.ts +10 -2
- 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/serializer.d.ts.map +1 -1
- 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/config-augmentation.test.ts +28 -0
- package/src/config-schema.ts +47 -1
- package/src/config.ts +44 -3
- package/src/crd/crd-sources.ts +41 -2
- package/src/crd/loader.ts +1 -1
- package/src/crd/parser.ts +9 -5
- package/src/crd/project-codegen.test.ts +239 -0
- package/src/crd/project-codegen.ts +327 -0
- 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/include/entity.ts +119 -0
- package/src/include/include.test.ts +345 -0
- package/src/include/resolve.ts +204 -0
- package/src/index.ts +25 -2
- package/src/kustomize/rendered-entity.ts +43 -1
- package/src/kustomize/root.test.ts +39 -0
- package/src/kustomize/root.ts +16 -30
- package/src/lint/audit-catalog.ts +6 -0
- package/src/lint/post-synth/crd-schema-helpers.ts +10 -2
- 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
- package/src/patch/json-patch.test.ts +91 -0
- package/src/patch/json-patch.ts +189 -0
- package/src/patch/rendered-patch.test.ts +143 -0
- package/src/patch/rendered-patch.ts +180 -0
- package/src/plugin.ts +16 -2
- package/src/project-kinds.ts +75 -0
- package/src/serializer.ts +10 -0
- package/src/testdata/include/bundle.yaml +45 -0
|
@@ -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
|
+
};
|
|
@@ -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
|
+
};
|
package/dist/serializer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAsC,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAsC,MAAM,6BAA6B,CAAC;AAoXlG,eAAO,MAAM,aAAa,EAAE,UAuO3B,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,6 +26,33 @@ export declare class Alert {
|
|
|
26
26
|
readonly uid: string;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export declare class Alertmanager {
|
|
30
|
+
constructor(props: {
|
|
31
|
+
/** spec defines the specification of the desired behavior of the Alertmanager cluster. More info:
|
|
32
|
+
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status */
|
|
33
|
+
spec: Record<string, unknown>;
|
|
34
|
+
/** Standard object's metadata. */
|
|
35
|
+
metadata?: ObjectMeta;
|
|
36
|
+
});
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly namespace: string;
|
|
39
|
+
readonly status: Record<string, unknown>;
|
|
40
|
+
readonly uid: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare class AlertmanagerConfig {
|
|
44
|
+
constructor(props: {
|
|
45
|
+
/** spec defines the specification of AlertmanagerConfigSpec */
|
|
46
|
+
spec: Record<string, unknown>;
|
|
47
|
+
/** Standard object's metadata. */
|
|
48
|
+
metadata?: ObjectMeta;
|
|
49
|
+
});
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly namespace: string;
|
|
52
|
+
readonly status: Record<string, unknown>;
|
|
53
|
+
readonly uid: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
29
56
|
export declare class APIGroup {
|
|
30
57
|
constructor(props: {
|
|
31
58
|
/** name is the name of the group. */
|
|
@@ -317,6 +344,18 @@ export declare class ClusterIssuer {
|
|
|
317
344
|
readonly uid: string;
|
|
318
345
|
}
|
|
319
346
|
|
|
347
|
+
export declare class ClusterObservability {
|
|
348
|
+
constructor(props: {
|
|
349
|
+
/** Standard object's metadata. */
|
|
350
|
+
metadata?: ObjectMeta;
|
|
351
|
+
spec?: Record<string, unknown>;
|
|
352
|
+
});
|
|
353
|
+
readonly name: string;
|
|
354
|
+
readonly namespace: string;
|
|
355
|
+
readonly status: Record<string, unknown>;
|
|
356
|
+
readonly uid: string;
|
|
357
|
+
}
|
|
358
|
+
|
|
320
359
|
export declare class ClusterResourceSet {
|
|
321
360
|
constructor(props: {
|
|
322
361
|
/** spec is the desired state of ClusterResourceSet. */
|
|
@@ -1569,6 +1608,18 @@ export declare class IngressRouteUDP {
|
|
|
1569
1608
|
readonly uid: string;
|
|
1570
1609
|
}
|
|
1571
1610
|
|
|
1611
|
+
export declare class Instrumentation {
|
|
1612
|
+
constructor(props: {
|
|
1613
|
+
/** Standard object's metadata. */
|
|
1614
|
+
metadata?: ObjectMeta;
|
|
1615
|
+
spec?: Record<string, unknown>;
|
|
1616
|
+
});
|
|
1617
|
+
readonly name: string;
|
|
1618
|
+
readonly namespace: string;
|
|
1619
|
+
readonly status: Record<string, unknown>;
|
|
1620
|
+
readonly uid: string;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1572
1623
|
export declare class IPAddress {
|
|
1573
1624
|
constructor(props: {
|
|
1574
1625
|
/** spec is the desired state of the IPAddress. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status */
|
|
@@ -1837,6 +1888,19 @@ export declare class MiddlewareTCP {
|
|
|
1837
1888
|
readonly uid: string;
|
|
1838
1889
|
}
|
|
1839
1890
|
|
|
1891
|
+
export declare class MonitoringProbe {
|
|
1892
|
+
constructor(props: {
|
|
1893
|
+
/** spec defines the specification of desired Ingress selection for target discovery by Prometheus. */
|
|
1894
|
+
spec: Record<string, unknown>;
|
|
1895
|
+
/** Standard object's metadata. */
|
|
1896
|
+
metadata?: ObjectMeta;
|
|
1897
|
+
});
|
|
1898
|
+
readonly name: string;
|
|
1899
|
+
readonly namespace: string;
|
|
1900
|
+
readonly status: Record<string, unknown>;
|
|
1901
|
+
readonly uid: string;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1840
1904
|
export declare class MutatingAdmissionPolicy {
|
|
1841
1905
|
constructor(props: {
|
|
1842
1906
|
/** metadata is the standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata. */
|
|
@@ -2032,6 +2096,30 @@ export declare class OCIRepository {
|
|
|
2032
2096
|
readonly uid: string;
|
|
2033
2097
|
}
|
|
2034
2098
|
|
|
2099
|
+
export declare class OpAMPBridge {
|
|
2100
|
+
constructor(props: {
|
|
2101
|
+
/** Standard object's metadata. */
|
|
2102
|
+
metadata?: ObjectMeta;
|
|
2103
|
+
spec?: Record<string, unknown>;
|
|
2104
|
+
});
|
|
2105
|
+
readonly name: string;
|
|
2106
|
+
readonly namespace: string;
|
|
2107
|
+
readonly status: Record<string, unknown>;
|
|
2108
|
+
readonly uid: string;
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
export declare class OpenTelemetryCollector {
|
|
2112
|
+
constructor(props: {
|
|
2113
|
+
/** Standard object's metadata. */
|
|
2114
|
+
metadata?: ObjectMeta;
|
|
2115
|
+
spec?: Record<string, unknown>;
|
|
2116
|
+
});
|
|
2117
|
+
readonly name: string;
|
|
2118
|
+
readonly namespace: string;
|
|
2119
|
+
readonly status: Record<string, unknown>;
|
|
2120
|
+
readonly uid: string;
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2035
2123
|
export declare class Order {
|
|
2036
2124
|
constructor(props: {
|
|
2037
2125
|
spec: Record<string, unknown>;
|
|
@@ -2193,6 +2281,19 @@ export declare class PodList {
|
|
|
2193
2281
|
readonly uid: string;
|
|
2194
2282
|
}
|
|
2195
2283
|
|
|
2284
|
+
export declare class PodMonitor {
|
|
2285
|
+
constructor(props: {
|
|
2286
|
+
/** spec defines the specification of desired Pod selection for target discovery by Prometheus. */
|
|
2287
|
+
spec: Record<string, unknown>;
|
|
2288
|
+
/** Standard object's metadata. */
|
|
2289
|
+
metadata?: ObjectMeta;
|
|
2290
|
+
});
|
|
2291
|
+
readonly name: string;
|
|
2292
|
+
readonly namespace: string;
|
|
2293
|
+
readonly status: Record<string, unknown>;
|
|
2294
|
+
readonly uid: string;
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2196
2297
|
export declare class PodTemplate {
|
|
2197
2298
|
constructor(props: {
|
|
2198
2299
|
/** Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata */
|
|
@@ -2307,15 +2408,44 @@ export declare class PriorityLevelConfigurationList {
|
|
|
2307
2408
|
readonly uid: string;
|
|
2308
2409
|
}
|
|
2309
2410
|
|
|
2411
|
+
export declare class Prometheus {
|
|
2412
|
+
constructor(props: {
|
|
2413
|
+
/** spec defines the specification of the desired behavior of the Prometheus cluster. More info:
|
|
2414
|
+
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status */
|
|
2415
|
+
spec: Record<string, unknown>;
|
|
2416
|
+
/** Standard object's metadata. */
|
|
2417
|
+
metadata?: ObjectMeta;
|
|
2418
|
+
});
|
|
2419
|
+
readonly name: string;
|
|
2420
|
+
readonly namespace: string;
|
|
2421
|
+
readonly status: Record<string, unknown>;
|
|
2422
|
+
readonly uid: string;
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
export declare class PrometheusAgent {
|
|
2426
|
+
constructor(props: {
|
|
2427
|
+
/** spec defines the specification of the desired behavior of the Prometheus agent. More info:
|
|
2428
|
+
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status */
|
|
2429
|
+
spec: Record<string, unknown>;
|
|
2430
|
+
/** Standard object's metadata. */
|
|
2431
|
+
metadata?: ObjectMeta;
|
|
2432
|
+
});
|
|
2433
|
+
readonly name: string;
|
|
2434
|
+
readonly namespace: string;
|
|
2435
|
+
readonly status: Record<string, unknown>;
|
|
2436
|
+
readonly uid: string;
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2310
2439
|
export declare class PrometheusRule {
|
|
2311
2440
|
constructor(props: {
|
|
2312
|
-
/**
|
|
2441
|
+
/** spec defines the specification of desired alerting rule definitions for Prometheus. */
|
|
2313
2442
|
spec: Record<string, unknown>;
|
|
2314
2443
|
/** Standard object's metadata. */
|
|
2315
2444
|
metadata?: ObjectMeta;
|
|
2316
2445
|
});
|
|
2317
2446
|
readonly name: string;
|
|
2318
2447
|
readonly namespace: string;
|
|
2448
|
+
readonly status: Record<string, unknown>;
|
|
2319
2449
|
readonly uid: string;
|
|
2320
2450
|
}
|
|
2321
2451
|
|
|
@@ -2726,6 +2856,19 @@ More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-
|
|
|
2726
2856
|
readonly uid: string;
|
|
2727
2857
|
}
|
|
2728
2858
|
|
|
2859
|
+
export declare class ScrapeConfig {
|
|
2860
|
+
constructor(props: {
|
|
2861
|
+
/** spec defines the specification of ScrapeConfigSpec. */
|
|
2862
|
+
spec: Record<string, unknown>;
|
|
2863
|
+
/** Standard object's metadata. */
|
|
2864
|
+
metadata?: ObjectMeta;
|
|
2865
|
+
});
|
|
2866
|
+
readonly name: string;
|
|
2867
|
+
readonly namespace: string;
|
|
2868
|
+
readonly status: Record<string, unknown>;
|
|
2869
|
+
readonly uid: string;
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2729
2872
|
export declare class Sec {
|
|
2730
2873
|
constructor(props: {
|
|
2731
2874
|
/** Data contains the secret data. Each key must consist of alphanumeric characters, '-', '_' or '.'. The serialized form of the secret data is a base64 encoded string, representing the arbitrary (possibly non-string) data value here. Described in https://tools.ietf.org/html/rfc4648#section-4 */
|
|
@@ -2910,7 +3053,7 @@ export declare class ServiceList {
|
|
|
2910
3053
|
|
|
2911
3054
|
export declare class ServiceMonitor {
|
|
2912
3055
|
constructor(props: {
|
|
2913
|
-
/**
|
|
3056
|
+
/** spec defines the specification of desired Service selection for target discovery by
|
|
2914
3057
|
Prometheus. */
|
|
2915
3058
|
spec: Record<string, unknown>;
|
|
2916
3059
|
/** Standard object's metadata. */
|
|
@@ -2918,6 +3061,7 @@ Prometheus. */
|
|
|
2918
3061
|
});
|
|
2919
3062
|
readonly name: string;
|
|
2920
3063
|
readonly namespace: string;
|
|
3064
|
+
readonly status: Record<string, unknown>;
|
|
2921
3065
|
readonly uid: string;
|
|
2922
3066
|
}
|
|
2923
3067
|
|
|
@@ -3059,6 +3203,32 @@ export declare class SubjectAccessReview {
|
|
|
3059
3203
|
readonly uid: string;
|
|
3060
3204
|
}
|
|
3061
3205
|
|
|
3206
|
+
export declare class TargetAllocator {
|
|
3207
|
+
constructor(props: {
|
|
3208
|
+
/** Standard object's metadata. */
|
|
3209
|
+
metadata?: ObjectMeta;
|
|
3210
|
+
spec?: Record<string, unknown>;
|
|
3211
|
+
});
|
|
3212
|
+
readonly name: string;
|
|
3213
|
+
readonly namespace: string;
|
|
3214
|
+
readonly status: Record<string, unknown>;
|
|
3215
|
+
readonly uid: string;
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
export declare class ThanosRuler {
|
|
3219
|
+
constructor(props: {
|
|
3220
|
+
/** spec defines the specification of the desired behavior of the ThanosRuler cluster. More info:
|
|
3221
|
+
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status */
|
|
3222
|
+
spec: Record<string, unknown>;
|
|
3223
|
+
/** Standard object's metadata. */
|
|
3224
|
+
metadata?: ObjectMeta;
|
|
3225
|
+
});
|
|
3226
|
+
readonly name: string;
|
|
3227
|
+
readonly namespace: string;
|
|
3228
|
+
readonly status: Record<string, unknown>;
|
|
3229
|
+
readonly uid: string;
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3062
3232
|
export declare class TLSOption {
|
|
3063
3233
|
constructor(props: {
|
|
3064
3234
|
/** TLSOptionSpec defines the desired state of a TLSOption. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-k8s",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.108.0",
|
|
4
4
|
"description": "Kubernetes lexicon for chant — declarative IaC in TypeScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@types/js-yaml": "^4.0.9"
|
|
79
79
|
},
|
|
80
80
|
"optionalDependencies": {
|
|
81
|
-
"@intentius/chant-k8s-client": "^0.
|
|
81
|
+
"@intentius/chant-k8s-client": "^0.108.0"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@intentius/chant": "*",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"zod": "^4.3.6",
|
|
89
|
-
"@intentius/chant": "^0.
|
|
89
|
+
"@intentius/chant": "^0.108.0",
|
|
90
90
|
"typescript": "^5.9.3"
|
|
91
91
|
}
|
|
92
92
|
}
|
package/src/codegen/naming.ts
CHANGED
|
@@ -80,6 +80,9 @@ const k8sNamingConfig: NamingConfig = {
|
|
|
80
80
|
// Events (core vs events.k8s.io — the core version wins)
|
|
81
81
|
"K8s::Core::Event": "Event",
|
|
82
82
|
|
|
83
|
+
// Prometheus Operator's Probe CRD would collide with the core Probe property type
|
|
84
|
+
"K8s::Monitoring::Probe": "MonitoringProbe",
|
|
85
|
+
|
|
83
86
|
// Property types
|
|
84
87
|
"K8s::Core::Container": "Container",
|
|
85
88
|
"K8s::Core::ContainerPort": "ContainerPort",
|
|
@@ -150,7 +153,18 @@ const k8sNamingConfig: NamingConfig = {
|
|
|
150
153
|
"K8s::Networking::NetworkPolicy": ["NetPol"],
|
|
151
154
|
},
|
|
152
155
|
|
|
153
|
-
|
|
156
|
+
// Names published before the Prometheus Operator CRDs (v0.94.1) added colliding
|
|
157
|
+
// property types stay with their original owners; the new CRDs' types are prefixed.
|
|
158
|
+
priorityPropertyAliases: {
|
|
159
|
+
"K8s::Monitoring::ServiceMonitor": {
|
|
160
|
+
AttachMetadata: "AttachMetadata",
|
|
161
|
+
NamespaceSelector: "NamespaceSelector",
|
|
162
|
+
Selector: "Selector",
|
|
163
|
+
},
|
|
164
|
+
"K8s::Traefik::Middleware": { BasicAuth: "BasicAuth" },
|
|
165
|
+
"K8s::Addons::HelmChartProxy": { TlsConfig: "TlsConfig" },
|
|
166
|
+
"K8s::S3::Bucket": { Lifecycle: "Lifecycle" },
|
|
167
|
+
},
|
|
154
168
|
|
|
155
169
|
serviceAbbreviations: {
|
|
156
170
|
Core: "Core",
|