@intentius/chant-lexicon-k8s 0.100.0 → 0.102.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/actions/apps.d.ts +4 -4
- package/dist/actions/apps.d.ts.map +1 -1
- package/dist/actions/core.d.ts +5 -5
- package/dist/actions/core.d.ts.map +1 -1
- package/dist/actions/networking.d.ts.map +1 -1
- package/dist/codegen/generate-typescript.d.ts +2 -2
- package/dist/codegen/generate-typescript.d.ts.map +1 -1
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/naming.d.ts.map +1 -1
- package/dist/codegen/versions.d.ts.map +1 -1
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/composites/catalog.d.ts.map +1 -1
- package/dist/composites/cockroachdb-cluster.d.ts +2 -2
- package/dist/composites/gke-otel-collector.d.ts.map +1 -1
- package/dist/composites/index.d.ts +1 -0
- package/dist/composites/index.d.ts.map +1 -1
- package/dist/composites/otel-collector-agent.d.ts +24 -2
- package/dist/composites/otel-collector-agent.d.ts.map +1 -1
- package/dist/composites/otel-collector-gateway.d.ts +37 -52
- package/dist/composites/otel-collector-gateway.d.ts.map +1 -1
- package/dist/composites/otel-collector-node.d.ts +88 -0
- package/dist/composites/otel-collector-node.d.ts.map +1 -0
- package/dist/composites/otel-collector-rbac.d.ts +74 -0
- package/dist/composites/otel-collector-rbac.d.ts.map +1 -0
- package/dist/composites/otel-collector-shape.d.ts +7 -0
- package/dist/composites/otel-collector-shape.d.ts.map +1 -1
- package/dist/composites/otel-collector.d.ts +17 -21
- package/dist/composites/otel-collector.d.ts.map +1 -1
- package/dist/composites/ray-cluster.d.ts +6 -6
- package/dist/composites/ray-job.d.ts +5 -5
- package/dist/composites/ray-service.d.ts +6 -6
- package/dist/crd/crd-sources.d.ts.map +1 -1
- package/dist/crd/loader.d.ts.map +1 -1
- package/dist/crd/oci-chart.d.ts +50 -0
- package/dist/crd/oci-chart.d.ts.map +1 -0
- package/dist/crd/types.d.ts +5 -0
- package/dist/crd/types.d.ts.map +1 -1
- package/dist/effect-receipt-row.d.ts.map +1 -1
- package/dist/generated/index.d.ts +752 -729
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/import/embedded.d.ts +4 -2
- package/dist/import/embedded.d.ts.map +1 -1
- package/dist/import/generator.d.ts.map +1 -1
- package/dist/import/live-export.d.ts +5 -0
- package/dist/import/live-export.d.ts.map +1 -1
- package/dist/import/parser.d.ts.map +1 -1
- package/dist/import/testdata/embedded/fixtures.d.ts +6 -0
- package/dist/import/testdata/embedded/fixtures.d.ts.map +1 -1
- package/dist/integrity.json +8 -6
- 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/otel-placement-helpers.d.ts +5 -1
- package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8604.d.ts +19 -0
- package/dist/lint/post-synth/wk8604.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8605.d.ts +23 -0
- package/dist/lint/post-synth/wk8605.d.ts.map +1 -0
- package/dist/manifest.json +1 -1
- package/dist/meta.json +156 -17
- package/dist/okf/index.md +5 -0
- package/dist/okf/rules/WK8604.md +11 -0
- package/dist/okf/rules/WK8605.md +11 -0
- package/dist/okf/types/APIGroup.md +3 -3
- package/dist/okf/types/APIGroupList.md +1 -1
- package/dist/okf/types/APIResourceList.md +1 -1
- package/dist/okf/types/APIService.md +1 -1
- package/dist/okf/types/APIServiceList.md +2 -2
- package/dist/okf/types/APIVersions.md +1 -1
- package/dist/okf/types/BatchJob.md +1 -1
- package/dist/okf/types/CSIDriver.md +1 -1
- package/dist/okf/types/CSIDriverList.md +2 -2
- package/dist/okf/types/CSINode.md +1 -1
- package/dist/okf/types/CSINodeList.md +2 -2
- package/dist/okf/types/CSIStorageCapacity.md +2 -2
- package/dist/okf/types/CSIStorageCapacityList.md +2 -2
- package/dist/okf/types/CertificateSigningRequest.md +1 -1
- package/dist/okf/types/CertificateSigningRequestList.md +2 -2
- package/dist/okf/types/ClusterRole.md +1 -1
- package/dist/okf/types/ClusterRoleBindingList.md +2 -2
- package/dist/okf/types/ClusterRoleList.md +2 -2
- package/dist/okf/types/ClusterTrustBundle.md +1 -1
- package/dist/okf/types/ClusterTrustBundleList.md +2 -2
- package/dist/okf/types/ComponentStatus.md +1 -1
- package/dist/okf/types/ComponentStatusList.md +2 -2
- package/dist/okf/types/ConfigMapList.md +2 -2
- package/dist/okf/types/ControllerRevisionList.md +2 -2
- package/dist/okf/types/CoreEventList.md +2 -2
- package/dist/okf/types/CronJob.md +1 -1
- package/dist/okf/types/CronJobList.md +2 -2
- package/dist/okf/types/CustomResourceDefinition.md +1 -1
- package/dist/okf/types/CustomResourceDefinitionList.md +2 -2
- package/dist/okf/types/DaemonSet.md +1 -1
- package/dist/okf/types/DaemonSetList.md +2 -2
- package/dist/okf/types/DeleteOptions.md +1 -1
- package/dist/okf/types/Deploy.md +1 -1
- package/dist/okf/types/DeploymentList.md +2 -2
- package/dist/okf/types/DeviceClass.md +1 -1
- package/dist/okf/types/DeviceClassList.md +2 -2
- package/dist/okf/types/DeviceTaintRule.md +1 -1
- package/dist/okf/types/DeviceTaintRuleList.md +2 -2
- package/dist/okf/types/EndpointSlice.md +2 -2
- package/dist/okf/types/EndpointSliceList.md +2 -2
- package/dist/okf/types/Endpoints.md +1 -1
- package/dist/okf/types/EndpointsList.md +2 -2
- package/dist/okf/types/Event.md +2 -2
- package/dist/okf/types/EventsEvent.md +2 -2
- package/dist/okf/types/EventsEventList.md +2 -2
- package/dist/okf/types/Eviction.md +1 -1
- package/dist/okf/types/FlowSchema.md +1 -1
- package/dist/okf/types/FlowSchemaList.md +2 -2
- package/dist/okf/types/GrafanaDashboard.md +14 -0
- package/dist/okf/types/GrafanaDatasource.md +14 -0
- package/dist/okf/types/GrafanaFolder.md +14 -0
- package/dist/okf/types/HorizontalPodAutoscaler.md +1 -1
- package/dist/okf/types/HorizontalPodAutoscalerList.md +2 -2
- package/dist/okf/types/IPAddress.md +1 -1
- package/dist/okf/types/IPAddressList.md +2 -2
- package/dist/okf/types/Ing.md +1 -1
- package/dist/okf/types/IngressClass.md +1 -1
- package/dist/okf/types/IngressClassList.md +2 -2
- package/dist/okf/types/IngressList.md +2 -2
- package/dist/okf/types/JobList.md +2 -2
- package/dist/okf/types/Lease.md +1 -1
- package/dist/okf/types/LeaseCandidate.md +1 -1
- package/dist/okf/types/LeaseCandidateList.md +2 -2
- package/dist/okf/types/LeaseList.md +2 -2
- package/dist/okf/types/LimitRange.md +1 -1
- package/dist/okf/types/LimitRangeList.md +2 -2
- package/dist/okf/types/LocalSubjectAccessReview.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicy.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicyBinding.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicyBindingList.md +2 -2
- package/dist/okf/types/MutatingAdmissionPolicyList.md +2 -2
- package/dist/okf/types/MutatingWebhookConfiguration.md +1 -1
- package/dist/okf/types/MutatingWebhookConfigurationList.md +2 -2
- package/dist/okf/types/Namespace.md +1 -1
- package/dist/okf/types/NamespaceList.md +2 -2
- package/dist/okf/types/NetPol.md +1 -1
- package/dist/okf/types/NetworkPolicyList.md +2 -2
- package/dist/okf/types/Node.md +1 -1
- package/dist/okf/types/NodeList.md +2 -2
- package/dist/okf/types/PersistentVolume.md +1 -1
- package/dist/okf/types/PersistentVolumeClaimList.md +2 -2
- package/dist/okf/types/PersistentVolumeList.md +2 -2
- package/dist/okf/types/PodCertificateRequest.md +1 -1
- package/dist/okf/types/PodCertificateRequestList.md +2 -2
- package/dist/okf/types/PodDisruptionBudgetList.md +2 -2
- package/dist/okf/types/PodList.md +2 -2
- package/dist/okf/types/PodTemplateList.md +2 -2
- package/dist/okf/types/PriorityClassList.md +2 -2
- package/dist/okf/types/PriorityLevelConfiguration.md +1 -1
- package/dist/okf/types/PriorityLevelConfigurationList.md +2 -2
- package/dist/okf/types/ReplicaSet.md +1 -1
- package/dist/okf/types/ReplicaSetList.md +2 -2
- package/dist/okf/types/ReplicationController.md +1 -1
- package/dist/okf/types/ReplicationControllerList.md +2 -2
- package/dist/okf/types/ResourceClaim.md +1 -1
- package/dist/okf/types/ResourceClaimList.md +2 -2
- package/dist/okf/types/ResourceClaimTemplate.md +1 -1
- package/dist/okf/types/ResourceClaimTemplateList.md +2 -2
- package/dist/okf/types/ResourceQuota.md +1 -1
- package/dist/okf/types/ResourceQuotaList.md +2 -2
- package/dist/okf/types/ResourceSlice.md +1 -1
- package/dist/okf/types/ResourceSliceList.md +2 -2
- package/dist/okf/types/RoleBindingList.md +2 -2
- package/dist/okf/types/RoleList.md +2 -2
- package/dist/okf/types/RuntimeClass.md +2 -2
- package/dist/okf/types/RuntimeClassList.md +2 -2
- package/dist/okf/types/Scale.md +1 -1
- package/dist/okf/types/SecretList.md +2 -2
- package/dist/okf/types/SelfSubjectAccessReview.md +1 -1
- package/dist/okf/types/SelfSubjectRulesReview.md +1 -1
- package/dist/okf/types/Service.md +1 -1
- package/dist/okf/types/ServiceAccountList.md +2 -2
- package/dist/okf/types/ServiceCIDR.md +1 -1
- package/dist/okf/types/ServiceCIDRList.md +2 -2
- package/dist/okf/types/ServiceList.md +2 -2
- package/dist/okf/types/StatefulSet.md +1 -1
- package/dist/okf/types/StatefulSetList.md +2 -2
- package/dist/okf/types/Status.md +2 -2
- package/dist/okf/types/StorageClass.md +1 -1
- package/dist/okf/types/StorageClassList.md +2 -2
- package/dist/okf/types/StorageVersionMigration.md +1 -1
- package/dist/okf/types/StorageVersionMigrationList.md +2 -2
- package/dist/okf/types/SubjectAccessReview.md +1 -1
- package/dist/okf/types/TokenRequest.md +1 -1
- package/dist/okf/types/TokenReview.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicy.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicyBinding.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicyBindingList.md +2 -2
- package/dist/okf/types/ValidatingAdmissionPolicyList.md +2 -2
- package/dist/okf/types/ValidatingWebhookConfiguration.md +1 -1
- package/dist/okf/types/ValidatingWebhookConfigurationList.md +2 -2
- package/dist/okf/types/VolumeAttachment.md +1 -1
- package/dist/okf/types/VolumeAttachmentList.md +2 -2
- package/dist/okf/types/VolumeAttributesClassList.md +2 -2
- package/dist/op/activities/argo.d.ts.map +1 -1
- package/dist/op/activities/index.d.ts +3 -3
- package/dist/op/activities/index.d.ts.map +1 -1
- package/dist/op/activities/wait-for-ready.d.ts.map +1 -1
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/rules/otel-placement-helpers.ts +7 -11
- package/dist/rules/wk8604.ts +29 -0
- package/dist/rules/wk8605.ts +131 -0
- package/dist/skills/chant-k8s.md +1 -1
- package/dist/spec/parse.d.ts +27 -0
- package/dist/spec/parse.d.ts.map +1 -1
- package/dist/types/index.d.ts +5360 -972
- package/dist/variables.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/codegen/declarations.test.ts +118 -0
- package/src/codegen/generate-typescript.ts +69 -4
- package/src/codegen/generate.ts +15 -6
- package/src/composites/__snapshots__/gke-otel-collector.snapshot.test.ts.snap +2 -68
- package/src/composites/catalog.ts +12 -0
- package/src/composites/gke-otel-collector.snapshot.test.ts +3 -1
- package/src/composites/gke-otel-collector.ts +13 -2
- package/src/composites/index.ts +1 -0
- package/src/composites/otel-collector-agent.ts +45 -11
- package/src/composites/otel-collector-gateway.test.ts +102 -5
- package/src/composites/otel-collector-gateway.ts +96 -18
- package/src/composites/otel-collector-node.test.ts +174 -0
- package/src/composites/otel-collector-node.ts +213 -0
- package/src/composites/otel-collector-rbac.test.ts +114 -0
- package/src/composites/otel-collector-rbac.ts +144 -0
- package/src/composites/otel-collector-shape.ts +19 -0
- package/src/composites/otel-collector.ts +40 -35
- package/src/crd/crd-sources.ts +26 -0
- package/src/crd/loader.test.ts +9 -1
- package/src/crd/loader.ts +26 -3
- package/src/crd/oci-chart.test.ts +149 -0
- package/src/crd/oci-chart.ts +178 -0
- package/src/crd/types.ts +5 -0
- package/src/generated/index.d.ts +5360 -972
- package/src/generated/index.ts +23 -0
- package/src/generated/lexicon-k8s.json +156 -17
- package/src/generated/operations.json +48 -0
- package/src/import/embedded-live.test.ts +180 -0
- package/src/import/embedded-roundtrip.test.ts +73 -7
- package/src/import/embedded-types.e2e.test.ts +3 -1
- package/src/import/embedded.test.ts +64 -0
- package/src/import/embedded.ts +31 -2
- package/src/import/generator.test.ts +19 -0
- package/src/import/generator.ts +20 -2
- package/src/import/live-export.ts +10 -2
- package/src/import/testdata/embedded/README.md +4 -1
- package/src/import/testdata/embedded/alertmanager-configmap.yaml +91 -0
- package/src/import/testdata/embedded/fixtures.ts +18 -0
- package/src/import/testdata/embedded/grafana-operator-dashboard.yaml +363 -0
- package/src/import/testdata/embedded/grafana-v2-dashboard-configmap.yaml +851 -0
- package/src/lint/audit-catalog.ts +2 -0
- package/src/lint/post-synth/index.ts +4 -0
- package/src/lint/post-synth/otel-placement-helpers.ts +7 -11
- package/src/lint/post-synth/otel-placement.test.ts +35 -0
- package/src/lint/post-synth/post-synth.test.ts +3 -3
- package/src/lint/post-synth/wk8604.ts +29 -0
- package/src/lint/post-synth/wk8605.test.ts +141 -0
- package/src/lint/post-synth/wk8605.ts +131 -0
- package/src/skills/chant-k8s.md +1 -1
- package/src/spec/parse.test.ts +118 -0
- package/src/spec/parse.ts +250 -29
|
@@ -49,6 +49,8 @@ export const k8sAuditCatalog: Record<string, RuleMeta> = {
|
|
|
49
49
|
WK8601: auditRule("WK8601", "merge-worthy", "guidance", "OpenTelemetry Collector runs tail_sampling on every node", "Move tail_sampling from the DaemonSet agent to a gateway Deployment, and send traces to it through a loadbalancing exporter routed by traceID.", { category: "correctness" }),
|
|
50
50
|
WK8602: auditRule("WK8602", "merge-worthy", "guidance", "Multi-replica tail sampling gateway reached without trace-aware load balancing", "Send traces to the gateway through a loadbalancing exporter with routing_key traceID (k8s resolver, or dns on a headless Service), or run the gateway with one replica. It goes silent when the senders are in another build root (chant #1939).", { category: "correctness" }),
|
|
51
51
|
WK8603: auditRule("WK8603", "merge-worthy", "guidance", "k8s_cluster receiver runs in every collector copy", "Run the k8s_cluster receiver in a single-replica Deployment, or set its k8s_leader_elector to a k8s_leader_elector extension enabled in service.extensions.", { category: "correctness" }),
|
|
52
|
+
WK8604: auditRule("WK8604", "merge-worthy", "guidance", "Collector config in a ConfigMap fails the otel config checks", "Fix the collector config the ConfigMap carries: each finding keeps its OTEL1xx id and names the ConfigMap and key. Change the declared components and pipelines, not the rendered YAML.", { category: "correctness" }),
|
|
53
|
+
WK8605: auditRule("WK8605", "merge-worthy", "guidance", "Collector config reads the node but its workload lacks the node name or host mounts", "Set the node name variable from spec.nodeName with the downward API and mount the host paths hostmetrics and filelog read, read-only; OtelCollector adds them from the config.", { category: "correctness" }),
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
// Prior art credits live beside the rules in ./audit-lineage.ts (see core audit/prior-art.ts).
|
|
@@ -43,6 +43,8 @@ import { wk8505 } from "./wk8505";
|
|
|
43
43
|
import { wk8601 } from "./wk8601";
|
|
44
44
|
import { wk8602 } from "./wk8602";
|
|
45
45
|
import { wk8603 } from "./wk8603";
|
|
46
|
+
import { wk8604 } from "./wk8604";
|
|
47
|
+
import { wk8605 } from "./wk8605";
|
|
46
48
|
|
|
47
49
|
export const postSynthChecks: PostSynthCheck[] = [
|
|
48
50
|
argo002,
|
|
@@ -88,4 +90,6 @@ export const postSynthChecks: PostSynthCheck[] = [
|
|
|
88
90
|
wk8601,
|
|
89
91
|
wk8602,
|
|
90
92
|
wk8603,
|
|
93
|
+
wk8604,
|
|
94
|
+
wk8605,
|
|
91
95
|
];
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* `OTEL_COLLECTOR_ANNOTATIONS`.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import { parseCollectorConfig as parseOtelCollectorConfig } from "@intentius/chant-lexicon-otel/configmap";
|
|
29
29
|
import { extractContainers, extractPodSpec, type K8sManifest } from "./k8s-helpers";
|
|
30
30
|
|
|
31
31
|
export const PLACEMENT_ANNOTATIONS = {
|
|
@@ -80,17 +80,13 @@ function isRecord(v: unknown): v is Record<string, unknown> {
|
|
|
80
80
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Parse a ConfigMap value as a collector config, or undefined when it isn't
|
|
85
|
+
* one. The otel lexicon's parser, shared with its config checks (OTEL101 and
|
|
86
|
+
* the rest) and WK8604 so every check agrees on what counts as a config.
|
|
87
|
+
*/
|
|
84
88
|
export function parseCollectorConfig(text: unknown): CollectorConfigShape | undefined {
|
|
85
|
-
|
|
86
|
-
let value: unknown;
|
|
87
|
-
try {
|
|
88
|
-
value = load(text);
|
|
89
|
-
} catch {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
if (!isRecord(value) || !isRecord(value.service) || !isRecord(value.service.pipelines)) return undefined;
|
|
93
|
-
return value as unknown as CollectorConfigShape;
|
|
89
|
+
return parseOtelCollectorConfig(text) as CollectorConfigShape | undefined;
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
/** The `type` of a component id: `tail_sampling/errors` is `tail_sampling`. */
|
|
@@ -30,6 +30,7 @@ import { docsToManifests } from "./k8s-helpers";
|
|
|
30
30
|
import { wk8601 } from "./wk8601";
|
|
31
31
|
import { wk8602 } from "./wk8602";
|
|
32
32
|
import { wk8603 } from "./wk8603";
|
|
33
|
+
import { wk8604 } from "./wk8604";
|
|
33
34
|
|
|
34
35
|
// ── Fixture builders ────────────────────────────────────────────────
|
|
35
36
|
|
|
@@ -399,3 +400,37 @@ service: { pipelines: { metrics: { receivers: [otlp], exporters: [debug] } } }
|
|
|
399
400
|
expect(wk8603.check(yaml(configMap("c", { "config.yaml": unused }), workload({ kind: "DaemonSet", name: "agent", configMap: "c" })))).toEqual([]);
|
|
400
401
|
});
|
|
401
402
|
});
|
|
403
|
+
|
|
404
|
+
// ── WK8604 ──────────────────────────────────────────────────────────
|
|
405
|
+
|
|
406
|
+
describe("WK8604: the otel config checks over ConfigMap configs", () => {
|
|
407
|
+
test("reports an undeclared exporter under OTEL101, naming the ConfigMap and key", () => {
|
|
408
|
+
const broken = PLAIN_CONFIG.replace("exporters: [debug]", "exporters: [debug, otlp/tempo]");
|
|
409
|
+
const diags = wk8604.check(yaml(configMap("agent-config", { "config.yaml": broken })));
|
|
410
|
+
expect(diags).toHaveLength(1);
|
|
411
|
+
expect(diags[0]).toMatchObject({ checkId: "OTEL101", severity: "error", lexicon: "otel" });
|
|
412
|
+
expect(diags[0].message).toMatch(/^ConfigMap obs\/agent-config, key config\.yaml: /);
|
|
413
|
+
expect(diags[0].message).toContain("otlp/tempo");
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("checks every key that holds a config, defaulting the namespace", () => {
|
|
417
|
+
const unused = PLAIN_CONFIG.replace("exporters: { debug: {} }", "exporters: { debug: {} }\nprocessors: { batch: {} }");
|
|
418
|
+
const cm = { apiVersion: "v1", kind: "ConfigMap", metadata: { name: "c" }, data: { "a.yaml": PLAIN_CONFIG, "b.yaml": unused } };
|
|
419
|
+
const diags = wk8604.check(yaml(cm));
|
|
420
|
+
expect(diags.map((d) => [d.checkId, d.entity])).toEqual([["OTEL103", "batch"]]);
|
|
421
|
+
expect(diags[0].message).toContain("ConfigMap default/c, key b.yaml");
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test("ignores ConfigMap values that are not collector configs", () => {
|
|
425
|
+
const ctx = yaml(configMap("prometheus-config", { "prometheus.yml": "scrape_configs: []\n", "rules.yml": "groups: [ {" }));
|
|
426
|
+
expect(wk8604.check(ctx)).toEqual([]);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
test("passes what OtelCollector, OtelCollectorGateway and GkeOtelCollector render", () => {
|
|
430
|
+
const gke = GkeOtelCollector({ clusterName: "c", projectId: "p", gcpServiceAccountEmail: "o@p.iam.gserviceaccount.com" });
|
|
431
|
+
const gateway = samplingGateway(2);
|
|
432
|
+
const agent = agentSending(gatewayExporter(gateway, { loadBalance: true }));
|
|
433
|
+
expect(wk8604.check(built({ gke, gateway, agent }))).toEqual([]);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
@@ -70,9 +70,9 @@ function manifestsCtx(...objs: unknown[]): PostSynthContext {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// ── WK8005: Secrets in env ──────────────────────────────────────────
|
|
73
|
-
// Note:
|
|
74
|
-
// ports, probes) use JSON format
|
|
75
|
-
//
|
|
73
|
+
// Note: tests with nested container properties (env, resources, securityContext,
|
|
74
|
+
// ports, probes) use JSON format, written when core's parseYAML was a line
|
|
75
|
+
// parser that misread them. It is js-yaml now (#3006), so YAML works too.
|
|
76
76
|
|
|
77
77
|
describe("WK8005: Hardcoded secrets in env", () => {
|
|
78
78
|
test("flags hardcoded password in env", () => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WK8604: the otel config checks over collector configs in ConfigMaps
|
|
3
|
+
*
|
|
4
|
+
* `OtelCollector`, `OtelCollectorGateway`, `GkeOtelCollector` and hand-written
|
|
5
|
+
* manifests carry the collector config as a string under a ConfigMap data key.
|
|
6
|
+
* `chant build` gives each lexicon's checks only that lexicon's output, so the
|
|
7
|
+
* otel lexicon's config checks never see a config that lives in the k8s output
|
|
8
|
+
* (chant #2930). This check runs them there: every ConfigMap data value that
|
|
9
|
+
* parses as a collector config (a `service.pipelines` map) goes through the
|
|
10
|
+
* otel lexicon's `validateCollectorConfig`.
|
|
11
|
+
*
|
|
12
|
+
* Findings keep the otel rule ids (OTEL101-OTEL106, OTEL112-OTEL117, and any config
|
|
13
|
+
* check the otel lexicon adds later), so `lint.rules` and suppressions name
|
|
14
|
+
* one id wherever the config lives. Each message names the ConfigMap's
|
|
15
|
+
* namespace, name and key. Needs only the k8s lexicon in the project.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
19
|
+
import { collectorConfigDiagnostics } from "@intentius/chant-lexicon-otel/lint/post-synth/otel-helpers";
|
|
20
|
+
|
|
21
|
+
export const wk8604: PostSynthCheck = {
|
|
22
|
+
id: "WK8604",
|
|
23
|
+
description:
|
|
24
|
+
"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.",
|
|
25
|
+
|
|
26
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
27
|
+
return collectorConfigDiagnostics(ctx, { configMapsOnly: true });
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WK8605: a collector config that reads the node, in a workload that
|
|
3
|
+
* doesn't give it the node name or the host mounts (chant #3103).
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, test } from "vitest";
|
|
6
|
+
import { dump } from "js-yaml";
|
|
7
|
+
import { expandComposite } from "@intentius/chant";
|
|
8
|
+
import type { Declarable } from "@intentius/chant/declarable";
|
|
9
|
+
import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
|
|
10
|
+
import { makePostSynthCtx } from "@intentius/chant-test-utils";
|
|
11
|
+
import { DebugExporter, NodeAgent, OtlpReceiver, Pipeline } from "@intentius/chant-lexicon-otel";
|
|
12
|
+
import { k8sSerializer } from "../../serializer";
|
|
13
|
+
import { OtelCollector } from "../../composites/otel-collector";
|
|
14
|
+
import { wk8605 } from "./wk8605";
|
|
15
|
+
|
|
16
|
+
function built(instances: Record<string, unknown>): PostSynthContext {
|
|
17
|
+
const entities = new Map<string, Declarable>();
|
|
18
|
+
for (const [name, instance] of Object.entries(instances)) {
|
|
19
|
+
for (const [k, v] of expandComposite(name, instance as never)) entities.set(k, v);
|
|
20
|
+
}
|
|
21
|
+
const out = k8sSerializer.serialize(entities);
|
|
22
|
+
return makePostSynthCtx("k8s", typeof out === "string" ? out : out.primary);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const yaml = (...docs: object[]) => makePostSynthCtx("k8s", docs.map((d) => dump(d, { lineWidth: -1 })).join("---\n"));
|
|
26
|
+
|
|
27
|
+
const NODE_CONFIG = `
|
|
28
|
+
receivers:
|
|
29
|
+
hostmetrics: { root_path: /hostfs, scrapers: { cpu: {} } }
|
|
30
|
+
filelog: { include: [/var/log/pods/*/*/*.log] }
|
|
31
|
+
processors:
|
|
32
|
+
k8sattributes: { filter: { node_from_env_var: K8S_NODE_NAME } }
|
|
33
|
+
exporters: { debug: {} }
|
|
34
|
+
service:
|
|
35
|
+
pipelines:
|
|
36
|
+
metrics: { receivers: [hostmetrics], processors: [k8sattributes], exporters: [debug] }
|
|
37
|
+
logs: { receivers: [filelog], processors: [k8sattributes], exporters: [debug] }
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
function daemonSet(pod: { env?: object[]; mounts?: object[]; volumes?: object[] }): object[] {
|
|
41
|
+
return [
|
|
42
|
+
{ apiVersion: "v1", kind: "ConfigMap", metadata: { name: "agent-config", namespace: "obs" }, data: { "config.yaml": NODE_CONFIG } },
|
|
43
|
+
{
|
|
44
|
+
apiVersion: "apps/v1",
|
|
45
|
+
kind: "DaemonSet",
|
|
46
|
+
metadata: { name: "agent", namespace: "obs" },
|
|
47
|
+
spec: {
|
|
48
|
+
selector: { matchLabels: { app: "agent" } },
|
|
49
|
+
template: {
|
|
50
|
+
metadata: { labels: { app: "agent" } },
|
|
51
|
+
spec: {
|
|
52
|
+
containers: [{
|
|
53
|
+
name: "otelcol",
|
|
54
|
+
image: "otel/opentelemetry-collector-contrib:0.130.0",
|
|
55
|
+
args: ["--config=/conf/config.yaml"],
|
|
56
|
+
...(pod.env ? { env: pod.env } : {}),
|
|
57
|
+
volumeMounts: [{ name: "conf", mountPath: "/conf" }, ...(pod.mounts ?? [])],
|
|
58
|
+
}],
|
|
59
|
+
volumes: [{ name: "conf", configMap: { name: "agent-config" } }, ...(pod.volumes ?? [])],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const NODE_ENV = { name: "K8S_NODE_NAME", valueFrom: { fieldRef: { fieldPath: "spec.nodeName" } } };
|
|
68
|
+
|
|
69
|
+
describe("WK8605: node-reading collector config without the node", () => {
|
|
70
|
+
const gateway = new DebugExporter({});
|
|
71
|
+
|
|
72
|
+
test("OtelCollector running NodeAgent passes: the composite adds what the config reads", () => {
|
|
73
|
+
const agent = NodeAgent({ exporters: [gateway], kubeletStats: true });
|
|
74
|
+
expect(wk8605.check(built({ agent: OtelCollector({ config: Object.values(agent.members) }) }))).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("a config that reads nothing from the node is not checked", () => {
|
|
78
|
+
const rx = new OtlpReceiver({ protocols: { grpc: { endpoint: "0.0.0.0:4317" } } });
|
|
79
|
+
const r = OtelCollector({ config: [new Pipeline({ signal: "traces", receivers: [rx], exporters: [gateway] })] });
|
|
80
|
+
expect(wk8605.check(built({ r }))).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("a hand-written DaemonSet without the variable or mounts is reported, naming each gap", () => {
|
|
84
|
+
const d = wk8605.check(yaml(...daemonSet({})));
|
|
85
|
+
expect(d).toHaveLength(1);
|
|
86
|
+
expect(d[0]).toMatchObject({ checkId: "WK8605", severity: "warning", entity: "agent" });
|
|
87
|
+
expect(d[0].message).toContain("DaemonSet obs/agent");
|
|
88
|
+
expect(d[0].message).toContain("no K8S_NODE_NAME variable (set it from spec.nodeName");
|
|
89
|
+
expect(d[0].message).toContain("hostmetrics reads host / at /hostfs");
|
|
90
|
+
expect(d[0].message).toContain("filelog reads host /var/log/pods at /var/log/pods");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("the variable from any source and covering hostPath mounts pass, including partial host root mounts", () => {
|
|
94
|
+
const d = wk8605.check(yaml(...daemonSet({
|
|
95
|
+
env: [{ name: "K8S_NODE_NAME", value: "fixed" }],
|
|
96
|
+
mounts: [
|
|
97
|
+
{ name: "proc", mountPath: "/hostfs/proc", readOnly: true },
|
|
98
|
+
{ name: "varlog", mountPath: "/var/log", readOnly: true },
|
|
99
|
+
],
|
|
100
|
+
volumes: [
|
|
101
|
+
{ name: "proc", hostPath: { path: "/proc" } },
|
|
102
|
+
{ name: "varlog", hostPath: { path: "/var/log" } },
|
|
103
|
+
],
|
|
104
|
+
})));
|
|
105
|
+
expect(d).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("a mount at the right path from the wrong host directory, or from a non-hostPath volume, doesn't count", () => {
|
|
109
|
+
const d = wk8605.check(yaml(...daemonSet({
|
|
110
|
+
env: [NODE_ENV],
|
|
111
|
+
mounts: [
|
|
112
|
+
{ name: "hostfs", mountPath: "/hostfs" },
|
|
113
|
+
{ name: "pods", mountPath: "/var/log/pods" },
|
|
114
|
+
],
|
|
115
|
+
volumes: [
|
|
116
|
+
{ name: "hostfs", emptyDir: {} },
|
|
117
|
+
{ name: "pods", hostPath: { path: "/var/lib/pods" } },
|
|
118
|
+
],
|
|
119
|
+
})));
|
|
120
|
+
expect(d).toHaveLength(1);
|
|
121
|
+
expect(d[0].message).toContain("hostmetrics reads host /");
|
|
122
|
+
expect(d[0].message).toContain("filelog reads host /var/log/pods");
|
|
123
|
+
expect(d[0].message).not.toContain("K8S_NODE_NAME");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("a sidecar's variable doesn't count for the collector container", () => {
|
|
127
|
+
const docs = daemonSet({}) as Array<Record<string, any>>;
|
|
128
|
+
docs[1].spec.template.spec.containers.push({ name: "sidecar", image: "busybox", env: [NODE_ENV] });
|
|
129
|
+
const d = wk8605.check(yaml(...docs));
|
|
130
|
+
expect(d[0].message).toContain("no K8S_NODE_NAME variable");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("defaults.daemonSet appends containers rather than replacing them, so the composite's additions stay", () => {
|
|
134
|
+
const agent = NodeAgent({ exporters: [gateway] });
|
|
135
|
+
const r = OtelCollector({
|
|
136
|
+
config: Object.values(agent.members),
|
|
137
|
+
defaults: { daemonSet: { spec: { template: { spec: { containers: [{ name: "sidecar", image: "busybox" }] } } } } },
|
|
138
|
+
});
|
|
139
|
+
expect(wk8605.check(built({ r }))).toEqual([]);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WK8605: a collector config reads the node, and its workload doesn't give it the node
|
|
3
|
+
*
|
|
4
|
+
* `k8sattributes` filtering to its node by `filter.node_from_env_var`, and
|
|
5
|
+
* `kubeletstats` addressing the kubelet by `${env:K8S_NODE_NAME}`, need that
|
|
6
|
+
* variable set in the pod; unset, the filter matches no pod and the kubelet
|
|
7
|
+
* address doesn't resolve. `hostmetrics` with `root_path` needs the host root
|
|
8
|
+
* mounted there, and `filelog` needs the directories it reads mounted from
|
|
9
|
+
* the host. None of this fails at startup: the collector runs and reports
|
|
10
|
+
* the container instead of the node, or nothing.
|
|
11
|
+
*
|
|
12
|
+
* What a config needs is worked out by `collectorNodeAccess`, the function
|
|
13
|
+
* `OtelCollector` uses to add it (chant #3103), so the composite's own
|
|
14
|
+
* output passes and this fires on hand-written workloads. Only the
|
|
15
|
+
* containers that pass `--config` count (every container when none does). A variable
|
|
16
|
+
* counts as set whatever its source; a mount counts when a hostPath volume
|
|
17
|
+
* covers the path. Whether the container may read root-owned log files is
|
|
18
|
+
* not checked, since that depends on the runtime. One build root at a time
|
|
19
|
+
* (chant #1939).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
|
|
23
|
+
import { docsToManifests, extractContainers, extractPodSpec, type K8sContainer, type K8sManifest } from "./k8s-helpers";
|
|
24
|
+
import { collectorPlacements, describePlacement } from "./otel-placement-helpers";
|
|
25
|
+
import { collectorNodeAccess, type NodeHostMount } from "../../composites/otel-collector-node";
|
|
26
|
+
|
|
27
|
+
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
28
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function within(path: string, dir: string): boolean {
|
|
32
|
+
const d = dir.replace(/\/+$/, "");
|
|
33
|
+
return d === "" || path === d || path.startsWith(`${d}/`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The containers that run a collector: those passing `--config`, or every
|
|
38
|
+
* container when none does. A sidecar's variables and mounts don't count.
|
|
39
|
+
*/
|
|
40
|
+
function collectorContainers(workload: K8sManifest): K8sContainer[] {
|
|
41
|
+
const all = extractContainers(workload);
|
|
42
|
+
const withConfig = all.filter((c) =>
|
|
43
|
+
[...(Array.isArray(c.command) ? c.command : []), ...(Array.isArray(c.args) ? c.args : [])].some(
|
|
44
|
+
(a) => typeof a === "string" && (a === "--config" || a.startsWith("--config=")),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
return withConfig.length > 0 ? withConfig : all;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Each container mount backed by a hostPath volume, as [host path, container path]. */
|
|
51
|
+
function hostMounts(workload: K8sManifest, containers: K8sContainer[]): Array<[string, string]> {
|
|
52
|
+
const pod = extractPodSpec(workload);
|
|
53
|
+
const hostPaths = new Map<string, string>();
|
|
54
|
+
for (const v of Array.isArray(pod?.volumes) ? pod.volumes : []) {
|
|
55
|
+
if (isRecord(v) && typeof v.name === "string" && isRecord(v.hostPath) && typeof v.hostPath.path === "string") {
|
|
56
|
+
hostPaths.set(v.name, v.hostPath.path);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const out: Array<[string, string]> = [];
|
|
60
|
+
for (const c of containers) {
|
|
61
|
+
for (const m of Array.isArray(c.volumeMounts) ? c.volumeMounts : []) {
|
|
62
|
+
if (!isRecord(m) || typeof m.name !== "string" || typeof m.mountPath !== "string") continue;
|
|
63
|
+
const host = hostPaths.get(m.name);
|
|
64
|
+
if (host !== undefined) out.push([host.replace(/\/+$/, "") || "/", m.mountPath.replace(/\/+$/, "") || "/"]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Whether some hostPath mount gives the container the host path a requirement names, at its path. */
|
|
71
|
+
function covered(need: NodeHostMount, mounts: Array<[string, string]>): boolean {
|
|
72
|
+
return mounts.some(([host, path]) => {
|
|
73
|
+
// hostmetrics takes the host root or parts of it anywhere at or under root_path.
|
|
74
|
+
if (need.partial && within(path, need.mountPath)) {
|
|
75
|
+
const rel = path.slice(need.mountPath.length);
|
|
76
|
+
return host === (rel || "/");
|
|
77
|
+
}
|
|
78
|
+
if (!within(need.mountPath, path)) return false;
|
|
79
|
+
const rel = need.mountPath.slice(path === "/" ? 0 : path.length);
|
|
80
|
+
const expected = `${host === "/" ? "" : host}${rel}` || "/";
|
|
81
|
+
return expected === need.hostPath;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function envNames(containers: K8sContainer[]): Set<string> {
|
|
86
|
+
const names = new Set<string>();
|
|
87
|
+
for (const c of containers) {
|
|
88
|
+
for (const e of Array.isArray(c.env) ? c.env : []) {
|
|
89
|
+
if (isRecord(e) && typeof e.name === "string") names.add(e.name);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return names;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const wk8605: PostSynthCheck = {
|
|
96
|
+
id: "WK8605",
|
|
97
|
+
description:
|
|
98
|
+
"OpenTelemetry Collector config reads the node (k8sattributes filtered to its node, kubeletstats, hostmetrics root_path, filelog) but its workload doesn't set the node name variable or mount the host paths. Sees one build root at a time (chant #1939).",
|
|
99
|
+
|
|
100
|
+
check(ctx: PostSynthContext): PostSynthDiagnostic[] {
|
|
101
|
+
const diagnostics: PostSynthDiagnostic[] = [];
|
|
102
|
+
for (const p of collectorPlacements(docsToManifests(ctx))) {
|
|
103
|
+
const need = collectorNodeAccess(p.config);
|
|
104
|
+
if (need.env.length === 0 && need.mounts.length === 0) continue;
|
|
105
|
+
|
|
106
|
+
const containers = collectorContainers(p.workload);
|
|
107
|
+
const env = envNames(containers);
|
|
108
|
+
const mounts = hostMounts(p.workload, containers);
|
|
109
|
+
const gaps: string[] = [];
|
|
110
|
+
for (const v of need.env) {
|
|
111
|
+
if (!env.has(v.name)) gaps.push(`no ${v.name} variable (set it from ${v.valueFrom.fieldRef.fieldPath} with the downward API)`);
|
|
112
|
+
}
|
|
113
|
+
for (const m of need.mounts) {
|
|
114
|
+
if (!covered(m, mounts)) gaps.push(`${m.component} reads host ${m.hostPath} at ${m.mountPath}, which no hostPath volume mounts`);
|
|
115
|
+
}
|
|
116
|
+
if (gaps.length === 0) continue;
|
|
117
|
+
|
|
118
|
+
diagnostics.push({
|
|
119
|
+
checkId: "WK8605",
|
|
120
|
+
severity: "warning",
|
|
121
|
+
message:
|
|
122
|
+
`${describePlacement(p)} runs a collector config that reads the node (ConfigMap ${p.configMap}, ${p.key}), but: ${gaps.join("; ")}. ` +
|
|
123
|
+
`Without them the collector reports on its own container, or nothing. OtelCollector adds these from the config; ` +
|
|
124
|
+
`in a hand-written workload, add them read-only.`,
|
|
125
|
+
entity: p.name,
|
|
126
|
+
lexicon: "k8s",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return diagnostics;
|
|
130
|
+
},
|
|
131
|
+
};
|
package/src/skills/chant-k8s.md
CHANGED
|
@@ -171,7 +171,7 @@ Composites are higher-level functions that produce multiple coordinated K8s reso
|
|
|
171
171
|
| Multi-host TLS Ingress (cert-manager) | **SecureIngress** | Ingress + optional Certificate |
|
|
172
172
|
| HPA metrics provider | **MetricsServer** | Deployment + Service + RBAC + APIService |
|
|
173
173
|
| CockroachDB cluster | **CockroachDbCluster** | StatefulSet + Services + PVCs + RBAC + optional CertificateRequests |
|
|
174
|
-
| OpenTelemetry agent on every node | **OtelCollector** | DaemonSet + node-local Service + RBAC + ConfigMap |
|
|
174
|
+
| OpenTelemetry agent on every node | **OtelCollector** | DaemonSet + node-local Service + RBAC + ConfigMap; a node-reading config (otel's `NodeAgent`) also gets the node name variable and read-only host mounts |
|
|
175
175
|
| OpenTelemetry gateway tier | **OtelCollectorGateway** | Deployment + ClusterIP and headless Services + PDB + ConfigMap; point agents at it with `gatewayExporter(gateway, { loadBalance: true })` |
|
|
176
176
|
|
|
177
177
|
### Decision Tree — AWS (EKS) Composites
|
package/src/spec/parse.test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
k8sShortName,
|
|
6
6
|
k8sServiceName,
|
|
7
7
|
specListMapKeyPairs,
|
|
8
|
+
parseK8sSwaggerTypes,
|
|
8
9
|
} from "./parse";
|
|
9
10
|
|
|
10
11
|
describe("gvkToTypeName", () => {
|
|
@@ -142,3 +143,120 @@ describe("specListMapKeyPairs", () => {
|
|
|
142
143
|
expect(specListMapKeyPairs(JSON.stringify({}))).toEqual([]);
|
|
143
144
|
});
|
|
144
145
|
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* chant #3093 — every object definition a resource reaches is typed, not
|
|
149
|
+
* only the well-known property types.
|
|
150
|
+
*/
|
|
151
|
+
describe("parseK8sSwaggerTypes", () => {
|
|
152
|
+
const ref = (key: string) => ({ $ref: `#/definitions/${key}` });
|
|
153
|
+
const gvk = (group: string, version: string, kind: string) => ({ "x-kubernetes-group-version-kind": [{ group, version, kind }] });
|
|
154
|
+
const spec = JSON.stringify({
|
|
155
|
+
definitions: {
|
|
156
|
+
"io.k8s.api.apps.v1.Deployment": {
|
|
157
|
+
...gvk("apps", "v1", "Deployment"),
|
|
158
|
+
properties: {
|
|
159
|
+
apiVersion: { type: "string" },
|
|
160
|
+
kind: { type: "string" },
|
|
161
|
+
metadata: ref("io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta"),
|
|
162
|
+
spec: ref("io.k8s.api.apps.v1.DeploymentSpec"),
|
|
163
|
+
status: ref("io.k8s.api.apps.v1.DeploymentStatus"),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
"io.k8s.api.apps.v1.DeploymentSpec": {
|
|
167
|
+
required: ["selector"],
|
|
168
|
+
properties: {
|
|
169
|
+
replicas: { type: "integer" },
|
|
170
|
+
selector: ref("io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector"),
|
|
171
|
+
strategy: ref("io.k8s.api.apps.v1.DeploymentStrategy"),
|
|
172
|
+
extra: ref("io.k8s.apimachinery.pkg.runtime.RawExtension"),
|
|
173
|
+
claims: { type: "array", items: ref("io.k8s.api.core.v1.ResourceClaim") },
|
|
174
|
+
subjects: { type: "array", items: ref("io.k8s.api.flowcontrol.v1.Subject") },
|
|
175
|
+
ports: { type: "array", items: ref("io.k8s.api.core.v1.EndpointPort") },
|
|
176
|
+
slicePorts: { type: "array", items: ref("io.k8s.api.discovery.v1.EndpointPort") },
|
|
177
|
+
schema: ref("io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps"),
|
|
178
|
+
templates: { type: "array", items: ref("io.k8s.api.core.v1.ConfigMap") },
|
|
179
|
+
cpu: ref("io.k8s.apimachinery.pkg.api.resource.Quantity"),
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
"io.k8s.api.apps.v1.DeploymentStatus": { properties: { replicas: { type: "integer" } } },
|
|
183
|
+
"io.k8s.api.apps.v1.DeploymentStrategy": { properties: { type: { type: "string" } } },
|
|
184
|
+
"io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": { properties: { name: { type: "string" } } },
|
|
185
|
+
"io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector": {
|
|
186
|
+
properties: { matchLabels: { type: "object", additionalProperties: { type: "string" } } },
|
|
187
|
+
},
|
|
188
|
+
"io.k8s.apimachinery.pkg.runtime.RawExtension": { type: "object", properties: { raw: { type: "string" } } },
|
|
189
|
+
// A resource kind elsewhere, so the core definition cannot take the bare name.
|
|
190
|
+
"io.k8s.api.resource.v1.ResourceClaim": { ...gvk("resource.k8s.io", "v1", "ResourceClaim"), properties: { metadata: {} } },
|
|
191
|
+
"io.k8s.api.core.v1.ResourceClaim": { properties: { name: { type: "string" } } },
|
|
192
|
+
// Clashes with the well-known rbac Subject.
|
|
193
|
+
"io.k8s.api.flowcontrol.v1.Subject": { properties: { kind: { type: "string" } } },
|
|
194
|
+
// Two groups want one name.
|
|
195
|
+
"io.k8s.api.core.v1.EndpointPort": { properties: { port: { type: "integer" } } },
|
|
196
|
+
"io.k8s.api.discovery.v1.EndpointPort": { properties: { port: { type: "integer" } } },
|
|
197
|
+
"io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps": {
|
|
198
|
+
properties: {
|
|
199
|
+
properties: { type: "object", additionalProperties: ref("io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps") },
|
|
200
|
+
items: ref("io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrArray"),
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
"io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrArray": {},
|
|
204
|
+
"io.k8s.api.core.v1.ConfigMap": {
|
|
205
|
+
...gvk("", "v1", "ConfigMap"),
|
|
206
|
+
required: ["metadata"],
|
|
207
|
+
properties: { kind: { type: "string" }, metadata: ref("io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta"), data: { type: "object", additionalProperties: { type: "string" } } },
|
|
208
|
+
},
|
|
209
|
+
"io.k8s.api.unrelated.v1.Unreached": { properties: { x: { type: "string" } } },
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
const parsed = parseK8sSwaggerTypes(spec);
|
|
213
|
+
const tsType = (props: Array<{ name: string; tsType: string }>, name: string) => props.find((p) => p.name === name)?.tsType;
|
|
214
|
+
const deployment = parsed.results.find((r) => r.resource.typeName === "K8s::Apps::Deployment")!;
|
|
215
|
+
const deploymentSpec = parsed.definitionTypes.find((d) => d.name === "DeploymentSpec")!;
|
|
216
|
+
|
|
217
|
+
test("a resource's spec is typed by its definition, not a Record", () => {
|
|
218
|
+
expect(tsType(deployment.resource.properties, "spec")).toBe("DeploymentSpec");
|
|
219
|
+
expect(deploymentSpec.defKey).toBe("io.k8s.api.apps.v1.DeploymentSpec");
|
|
220
|
+
expect(deploymentSpec.properties.find((p) => p.name === "selector")).toMatchObject({ tsType: "LabelSelector", required: true });
|
|
221
|
+
expect(tsType(deploymentSpec.properties, "replicas")).toBe("number");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("the well-known property types keep their names and stay classes, not interfaces", () => {
|
|
225
|
+
expect(tsType(deploymentSpec.properties, "strategy")).toBe("DeploymentStrategy");
|
|
226
|
+
expect(parsed.definitionTypes.map((d) => d.name)).not.toContain("DeploymentStrategy");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("a name taken by a resource kind or a well-known type is qualified by group, then by version", () => {
|
|
230
|
+
expect(tsType(deploymentSpec.properties, "claims")).toBe("CoreResourceClaim[]");
|
|
231
|
+
expect(tsType(deploymentSpec.properties, "subjects")).toBe("FlowcontrolSubject[]");
|
|
232
|
+
expect(tsType(deploymentSpec.properties, "ports")).toBe("CoreEndpointPort[]");
|
|
233
|
+
expect(tsType(deploymentSpec.properties, "slicePorts")).toBe("DiscoveryEndpointPort[]");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("a recursive definition refers to itself by name", () => {
|
|
237
|
+
const schema = parsed.definitionTypes.find((d) => d.name === "JSONSchemaProps")!;
|
|
238
|
+
expect(tsType(schema.properties, "properties")).toBe("Record<string, JSONSchemaProps>");
|
|
239
|
+
expect(tsType(schema.properties, "items")).toBe("any");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("RawExtension stays open; a Quantity takes a string or a number", () => {
|
|
243
|
+
expect(tsType(deploymentSpec.properties, "extra")).toBe("Record<string, any>");
|
|
244
|
+
expect(tsType(deploymentSpec.properties, "cpu")).toBe("string | number");
|
|
245
|
+
expect(parsed.definitionTypes.map((d) => d.name)).not.toContain("RawExtension");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("an embedded resource is typed inline with its class's props", () => {
|
|
249
|
+
expect(tsType(deploymentSpec.properties, "templates")).toBe("{ data?: Record<string, string>; metadata: ObjectMeta }[]");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test("status-only and unreachable definitions are not emitted", () => {
|
|
253
|
+
const names = parsed.definitionTypes.map((d) => d.name);
|
|
254
|
+
expect(names).not.toContain("DeploymentStatus");
|
|
255
|
+
expect(names).not.toContain("Unreached");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("definitions come out sorted by name", () => {
|
|
259
|
+
const names = parsed.definitionTypes.map((d) => d.name);
|
|
260
|
+
expect(names).toEqual([...names].sort());
|
|
261
|
+
});
|
|
262
|
+
});
|