@intentius/chant-lexicon-k8s 0.101.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 +19 -1
- package/dist/composites/otel-collector-agent.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-shape.d.ts.map +1 -1
- package/dist/composites/otel-collector.d.ts +9 -1
- 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/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 +6 -5
- 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.map +1 -1
- 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 +4 -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/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/catalog.ts +6 -0
- package/src/composites/gke-otel-collector.ts +6 -1
- package/src/composites/index.ts +1 -0
- package/src/composites/otel-collector-agent.ts +39 -2
- package/src/composites/otel-collector-node.test.ts +174 -0
- package/src/composites/otel-collector-node.ts +213 -0
- package/src/composites/otel-collector.ts +15 -1
- 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 +46 -4
- 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/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 +1 -0
- package/src/lint/post-synth/index.ts +2 -0
- package/src/lint/post-synth/post-synth.test.ts +3 -3
- 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
package/dist/variables.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS;IACpB,6BAA6B
|
|
1
|
+
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS;IACpB,6BAA6B;aAC7B,OAAO,EAAE,wBAAwB;IACjC,iCAAiC;aACjC,WAAW,EAAE,4BAA4B;IACzC,gCAAgC;aAChC,UAAU,EAAE,2BAA2B;IACvC,kCAAkC;aAClC,YAAY,EAAE,6BAA6B;IAC3C,gCAAgC;aAChC,SAAS,EAAE,2BAA2B;IACtC,mCAAmC;aACnC,YAAY,EAAE,8BAA8B;CACpC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB,iCAAiC;aACjC,WAAW,EAAE,4BAA4B;IACzC,gCAAgC;aAChC,WAAW,EAAE,2BAA2B;CAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-k8s",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.102.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",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"validate": "tsx src/validate-cli.ts",
|
|
70
70
|
"docs": "tsx src/codegen/docs-cli.ts",
|
|
71
71
|
"prepack": "npm run generate && npm run bundle && npm run validate && npm run build",
|
|
72
|
-
"build": "
|
|
72
|
+
"build": "../../scripts/tsc7.sh -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && find dist -type f \\( -name \"*.js\" -o -name \"*.js.map\" \\) -delete"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@intentius/chant-lexicon-otel": "*",
|
|
@@ -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.102.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.102.0",
|
|
90
90
|
"typescript": "^5.9.3"
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generated declarations check nested objects (chant #3093). Before,
|
|
3
|
+
* `Deployment.spec` was `Record<string, unknown>` and the property classes
|
|
4
|
+
* had no members, so a wrong type or an unknown key below a resource's top
|
|
5
|
+
* level type-checked.
|
|
6
|
+
*
|
|
7
|
+
* Compiled against `src/generated/index.d.ts`, the file the package ships as
|
|
8
|
+
* `@intentius/chant-lexicon-k8s/types` (which entry consumers get is #2224).
|
|
9
|
+
*/
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
|
+
import { copyFileSync, existsSync, mkdtempSync, rmSync, writeFileSync } from "fs";
|
|
12
|
+
import { tmpdir } from "os";
|
|
13
|
+
import { dirname, join } from "path";
|
|
14
|
+
import { fileURLToPath } from "url";
|
|
15
|
+
import * as ts from "typescript";
|
|
16
|
+
|
|
17
|
+
const pkgDir = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
18
|
+
const dts = join(pkgDir, "src", "generated", "index.d.ts");
|
|
19
|
+
|
|
20
|
+
/** Type errors in each probe, by probe name, compiled against the generated declarations. */
|
|
21
|
+
function typeErrors(probes: Record<string, string>): Record<string, string[]> {
|
|
22
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-k8s-dts-"));
|
|
23
|
+
try {
|
|
24
|
+
copyFileSync(dts, join(dir, "k8s.d.ts"));
|
|
25
|
+
const files = Object.entries(probes).map(([name, body]) => {
|
|
26
|
+
const file = join(dir, `${name}.ts`);
|
|
27
|
+
writeFileSync(file, body);
|
|
28
|
+
return file;
|
|
29
|
+
});
|
|
30
|
+
const program = ts.createProgram(files, {
|
|
31
|
+
strict: true,
|
|
32
|
+
noEmit: true,
|
|
33
|
+
target: ts.ScriptTarget.ES2022,
|
|
34
|
+
module: ts.ModuleKind.ESNext,
|
|
35
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
36
|
+
types: [],
|
|
37
|
+
});
|
|
38
|
+
const out: Record<string, string[]> = Object.fromEntries(Object.keys(probes).map((n) => [n, []]));
|
|
39
|
+
for (const d of ts.getPreEmitDiagnostics(program)) {
|
|
40
|
+
const name = d.file ? d.file.fileName.split("/").pop()!.replace(/(\.d)?\.ts$/, "") : "global";
|
|
41
|
+
(out[name] ??= []).push(`TS${d.code}: ${ts.flattenDiagnosticMessageText(d.messageText, " ")}`);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
} finally {
|
|
45
|
+
rmSync(dir, { recursive: true, force: true });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const IMPORT = `import { ConfigMap, Container, ControllerRevision, CustomResourceDefinition, Deployment, Probe, Role, StatefulSet } from "./k8s";\n`;
|
|
50
|
+
|
|
51
|
+
describe.skipIf(!existsSync(dts))("the generated declarations type nested objects", () => {
|
|
52
|
+
test("nested mistakes are errors, valid manifests are not", () => {
|
|
53
|
+
const errors = typeErrors({
|
|
54
|
+
replicasString: `${IMPORT}new Deployment({ spec: { replicas: "three", selector: {}, template: {} } });`,
|
|
55
|
+
unknownSpecKey: `${IMPORT}new Deployment({ spec: { bogusField: true, selector: {}, template: {} } });`,
|
|
56
|
+
unknownContainerKey: `${IMPORT}new Deployment({ spec: { selector: {}, template: { spec: { containers: [{ name: "a", imag: "b" }] } } } });`,
|
|
57
|
+
wrongProbeField: `${IMPORT}new Container({ name: "a", livenessProbe: new Probe({ httpGet: { path: "/", port: 80, verb: "GET" } }) });`,
|
|
58
|
+
missingSelector: `${IMPORT}new Deployment({ spec: { template: {} } });`,
|
|
59
|
+
valid: `${IMPORT}
|
|
60
|
+
export const deployment = new Deployment({
|
|
61
|
+
metadata: { name: "app", labels: { app: "app" } },
|
|
62
|
+
spec: {
|
|
63
|
+
replicas: 2,
|
|
64
|
+
selector: { matchLabels: { app: "app" } },
|
|
65
|
+
strategy: { type: "RollingUpdate", rollingUpdate: { maxSurge: "25%", maxUnavailable: 0 } },
|
|
66
|
+
template: {
|
|
67
|
+
metadata: { labels: { app: "app" } },
|
|
68
|
+
spec: {
|
|
69
|
+
securityContext: { runAsNonRoot: true, fsGroup: 1000 },
|
|
70
|
+
containers: [
|
|
71
|
+
new Container({
|
|
72
|
+
name: "app",
|
|
73
|
+
image: "app:1.0",
|
|
74
|
+
ports: [{ containerPort: 8080, name: "http" }],
|
|
75
|
+
resources: { limits: { cpu: 1, memory: "256Mi" }, requests: { cpu: "100m" } },
|
|
76
|
+
readinessProbe: new Probe({ httpGet: { path: "/readyz", port: "http" } }),
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
export const sts = new StatefulSet({
|
|
84
|
+
spec: {
|
|
85
|
+
serviceName: "db",
|
|
86
|
+
selector: { matchLabels: { app: "db" } },
|
|
87
|
+
template: { spec: { containers: [{ name: "db", image: "postgres:16" }] } },
|
|
88
|
+
volumeClaimTemplates: [{ metadata: { name: "data" }, spec: { accessModes: ["ReadWriteOnce"], resources: { requests: { storage: "1Gi" } } } }],
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
export const role = new Role({ rules: [{ apiGroups: [""], resources: ["pods"], verbs: ["get"] }] });
|
|
92
|
+
export const cm = new ConfigMap({ data: { key: "value" } });
|
|
93
|
+
// RawExtension stays open.
|
|
94
|
+
export const rev = new ControllerRevision({ revision: 1, data: { anything: { goes: true } } });
|
|
95
|
+
// JSONSchemaProps refers to itself.
|
|
96
|
+
export const crd = new CustomResourceDefinition({
|
|
97
|
+
spec: {
|
|
98
|
+
group: "example.com",
|
|
99
|
+
names: { kind: "Widget", plural: "widgets" },
|
|
100
|
+
scope: "Namespaced",
|
|
101
|
+
versions: [{
|
|
102
|
+
name: "v1", served: true, storage: true,
|
|
103
|
+
schema: { openAPIV3Schema: { type: "object", properties: { spec: { type: "object", properties: { size: { type: "integer" } } } } } },
|
|
104
|
+
}],
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
`,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(errors.global ?? []).toEqual([]);
|
|
111
|
+
expect(errors.valid).toEqual([]);
|
|
112
|
+
expect(errors.replicasString).toEqual(["TS2322: Type 'string' is not assignable to type 'number'."]);
|
|
113
|
+
expect(errors.unknownSpecKey.join("\n")).toMatch(/TS2353: .*'bogusField' does not exist in type 'DeploymentSpec'/);
|
|
114
|
+
expect(errors.unknownContainerKey.join("\n")).toMatch(/TS2561: .*'imag' does not exist in type 'Container'/);
|
|
115
|
+
expect(errors.wrongProbeField.join("\n")).toMatch(/'verb' does not exist in type 'HTTPGetAction'/);
|
|
116
|
+
expect(errors.missingSelector.join("\n")).toMatch(/TS2741: Property 'selector' is missing/);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* Kubernetes resource and property type classes.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { K8sParseResult } from "../spec/parse";
|
|
6
|
+
import type { K8sParseResult, ParsedDefinitionType } from "../spec/parse";
|
|
7
7
|
import { k8sShortName } from "../spec/parse";
|
|
8
8
|
import type { NamingStrategy } from "./naming";
|
|
9
9
|
import { propertyTypeName, extractDefName } from "./naming";
|
|
10
10
|
import {
|
|
11
11
|
writeResourceClass,
|
|
12
|
-
|
|
13
|
-
writeEnumType,
|
|
12
|
+
resolveConstructorType,
|
|
14
13
|
type DtsProperty,
|
|
15
14
|
type DtsAttribute,
|
|
16
15
|
} from "@intentius/chant/codegen/generate-typescript";
|
|
@@ -29,6 +28,7 @@ interface ResourceEntry {
|
|
|
29
28
|
export function generateTypeScriptDeclarations(
|
|
30
29
|
results: K8sParseResult[],
|
|
31
30
|
naming: NamingStrategy,
|
|
31
|
+
definitionTypes: ParsedDefinitionType[] = [],
|
|
32
32
|
): string {
|
|
33
33
|
const lines: string[] = [];
|
|
34
34
|
lines.push("// Code generated by chant k8s generate. DO NOT EDIT.");
|
|
@@ -88,10 +88,75 @@ export function generateTypeScriptDeclarations(
|
|
|
88
88
|
lines.push("");
|
|
89
89
|
lines.push("// --- Property type classes ---");
|
|
90
90
|
for (const pe of propertyEntries) {
|
|
91
|
-
|
|
91
|
+
writeMembersInterface(lines, pe.tsName, undefined, pe.properties, pe.remap);
|
|
92
|
+
lines.push(`export declare class ${pe.tsName} {`);
|
|
93
|
+
lines.push(` constructor(props: ${pe.tsName});`);
|
|
94
|
+
lines.push("}");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// chant #3093 — every other object definition a resource reaches. Declared
|
|
99
|
+
// as interfaces: nothing constructs them at runtime, an author writes them
|
|
100
|
+
// as object literals.
|
|
101
|
+
if (definitionTypes.length > 0) {
|
|
102
|
+
const classNames = new Set(resources.map((r) => r.tsName));
|
|
103
|
+
lines.push("");
|
|
104
|
+
lines.push("// --- Definition interfaces ---");
|
|
105
|
+
for (const dt of definitionTypes) {
|
|
106
|
+
if (classNames.has(dt.name)) {
|
|
107
|
+
throw new Error(`k8s codegen: definition ${dt.defKey} would be declared as ${dt.name}, which is already a class`);
|
|
108
|
+
}
|
|
109
|
+
const props: DtsProperty[] = dt.properties.map((p) => ({
|
|
110
|
+
name: p.name,
|
|
111
|
+
type: p.tsType,
|
|
112
|
+
required: p.required,
|
|
113
|
+
description: p.description,
|
|
114
|
+
}));
|
|
115
|
+
writeMembersInterface(lines, dt.name, dt.description, props, undefined);
|
|
92
116
|
}
|
|
93
117
|
}
|
|
94
118
|
|
|
95
119
|
lines.push("");
|
|
96
120
|
return lines.join("\n");
|
|
97
121
|
}
|
|
122
|
+
|
|
123
|
+
const IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Write the members of a property type or definition as an interface. For a
|
|
127
|
+
* property type the interface merges with its class, so `new Container({...})`
|
|
128
|
+
* and a `{...}` literal both check against the same members, and so does a
|
|
129
|
+
* field typed `Container`. A class with only a constructor has no members, and
|
|
130
|
+
* an empty instance type accepts any object (chant #3093).
|
|
131
|
+
*/
|
|
132
|
+
function writeMembersInterface(
|
|
133
|
+
lines: string[],
|
|
134
|
+
tsName: string,
|
|
135
|
+
description: string | undefined,
|
|
136
|
+
props: DtsProperty[],
|
|
137
|
+
remap: Map<string, string> | undefined,
|
|
138
|
+
): void {
|
|
139
|
+
lines.push("");
|
|
140
|
+
if (description) lines.push(`/** ${jsdoc(description)} */`);
|
|
141
|
+
if (props.length === 0) {
|
|
142
|
+
lines.push(`export interface ${tsName} {}`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// Required first, then optional, each alphabetical — the constructor order.
|
|
146
|
+
const sorted = [...props].sort((a, b) => {
|
|
147
|
+
if (a.required !== b.required) return a.required ? -1 : 1;
|
|
148
|
+
return a.name.localeCompare(b.name);
|
|
149
|
+
});
|
|
150
|
+
lines.push(`export interface ${tsName} {`);
|
|
151
|
+
for (const p of sorted) {
|
|
152
|
+
if (p.description) lines.push(` /** ${jsdoc(p.description)} */`);
|
|
153
|
+
const key = IDENT.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
154
|
+
lines.push(` ${key}${p.required ? "" : "?"}: ${resolveConstructorType(p.type, remap)};`);
|
|
155
|
+
}
|
|
156
|
+
lines.push("}");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A description made safe for a one-line JSDoc comment. */
|
|
160
|
+
function jsdoc(text: string): string {
|
|
161
|
+
return text.replace(/\*\//g, "*\\/");
|
|
162
|
+
}
|
package/src/codegen/generate.ts
CHANGED
|
@@ -12,7 +12,13 @@ import {
|
|
|
12
12
|
type GeneratePipelineConfig,
|
|
13
13
|
} from "@intentius/chant/codegen/generate";
|
|
14
14
|
import { fetchSchemas } from "../spec/fetch";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
parseK8sSwaggerTypes,
|
|
17
|
+
specListMapKeyPairs,
|
|
18
|
+
k8sShortName,
|
|
19
|
+
type K8sParseResult,
|
|
20
|
+
type ParsedDefinitionType,
|
|
21
|
+
} from "../spec/parse";
|
|
16
22
|
import { loadMultipleCRDs } from "../crd/loader";
|
|
17
23
|
import { CRD_SOURCES } from "../crd/crd-sources";
|
|
18
24
|
import { NamingStrategy, propertyTypeName, extractDefName } from "./naming";
|
|
@@ -42,6 +48,8 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
42
48
|
// chant #1441 — read off the raw document in `parseSchema`, since the
|
|
43
49
|
// result set covers only the definitions chant emits types for.
|
|
44
50
|
let specPairs: Array<[string, string[]]> = [];
|
|
51
|
+
// chant #3093 — the declaration-only interfaces, which only the `.d.ts` emits.
|
|
52
|
+
let definitionTypes: ParsedDefinitionType[] = [];
|
|
45
53
|
|
|
46
54
|
const config: GeneratePipelineConfig<K8sParseResult> = {
|
|
47
55
|
fetchSchemas: async (fetchOpts) => {
|
|
@@ -49,10 +57,11 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
49
57
|
},
|
|
50
58
|
|
|
51
59
|
parseSchema: (_typeName, data) => {
|
|
52
|
-
// The K8s schema is a single document —
|
|
60
|
+
// The K8s schema is a single document — parseK8sSwaggerTypes returns multiple results.
|
|
53
61
|
// The pipeline calls this once per schema entry. We return the first result
|
|
54
62
|
// and use augmentResults to inject the rest.
|
|
55
|
-
const results =
|
|
63
|
+
const { results, definitionTypes: defs } = parseK8sSwaggerTypes(data);
|
|
64
|
+
definitionTypes = defs;
|
|
56
65
|
specPairs = specListMapKeyPairs(data);
|
|
57
66
|
if (results.length === 0) return null;
|
|
58
67
|
// Return the first result; stash the rest for augmentResults
|
|
@@ -71,10 +80,10 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
71
80
|
try {
|
|
72
81
|
const parsed = await loadMultipleCRDs([source]);
|
|
73
82
|
crdResults.push(...parsed);
|
|
74
|
-
log(`Loaded ${parsed.length} CRD type(s) from ${source.url ?? source.path ?? "cluster"}`);
|
|
83
|
+
log(`Loaded ${parsed.length} CRD type(s) from ${source.url ?? source.path ?? source.chart ?? "cluster"}`);
|
|
75
84
|
} catch (err) {
|
|
76
85
|
const msg = err instanceof Error ? err.message : String(err);
|
|
77
|
-
warnings.push({ file: source.url ?? source.path ?? "cluster", error: msg });
|
|
86
|
+
warnings.push({ file: source.url ?? source.path ?? source.chart ?? "cluster", error: msg });
|
|
78
87
|
log(`Warning: failed to load CRD: ${msg}`);
|
|
79
88
|
}
|
|
80
89
|
}
|
|
@@ -98,7 +107,7 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
98
107
|
},
|
|
99
108
|
|
|
100
109
|
generateTypes: (results, naming) => {
|
|
101
|
-
return generateTypeScriptDeclarations(results, naming as NamingStrategy);
|
|
110
|
+
return generateTypeScriptDeclarations(results, naming as NamingStrategy, definitionTypes);
|
|
102
111
|
},
|
|
103
112
|
|
|
104
113
|
generateRuntimeIndex: (results, naming) => {
|
|
@@ -2953,6 +2953,12 @@ export const compositeCatalog: CompositeEntry[] = [
|
|
|
2953
2953
|
"required": false,
|
|
2954
2954
|
"description": "Additional labels."
|
|
2955
2955
|
},
|
|
2956
|
+
{
|
|
2957
|
+
"name": "logAccess",
|
|
2958
|
+
"type": "CollectorLogAccess",
|
|
2959
|
+
"required": false,
|
|
2960
|
+
"description": "How a config with a `filelog` receiver reads the node's container logs, which are root's."
|
|
2961
|
+
},
|
|
2956
2962
|
{
|
|
2957
2963
|
"name": "cpuRequest",
|
|
2958
2964
|
"type": "string",
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
} from "@intentius/chant-lexicon-otel";
|
|
22
22
|
import { collectorAgentResources, type CollectorAgentResources } from "./otel-collector-agent";
|
|
23
23
|
import { agentClusterRules } from "./otel-collector-rbac";
|
|
24
|
+
import { collectorNodeAccess } from "./otel-collector-node";
|
|
24
25
|
|
|
25
26
|
export interface GkeOtelCollectorProps {
|
|
26
27
|
/** GKE cluster name. */
|
|
@@ -121,6 +122,7 @@ export const GkeOtelCollector = Composite((props: GkeOtelCollectorProps) => {
|
|
|
121
122
|
new Pipeline({ signal: "traces", receivers: [otlp], processors: [batch, resourceDetection], exporters: [googleCloud] }),
|
|
122
123
|
];
|
|
123
124
|
const otelConfig = collectorYaml(entities);
|
|
125
|
+
const built = buildCollectorConfig(entities).config;
|
|
124
126
|
|
|
125
127
|
// The DaemonSet, RBAC and ConfigMap are the ones OtelCollector builds too.
|
|
126
128
|
return collectorAgentResources({
|
|
@@ -133,7 +135,10 @@ export const GkeOtelCollector = Composite((props: GkeOtelCollectorProps) => {
|
|
|
133
135
|
configDir: "/etc/otel",
|
|
134
136
|
// The ClusterRole OtelCollector shares: k8sattributes' rules, and none
|
|
135
137
|
// for receivers, since the config's only receiver is otlp (#2923).
|
|
136
|
-
clusterRules: agentClusterRules(
|
|
138
|
+
clusterRules: agentClusterRules(built),
|
|
139
|
+
// Derived like OtelCollector's (#3103). The config reads nothing from the
|
|
140
|
+
// node, so this adds no variable or mount and the output is unchanged.
|
|
141
|
+
nodeAccess: collectorNodeAccess(built, "/etc/otel"),
|
|
137
142
|
ports: [
|
|
138
143
|
{ containerPort: 4317, name: "otlp-grpc" },
|
|
139
144
|
{ containerPort: 4318, name: "otlp-http" },
|
package/src/composites/index.ts
CHANGED
|
@@ -67,6 +67,7 @@ export { GkeFluentBitAgent } from "./gke-fluent-bit-agent";
|
|
|
67
67
|
export type { GkeFluentBitAgentProps, GkeFluentBitAgentResult } from "./gke-fluent-bit-agent";
|
|
68
68
|
export { OtelCollector } from "./otel-collector";
|
|
69
69
|
export type { OtelCollectorProps, OtelCollectorResult } from "./otel-collector";
|
|
70
|
+
export type { CollectorLogAccess } from "./otel-collector-agent";
|
|
70
71
|
export { OtelCollectorGateway, gatewayExporter } from "./otel-collector-gateway";
|
|
71
72
|
export type {
|
|
72
73
|
OtelCollectorGatewayProps,
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
import { mergeDefaults } from "@intentius/chant";
|
|
18
18
|
import { DaemonSet, ServiceAccount, ClusterRole, ClusterRoleBinding, ConfigMap } from "../generated";
|
|
19
19
|
import type { CollectorPolicyRule } from "./otel-collector-rbac";
|
|
20
|
+
import { nodeVolumeMounts, nodeVolumes, type CollectorNodeAccess } from "./otel-collector-node";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How a collector that reads the kubelet's container logs gets past their
|
|
24
|
+
* owner. The files are root's, readable by group root (containerd writes
|
|
25
|
+
* them mode 0640), so `group` keeps user 10001 and adds the pod to group 0
|
|
26
|
+
* with `supplementalGroups`. `root` runs the container as user 0 instead,
|
|
27
|
+
* for a runtime that writes the logs readable by their owner only.
|
|
28
|
+
*/
|
|
29
|
+
export type CollectorLogAccess = "group" | "root";
|
|
20
30
|
|
|
21
31
|
export interface CollectorAgentOptions {
|
|
22
32
|
name: string;
|
|
@@ -45,6 +55,10 @@ export interface CollectorAgentOptions {
|
|
|
45
55
|
workloadAnnotations?: Record<string, string>;
|
|
46
56
|
/** Annotations on the ConfigMap. */
|
|
47
57
|
configMapAnnotations?: Record<string, string>;
|
|
58
|
+
/** What the config reads from the node, from `collectorNodeAccess`: the node name variables and host mounts. */
|
|
59
|
+
nodeAccess?: CollectorNodeAccess;
|
|
60
|
+
/** How a config that reads container logs gets read access to them (default `group`). */
|
|
61
|
+
logAccess?: CollectorLogAccess;
|
|
48
62
|
defaults?: {
|
|
49
63
|
daemonSet?: Partial<Record<string, unknown>>;
|
|
50
64
|
serviceAccount?: Partial<Record<string, unknown>>;
|
|
@@ -69,7 +83,15 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
|
|
|
69
83
|
const bindingName = `${name}-binding`;
|
|
70
84
|
const configMapName = `${name}-config`;
|
|
71
85
|
|
|
72
|
-
const
|
|
86
|
+
const access = opts.nodeAccess;
|
|
87
|
+
const asRoot = access?.readsLogs === true && opts.logAccess === "root";
|
|
88
|
+
const baseContainer = collectorContainer({
|
|
89
|
+
...opts,
|
|
90
|
+
env: access?.env,
|
|
91
|
+
extraVolumeMounts: access ? nodeVolumeMounts(access.mounts) : undefined,
|
|
92
|
+
});
|
|
93
|
+
const container = asRoot ? runAsRoot(baseContainer) : baseContainer;
|
|
94
|
+
const podSecurity = access?.readsLogs && !asRoot ? { securityContext: { supplementalGroups: [0] } } : {};
|
|
73
95
|
|
|
74
96
|
const daemonSet = new DaemonSet(mergeDefaults({
|
|
75
97
|
metadata: {
|
|
@@ -87,8 +109,10 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
|
|
|
87
109
|
containers: [container],
|
|
88
110
|
volumes: [
|
|
89
111
|
{ name: "config", configMap: { name: configMapName } },
|
|
112
|
+
...(access ? nodeVolumes(access.mounts) : []),
|
|
90
113
|
],
|
|
91
114
|
tolerations: [{ operator: "Exists" }],
|
|
115
|
+
...podSecurity,
|
|
92
116
|
},
|
|
93
117
|
},
|
|
94
118
|
},
|
|
@@ -139,7 +163,12 @@ export function collectorAgentResources(opts: CollectorAgentOptions): CollectorA
|
|
|
139
163
|
export type CollectorContainerOptions = Pick<
|
|
140
164
|
CollectorAgentOptions,
|
|
141
165
|
"name" | "image" | "configDir" | "ports" | "cpuRequest" | "memoryRequest" | "cpuLimit" | "memoryLimit" | "containerExtra"
|
|
142
|
-
|
|
166
|
+
> & {
|
|
167
|
+
/** Environment variables, such as the node name from the downward API. Left out when empty. */
|
|
168
|
+
env?: Array<Record<string, unknown>>;
|
|
169
|
+
/** Mounts after the config mount, such as read-only host directories. */
|
|
170
|
+
extraVolumeMounts?: Array<Record<string, unknown>>;
|
|
171
|
+
};
|
|
143
172
|
|
|
144
173
|
/**
|
|
145
174
|
* The collector container: the image, the config file argument, the ports,
|
|
@@ -152,6 +181,7 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
|
|
|
152
181
|
name: opts.name,
|
|
153
182
|
image: opts.image,
|
|
154
183
|
args: [`--config=${opts.configDir}/config.yaml`],
|
|
184
|
+
...(opts.env?.length ? { env: opts.env } : {}),
|
|
155
185
|
ports: opts.ports,
|
|
156
186
|
resources: {
|
|
157
187
|
requests: { cpu: opts.cpuRequest, memory: opts.memoryRequest },
|
|
@@ -159,6 +189,7 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
|
|
|
159
189
|
},
|
|
160
190
|
volumeMounts: [
|
|
161
191
|
{ name: "config", mountPath: opts.configDir, readOnly: true },
|
|
192
|
+
...(opts.extraVolumeMounts ?? []),
|
|
162
193
|
],
|
|
163
194
|
securityContext: {
|
|
164
195
|
runAsNonRoot: true,
|
|
@@ -170,6 +201,12 @@ export function collectorContainer(opts: CollectorContainerOptions): Record<stri
|
|
|
170
201
|
};
|
|
171
202
|
}
|
|
172
203
|
|
|
204
|
+
/** The container run as user 0, for `logAccess: "root"`; the rest of its security context is kept. */
|
|
205
|
+
function runAsRoot(container: Record<string, unknown>): Record<string, unknown> {
|
|
206
|
+
const sc = (container.securityContext ?? {}) as Record<string, unknown>;
|
|
207
|
+
return { ...container, securityContext: { ...sc, runAsNonRoot: false, runAsUser: 0 } };
|
|
208
|
+
}
|
|
209
|
+
|
|
173
210
|
/** The ConfigMap holding the rendered collector config under `config.yaml`. */
|
|
174
211
|
export function collectorConfigMap(
|
|
175
212
|
opts: Pick<CollectorAgentOptions, "namespace" | "commonLabels" | "configYaml"> & {
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
DebugExporter,
|
|
4
|
+
FileLogReceiver,
|
|
5
|
+
HostMetricsReceiver,
|
|
6
|
+
NodeAgent,
|
|
7
|
+
OtlpExporter,
|
|
8
|
+
OtlpReceiver,
|
|
9
|
+
Pipeline,
|
|
10
|
+
} from "@intentius/chant-lexicon-otel";
|
|
11
|
+
import { collectorNodeAccess, fixedDirectory } from "./otel-collector-node";
|
|
12
|
+
import { OtelCollector } from "./otel-collector";
|
|
13
|
+
import { GkeOtelCollector } from "./gke-otel-collector";
|
|
14
|
+
|
|
15
|
+
const NODE_NAME = { name: "K8S_NODE_NAME", valueFrom: { fieldRef: { fieldPath: "spec.nodeName" } } };
|
|
16
|
+
|
|
17
|
+
/** A config whose pipelines run the given receivers and processors. */
|
|
18
|
+
function cfg(receivers: Record<string, unknown>, processors: Record<string, unknown> = {}) {
|
|
19
|
+
return {
|
|
20
|
+
receivers,
|
|
21
|
+
processors,
|
|
22
|
+
service: { pipelines: { logs: { receivers: Object.keys(receivers), processors: Object.keys(processors), exporters: ["debug"] } } },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Props = { props: Record<string, any> };
|
|
27
|
+
const podSpec = (r: { daemonSet: unknown }) => (r.daemonSet as Props).props.spec.template.spec;
|
|
28
|
+
const containerOf = (r: { daemonSet: unknown }) => podSpec(r).containers[0];
|
|
29
|
+
|
|
30
|
+
describe("fixedDirectory", () => {
|
|
31
|
+
test.each([
|
|
32
|
+
["/var/log/pods/*/*/*.log", "/var/log/pods"],
|
|
33
|
+
["/var/log/containers/*.log", "/var/log/containers"],
|
|
34
|
+
["/var/log/syslog", "/var/log"],
|
|
35
|
+
["/var/log/{a,b}/x.log", "/var/log"],
|
|
36
|
+
["/*.log", undefined],
|
|
37
|
+
["logs/*.log", undefined],
|
|
38
|
+
])("%s gives %s", (pattern, dir) => {
|
|
39
|
+
expect(fixedDirectory(pattern)).toBe(dir);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("collectorNodeAccess", () => {
|
|
44
|
+
test("a config that reads nothing from the node needs nothing", () => {
|
|
45
|
+
expect(collectorNodeAccess(cfg({ otlp: {} }, { batch: {}, k8sattributes: {} }))).toEqual({ env: [], mounts: [], readsLogs: false });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("k8sattributes filtering by node gets its variable from spec.nodeName", () => {
|
|
49
|
+
const access = collectorNodeAccess(cfg({ otlp: {} }, { "k8sattributes/node": { filter: { node_from_env_var: "KUBE_NODE_NAME" } } }));
|
|
50
|
+
expect(access.env).toEqual([{ name: "KUBE_NODE_NAME", valueFrom: { fieldRef: { fieldPath: "spec.nodeName" } } }]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("kubeletstats: node and a NODE_NAME endpoint get the node name, a NODE_IP endpoint the host IP", () => {
|
|
54
|
+
expect(collectorNodeAccess(cfg({ kubeletstats: { endpoint: "https://${env:K8S_NODE_NAME}:10250", node: "${env:K8S_NODE_NAME}" } })).env).toEqual([NODE_NAME]);
|
|
55
|
+
expect(collectorNodeAccess(cfg({ kubeletstats: { endpoint: "https://${env:K8S_NODE_IP}:10250" } })).env).toEqual([
|
|
56
|
+
{ name: "K8S_NODE_IP", valueFrom: { fieldRef: { fieldPath: "status.hostIP" } } },
|
|
57
|
+
]);
|
|
58
|
+
// A variable whose meaning can't be told from its name is the caller's to set.
|
|
59
|
+
expect(collectorNodeAccess(cfg({ kubeletstats: { endpoint: "${env:KUBELET}:10250" } })).env).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("hostmetrics with root_path mounts the host root there; without it, nothing", () => {
|
|
63
|
+
expect(collectorNodeAccess(cfg({ hostmetrics: { root_path: "/hostfs/" } })).mounts).toEqual([
|
|
64
|
+
{ name: "hostfs", hostPath: "/", mountPath: "/hostfs", component: "hostmetrics", partial: true, mountPropagation: "HostToContainer" },
|
|
65
|
+
]);
|
|
66
|
+
expect(collectorNodeAccess(cfg({ hostmetrics: { scrapers: { cpu: {} } } })).mounts).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("filelog mounts the outermost fixed directory of its patterns, and /var/log/pods behind /var/log/containers", () => {
|
|
70
|
+
const access = collectorNodeAccess(cfg({
|
|
71
|
+
filelog: { include: ["/var/log/pods/*/*/*.log", "/var/log/pods/x/*.log"] },
|
|
72
|
+
"filelog/symlinks": { include: ["/var/log/containers/*.log"] },
|
|
73
|
+
}));
|
|
74
|
+
expect(access.mounts.map((m) => [m.name, m.hostPath, m.mountPath])).toEqual([
|
|
75
|
+
["host-var-log-pods", "/var/log/pods", "/var/log/pods"],
|
|
76
|
+
["host-var-log-containers", "/var/log/containers", "/var/log/containers"],
|
|
77
|
+
]);
|
|
78
|
+
expect(access.readsLogs).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("a log directory covering the config directory, or under the host root mount, is not mounted", () => {
|
|
82
|
+
expect(collectorNodeAccess(cfg({ filelog: { include: ["/etc/**/*.log"] } })).mounts).toEqual([]);
|
|
83
|
+
const access = collectorNodeAccess(cfg({ hostmetrics: { root_path: "/hostfs" }, filelog: { include: ["/hostfs/var/log/*.log"] } }));
|
|
84
|
+
expect(access.mounts.map((m) => m.name)).toEqual(["hostfs"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a component no pipeline runs needs nothing", () => {
|
|
88
|
+
const access = collectorNodeAccess({
|
|
89
|
+
receivers: { otlp: {}, filelog: { include: ["/var/log/pods/*.log"] } },
|
|
90
|
+
service: { pipelines: { logs: { receivers: ["otlp"], exporters: ["debug"] } } },
|
|
91
|
+
});
|
|
92
|
+
expect(access.mounts).toEqual([]);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("OtelCollector running NodeAgent", () => {
|
|
97
|
+
const gateway = new OtlpExporter({ name: "gateway", endpoint: "otel-gateway.observability.svc:4317", tls: { insecure: true } });
|
|
98
|
+
const agent = (props: Parameters<typeof NodeAgent>[0]) => Object.values(NodeAgent(props).members);
|
|
99
|
+
|
|
100
|
+
test("gets the node name, read-only host mounts, group access to the logs and nodes/stats", () => {
|
|
101
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway], kubeletStats: true }) });
|
|
102
|
+
const c = containerOf(r);
|
|
103
|
+
expect(c.env).toEqual([NODE_NAME]);
|
|
104
|
+
expect(c.volumeMounts).toEqual([
|
|
105
|
+
{ name: "config", mountPath: "/etc/otel", readOnly: true },
|
|
106
|
+
{ name: "hostfs", mountPath: "/hostfs", readOnly: true, mountPropagation: "HostToContainer" },
|
|
107
|
+
{ name: "host-var-log-pods", mountPath: "/var/log/pods", readOnly: true },
|
|
108
|
+
]);
|
|
109
|
+
expect(c.securityContext).toMatchObject({ runAsNonRoot: true, runAsUser: 10001 });
|
|
110
|
+
const pod = podSpec(r);
|
|
111
|
+
expect(pod.volumes).toEqual([
|
|
112
|
+
{ name: "config", configMap: { name: "otel-collector-config" } },
|
|
113
|
+
{ name: "hostfs", hostPath: { path: "/" } },
|
|
114
|
+
{ name: "host-var-log-pods", hostPath: { path: "/var/log/pods" } },
|
|
115
|
+
]);
|
|
116
|
+
expect(pod.securityContext).toEqual({ supplementalGroups: [0] });
|
|
117
|
+
const rules = (r.clusterRole as unknown as Props).props.rules;
|
|
118
|
+
expect(rules).toContainEqual({ apiGroups: [""], resources: ["nodes/stats"], verbs: ["get"] });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("logAccess root runs the container as user 0 instead of adding group 0", () => {
|
|
122
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway] }), logAccess: "root" });
|
|
123
|
+
expect(containerOf(r).securityContext).toMatchObject({ runAsNonRoot: false, runAsUser: 0, readOnlyRootFilesystem: true, allowPrivilegeEscalation: false });
|
|
124
|
+
expect(podSpec(r).securityContext).toBeUndefined();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("without logs or host metrics, only the node name is added", () => {
|
|
128
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway], hostMetrics: false, containerLogs: false }) });
|
|
129
|
+
expect(containerOf(r).env).toEqual([NODE_NAME]);
|
|
130
|
+
expect(containerOf(r).volumeMounts).toHaveLength(1);
|
|
131
|
+
expect(podSpec(r).securityContext).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("a custom nodeNameEnv is the variable set", () => {
|
|
135
|
+
const r = OtelCollector({ config: agent({ exporters: [gateway], nodeNameEnv: "MY_NODE", kubeletStats: true }) });
|
|
136
|
+
expect(containerOf(r).env).toEqual([{ name: "MY_NODE", valueFrom: { fieldRef: { fieldPath: "spec.nodeName" } } }]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("a hand-declared filelog and hostmetrics config is wired the same way", () => {
|
|
140
|
+
const logs = new FileLogReceiver({ include: ["/var/log/pods/*/*/*.log"] });
|
|
141
|
+
const host = new HostMetricsReceiver({ root_path: "/hostfs", scrapers: { cpu: {} } });
|
|
142
|
+
const debug = new DebugExporter({});
|
|
143
|
+
const r = OtelCollector({
|
|
144
|
+
config: [
|
|
145
|
+
new Pipeline({ signal: "logs", receivers: [logs], exporters: [debug] }),
|
|
146
|
+
new Pipeline({ signal: "metrics", receivers: [host], exporters: [debug] }),
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
150
|
+
expect(podSpec(r).volumes.map((v: { name: string }) => v.name)).toEqual(["config", "hostfs", "host-var-log-pods"]);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("configs that don't read the node keep their output", () => {
|
|
155
|
+
test("OtelCollector's default config adds no env, volume or pod security context", () => {
|
|
156
|
+
const r = OtelCollector({});
|
|
157
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
158
|
+
expect(containerOf(r).volumeMounts).toEqual([{ name: "config", mountPath: "/etc/otel", readOnly: true }]);
|
|
159
|
+
expect(Object.keys(podSpec(r))).toEqual(["serviceAccountName", "containers", "volumes", "tolerations"]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("an OTLP-only full config adds nothing either", () => {
|
|
163
|
+
const rx = new OtlpReceiver({ protocols: { grpc: { endpoint: "0.0.0.0:4317" } } });
|
|
164
|
+
const r = OtelCollector({ config: [new Pipeline({ signal: "traces", receivers: [rx], exporters: [new DebugExporter({})] })] });
|
|
165
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
166
|
+
expect(podSpec(r).volumes).toHaveLength(1);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("GkeOtelCollector, whose config is OTLP only, adds nothing", () => {
|
|
170
|
+
const r = GkeOtelCollector({ clusterName: "c", projectId: "p" });
|
|
171
|
+
expect(containerOf(r).env).toBeUndefined();
|
|
172
|
+
expect(Object.keys(podSpec(r))).toEqual(["serviceAccountName", "containers", "volumes", "tolerations"]);
|
|
173
|
+
});
|
|
174
|
+
});
|