@intentius/chant-lexicon-k8s 0.101.0 → 0.104.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 +26 -0
- 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/components/kubectl-apply.d.ts +4 -1
- package/dist/components/kubectl-apply.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-rbac.d.ts.map +1 -1
- package/dist/composites/otel-collector-shape.d.ts +3 -1
- 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 +764 -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 +8 -7
- 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/wk8604.d.ts +3 -2
- package/dist/lint/post-synth/wk8604.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 +194 -17
- package/dist/okf/index.md +5 -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/GrafanaLibraryPanel.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/wk8602.ts +2 -2
- package/dist/rules/wk8604.ts +3 -2
- package/dist/rules/wk8605.ts +131 -0
- package/dist/serializer.d.ts +0 -3
- package/dist/serializer.d.ts.map +1 -1
- 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/telemetry-release.d.ts +15 -0
- package/dist/telemetry-release.d.ts.map +1 -0
- package/dist/types/index.d.ts +5373 -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-crd-sources.test.ts +49 -0
- package/src/codegen/generate-typescript.ts +69 -4
- package/src/codegen/generate.ts +66 -18
- package/src/components/kubectl-apply.test.ts +87 -0
- package/src/components/kubectl-apply.ts +17 -1
- 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-gateway.test.ts +24 -1
- package/src/composites/otel-collector-gateway.ts +1 -1
- package/src/composites/otel-collector-node.test.ts +193 -0
- package/src/composites/otel-collector-node.ts +211 -0
- package/src/composites/otel-collector-rbac.test.ts +11 -0
- package/src/composites/otel-collector-rbac.ts +6 -4
- package/src/composites/otel-collector-shape.ts +9 -8
- package/src/composites/otel-collector.ts +16 -2
- package/src/crd/crd-sources.ts +28 -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 +5373 -972
- package/src/generated/index.ts +35 -0
- package/src/generated/lexicon-k8s.json +194 -17
- package/src/generated/operations.json +64 -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/otel-placement.test.ts +14 -0
- package/src/lint/post-synth/post-synth.test.ts +3 -3
- package/src/lint/post-synth/wk8602.ts +2 -2
- package/src/lint/post-synth/wk8604.ts +3 -2
- package/src/lint/post-synth/wk8605.test.ts +153 -0
- package/src/lint/post-synth/wk8605.ts +131 -0
- package/src/serializer-telemetry.test.ts +146 -0
- package/src/serializer.ts +75 -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/src/telemetry-build.test.ts +79 -0
- package/src/telemetry-release.ts +93 -0
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.104.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.104.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.104.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
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CRD source that fails to load fails generation, naming the source (#3310).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { loadCrdSources } from "./generate";
|
|
7
|
+
import type { CRDSource } from "../crd/types";
|
|
8
|
+
import type { K8sParseResult } from "../spec/parse";
|
|
9
|
+
|
|
10
|
+
const good: CRDSource = { type: "url", url: "https://example.test/good.yaml" };
|
|
11
|
+
const down: CRDSource = { type: "helm", chart: "oci://registry.example.test/charts/operator", version: "1.0.0" };
|
|
12
|
+
const moved: CRDSource = { type: "url", url: "https://example.test/moved.yaml" };
|
|
13
|
+
|
|
14
|
+
const fakeResult = { resource: { typeName: "K8s::Example::Thing" } } as unknown as K8sParseResult;
|
|
15
|
+
|
|
16
|
+
async function fakeLoad(sources: CRDSource[]): Promise<K8sParseResult[]> {
|
|
17
|
+
const [source] = sources;
|
|
18
|
+
if (source === down) throw new Error("registry unreachable");
|
|
19
|
+
if (source === moved) throw new Error("404 Not Found");
|
|
20
|
+
return [fakeResult];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("loadCrdSources (#3310)", () => {
|
|
24
|
+
it("returns every source's types when all load", async () => {
|
|
25
|
+
const out = await loadCrdSources([good], () => {}, { load: fakeLoad });
|
|
26
|
+
expect(out.results).toEqual([fakeResult]);
|
|
27
|
+
expect(out.warnings).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("fails naming each source that failed to load, after trying them all", async () => {
|
|
31
|
+
const attempted: CRDSource[] = [];
|
|
32
|
+
const load = async (sources: CRDSource[]) => {
|
|
33
|
+
attempted.push(...sources);
|
|
34
|
+
return fakeLoad(sources);
|
|
35
|
+
};
|
|
36
|
+
const run = loadCrdSources([down, good, moved], () => {}, { load });
|
|
37
|
+
await expect(run).rejects.toThrow(/2 CRD source\(s\) failed to load/);
|
|
38
|
+
await expect(run).rejects.toThrow(/oci:\/\/registry\.example\.test\/charts\/operator: registry unreachable/);
|
|
39
|
+
await expect(run).rejects.toThrow(/https:\/\/example\.test\/moved\.yaml: 404 Not Found/);
|
|
40
|
+
await expect(run).rejects.toThrow(/CHANT_K8S_ALLOW_CRD_FAILURES=1/);
|
|
41
|
+
expect(attempted).toEqual([down, good, moved]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("generates without a failed source, as a warning, only when allowed", async () => {
|
|
45
|
+
const out = await loadCrdSources([down, good], () => {}, { load: fakeLoad, allowFailures: true });
|
|
46
|
+
expect(out.results).toEqual([fakeResult]);
|
|
47
|
+
expect(out.warnings).toEqual([{ file: "oci://registry.example.test/charts/operator", error: "registry unreachable" }]);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -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,9 +12,16 @@ 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";
|
|
24
|
+
import type { CRDSource } from "../crd/types";
|
|
18
25
|
import { NamingStrategy, propertyTypeName, extractDefName } from "./naming";
|
|
19
26
|
import { generateLexiconJSON } from "./generate-lexicon";
|
|
20
27
|
import { generateOperationsJSON } from "./generate-operations";
|
|
@@ -31,6 +38,56 @@ export type { GenerateResult };
|
|
|
31
38
|
export interface K8sGenerateOptions extends GenerateOptions {
|
|
32
39
|
/** Kubernetes version tag to fetch the schema from. */
|
|
33
40
|
schemaVersion?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Generate without a CRD source that fails to load, as a warning, instead
|
|
43
|
+
* of failing (#3310). For a deliberate offline or partial run only: the
|
|
44
|
+
* output then lacks that source's kinds. Defaults to
|
|
45
|
+
* `CHANT_K8S_ALLOW_CRD_FAILURES=1` in the environment.
|
|
46
|
+
*/
|
|
47
|
+
allowCrdFailures?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Where a CRD source comes from, as a log line or an error names it. */
|
|
51
|
+
function crdSourceLabel(source: CRDSource): string {
|
|
52
|
+
return source.url ?? source.path ?? source.chart ?? "cluster";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Load every CRD source. A source that fails to load fails generation and the
|
|
57
|
+
* error names it (#3310): skipping it shrinks the output silently, and the loss
|
|
58
|
+
* shows up only later as a surface-snapshot diff. Every source is tried first,
|
|
59
|
+
* so one run names all the failures. `allowFailures` turns them back into
|
|
60
|
+
* warnings for a deliberate partial run.
|
|
61
|
+
*/
|
|
62
|
+
export async function loadCrdSources(
|
|
63
|
+
sources: readonly CRDSource[],
|
|
64
|
+
log: (msg: string) => void,
|
|
65
|
+
opts: { allowFailures?: boolean; load?: (sources: CRDSource[]) => Promise<K8sParseResult[]> } = {},
|
|
66
|
+
): Promise<{ results: K8sParseResult[]; warnings: Array<{ file: string; error: string }> }> {
|
|
67
|
+
const load = opts.load ?? loadMultipleCRDs;
|
|
68
|
+
const results: K8sParseResult[] = [];
|
|
69
|
+
const failures: Array<{ file: string; error: string }> = [];
|
|
70
|
+
for (const source of sources) {
|
|
71
|
+
const label = crdSourceLabel(source);
|
|
72
|
+
try {
|
|
73
|
+
const parsed = await load([source]);
|
|
74
|
+
results.push(...parsed);
|
|
75
|
+
log(`Loaded ${parsed.length} CRD type(s) from ${label}`);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
78
|
+
failures.push({ file: label, error: msg });
|
|
79
|
+
log(`${opts.allowFailures ? "Warning: skipping" : "Error:"} CRD source ${label} failed to load: ${msg}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (failures.length > 0 && !opts.allowFailures) {
|
|
83
|
+
const lines = failures.map((f) => ` ${f.file}: ${f.error}`).join("\n");
|
|
84
|
+
throw new Error(
|
|
85
|
+
`${failures.length} CRD source(s) failed to load, so generation would drop their kinds:\n${lines}\n` +
|
|
86
|
+
`Set CHANT_K8S_ALLOW_CRD_FAILURES=1 to generate without them deliberately.`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
log(`Total CRD types loaded: ${results.length}`);
|
|
90
|
+
return { results, warnings: failures };
|
|
34
91
|
}
|
|
35
92
|
|
|
36
93
|
/**
|
|
@@ -42,6 +99,8 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
42
99
|
// chant #1441 — read off the raw document in `parseSchema`, since the
|
|
43
100
|
// result set covers only the definitions chant emits types for.
|
|
44
101
|
let specPairs: Array<[string, string[]]> = [];
|
|
102
|
+
// chant #3093 — the declaration-only interfaces, which only the `.d.ts` emits.
|
|
103
|
+
let definitionTypes: ParsedDefinitionType[] = [];
|
|
45
104
|
|
|
46
105
|
const config: GeneratePipelineConfig<K8sParseResult> = {
|
|
47
106
|
fetchSchemas: async (fetchOpts) => {
|
|
@@ -49,10 +108,11 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
49
108
|
},
|
|
50
109
|
|
|
51
110
|
parseSchema: (_typeName, data) => {
|
|
52
|
-
// The K8s schema is a single document —
|
|
111
|
+
// The K8s schema is a single document — parseK8sSwaggerTypes returns multiple results.
|
|
53
112
|
// The pipeline calls this once per schema entry. We return the first result
|
|
54
113
|
// and use augmentResults to inject the rest.
|
|
55
|
-
const results =
|
|
114
|
+
const { results, definitionTypes: defs } = parseK8sSwaggerTypes(data);
|
|
115
|
+
definitionTypes = defs;
|
|
56
116
|
specPairs = specListMapKeyPairs(data);
|
|
57
117
|
if (results.length === 0) return null;
|
|
58
118
|
// Return the first result; stash the rest for augmentResults
|
|
@@ -65,20 +125,8 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
65
125
|
augmentSchemas: async (schemas, _opts, log) => {
|
|
66
126
|
// Load third-party CRDs and return as extraResults so they are
|
|
67
127
|
// included in the generated types alongside the core K8s resources.
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
for (const source of CRD_SOURCES) {
|
|
71
|
-
try {
|
|
72
|
-
const parsed = await loadMultipleCRDs([source]);
|
|
73
|
-
crdResults.push(...parsed);
|
|
74
|
-
log(`Loaded ${parsed.length} CRD type(s) from ${source.url ?? source.path ?? "cluster"}`);
|
|
75
|
-
} catch (err) {
|
|
76
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
77
|
-
warnings.push({ file: source.url ?? source.path ?? "cluster", error: msg });
|
|
78
|
-
log(`Warning: failed to load CRD: ${msg}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
log(`Total CRD types loaded: ${crdResults.length}`);
|
|
128
|
+
const allowFailures = opts.allowCrdFailures ?? process.env.CHANT_K8S_ALLOW_CRD_FAILURES === "1";
|
|
129
|
+
const { results: crdResults, warnings } = await loadCrdSources(CRD_SOURCES, log, { allowFailures });
|
|
82
130
|
return { schemas, extraResults: crdResults, warnings };
|
|
83
131
|
},
|
|
84
132
|
|
|
@@ -98,7 +146,7 @@ export async function generate(opts: K8sGenerateOptions = {}): Promise<GenerateR
|
|
|
98
146
|
},
|
|
99
147
|
|
|
100
148
|
generateTypes: (results, naming) => {
|
|
101
|
-
return generateTypeScriptDeclarations(results, naming as NamingStrategy);
|
|
149
|
+
return generateTypeScriptDeclarations(results, naming as NamingStrategy, definitionTypes);
|
|
102
150
|
},
|
|
103
151
|
|
|
104
152
|
generateRuntimeIndex: (results, naming) => {
|
|
@@ -39,3 +39,90 @@ describe("kubectl-apply capability (#1495 piece 2)", () => {
|
|
|
39
39
|
expect(units).toEqual([{ unit: "kubemicrovm-ops", lexicon: "k8s" }]);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
describe("kubectl-apply with a release (#3061, ws-081)", () => {
|
|
44
|
+
const stamped = () => ({
|
|
45
|
+
apiVersion: "apps/v1",
|
|
46
|
+
kind: "Deployment",
|
|
47
|
+
metadata: { name: "api" },
|
|
48
|
+
spec: {
|
|
49
|
+
template: {
|
|
50
|
+
metadata: { labels: { app: "api" } },
|
|
51
|
+
spec: {
|
|
52
|
+
containers: [
|
|
53
|
+
{
|
|
54
|
+
name: "api",
|
|
55
|
+
image: "x",
|
|
56
|
+
env: [
|
|
57
|
+
{ name: "CHANT_RELEASE_ATTRIBUTES", valueFrom: { fieldRef: { fieldPath: "metadata.annotations['chant.intentius.io/release-attributes']" } } },
|
|
58
|
+
{ name: "OTEL_RESOURCE_ATTRIBUTES", value: "chant.decl=api$(CHANT_RELEASE_ATTRIBUTES)" },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const plain = () => ({ apiVersion: "v1", kind: "Service", metadata: { name: "api" }, spec: { ports: [{ port: 80 }] } });
|
|
67
|
+
const release = { version: "sha256:abc", revision: "0123abc" };
|
|
68
|
+
|
|
69
|
+
test("sets the release attributes on the pod template of each stamped workload it applies", async () => {
|
|
70
|
+
let seen: { documents?: Record<string, any>[] } = {};
|
|
71
|
+
const cap = createKubectlApplyCapability(
|
|
72
|
+
async (args) => {
|
|
73
|
+
seen = args as typeof seen;
|
|
74
|
+
return { applied: [], pruned: [], fieldManager: "chant:x" };
|
|
75
|
+
},
|
|
76
|
+
() => [stamped(), plain()],
|
|
77
|
+
);
|
|
78
|
+
await cap.run({ env: "prod", component: "api", release }, { manifest: "k8s.yaml", stack: "x" });
|
|
79
|
+
expect(seen.documents![0].spec.template.metadata).toEqual({
|
|
80
|
+
labels: { app: "api" },
|
|
81
|
+
annotations: { "chant.intentius.io/release-attributes": ",service.version=sha256%3Aabc,vcs.ref.head.revision=0123abc" },
|
|
82
|
+
});
|
|
83
|
+
expect(seen.documents![1]).toEqual(plain());
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("without a release, or with no stamped workload, it applies the manifest as read", async () => {
|
|
87
|
+
const calls: Record<string, unknown>[] = [];
|
|
88
|
+
let reads = 0;
|
|
89
|
+
const cap = createKubectlApplyCapability(
|
|
90
|
+
async (args) => {
|
|
91
|
+
calls.push({ ...args });
|
|
92
|
+
return { applied: [], pruned: [], fieldManager: "chant:x" };
|
|
93
|
+
},
|
|
94
|
+
() => {
|
|
95
|
+
reads++;
|
|
96
|
+
return [plain()];
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
await cap.run({ env: "prod", component: "api" }, { manifest: "k8s.yaml" });
|
|
100
|
+
await cap.run({ env: "prod", component: "api", release }, { manifest: "k8s.yaml" });
|
|
101
|
+
expect(reads).toBe(1);
|
|
102
|
+
expect(calls.every((c) => !("documents" in c))).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("the committed manifest is the same bytes after a release apply", async () => {
|
|
106
|
+
const { mkdtempSync, readFileSync, rmSync, writeFileSync } = await import("node:fs");
|
|
107
|
+
const { tmpdir } = await import("node:os");
|
|
108
|
+
const { join } = await import("node:path");
|
|
109
|
+
const { dump } = await import("js-yaml");
|
|
110
|
+
const { readManifestDocuments } = await import("../op/activities/kubectl");
|
|
111
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-3061-"));
|
|
112
|
+
try {
|
|
113
|
+
const file = join(dir, "k8s.yaml");
|
|
114
|
+
writeFileSync(file, `${dump(stamped())}---\n${dump(plain())}`);
|
|
115
|
+
const before = readFileSync(file, "utf-8");
|
|
116
|
+
let annotated = 0;
|
|
117
|
+
const cap = createKubectlApplyCapability(async (args) => {
|
|
118
|
+
annotated = (args.documents ?? []).filter((d: any) => d.spec?.template?.metadata?.annotations).length;
|
|
119
|
+
return { applied: [], pruned: [], fieldManager: "chant:x" };
|
|
120
|
+
}, readManifestDocuments);
|
|
121
|
+
await cap.run({ env: "prod", component: "api", release }, { manifest: file });
|
|
122
|
+
expect(annotated).toBe(1);
|
|
123
|
+
expect(readFileSync(file, "utf-8")).toBe(before);
|
|
124
|
+
} finally {
|
|
125
|
+
rmSync(dir, { recursive: true, force: true });
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* pairing `cfn-deploy` has with its stack.
|
|
17
17
|
*/
|
|
18
18
|
import type { Capability, DeployContext } from "@intentius/chant/components/capability";
|
|
19
|
+
import { releaseAttributesSuffix } from "@intentius/chant/telemetry-attribution";
|
|
20
|
+
import { annotateRelease } from "../telemetry-release";
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Structural mirrors of the activity module's argument/result shapes.
|
|
@@ -51,6 +53,8 @@ export interface KubectlApplyOutcome {
|
|
|
51
53
|
|
|
52
54
|
interface ApplierArgs {
|
|
53
55
|
manifest: string;
|
|
56
|
+
/** The parsed documents to apply instead of reading `manifest`, when the step changed them in memory. */
|
|
57
|
+
documents?: Record<string, unknown>[];
|
|
54
58
|
environment?: string;
|
|
55
59
|
stack?: string;
|
|
56
60
|
context?: string;
|
|
@@ -58,6 +62,7 @@ interface ApplierArgs {
|
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
type Applier = (args: ApplierArgs) => Promise<KubectlApplyOutcome>;
|
|
65
|
+
type ManifestReader = (path: string) => Record<string, unknown>[];
|
|
61
66
|
|
|
62
67
|
export interface KubectlApplyInput {
|
|
63
68
|
/** Path to a manifest file, or a directory of them. */
|
|
@@ -86,6 +91,7 @@ export interface KubectlApplyInput {
|
|
|
86
91
|
* chain off the build path (#1074). */
|
|
87
92
|
export function createKubectlApplyCapability(
|
|
88
93
|
apply?: Applier,
|
|
94
|
+
read?: ManifestReader,
|
|
89
95
|
): Capability<KubectlApplyInput, KubectlApplyOutcome> {
|
|
90
96
|
return {
|
|
91
97
|
kind: "kubectl-apply",
|
|
@@ -94,9 +100,19 @@ export function createKubectlApplyCapability(
|
|
|
94
100
|
// the compensation gap — the same posture as s3-sync/run-migration.
|
|
95
101
|
rollbackPolicy: "needs-opt-out",
|
|
96
102
|
async run(ctx: DeployContext, input: KubectlApplyInput): Promise<KubectlApplyOutcome> {
|
|
97
|
-
const
|
|
103
|
+
const activities = apply && read ? undefined : await import("../op/activities/kubectl");
|
|
104
|
+
const applier: Applier = apply ?? activities!.applyManifest;
|
|
105
|
+
// A release run (#3061, ws-081) sets the release attributes on the pod template of each
|
|
106
|
+
// workload the build stamped, in what it applies; the committed manifest is not touched.
|
|
107
|
+
const suffix = releaseAttributesSuffix(ctx.release);
|
|
108
|
+
let documents: Record<string, unknown>[] | undefined;
|
|
109
|
+
if (suffix !== "") {
|
|
110
|
+
documents = (read ?? activities!.readManifestDocuments)(input.manifest);
|
|
111
|
+
if (annotateRelease(documents, suffix) === 0) documents = undefined;
|
|
112
|
+
}
|
|
98
113
|
return applier({
|
|
99
114
|
manifest: input.manifest,
|
|
115
|
+
...(documents ? { documents } : {}),
|
|
100
116
|
environment: ctx.env,
|
|
101
117
|
...(input.stack !== undefined ? { stack: input.stack } : {}),
|
|
102
118
|
...(input.context !== undefined ? { context: input.context } : {}),
|
|
@@ -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,
|