@intentius/chant-lexicon-k8s 0.106.4 → 0.108.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codegen/naming.d.ts.map +1 -1
- package/dist/composites/catalog.d.ts.map +1 -1
- package/dist/composites/index.d.ts +2 -0
- package/dist/composites/index.d.ts.map +1 -1
- package/dist/composites/otel-collector-shape.d.ts +2 -0
- package/dist/composites/otel-collector-shape.d.ts.map +1 -1
- package/dist/composites/otel-operator-collector.d.ts +101 -0
- package/dist/composites/otel-operator-collector.d.ts.map +1 -0
- package/dist/config-schema.d.ts +115 -1
- package/dist/config-schema.d.ts.map +1 -1
- package/dist/config.d.ts +58 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/crd/crd-sources.d.ts.map +1 -1
- package/dist/crd/loader.d.ts +4 -0
- package/dist/crd/loader.d.ts.map +1 -1
- package/dist/crd/parser.d.ts +5 -0
- package/dist/crd/parser.d.ts.map +1 -1
- package/dist/crd/project-codegen.d.ts +33 -0
- package/dist/crd/project-codegen.d.ts.map +1 -0
- package/dist/generated/index.d.d.ts +172 -2
- package/dist/generated/index.d.ts +301 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/group-namespace.d.ts.map +1 -1
- package/dist/import/embedded.d.ts +3 -0
- package/dist/import/embedded.d.ts.map +1 -1
- package/dist/include/entity.d.ts +73 -0
- package/dist/include/entity.d.ts.map +1 -0
- package/dist/include/resolve.d.ts +29 -0
- package/dist/include/resolve.d.ts.map +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/integrity.json +17 -10
- package/dist/kustomize/rendered-entity.d.ts +15 -1
- package/dist/kustomize/rendered-entity.d.ts.map +1 -1
- package/dist/kustomize/root.d.ts +11 -2
- package/dist/kustomize/root.d.ts.map +1 -1
- package/dist/lint/audit-catalog.d.ts.map +1 -1
- package/dist/lint/post-synth/crd-schema-helpers.d.ts +5 -1
- package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/lint/post-synth/monitoring-selection-helpers.d.ts +55 -0
- package/dist/lint/post-synth/monitoring-selection-helpers.d.ts.map +1 -0
- package/dist/lint/post-synth/otel-placement-helpers.d.ts +16 -0
- package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8604.d.ts +6 -0
- package/dist/lint/post-synth/wk8604.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8605.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8606.d.ts +17 -0
- package/dist/lint/post-synth/wk8606.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8701.d.ts +17 -0
- package/dist/lint/post-synth/wk8701.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8702.d.ts +17 -0
- package/dist/lint/post-synth/wk8702.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8703.d.ts +17 -0
- package/dist/lint/post-synth/wk8703.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8704.d.ts +21 -0
- package/dist/lint/post-synth/wk8704.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8705.d.ts +18 -0
- package/dist/lint/post-synth/wk8705.d.ts.map +1 -0
- package/dist/manifest.json +1 -1
- package/dist/meta.json +2284 -370
- package/dist/okf/index.md +20 -1
- package/dist/okf/rules/WK8604.md +6 -2
- package/dist/okf/rules/WK8605.md +4 -0
- package/dist/okf/rules/WK8606.md +15 -0
- package/dist/okf/rules/WK8701.md +18 -0
- package/dist/okf/rules/WK8702.md +20 -0
- package/dist/okf/rules/WK8703.md +17 -0
- package/dist/okf/rules/WK8704.md +22 -0
- package/dist/okf/rules/WK8705.md +18 -0
- package/dist/okf/types/Alertmanager.md +18 -0
- package/dist/okf/types/AlertmanagerConfig.md +18 -0
- package/dist/okf/types/ClusterObservability.md +14 -0
- package/dist/okf/types/CronJob.md +1 -0
- package/dist/okf/types/DaemonSet.md +1 -0
- package/dist/okf/types/Instrumentation.md +14 -0
- package/dist/okf/types/MonitoringProbe.md +14 -0
- package/dist/okf/types/Namespace.md +3 -0
- package/dist/okf/types/OpAMPBridge.md +14 -0
- package/dist/okf/types/OpenTelemetryCollector.md +19 -0
- package/dist/okf/types/Pod.md +1 -0
- package/dist/okf/types/PodMonitor.md +20 -0
- package/dist/okf/types/Prometheus.md +21 -0
- package/dist/okf/types/PrometheusAgent.md +18 -0
- package/dist/okf/types/PrometheusRule.md +6 -1
- package/dist/okf/types/ScrapeConfig.md +19 -0
- package/dist/okf/types/Service.md +1 -0
- package/dist/okf/types/ServiceMonitor.md +7 -1
- package/dist/okf/types/StatefulSet.md +1 -0
- package/dist/okf/types/TargetAllocator.md +14 -0
- package/dist/okf/types/ThanosRuler.md +18 -0
- package/dist/patch/json-patch.d.ts +51 -0
- package/dist/patch/json-patch.d.ts.map +1 -0
- package/dist/patch/rendered-patch.d.ts +90 -0
- package/dist/patch/rendered-patch.d.ts.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/project-kinds.d.ts +46 -0
- package/dist/project-kinds.d.ts.map +1 -0
- package/dist/rules/crd-schema-helpers.ts +10 -2
- package/dist/rules/monitoring-selection-helpers.ts +185 -0
- package/dist/rules/otel-placement-helpers.ts +61 -1
- package/dist/rules/wk8601.ts +1 -1
- package/dist/rules/wk8603.ts +1 -1
- package/dist/rules/wk8604.ts +8 -2
- package/dist/rules/wk8605.ts +5 -3
- package/dist/rules/wk8606.ts +27 -0
- package/dist/rules/wk8701.ts +37 -0
- package/dist/rules/wk8702.ts +43 -0
- package/dist/rules/wk8703.ts +37 -0
- package/dist/rules/wk8704.ts +134 -0
- package/dist/rules/wk8705.ts +45 -0
- package/dist/serializer.d.ts.map +1 -1
- package/dist/types/index.d.ts +172 -2
- package/package.json +3 -3
- package/src/codegen/naming.ts +15 -1
- package/src/composites/catalog.ts +105 -0
- package/src/composites/index.ts +2 -0
- package/src/composites/otel-collector-shape.ts +2 -0
- package/src/composites/otel-operator-collector.test.ts +267 -0
- package/src/composites/otel-operator-collector.ts +221 -0
- package/src/config-augmentation.test.ts +28 -0
- package/src/config-schema.ts +47 -1
- package/src/config.ts +44 -3
- package/src/crd/crd-sources.ts +41 -2
- package/src/crd/loader.ts +1 -1
- package/src/crd/parser.ts +9 -5
- package/src/crd/project-codegen.test.ts +239 -0
- package/src/crd/project-codegen.ts +327 -0
- package/src/generated/index.d.ts +172 -2
- package/src/generated/index.ts +303 -2
- package/src/generated/lexicon-k8s.json +2284 -370
- package/src/generated/operations.json +208 -0
- package/src/group-namespace.test.ts +4 -0
- package/src/group-namespace.ts +4 -0
- package/src/import/embedded.ts +26 -0
- package/src/import/operator-collector-roundtrip.test.ts +105 -0
- package/src/include/entity.ts +119 -0
- package/src/include/include.test.ts +345 -0
- package/src/include/resolve.ts +204 -0
- package/src/index.ts +25 -2
- package/src/kustomize/rendered-entity.ts +43 -1
- package/src/kustomize/root.test.ts +39 -0
- package/src/kustomize/root.ts +16 -30
- package/src/lint/audit-catalog.ts +6 -0
- package/src/lint/post-synth/crd-schema-helpers.ts +10 -2
- package/src/lint/post-synth/index.ts +12 -0
- package/src/lint/post-synth/monitoring-selection-helpers.ts +185 -0
- package/src/lint/post-synth/monitoring-selection.test.ts +316 -0
- package/src/lint/post-synth/otel-placement-helpers.ts +61 -1
- package/src/lint/post-synth/wk8601.ts +1 -1
- package/src/lint/post-synth/wk8603.ts +1 -1
- package/src/lint/post-synth/wk8604.ts +8 -2
- package/src/lint/post-synth/wk8605.ts +5 -3
- package/src/lint/post-synth/wk8606.ts +27 -0
- package/src/lint/post-synth/wk8701.ts +37 -0
- package/src/lint/post-synth/wk8702.ts +43 -0
- package/src/lint/post-synth/wk8703.ts +37 -0
- package/src/lint/post-synth/wk8704.ts +134 -0
- package/src/lint/post-synth/wk8705.ts +45 -0
- package/src/patch/json-patch.test.ts +91 -0
- package/src/patch/json-patch.ts +189 -0
- package/src/patch/rendered-patch.test.ts +143 -0
- package/src/patch/rendered-patch.ts +180 -0
- package/src/plugin.ts +16 -2
- package/src/project-kinds.ts +75 -0
- package/src/serializer.ts +10 -0
- package/src/testdata/include/bundle.yaml +45 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `k8sInclude` (#3566 item 4). What must hold: a local file or a pinned URL
|
|
3
|
+
* resolves at `buildRoots()` into verbatim manifest entities with
|
|
4
|
+
* deterministic names and source provenance; a URL's bytes must match the
|
|
5
|
+
* digest and are cached by it, so later builds are offline; patches apply
|
|
6
|
+
* before the documents become entities; and every way an include can be
|
|
7
|
+
* wrong fails with the path or URL in the message. No test touches the
|
|
8
|
+
* network: the fetcher is injected.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, test, expect, beforeEach, afterEach } from "vitest";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { build } from "@intentius/chant";
|
|
17
|
+
import type { Declarable } from "@intentius/chant/declarable";
|
|
18
|
+
import type { PostSynthContext } from "@intentius/chant/lint/post-synth";
|
|
19
|
+
import { k8sInclude, isK8sInclude, INCLUDE_SOURCE_ANNOTATION, type K8sIncludeDeclaration } from "./entity";
|
|
20
|
+
import { includeBuildRoot, resolveIncludes, sha256Digest, type IncludeFetcher } from "./resolve";
|
|
21
|
+
import { isRenderedManifestEntity } from "../manifest-entity";
|
|
22
|
+
import { k8sSerializer } from "../serializer";
|
|
23
|
+
import { k8sPlugin } from "../plugin";
|
|
24
|
+
import { wk8005 } from "../lint/post-synth/wk8005";
|
|
25
|
+
|
|
26
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
27
|
+
const fixtureRoot = join(here, "..", "testdata", "include");
|
|
28
|
+
const BUNDLE = readFileSync(join(fixtureRoot, "bundle.yaml"));
|
|
29
|
+
const BUNDLE_DIGEST = sha256Digest(BUNDLE);
|
|
30
|
+
const URL_SOURCE = "https://example.com/releases/v0.4.1/widget.yaml";
|
|
31
|
+
/** Absolute path to the factory — a temp project cannot resolve the package name. */
|
|
32
|
+
const ENTITY_MODULE = join(here, "entity");
|
|
33
|
+
|
|
34
|
+
const EXPECTED_KEYS = [
|
|
35
|
+
"widgets/namespaceWidgetSystem",
|
|
36
|
+
"widgets/configMapWidgetConfig",
|
|
37
|
+
"widgets/configMapWidgetConfig.widget-edge",
|
|
38
|
+
"widgets/deploymentWidgetController",
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
function decls(...pairs: Array<[string, K8sIncludeDeclaration]>) {
|
|
42
|
+
return new Map(pairs);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function propsOf(entity: Declarable | undefined): Record<string, unknown> {
|
|
46
|
+
return (entity as unknown as { props: Record<string, unknown> }).props;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let cacheRoot: string;
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
cacheRoot = mkdtempSync(join(tmpdir(), "chant-include-cache-"));
|
|
52
|
+
});
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
rmSync(cacheRoot, { recursive: true, force: true });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("k8sInclude — the declaration", () => {
|
|
58
|
+
test("is a k8s declarable with no props, so it never reaches the live read paths", () => {
|
|
59
|
+
const decl = k8sInclude({ source: "manifests/bundle.yaml" });
|
|
60
|
+
expect(isK8sInclude(decl)).toBe(true);
|
|
61
|
+
expect(decl.lexicon).toBe("k8s");
|
|
62
|
+
expect("props" in decl).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("a URL without a digest is refused at declaration time", () => {
|
|
66
|
+
expect(() => k8sInclude({ source: URL_SOURCE })).toThrow(/must be pinned with `digest: "sha256:<hex>"`/);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("a malformed digest is refused", () => {
|
|
70
|
+
expect(() => k8sInclude({ source: URL_SOURCE, digest: "sha256:abc" })).toThrow(/not of the form/);
|
|
71
|
+
expect(() => k8sInclude({ source: URL_SOURCE, digest: BUNDLE_DIGEST.replace("sha256:", "md5:") })).toThrow(
|
|
72
|
+
/not of the form/,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("schemes other than http(s) are refused", () => {
|
|
77
|
+
expect(() => k8sInclude({ source: "oci://registry/bundle" })).toThrow(/only local paths and http\(s\) URLs/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("the serializer emits nothing for the declaration itself", () => {
|
|
81
|
+
const out = k8sSerializer.serialize(new Map<string, Declarable>([["inc", k8sInclude({ source: "x.yaml" })]]));
|
|
82
|
+
expect(typeof out === "string" ? out : out.primary).toBe("");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("resolveIncludes — local files", () => {
|
|
87
|
+
test("resolves relative to the project root into verbatim entities with deterministic keys", async () => {
|
|
88
|
+
const entities = await resolveIncludes({
|
|
89
|
+
projectRoot: join(fixtureRoot, ".."),
|
|
90
|
+
declarations: decls(["widgets", k8sInclude({ source: "include/bundle.yaml" })]),
|
|
91
|
+
cacheRoot,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// The stray `---` empties are skipped; the two same-name ConfigMaps are
|
|
95
|
+
// qualified by namespace, in document order.
|
|
96
|
+
expect([...entities.keys()]).toEqual(EXPECTED_KEYS);
|
|
97
|
+
const deployment = entities.get("widgets/deploymentWidgetController")!;
|
|
98
|
+
expect(isRenderedManifestEntity(deployment)).toBe(true);
|
|
99
|
+
expect(deployment.entityType).toBe("K8s::Apps::Deployment");
|
|
100
|
+
const metadata = propsOf(deployment).metadata as { annotations: Record<string, string> };
|
|
101
|
+
expect(metadata.annotations[INCLUDE_SOURCE_ANNOTATION]).toBe("include/bundle.yaml");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("names are the same on every resolve, and a third same-name document is numbered", async () => {
|
|
105
|
+
const readFile = () =>
|
|
106
|
+
Buffer.from(
|
|
107
|
+
["a", "a", "b"]
|
|
108
|
+
.map((ns) => `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: c\n namespace: ${ns}\n`)
|
|
109
|
+
.join("---\n"),
|
|
110
|
+
);
|
|
111
|
+
const run = () =>
|
|
112
|
+
resolveIncludes({ projectRoot: "/p", declarations: decls(["inc", k8sInclude({ source: "c.yaml" })]), readFile });
|
|
113
|
+
const first = [...(await run()).keys()];
|
|
114
|
+
expect(first).toEqual(["inc/configMapC", "inc/configMapC.a", "inc/configMapC.b"]);
|
|
115
|
+
expect([...(await run()).keys()]).toEqual(first);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("a local file with a digest must match it", async () => {
|
|
119
|
+
const wrong = `sha256:${"0".repeat(64)}`;
|
|
120
|
+
await expect(
|
|
121
|
+
resolveIncludes({
|
|
122
|
+
projectRoot: fixtureRoot,
|
|
123
|
+
declarations: decls(["w", k8sInclude({ source: "bundle.yaml", digest: wrong })]),
|
|
124
|
+
}),
|
|
125
|
+
).rejects.toThrow(/bundle\.yaml does not match its pinned digest: expected sha256:0+, found sha256:/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("a missing file fails with the declared source and the resolved path", async () => {
|
|
129
|
+
await expect(
|
|
130
|
+
resolveIncludes({ projectRoot: fixtureRoot, declarations: decls(["w", k8sInclude({ source: "nope.yaml" })]) }),
|
|
131
|
+
).rejects.toThrow(new RegExp(`k8sInclude "w" \\(nope\\.yaml\\): file not readable at ${join(fixtureRoot, "nope.yaml")}`));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("a document without apiVersion/kind fails with its index", async () => {
|
|
135
|
+
const readFile = () => Buffer.from("apiVersion: v1\nkind: Namespace\nmetadata:\n name: x\n---\njust: data\n");
|
|
136
|
+
await expect(
|
|
137
|
+
resolveIncludes({ projectRoot: "/p", declarations: decls(["w", k8sInclude({ source: "m.yaml" })]), readFile }),
|
|
138
|
+
).rejects.toThrow(/k8sInclude "w" \(m\.yaml\): document 1 has no string apiVersion and kind/);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("a file holding only empty documents fails", async () => {
|
|
142
|
+
const readFile = () => Buffer.from("---\n---\n# nothing\n");
|
|
143
|
+
await expect(
|
|
144
|
+
resolveIncludes({ projectRoot: "/p", declarations: decls(["w", k8sInclude({ source: "m.yaml" })]), readFile }),
|
|
145
|
+
).rejects.toThrow(/k8sInclude "w" \(m\.yaml\) contains no YAML documents/);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("patches apply before the documents become entities", async () => {
|
|
149
|
+
const entities = await resolveIncludes({
|
|
150
|
+
projectRoot: fixtureRoot,
|
|
151
|
+
declarations: decls([
|
|
152
|
+
"widgets",
|
|
153
|
+
k8sInclude({
|
|
154
|
+
source: "bundle.yaml",
|
|
155
|
+
patches: [
|
|
156
|
+
{ kind: "Deployment", name: "widget-controller", merge: { spec: { replicas: 2 } } },
|
|
157
|
+
{
|
|
158
|
+
kind: "ConfigMap",
|
|
159
|
+
name: "widget-config",
|
|
160
|
+
namespace: "widget-edge",
|
|
161
|
+
jsonPatch: [
|
|
162
|
+
{ op: "test", path: "/data/level", value: "debug" },
|
|
163
|
+
{ op: "replace", path: "/data/level", value: "info" },
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
}),
|
|
168
|
+
]),
|
|
169
|
+
});
|
|
170
|
+
expect((propsOf(entities.get("widgets/deploymentWidgetController")).spec as { replicas: number }).replicas).toBe(2);
|
|
171
|
+
expect(propsOf(entities.get("widgets/configMapWidgetConfig.widget-edge")).data).toEqual({ level: "info" });
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("a patch selecting nothing fails, naming the include", async () => {
|
|
175
|
+
await expect(
|
|
176
|
+
resolveIncludes({
|
|
177
|
+
projectRoot: fixtureRoot,
|
|
178
|
+
declarations: decls([
|
|
179
|
+
"widgets",
|
|
180
|
+
k8sInclude({ source: "bundle.yaml", patches: [{ kind: "Deployment", name: "widget-manager", merge: {} }] }),
|
|
181
|
+
]),
|
|
182
|
+
}),
|
|
183
|
+
).rejects.toThrow(/k8sInclude "widgets" \(bundle\.yaml\): patch 0 .* matched no document\. Deployment documents present: widget-system\/widget-controller/);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe("resolveIncludes — pinned URLs", () => {
|
|
188
|
+
test("fetches once, verifies the digest, then resolves offline from the cache", async () => {
|
|
189
|
+
const fetched: string[] = [];
|
|
190
|
+
const fetcher: IncludeFetcher = async (url) => {
|
|
191
|
+
fetched.push(url);
|
|
192
|
+
return BUNDLE;
|
|
193
|
+
};
|
|
194
|
+
const declarations = decls(["widgets", k8sInclude({ source: URL_SOURCE, digest: BUNDLE_DIGEST })]);
|
|
195
|
+
|
|
196
|
+
const first = await resolveIncludes({ projectRoot: "/p", declarations, fetch: fetcher, cacheRoot });
|
|
197
|
+
expect(fetched).toEqual([URL_SOURCE]);
|
|
198
|
+
expect([...first.keys()]).toEqual(EXPECTED_KEYS);
|
|
199
|
+
expect(existsSync(join(cacheRoot, `${BUNDLE_DIGEST.replace(":", "-")}.yaml`))).toBe(true);
|
|
200
|
+
|
|
201
|
+
// The second build has no network at all.
|
|
202
|
+
const offline: IncludeFetcher = async () => {
|
|
203
|
+
throw new Error("network unavailable");
|
|
204
|
+
};
|
|
205
|
+
const second = await resolveIncludes({ projectRoot: "/p", declarations, fetch: offline, cacheRoot });
|
|
206
|
+
expect([...second.keys()]).toEqual(EXPECTED_KEYS);
|
|
207
|
+
const ns = propsOf(second.get("widgets/namespaceWidgetSystem")).metadata as { annotations: Record<string, string> };
|
|
208
|
+
expect(ns.annotations[INCLUDE_SOURCE_ANNOTATION]).toBe(URL_SOURCE);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("fetched bytes that do not match the digest fail the build and are not cached", async () => {
|
|
212
|
+
const tampered = Buffer.concat([BUNDLE, Buffer.from("\n# changed upstream\n")]);
|
|
213
|
+
await expect(
|
|
214
|
+
resolveIncludes({
|
|
215
|
+
projectRoot: "/p",
|
|
216
|
+
declarations: decls(["widgets", k8sInclude({ source: URL_SOURCE, digest: BUNDLE_DIGEST })]),
|
|
217
|
+
fetch: async () => tampered,
|
|
218
|
+
cacheRoot,
|
|
219
|
+
}),
|
|
220
|
+
).rejects.toThrow(
|
|
221
|
+
new RegExp(
|
|
222
|
+
`k8sInclude "widgets" \\(${URL_SOURCE.replace(/[.]/g, "\\.")}\\): fetched bytes do not match the pinned digest: ` +
|
|
223
|
+
`expected ${BUNDLE_DIGEST}, fetched ${sha256Digest(tampered)}`,
|
|
224
|
+
),
|
|
225
|
+
);
|
|
226
|
+
expect(existsSync(join(cacheRoot, `${BUNDLE_DIGEST.replace(":", "-")}.yaml`))).toBe(false);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("a corrupt cache entry is refetched, not trusted", async () => {
|
|
230
|
+
writeFileSync(join(cacheRoot, `${BUNDLE_DIGEST.replace(":", "-")}.yaml`), "apiVersion: v1\nkind: Namespace\nmetadata:\n name: evil\n");
|
|
231
|
+
let fetches = 0;
|
|
232
|
+
const entities = await resolveIncludes({
|
|
233
|
+
projectRoot: "/p",
|
|
234
|
+
declarations: decls(["widgets", k8sInclude({ source: URL_SOURCE, digest: BUNDLE_DIGEST })]),
|
|
235
|
+
fetch: async () => {
|
|
236
|
+
fetches++;
|
|
237
|
+
return BUNDLE;
|
|
238
|
+
},
|
|
239
|
+
cacheRoot,
|
|
240
|
+
});
|
|
241
|
+
expect(fetches).toBe(1);
|
|
242
|
+
expect([...entities.keys()]).toEqual(EXPECTED_KEYS);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("a failed fetch names the URL", async () => {
|
|
246
|
+
await expect(
|
|
247
|
+
resolveIncludes({
|
|
248
|
+
projectRoot: "/p",
|
|
249
|
+
declarations: decls(["widgets", k8sInclude({ source: URL_SOURCE, digest: BUNDLE_DIGEST })]),
|
|
250
|
+
fetch: async () => {
|
|
251
|
+
throw new Error("HTTP 404 Not Found");
|
|
252
|
+
},
|
|
253
|
+
cacheRoot,
|
|
254
|
+
}),
|
|
255
|
+
).rejects.toThrow(/widget\.yaml\): fetch failed — HTTP 404 Not Found/);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("CHANT_INCLUDE_CACHE_ROOT moves the cache", async () => {
|
|
259
|
+
const orig = process.env.CHANT_INCLUDE_CACHE_ROOT;
|
|
260
|
+
process.env.CHANT_INCLUDE_CACHE_ROOT = cacheRoot;
|
|
261
|
+
try {
|
|
262
|
+
await resolveIncludes({
|
|
263
|
+
projectRoot: "/p",
|
|
264
|
+
declarations: decls(["widgets", k8sInclude({ source: URL_SOURCE, digest: BUNDLE_DIGEST })]),
|
|
265
|
+
fetch: async () => BUNDLE,
|
|
266
|
+
});
|
|
267
|
+
expect(existsSync(join(cacheRoot, `${BUNDLE_DIGEST.replace(":", "-")}.yaml`))).toBe(true);
|
|
268
|
+
} finally {
|
|
269
|
+
if (orig === undefined) delete process.env.CHANT_INCLUDE_CACHE_ROOT;
|
|
270
|
+
else process.env.CHANT_INCLUDE_CACHE_ROOT = orig;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe("k8sInclude through the build pipeline", () => {
|
|
276
|
+
test("included docs reach the output ownership-stamped, patched, and seen by post-synth checks", async () => {
|
|
277
|
+
const dir = join(tmpdir(), `chant-include-build-${Date.now()}-${Math.random()}`);
|
|
278
|
+
await mkdir(dir, { recursive: true });
|
|
279
|
+
try {
|
|
280
|
+
await writeFile(join(dir, "bundle.yaml"), BUNDLE);
|
|
281
|
+
await writeFile(
|
|
282
|
+
join(dir, "widgets.infra.ts"),
|
|
283
|
+
`import { k8sInclude } from ${JSON.stringify(ENTITY_MODULE)};
|
|
284
|
+
export const widgets = k8sInclude({
|
|
285
|
+
source: "bundle.yaml",
|
|
286
|
+
patches: [{ kind: "Deployment", name: "widget-controller", merge: { spec: { replicas: 4 } } }],
|
|
287
|
+
});
|
|
288
|
+
`,
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const result = await build(dir, [k8sSerializer], undefined, {
|
|
292
|
+
ownership: { stack: "widgets", env: "prod" },
|
|
293
|
+
buildRoots: [(ctx) => k8sPlugin.buildRoots!({ projectRoot: dir, config: {}, entities: ctx.entities })],
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
expect(result.errors).toEqual([]);
|
|
297
|
+
for (const key of EXPECTED_KEYS) expect(result.entities.has(key)).toBe(true);
|
|
298
|
+
|
|
299
|
+
const output = result.outputs.get("k8s")!;
|
|
300
|
+
const yaml = typeof output === "string" ? output : output.primary;
|
|
301
|
+
expect(yaml).toContain("name: widget-controller");
|
|
302
|
+
expect(yaml).toContain("replicas: 4");
|
|
303
|
+
expect(yaml).toContain("app.kubernetes.io/managed-by: chant");
|
|
304
|
+
expect(yaml).toContain("chant.intentius.io/stack: widgets");
|
|
305
|
+
expect(yaml).toContain(`${INCLUDE_SOURCE_ANNOTATION}: bundle.yaml`);
|
|
306
|
+
// Four documents, the declaration itself emits nothing.
|
|
307
|
+
expect(yaml.split(/^---$/m).filter((d) => d.trim()).length).toBe(4);
|
|
308
|
+
|
|
309
|
+
const ctx: PostSynthContext = {
|
|
310
|
+
outputs: result.outputs,
|
|
311
|
+
entities: result.entities,
|
|
312
|
+
buildResult: {
|
|
313
|
+
outputs: result.outputs,
|
|
314
|
+
entities: result.entities,
|
|
315
|
+
warnings: result.warnings,
|
|
316
|
+
errors: [],
|
|
317
|
+
sourceFileCount: result.sourceFileCount,
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
expect(wk8005.check(ctx).some((d) => d.message.includes("API_TOKEN"))).toBe(true);
|
|
321
|
+
} finally {
|
|
322
|
+
await rm(dir, { recursive: true, force: true });
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("an include that does not resolve is a build error naming it", async () => {
|
|
327
|
+
const dir = join(tmpdir(), `chant-include-build-bad-${Date.now()}-${Math.random()}`);
|
|
328
|
+
await mkdir(dir, { recursive: true });
|
|
329
|
+
try {
|
|
330
|
+
await writeFile(
|
|
331
|
+
join(dir, "widgets.infra.ts"),
|
|
332
|
+
`import { k8sInclude } from ${JSON.stringify(ENTITY_MODULE)};
|
|
333
|
+
export const widgets = k8sInclude({ source: "vendor/missing.yaml" });
|
|
334
|
+
`,
|
|
335
|
+
);
|
|
336
|
+
const result = await build(dir, [k8sSerializer], undefined, {
|
|
337
|
+
buildRoots: [(ctx) => includeBuildRoot({ projectRoot: dir, config: {}, entities: ctx.entities })],
|
|
338
|
+
});
|
|
339
|
+
expect(result.errors).toHaveLength(1);
|
|
340
|
+
expect(result.errors[0].message).toContain('k8sInclude "widgets" (vendor/missing.yaml): file not readable');
|
|
341
|
+
} finally {
|
|
342
|
+
await rm(dir, { recursive: true, force: true });
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolving `k8sInclude` declarations at `buildRoots()` (#3566 item 4).
|
|
3
|
+
*
|
|
4
|
+
* For each declaration in the discovered entity set: read the local file or
|
|
5
|
+
* fetch the URL, check the bytes against the pinned digest, parse the
|
|
6
|
+
* multi-document YAML, apply the declaration's patches, and wrap each
|
|
7
|
+
* document in a verbatim manifest entity stamped with the source.
|
|
8
|
+
*
|
|
9
|
+
* - Local paths resolve against the project root (the directory holding
|
|
10
|
+
* `chant.config.*`), as `declareSecret`'s committed ciphertext and
|
|
11
|
+
* `k8s.kustomize.roots` do.
|
|
12
|
+
* - A URL is fetched once. The bytes are cached under their digest in
|
|
13
|
+
* `~/.chant/includes/` (override with `CHANT_INCLUDE_CACHE_ROOT`, the
|
|
14
|
+
* counterpart of the helm lexicon's `CHANT_HELM_RENDER_ROOT`), and a build
|
|
15
|
+
* that finds a cached copy matching the digest never touches the network.
|
|
16
|
+
* Fetched bytes that do not match the digest fail the build and are not
|
|
17
|
+
* cached.
|
|
18
|
+
* - Entity names are `<declaration name>/<kindName>`, qualified by
|
|
19
|
+
* namespace and then numbered in document order on collision, the scheme
|
|
20
|
+
* kustomize roots use. Keying on the declaration's export name rather than
|
|
21
|
+
* the URL keeps the names stable when a pinned version is bumped, so the
|
|
22
|
+
* live diff lines up across the upgrade.
|
|
23
|
+
* - A missing file, a failed fetch, a file with no documents, and a
|
|
24
|
+
* document without a string `apiVersion` and `kind` each fail the build
|
|
25
|
+
* with the path or URL in the message. Empty documents (a stray `---`)
|
|
26
|
+
* are skipped.
|
|
27
|
+
*/
|
|
28
|
+
import { createHash } from "node:crypto";
|
|
29
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
30
|
+
import { homedir } from "node:os";
|
|
31
|
+
import { join, resolve } from "node:path";
|
|
32
|
+
import { loadAll } from "js-yaml";
|
|
33
|
+
import type { Declarable } from "@intentius/chant/declarable";
|
|
34
|
+
import type { BuildRootContext, BuildRootContribution } from "@intentius/chant/lexicon";
|
|
35
|
+
import { applyRenderedPatches } from "../patch/rendered-patch";
|
|
36
|
+
import { addRenderedEntity, renderedManifestEntity } from "../kustomize/rendered-entity";
|
|
37
|
+
import { INCLUDE_SOURCE_ANNOTATION, isK8sInclude, isRemoteSource, type K8sIncludeDeclaration } from "./entity";
|
|
38
|
+
|
|
39
|
+
/** Fetches a URL's bytes. Injectable so tests never touch the network. */
|
|
40
|
+
export type IncludeFetcher = (url: string) => Promise<Uint8Array>;
|
|
41
|
+
|
|
42
|
+
export const defaultIncludeFetcher: IncludeFetcher = async (url) => {
|
|
43
|
+
const response = await fetch(url, { redirect: "follow" });
|
|
44
|
+
if (!response.ok) throw new Error(`HTTP ${response.status} ${response.statusText}`.trim());
|
|
45
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Where fetched include sources are cached, keyed by digest. */
|
|
49
|
+
export function includeCacheRoot(): string {
|
|
50
|
+
return process.env.CHANT_INCLUDE_CACHE_ROOT ?? join(homedir(), ".chant", "includes");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function sha256Digest(bytes: Uint8Array): string {
|
|
54
|
+
return `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `sha256:<hex>` -> `sha256-<hex>.yaml`; colons are not filesystem-safe everywhere. */
|
|
58
|
+
function cachePath(root: string, digest: string): string {
|
|
59
|
+
return join(root, `${digest.replace(":", "-")}.yaml`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ResolveIncludesOptions {
|
|
63
|
+
projectRoot: string;
|
|
64
|
+
/** Declarations keyed by entity (export) name. */
|
|
65
|
+
declarations: ReadonlyMap<string, K8sIncludeDeclaration>;
|
|
66
|
+
fetch?: IncludeFetcher;
|
|
67
|
+
readFile?: (path: string) => Uint8Array;
|
|
68
|
+
/** Cache directory; defaults to {@link includeCacheRoot}. */
|
|
69
|
+
cacheRoot?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function loadBytes(
|
|
73
|
+
name: string,
|
|
74
|
+
decl: K8sIncludeDeclaration,
|
|
75
|
+
opts: ResolveIncludesOptions,
|
|
76
|
+
): Promise<Uint8Array> {
|
|
77
|
+
const read = opts.readFile ?? ((path: string) => readFileSync(path));
|
|
78
|
+
const label = `k8sInclude "${name}" (${decl.source})`;
|
|
79
|
+
|
|
80
|
+
if (!isRemoteSource(decl.source)) {
|
|
81
|
+
const absolute = resolve(opts.projectRoot, decl.source);
|
|
82
|
+
let bytes: Uint8Array;
|
|
83
|
+
try {
|
|
84
|
+
bytes = read(absolute);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`${label}: file not readable at ${absolute} — ${err instanceof Error ? err.message : String(err)}`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (decl.digest !== undefined) {
|
|
91
|
+
const actual = sha256Digest(bytes);
|
|
92
|
+
if (actual !== decl.digest) {
|
|
93
|
+
throw new Error(`${label}: ${absolute} does not match its pinned digest: expected ${decl.digest}, found ${actual}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return bytes;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// The factory refuses an unpinned URL; this guards a declaration revived
|
|
100
|
+
// from the entity wire format or built by hand.
|
|
101
|
+
if (decl.digest === undefined) {
|
|
102
|
+
throw new Error(`${label}: a URL source must be pinned with a sha256 digest`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const root = opts.cacheRoot ?? includeCacheRoot();
|
|
106
|
+
const cached = cachePath(root, decl.digest);
|
|
107
|
+
if (existsSync(cached)) {
|
|
108
|
+
const bytes = readFileSync(cached);
|
|
109
|
+
// A corrupt or hand-edited cache entry is refetched, never trusted.
|
|
110
|
+
if (sha256Digest(bytes) === decl.digest) return bytes;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const fetcher = opts.fetch ?? defaultIncludeFetcher;
|
|
114
|
+
let bytes: Uint8Array;
|
|
115
|
+
try {
|
|
116
|
+
bytes = await fetcher(decl.source);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
throw new Error(`${label}: fetch failed — ${err instanceof Error ? err.message : String(err)}`);
|
|
119
|
+
}
|
|
120
|
+
const actual = sha256Digest(bytes);
|
|
121
|
+
if (actual !== decl.digest) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`${label}: fetched bytes do not match the pinned digest: expected ${decl.digest}, fetched ${actual}. ` +
|
|
124
|
+
`The content at the URL changed, or the digest is wrong.`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
mkdirSync(root, { recursive: true });
|
|
130
|
+
const tmp = `${cached}.${process.pid}.tmp`;
|
|
131
|
+
writeFileSync(tmp, bytes);
|
|
132
|
+
renameSync(tmp, cached);
|
|
133
|
+
} catch {
|
|
134
|
+
// A cache write failure is not fatal: the verified bytes are in memory,
|
|
135
|
+
// and the next build fetches again.
|
|
136
|
+
}
|
|
137
|
+
return bytes;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Parse, validate and patch one source's documents. */
|
|
141
|
+
function documentsOf(name: string, decl: K8sIncludeDeclaration, text: string): Array<Record<string, unknown>> {
|
|
142
|
+
const label = `k8sInclude "${name}" (${decl.source})`;
|
|
143
|
+
let parsed: unknown[];
|
|
144
|
+
try {
|
|
145
|
+
parsed = loadAll(text);
|
|
146
|
+
} catch (err) {
|
|
147
|
+
throw new Error(`${label} is not valid YAML: ${err instanceof Error ? err.message : String(err)}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const docs: Array<Record<string, unknown>> = [];
|
|
151
|
+
parsed.forEach((doc, i) => {
|
|
152
|
+
if (doc === null || doc === undefined) return;
|
|
153
|
+
if (typeof doc !== "object" || Array.isArray(doc)) {
|
|
154
|
+
throw new Error(`${label}: document ${i} is not a Kubernetes object`);
|
|
155
|
+
}
|
|
156
|
+
const record = doc as Record<string, unknown>;
|
|
157
|
+
if (typeof record.apiVersion !== "string" || !record.apiVersion || typeof record.kind !== "string" || !record.kind) {
|
|
158
|
+
throw new Error(`${label}: document ${i} has no string apiVersion and kind`);
|
|
159
|
+
}
|
|
160
|
+
docs.push(record);
|
|
161
|
+
});
|
|
162
|
+
if (docs.length === 0) throw new Error(`${label} contains no YAML documents`);
|
|
163
|
+
|
|
164
|
+
return applyRenderedPatches(docs, decl.patches, label);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Resolve every declaration into entities. Throws on the first one that
|
|
169
|
+
* does not resolve: a build that would silently drop an included bundle
|
|
170
|
+
* must not proceed.
|
|
171
|
+
*/
|
|
172
|
+
export async function resolveIncludes(opts: ResolveIncludesOptions): Promise<Map<string, Declarable>> {
|
|
173
|
+
const entities = new Map<string, Declarable>();
|
|
174
|
+
for (const [name, decl] of opts.declarations) {
|
|
175
|
+
const bytes = await loadBytes(name, decl, opts);
|
|
176
|
+
const text = Buffer.from(bytes).toString("utf-8");
|
|
177
|
+
for (const doc of documentsOf(name, decl, text)) {
|
|
178
|
+
// documentsOf checked apiVersion/kind, so the wrap cannot return null.
|
|
179
|
+
addRenderedEntity(entities, name, renderedManifestEntity(doc, decl.source, INCLUDE_SOURCE_ANNOTATION)!);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return entities;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Every `k8sInclude` declaration in an entity map, keyed by entity name. */
|
|
186
|
+
export function includeDeclarations(
|
|
187
|
+
entities: ReadonlyMap<string, Declarable>,
|
|
188
|
+
): Map<string, K8sIncludeDeclaration> {
|
|
189
|
+
const out = new Map<string, K8sIncludeDeclaration>();
|
|
190
|
+
for (const [name, entity] of entities) {
|
|
191
|
+
if (isK8sInclude(entity)) out.set(name, entity);
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The `buildRoots` contribution: the documents of every `k8sInclude`. */
|
|
197
|
+
export async function includeBuildRoot(
|
|
198
|
+
ctx: BuildRootContext,
|
|
199
|
+
overrides?: Pick<ResolveIncludesOptions, "fetch" | "readFile" | "cacheRoot">,
|
|
200
|
+
): Promise<BuildRootContribution> {
|
|
201
|
+
const declarations = includeDeclarations(ctx.entities ?? new Map());
|
|
202
|
+
if (declarations.size === 0) return { entities: new Map() };
|
|
203
|
+
return { entities: await resolveIncludes({ projectRoot: ctx.projectRoot, declarations, ...overrides }) };
|
|
204
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -61,6 +61,23 @@ export { microTime, isMicroTimeFormatted } from "./micro-time";
|
|
|
61
61
|
export { k8sManifest } from "./manifest-entity";
|
|
62
62
|
export type { RenderedManifestEntity } from "./manifest-entity";
|
|
63
63
|
|
|
64
|
+
// Plain YAML included as it is, local or pinned URL (#3566). The factory is
|
|
65
|
+
// pure; the bytes are read at buildRoots() (./include/resolve.ts).
|
|
66
|
+
export { k8sInclude, isK8sInclude, INCLUDE_SOURCE_ANNOTATION } from "./include/entity";
|
|
67
|
+
export type { K8sIncludeProps, K8sIncludeDeclaration } from "./include/entity";
|
|
68
|
+
|
|
69
|
+
// Patches on rendered documents: k8sInclude, kustomize roots, HelmRender (#3566).
|
|
70
|
+
export { renderedPatch, applyRenderedPatches, applyJsonPatch, applyMergePatch } from "./patch/rendered-patch";
|
|
71
|
+
export type {
|
|
72
|
+
RenderedPatch,
|
|
73
|
+
RenderedJsonPatch,
|
|
74
|
+
RenderedMergePatch,
|
|
75
|
+
RenderedSelector,
|
|
76
|
+
JsonPatchOperation,
|
|
77
|
+
MergePatchOf,
|
|
78
|
+
KindProps,
|
|
79
|
+
} from "./patch/rendered-patch";
|
|
80
|
+
|
|
64
81
|
// Generated entities — export everything from generated index
|
|
65
82
|
// After running `chant generate`, this re-exports all K8s resource classes
|
|
66
83
|
export * from "./generated/index";
|
|
@@ -70,7 +87,7 @@ export {
|
|
|
70
87
|
WebApp, StatefulApp, CronWorkload, AutoscaledService, WorkerPool, NamespaceEnv, NodeAgent,
|
|
71
88
|
BatchJob, SecureIngress, ConfiguredApp, SidecarApp, MonitoredService, NetworkIsolatedApp,
|
|
72
89
|
IrsaServiceAccount, AlbIngress, EbsStorageClass, EfsStorageClass, FluentBitAgent, ExternalDnsAgent, AdotCollector, OtelCollector,
|
|
73
|
-
OtelCollectorGateway, gatewayExporter, OTEL_COLLECTOR_ANNOTATIONS,
|
|
90
|
+
OtelCollectorGateway, gatewayExporter, OTEL_COLLECTOR_ANNOTATIONS, OtelOperatorCollector,
|
|
74
91
|
MetricsServer, WorkloadIdentityServiceAccount, GcePdStorageClass, FilestoreStorageClass, GkeGateway, ConfigConnectorContext,
|
|
75
92
|
GceIngress, CockroachDbCluster, CockroachDbRegionStack,
|
|
76
93
|
RayCluster, RayJob, RayService,
|
|
@@ -93,7 +110,7 @@ export type {
|
|
|
93
110
|
EbsStorageClassProps, EbsStorageClassResult, EfsStorageClassProps, EfsStorageClassResult,
|
|
94
111
|
FluentBitAgentProps, FluentBitAgentResult, ExternalDnsAgentProps, ExternalDnsAgentResult,
|
|
95
112
|
AdotCollectorProps, AdotCollectorResult,
|
|
96
|
-
OtelCollectorProps, OtelCollectorResult,
|
|
113
|
+
OtelCollectorProps, OtelCollectorResult, OtelOperatorCollectorProps, OtelOperatorCollectorResult, OtelOperatorMode,
|
|
97
114
|
OtelCollectorGatewayProps, OtelCollectorGatewayResult, GatewayExporterOptions, CollectorPolicyRule,
|
|
98
115
|
CollectorRole, GatewayRouting,
|
|
99
116
|
MetricsServerProps, MetricsServerResult,
|
|
@@ -145,5 +162,11 @@ export type { CRDSource, CRDSpec } from "./crd/types";
|
|
|
145
162
|
export { parseCRD, parseCRDSpec } from "./crd/parser";
|
|
146
163
|
export { loadCRDs, loadMultipleCRDs } from "./crd/loader";
|
|
147
164
|
|
|
165
|
+
// Project-local CRD classes (`k8s.crds`, `chant generate`): the generated
|
|
166
|
+
// module registers its kinds through this.
|
|
167
|
+
export { registerProjectKinds } from "./project-kinds";
|
|
168
|
+
export type { ProjectKind } from "./project-kinds";
|
|
169
|
+
export type { K8sProjectCrdSource } from "./config";
|
|
170
|
+
|
|
148
171
|
// Environment → cluster binding config shape (chant #1100)
|
|
149
172
|
export type { K8sChantConfig, K8sClusterProfile } from "./config";
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { manifestEntity, RENDERED_MANIFEST_MARKER, isRenderedManifestEntity } from "../manifest-entity";
|
|
17
17
|
import type { RenderedManifestEntity } from "../manifest-entity";
|
|
18
|
+
import type { Declarable } from "@intentius/chant/declarable";
|
|
18
19
|
|
|
19
20
|
export { RENDERED_MANIFEST_MARKER, isRenderedManifestEntity };
|
|
20
21
|
export type { RenderedManifestEntity };
|
|
@@ -25,16 +26,57 @@ export const KUSTOMIZE_ROOT_ANNOTATION = "chant.intentius.io/kustomize-root";
|
|
|
25
26
|
/**
|
|
26
27
|
* Wrap one rendered document. Returns null when the document has no string
|
|
27
28
|
* `apiVersion`/`kind` — not a Kubernetes object, nothing to declare.
|
|
29
|
+
*
|
|
30
|
+
* `annotation` is the provenance key: the kustomize root annotation by
|
|
31
|
+
* default, `k8sInclude`'s source annotation for an included file (#3566).
|
|
28
32
|
*/
|
|
29
33
|
export function renderedManifestEntity(
|
|
30
34
|
doc: Record<string, unknown>,
|
|
31
35
|
root: string,
|
|
36
|
+
annotation: string = KUSTOMIZE_ROOT_ANNOTATION,
|
|
32
37
|
): RenderedManifestEntity | null {
|
|
33
38
|
const metadata = { ...((doc.metadata as Record<string, unknown> | undefined) ?? {}) };
|
|
34
39
|
metadata.annotations = {
|
|
35
40
|
...((metadata.annotations as Record<string, unknown> | undefined) ?? {}),
|
|
36
|
-
[
|
|
41
|
+
[annotation]: root,
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
return manifestEntity({ ...doc, metadata });
|
|
40
45
|
}
|
|
46
|
+
|
|
47
|
+
/** `Deployment` + `my-app` → `deploymentMyApp`, the import path's naming. */
|
|
48
|
+
export function renderedLogicalId(kind: string, name: string | undefined): string {
|
|
49
|
+
const prefix = kind.charAt(0).toLowerCase() + kind.slice(1);
|
|
50
|
+
if (!name) return prefix;
|
|
51
|
+
const pascal = name
|
|
52
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
55
|
+
.join("");
|
|
56
|
+
return `${prefix}${pascal}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Add a rendered entity under a deterministic, human-readable key:
|
|
61
|
+
* `<prefix>/<kindName>`. Two documents can share kind+name (different
|
|
62
|
+
* namespaces, or different API groups with the same kind word), so a
|
|
63
|
+
* collision is qualified by namespace first, then numbered in document
|
|
64
|
+
* order. Returns the key used.
|
|
65
|
+
*/
|
|
66
|
+
export function addRenderedEntity(
|
|
67
|
+
entities: Map<string, Declarable>,
|
|
68
|
+
prefix: string,
|
|
69
|
+
entity: RenderedManifestEntity,
|
|
70
|
+
): string {
|
|
71
|
+
const metadata = entity.props.metadata as Record<string, unknown>;
|
|
72
|
+
const kind = entity.props.kind as string;
|
|
73
|
+
const name = typeof metadata.name === "string" ? metadata.name : undefined;
|
|
74
|
+
const namespace = typeof metadata.namespace === "string" ? metadata.namespace : undefined;
|
|
75
|
+
|
|
76
|
+
const base = `${prefix}/${renderedLogicalId(kind, name)}`;
|
|
77
|
+
let key = base;
|
|
78
|
+
if (entities.has(key) && namespace) key = `${base}.${namespace}`;
|
|
79
|
+
for (let n = 2; entities.has(key); n++) key = `${base}~${n}`;
|
|
80
|
+
entities.set(key, entity);
|
|
81
|
+
return key;
|
|
82
|
+
}
|