@intentius/chant-lexicon-k8s 0.124.52 → 0.124.55

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.
@@ -1 +1 @@
1
- {"version":3,"file":"kubectl-apply.d.ts","sourceRoot":"","sources":["../../src/components/kubectl-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,UAAU,EAAiD,MAAM,wCAAwC,CAAC;AAOxH;;;;;;;;;;GAUG;AACH,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,4DAA4D;AAC5D,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,sFAAsF;IACtF,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,2GAA2G;IAC3G,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,UAAU,WAAW;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,yGAAyG;IACzG,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,OAAO,CAAC;CAC/C;AAED,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACnE,KAAK,cAAc,GAAG,CAAC,I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
@@ -117,6 +117,36 @@ function dryRunDigest(ctx, member, input, documents, dryRun) {
117
117
  deletes: dryRun.deletes.map((r) => `${typeOf(r)}/${r.namespace ?? ""}/${r.name}`).sort(),
118
118
  });
119
119
  }
120
+ /**
121
+ * The plan of a step whose inputs wait on other components (#4467): one hole
122
+ * naming them, no artifact, and a digest over the environment, the member,
123
+ * the input and the unresolved names.
124
+ */
125
+ function unresolvedPlan(ctx, input, member, unresolved) {
126
+ const planDigest = computePlanDigest("kubectl-apply-plan", {
127
+ env: ctx.env,
128
+ member,
129
+ manifest: input.manifest ?? null,
130
+ context: input.context ?? null,
131
+ delete: input.delete ?? "never",
132
+ unresolved,
133
+ });
134
+ return {
135
+ member,
136
+ planDigest,
137
+ changeSet: {
138
+ member: {
139
+ member,
140
+ lexicon: "k8s",
141
+ planner: "chant",
142
+ status: "planned",
143
+ planDigest,
144
+ holes: [{ address: member, type: "kubectl-apply", reason: `inputs from ${unresolved.join(", ")}; re-checked on apply` }],
145
+ },
146
+ entries: [],
147
+ },
148
+ };
149
+ }
120
150
  /** The value at a dot path, or `undefined`. */
121
151
  function fieldAt(object, path) {
122
152
  return path.split(".").reduce((acc, key) => (acc !== null && typeof acc === "object" ? acc[key] : undefined), object);
@@ -269,10 +299,17 @@ export function createKubectlApplyCapability(apply, read, dryRun, readLive) {
269
299
  * would apply, release attributes set, server-side applied with
270
300
  * `dryRun=All` as the same field manager, each compared with its live
271
301
  * object. The member is the step's `stack`, or the component.
302
+ *
303
+ * A step whose inputs wait on another component's outputs (#4467) reads
304
+ * nothing and dry-runs nothing: its manifest or context may be one of
305
+ * them, so the member gets one hole and no artifact, as `gcp-apply` does.
272
306
  */
273
307
  async plan(ctx, stepInput) {
274
308
  const input = narrowedInput(ctx, stepInput);
275
309
  const member = input.stack ?? ctx.component;
310
+ const unresolved = [...(ctx.unresolvedInputs ?? [])].sort();
311
+ if (unresolved.length > 0)
312
+ return unresolvedPlan(ctx, input, member, unresolved);
276
313
  const read_ = (read ?? (await activities()).readManifestDocuments)(input.manifest);
277
314
  const targets = ctx.targets && ctx.targets.length > 0 ? ctx.targets : undefined;
278
315
  const documents = targets ? targetedDocuments(member, input.manifest, read_, targets) : read_;
@@ -12,7 +12,14 @@ import type { TemplateIR } from "@intentius/chant/import/parser";
12
12
  export declare class K8sGenerator implements TypeScriptGenerator {
13
13
  /** The imports for embedded content the current `generate()` call references (#2962). */
14
14
  private scope;
15
+ /** Whether the current `generate()` call wrote a `maskedValue(...)` (chant import --index, #4538). */
16
+ private usesMaskedValue;
15
17
  generate(ir: TemplateIR): GeneratedFile[];
18
+ /**
19
+ * The helper a value masked in the index reads its environment variable
20
+ * through, with the parameters it stands for listed above it.
21
+ */
22
+ private maskedValueHelper;
16
23
  /**
17
24
  * Resolve a K8s type name to a constructor class name.
18
25
  * Falls back to extracting the last segment of the type.
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/import/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,gCAAgC,CAAC;AAsH7E;;GAEG;AACH,qBAAa,YAAa,YAAW,mBAAmB;IACtD,yFAAyF;IACzF,OAAO,CAAC,KAAK,CAA+B;IAE5C,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,aAAa,EAAE,CAsDxC;IAED;;;OAGG;IACH,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,yBAAyB;IAmCjC,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,SAAS;IA0BjB,OAAO,CAAC,oBAAoB;IAuB5B,OAAO,CAAC,WAAW;CA6BpB"}
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/import/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,gCAAgC,CAAC;AAwH7E;;GAEG;AACH,qBAAa,YAAa,YAAW,mBAAmB;IACtD,yFAAyF;IACzF,OAAO,CAAC,KAAK,CAA+B;IAE5C,sGAAsG;IACtG,OAAO,CAAC,eAAe,CAAS;IAEhC,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,aAAa,EAAE,CAqExC;IAED;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,yBAAyB;IAmCjC,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,SAAS;IA2BjB,OAAO,CAAC,oBAAoB;IAwB5B,OAAO,CAAC,WAAW;CAiCpB"}
@@ -5,6 +5,8 @@
5
5
  * source code using the @intentius/chant-lexicon-k8s constructors.
6
6
  */
7
7
  import { EmbeddedImportScope, isEmbeddedReference, renderEmbeddedReference, } from "@intentius/chant/import/embedded";
8
+ import { SECRET_DECLARATION_ENTITY_TYPE } from "@intentius/chant/secret-provenance";
9
+ import { isMaskedValueRef } from "../index-import.js";
8
10
  const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
9
11
  /** An object key as TypeScript: bare when it is an identifier, quoted otherwise (`"config.yaml"`, `"app.kubernetes.io/name"`). */
10
12
  function propertyKey(key) {
@@ -110,9 +112,13 @@ export class K8sGenerator {
110
112
  constructor() {
111
113
  /** The imports for embedded content the current `generate()` call references (#2962). */
112
114
  this.scope = new EmbeddedImportScope("");
115
+ /** Whether the current `generate()` call wrote a `maskedValue(...)` (chant import --index, #4538). */
116
+ this.usesMaskedValue = false;
113
117
  }
114
118
  generate(ir) {
115
119
  const lines = [];
120
+ this.usesMaskedValue = false;
121
+ let usesDeclareSecret = false;
116
122
  // Collect which constructors are needed
117
123
  const usedConstructors = new Set();
118
124
  for (const resource of ir.resources) {
@@ -137,6 +143,13 @@ export class K8sGenerator {
137
143
  }
138
144
  // Emit resources
139
145
  for (const resource of ir.resources) {
146
+ // A Secret `chant import --index` read masked: a referenced secret the user supplies (#4538).
147
+ if (resource.type === SECRET_DECLARATION_ENTITY_TYPE) {
148
+ usesDeclareSecret = true;
149
+ lines.push(`export const ${resource.logicalId} = declareSecret(${this.emitLiteral(resource.properties, 0, resource.type)});`);
150
+ lines.push("");
151
+ continue;
152
+ }
140
153
  const cls = this.resolveClass(resource.type);
141
154
  if (!cls) {
142
155
  lines.push(`// TODO: unsupported type ${resource.type} (${resource.logicalId})`);
@@ -156,9 +169,31 @@ export class K8sGenerator {
156
169
  for (const m of code.matchAll(/\bnew ([A-Z][A-Za-z0-9_]*)\(/g))
157
170
  usedConstructors.add(m[1]);
158
171
  const imports = [...usedConstructors].sort().join(", ");
159
- const head = [`import { ${imports} } from "@intentius/chant-lexicon-k8s";`, ...this.scope.lines(), ""];
172
+ const head = [
173
+ ...(usesDeclareSecret ? [`import { declareSecret } from "@intentius/chant";`] : []),
174
+ ...(imports ? [`import { ${imports} } from "@intentius/chant-lexicon-k8s";`] : []),
175
+ ...this.scope.lines(),
176
+ "",
177
+ ];
178
+ if (this.usesMaskedValue)
179
+ head.push(...this.maskedValueHelper(ir), "");
160
180
  return [{ path: "main.ts", content: [...head, ...lines].join("\n") }];
161
181
  }
182
+ /**
183
+ * The helper a value masked in the index reads its environment variable
184
+ * through, with the parameters it stands for listed above it.
185
+ */
186
+ maskedValueHelper(ir) {
187
+ return [
188
+ "// Values the index masked. Set each environment variable before building:",
189
+ ...ir.parameters.map((p) => `// ${p.name}: ${(p.description ?? "").replace(/\r?\n/g, " ")}`),
190
+ "function maskedValue(name: string): any {",
191
+ " const raw = process.env[name];",
192
+ " if (raw === undefined) throw new Error(`${name} is not set: the value was masked in the index`);",
193
+ " return /^\\s*[[{]/.test(raw) ? JSON.parse(raw) : raw;",
194
+ "}",
195
+ ];
196
+ }
162
197
  /**
163
198
  * Resolve a K8s type name to a constructor class name.
164
199
  * Falls back to extracting the last segment of the type.
@@ -174,7 +209,7 @@ export class K8sGenerator {
174
209
  }
175
210
  collectNestedConstructors(props, used, parentType) {
176
211
  for (const [key, value] of Object.entries(props)) {
177
- if (value === undefined || value === null)
212
+ if (value === undefined || value === null || isMaskedValueRef(value))
178
213
  continue;
179
214
  // Special case: "ports" on Service resources → ServicePort
180
215
  if (key === "ports" && SERVICE_PORT_TYPES.has(parentType)) {
@@ -220,6 +255,8 @@ export class K8sGenerator {
220
255
  return "undefined";
221
256
  if (isEmbeddedReference(value))
222
257
  return renderEmbeddedReference(value, this.scope, depth * 2);
258
+ if (isMaskedValueRef(value))
259
+ return this.emitLiteral(value, depth, parentType);
223
260
  // Special case: "ports" on Service → ServicePort constructor
224
261
  if (key === "ports" && SERVICE_PORT_TYPES.has(parentType) && Array.isArray(value)) {
225
262
  return this.emitConstructorArray("ServicePort", value, depth, parentType);
@@ -243,6 +280,8 @@ export class K8sGenerator {
243
280
  const indent = " ".repeat(depth);
244
281
  const innerIndent = " ".repeat(depth + 1);
245
282
  const emitted = items.map((item) => {
283
+ if (isMaskedValueRef(item))
284
+ return this.emitLiteral(item, depth + 1, parentType);
246
285
  if (typeof item === "object" && item !== null && !Array.isArray(item)) {
247
286
  const propsStr = this.emitProps(item, depth + 1, parentType);
248
287
  return `new ${constructor}(${propsStr})`;
@@ -259,6 +298,10 @@ export class K8sGenerator {
259
298
  return "undefined";
260
299
  if (isEmbeddedReference(value))
261
300
  return renderEmbeddedReference(value, this.scope, depth * 2);
301
+ if (isMaskedValueRef(value)) {
302
+ this.usesMaskedValue = true;
303
+ return `maskedValue(${JSON.stringify(value.__k8sMaskedValue)})`;
304
+ }
262
305
  if (typeof value === "string")
263
306
  return JSON.stringify(value);
264
307
  if (typeof value === "number" || typeof value === "boolean")
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The k8s lexicon's identity rule for indexed objects (#4538, on #4523's
3
+ * matcher, ../../../packages/core/src/lifecycle/identity-match.ts).
4
+ *
5
+ * core's Kubernetes lister (packages/core/src/cloud-lister/kubernetes.ts)
6
+ * writes each object as:
7
+ *
8
+ * - `listedType` `<apiVersion>/<kind>` (`apps/v1/Deployment`, `v1/Secret`);
9
+ * - `location` its namespace, or `cluster` for a cluster-scoped kind;
10
+ * - `nativeId` `<namespace>/<name>`, or `<name>` for a cluster-scoped kind;
11
+ * - one cloud id, `k8s-uid`, the object's `metadata.uid`.
12
+ *
13
+ * apiVersion, kind, namespace and name are all spelled by the user, so a
14
+ * declaration that was never applied still matches its object by value.
15
+ * The uid is assigned by the API server, so no declaration states it. It
16
+ * still names an indexed node to the identity edge pass, where another
17
+ * object's `ownerReferences[].uid` points at its owner.
18
+ *
19
+ * The match is by lexicon kind, not by listed type: discovery lists a
20
+ * group at its preferred version, which need not be the version the
21
+ * lexicon writes, and the kind is the same at any version. Coverage is
22
+ * still read for the declared listed type, so a version the index did not
23
+ * list reads not observed, never absent.
24
+ *
25
+ * What cannot match (`no-binding`):
26
+ * - a name the declaration leaves out, spells with a reference, or asks the
27
+ * API server to generate (`metadata.generateName`);
28
+ * - a namespaced kind with no `metadata.namespace`. The namespace kubectl
29
+ * or a GitOps controller would apply it to is not in the declaration.
30
+ *
31
+ * A type the lexicon has no API address for (`K8s::Sops::EncryptedSecretFile`,
32
+ * a kind outside the generated surface) is `unsupported-kind`.
33
+ */
34
+ import type { DeclaredIdentity, IndexIdentity } from "@intentius/chant/lifecycle/identity-match";
35
+ import type { NodeIdentityValue } from "@intentius/chant/graph-refs";
36
+ import type { IRNode } from "@intentius/chant/graph-ir";
37
+ import { type K8sOperationTable } from "./api/operation-surface.js";
38
+ /** The location core's Kubernetes lister gives a cluster-scoped object. */
39
+ export declare const K8S_CLUSTER_LOCATION = "cluster";
40
+ /** The cloud id kind holding an object's `metadata.uid`. */
41
+ export declare const K8S_UID_CLOUD_ID = "k8s-uid";
42
+ /**
43
+ * The identifier a k8s declaration spells for the index, or why it spells
44
+ * none. `table` is the generated operation surface; a test passes one.
45
+ */
46
+ export declare function k8sDeclaredIdentity(entityType: string, props: Record<string, unknown>, table?: K8sOperationTable): DeclaredIdentity;
47
+ /** The values that name an indexed k8s object: its `<namespace>/<name>` and its uid. */
48
+ export declare function k8sNodeIdentities(node: IRNode): NodeIdentityValue[];
49
+ export declare function createK8sIndexIdentity(table?: K8sOperationTable): IndexIdentity;
50
+ export declare const k8sIndexIdentity: IndexIdentity;
51
+ //# sourceMappingURL=index-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-identity.d.ts","sourceRoot":"","sources":["../src/index-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AACjG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAA6D,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5H,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAsB1C;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CA+BnI;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAKnE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,CAAC,EAAE,iBAAiB,GAAG,aAAa,CAM/E;AAED,eAAO,MAAM,gBAAgB,EAAE,aAAwC,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { operationFor, operationTable } from "./api/operation-surface.js";
2
+ import { k8sListedTypeFor } from "./listed-types.js";
3
+ /** The location core's Kubernetes lister gives a cluster-scoped object. */
4
+ export const K8S_CLUSTER_LOCATION = "cluster";
5
+ /** The cloud id kind holding an object's `metadata.uid`. */
6
+ export const K8S_UID_CLOUD_ID = "k8s-uid";
7
+ function isRecord(v) {
8
+ return typeof v === "object" && v !== null && !Array.isArray(v);
9
+ }
10
+ const nonEmptyString = (v) => typeof v === "string" && v !== "";
11
+ /**
12
+ * The descriptor for `entityType` and whether its scope is known: from the
13
+ * generated table when there is one, else derived (and the derived scope is
14
+ * a guess, so it is not trusted for a declaration without a namespace).
15
+ */
16
+ function addressOf(entityType, table) {
17
+ const t = table ?? operationTable();
18
+ if (t[entityType])
19
+ return { op: t[entityType], scopeKnown: true };
20
+ // Only the generated table knows CRDs and cluster-scoped kinds. A test table stands alone.
21
+ if (table)
22
+ return undefined;
23
+ const derived = operationFor(entityType);
24
+ return derived ? { op: derived, scopeKnown: false } : undefined;
25
+ }
26
+ /**
27
+ * The identifier a k8s declaration spells for the index, or why it spells
28
+ * none. `table` is the generated operation surface; a test passes one.
29
+ */
30
+ export function k8sDeclaredIdentity(entityType, props, table) {
31
+ const address = addressOf(entityType, table);
32
+ if (!address) {
33
+ return { kind: "unmatchable", reason: "unsupported-kind", detail: `${entityType} has no Kubernetes API address on record` };
34
+ }
35
+ const { op, scopeKnown } = address;
36
+ const metadata = isRecord(props.metadata) ? props.metadata : {};
37
+ if (!nonEmptyString(metadata.name)) {
38
+ const detail = nonEmptyString(metadata.generateName)
39
+ ? `the name of ${entityType} is generated by the API server (metadata.generateName), so no declaration states it`
40
+ : `identity is not in the declaration (${entityType} metadata.name)`;
41
+ return { kind: "unmatchable", reason: "no-binding", detail };
42
+ }
43
+ const name = metadata.name;
44
+ const apiVersion = nonEmptyString(props.apiVersion) ? props.apiVersion : op.apiVersion;
45
+ const listedType = k8sListedTypeFor(apiVersion, op.kind);
46
+ const namespace = nonEmptyString(metadata.namespace) ? metadata.namespace : undefined;
47
+ if (scopeKnown && op.scope === "Cluster") {
48
+ return { kind: "identifier", listedType, identifier: name, global: true, location: K8S_CLUSTER_LOCATION, entityKind: entityType };
49
+ }
50
+ if (!namespace) {
51
+ return {
52
+ kind: "unmatchable",
53
+ reason: "no-binding",
54
+ detail: scopeKnown
55
+ ? `identity is not in the declaration (${entityType} ${name} names no metadata.namespace)`
56
+ : `${entityType} ${name} names no metadata.namespace, and without a generated surface its scope is not known`,
57
+ };
58
+ }
59
+ return { kind: "identifier", listedType, identifier: `${namespace}/${name}`, global: false, location: namespace, entityKind: entityType };
60
+ }
61
+ /** The values that name an indexed k8s object: its `<namespace>/<name>` and its uid. */
62
+ export function k8sNodeIdentities(node) {
63
+ const out = [];
64
+ if (node.nativeId)
65
+ out.push({ kind: "native-id", value: node.nativeId });
66
+ for (const c of node.facts?.cloudIds ?? [])
67
+ if (c.kind === K8S_UID_CLOUD_ID)
68
+ out.push({ kind: c.kind, value: c.value });
69
+ return out;
70
+ }
71
+ export function createK8sIndexIdentity(table) {
72
+ return {
73
+ substrate: "kubernetes",
74
+ declaredIdentity: (entityType, props) => k8sDeclaredIdentity(entityType, props, table),
75
+ nodeIdentities: k8sNodeIdentities,
76
+ };
77
+ }
78
+ export const k8sIndexIdentity = createK8sIndexIdentity();
@@ -0,0 +1,20 @@
1
+ import type { IRNode } from "@intentius/chant/graph-ir";
2
+ import type { IndexImportCodegen } from "@intentius/chant/lifecycle/index-import";
3
+ /** A property value standing for a masked one: the generator writes `maskedValue("<ENV_VAR>")`. */
4
+ export interface K8sMaskedValueRef {
5
+ /** The environment variable the value is read from. */
6
+ __k8sMaskedValue: string;
7
+ }
8
+ export declare function isMaskedValueRef(v: unknown): v is K8sMaskedValueRef;
9
+ /** The properties a declaration of the node's kind can hold. */
10
+ export declare function k8sImportProperties(node: IRNode): Record<string, unknown>;
11
+ /** The referenced-secret declaration for a Secret whose data the index masked, and the note naming what it held. */
12
+ export declare function k8sReferencedSecret(node: IRNode): {
13
+ properties: Record<string, unknown>;
14
+ note: string;
15
+ };
16
+ /** The environment variable a masked value is read from: the parameter name in upper snake case. */
17
+ export declare function maskedValueEnvVar(name: string): string;
18
+ export declare function createK8sIndexImport(): IndexImportCodegen;
19
+ export declare const k8sIndexImport: IndexImportCodegen;
20
+ //# sourceMappingURL=index-import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-import.d.ts","sourceRoot":"","sources":["../src/index-import.ts"],"names":[],"mappings":"AA+CA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAOlF,mGAAmG;AACnG,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,iBAAiB,CAEnE;AAiCD,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAezE;AAED,oHAAoH;AACpH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAevG;AAED,oGAAoG;AACpG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKtD;AAED,wBAAgB,oBAAoB,IAAI,kBAAkB,CAsCzD;AAED,eAAO,MAAM,cAAc,EAAE,kBAA2C,CAAC"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * The k8s lexicon's index import seam (#4538, on #4524's
3
+ * `chant import --index`).
4
+ *
5
+ * An indexed k8s object's `attrs` are its manifest without `apiVersion` and
6
+ * `kind` (./listed-types.ts), normalized by this lexicon's deep hooks, so
7
+ * the import IR is what the YAML parser (./import/parser.ts) writes for the
8
+ * same object and `K8sGenerator` turns it into source.
9
+ *
10
+ * What is left out of the properties:
11
+ * - what the deep hooks prune from a live object nobody declared: the
12
+ * envelope (`status`, `metadata.uid`, `resourceVersion`, ...), the
13
+ * controllers' bookkeeping labels and annotations, chant's own ownership
14
+ * labels (the serializer writes them again), server-assigned fields
15
+ * (`spec.clusterIP`) and values equal to the API server's defaults;
16
+ * - `metadata.deletionTimestamp` and `metadata.deletionGracePeriodSeconds`.
17
+ *
18
+ * `apiVersion` is kept only when the listed version is not the one the
19
+ * lexicon writes for the kind, as the YAML parser keeps an aliased one.
20
+ *
21
+ * Refused, by name:
22
+ * - an object with `metadata.ownerReferences`: its controller makes it
23
+ * (a Deployment's ReplicaSets and Pods), so the owner is what to import;
24
+ * - an `Event`, and a Secret of type `kubernetes.io/service-account-token`,
25
+ * which the cluster writes.
26
+ *
27
+ * References stay literals. A k8s object names another by its name, and
28
+ * that literal is how the lexicon spells it.
29
+ *
30
+ * Masked values. k8s has no template parameters, so a masked value takes
31
+ * one of two k8s forms:
32
+ * - a Secret whose `data` or `stringData` the index masked (all of it is:
33
+ * the k8s mask hook masks every value of a Secret) is written as a
34
+ * referenced secret, `declareSecret({ name, provenance: "referenced",
35
+ * scope: <namespace> })`. The Secret object stays in the cluster and the
36
+ * user supplies it out of band (kubectl, sops through a
37
+ * `committed-encrypted` declaration, an external secrets operator). Its
38
+ * key names and type go into the header comment. Nothing value-shaped is
39
+ * written;
40
+ * - any other masked value (a key-name match such as a ConfigMap's
41
+ * `db.password`, or a container's `secretKeyRef`) reads an environment
42
+ * variable at build time: `maskedValue("<ENV_VAR>")` in the generated
43
+ * file, which throws when the variable is unset. The variable is the
44
+ * parameter's name in upper snake case (`CONFIG_MAP_APP_DATA_DB_PASSWORD`). A value that starts with `{` or
45
+ * `[` is parsed as JSON, for an object the index masked whole.
46
+ */
47
+ import { MASKED } from "@intentius/chant/deep-observation";
48
+ import { SECRET_DECLARATION_ENTITY_TYPE } from "@intentius/chant/secret-provenance";
49
+ import { k8sDeepNormalizationHooks } from "./deep-observe-hooks.js";
50
+ import { operationFor } from "./api/operation-surface.js";
51
+ import { parseListedGvk } from "./listed-types.js";
52
+ export function isMaskedValueRef(v) {
53
+ return typeof v === "object" && v !== null && typeof v.__k8sMaskedValue === "string";
54
+ }
55
+ const SECRET_KIND = "K8s::Core::Secret";
56
+ const CLUSTER_WRITTEN_KINDS = new Set(["K8s::Core::Event", "K8s::Events::Event"]);
57
+ const CLUSTER_WRITTEN_SECRET_TYPES = new Set(["kubernetes.io/service-account-token"]);
58
+ const DROPPED_METADATA = new Set(["deletionTimestamp", "deletionGracePeriodSeconds"]);
59
+ function isRecord(v) {
60
+ return typeof v === "object" && v !== null && !Array.isArray(v);
61
+ }
62
+ function containsMasked(v) {
63
+ if (v === MASKED)
64
+ return true;
65
+ if (Array.isArray(v))
66
+ return v.some(containsMasked);
67
+ if (isRecord(v))
68
+ return Object.values(v).some(containsMasked);
69
+ return false;
70
+ }
71
+ /** `tree` without what the deep hooks prune from an undeclared live object. */
72
+ function pruneLive(entityType, tree, path, pattern) {
73
+ if (Array.isArray(tree))
74
+ return tree.map((v, i) => pruneLive(entityType, v, `${path}[${i}]`, `${pattern}[]`));
75
+ if (!isRecord(tree))
76
+ return tree;
77
+ const out = {};
78
+ for (const key of Object.keys(tree).sort()) {
79
+ const value = tree[key];
80
+ const p = path === "" ? key : `${path}.${key}`;
81
+ const pat = pattern === "" ? key : `${pattern}.${key}`;
82
+ if (k8sDeepNormalizationHooks.prune?.({ entityType, path: p, pattern: pat, key, value, side: "live", counterpart: "absent" }))
83
+ continue;
84
+ out[key] = pruneLive(entityType, value, p, pat);
85
+ }
86
+ return out;
87
+ }
88
+ /** The properties a declaration of the node's kind can hold. */
89
+ export function k8sImportProperties(node) {
90
+ const props = pruneLive(node.kind, node.attrs ?? {}, "", "");
91
+ if (isRecord(props.metadata)) {
92
+ const metadata = Object.fromEntries(Object.entries(props.metadata).filter(([k]) => !DROPPED_METADATA.has(k)));
93
+ for (const k of ["labels", "annotations"]) {
94
+ if (isRecord(metadata[k]) && Object.keys(metadata[k]).length === 0)
95
+ delete metadata[k];
96
+ }
97
+ props.metadata = metadata;
98
+ }
99
+ const gvk = node.listedType ? parseListedGvk(node.listedType) : undefined;
100
+ if (gvk) {
101
+ const listedApiVersion = gvk.group ? `${gvk.group}/${gvk.version}` : gvk.version;
102
+ if (operationFor(node.kind)?.apiVersion !== listedApiVersion)
103
+ return { apiVersion: listedApiVersion, ...props };
104
+ }
105
+ return props;
106
+ }
107
+ /** The referenced-secret declaration for a Secret whose data the index masked, and the note naming what it held. */
108
+ export function k8sReferencedSecret(node) {
109
+ const attrs = node.attrs ?? {};
110
+ const metadata = isRecord(attrs.metadata) ? attrs.metadata : {};
111
+ const name = typeof metadata.name === "string" ? metadata.name : (node.nativeId ?? node.id).split("/").pop();
112
+ const namespace = typeof metadata.namespace === "string" ? metadata.namespace : undefined;
113
+ const keys = [
114
+ ...new Set(["data", "stringData"].flatMap((f) => (isRecord(attrs[f]) ? Object.keys(attrs[f]) : []))),
115
+ ].sort();
116
+ const type = typeof attrs.type === "string" ? attrs.type : "Opaque";
117
+ return {
118
+ properties: { name, provenance: "referenced", ...(namespace ? { scope: namespace } : {}) },
119
+ note: `the Secret ${namespace ? `${namespace}/` : ""}${name} (type ${type}, keys ${keys.join(", ") || "none"}) was masked in the index, ` +
120
+ `so it is declared as a referenced secret: supply it out of band`,
121
+ };
122
+ }
123
+ /** The environment variable a masked value is read from: the parameter name in upper snake case. */
124
+ export function maskedValueEnvVar(name) {
125
+ return name
126
+ .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
127
+ .replace(/[^A-Za-z0-9]+/g, "_")
128
+ .toUpperCase();
129
+ }
130
+ export function createK8sIndexImport() {
131
+ return {
132
+ resource(node) {
133
+ if (!node.kind.startsWith("K8s::") || node.kind.split("::").length !== 3) {
134
+ return { unsupported: `${node.kind} is not a Kubernetes kind of the k8s lexicon` };
135
+ }
136
+ if (CLUSTER_WRITTEN_KINDS.has(node.kind))
137
+ return { unsupported: `${node.kind} objects are written by the cluster` };
138
+ const attrs = node.attrs ?? {};
139
+ const metadata = isRecord(attrs.metadata) ? attrs.metadata : {};
140
+ const owners = Array.isArray(metadata.ownerReferences) ? metadata.ownerReferences.filter(isRecord) : [];
141
+ if (owners.length > 0) {
142
+ const named = owners.map((o) => `${String(o.kind ?? "?")}/${String(o.name ?? "?")}`).join(", ");
143
+ return { unsupported: `owned by ${named} (metadata.ownerReferences): its controller makes this object, so import the owner` };
144
+ }
145
+ if (node.kind === SECRET_KIND) {
146
+ if (typeof attrs.type === "string" && CLUSTER_WRITTEN_SECRET_TYPES.has(attrs.type)) {
147
+ return { unsupported: `a Secret of type ${attrs.type} is written by the cluster` };
148
+ }
149
+ if (containsMasked(attrs.data) || containsMasked(attrs.stringData)) {
150
+ const { properties, note } = k8sReferencedSecret(node);
151
+ return { type: SECRET_DECLARATION_ENTITY_TYPE, properties, notes: [note] };
152
+ }
153
+ }
154
+ return { type: node.kind, properties: k8sImportProperties(node) };
155
+ },
156
+ // A k8s object names another by name; the literal is the lexicon's spelling.
157
+ reference: () => undefined,
158
+ secretParameter(name, context) {
159
+ return {
160
+ name,
161
+ type: "String",
162
+ description: `${context.path} of ${context.node.id}, masked in the index; set ${maskedValueEnvVar(name)} before building`,
163
+ required: true,
164
+ };
165
+ },
166
+ parameterReference: (name) => ({ __k8sMaskedValue: maskedValueEnvVar(name) }),
167
+ typeLabel: (node) => node.kind.split("::").pop() ?? "Resource",
168
+ };
169
+ }
170
+ export const k8sIndexImport = createK8sIndexImport();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "8c2dbae73b38228f15aa4d329e1f007428f75521fc58316372bf9f36fccf12ba",
4
+ "manifest.json": "1b0dd2eba4cd760b5a21ca729177e2f4c2d38215c6c6579aa1ef4feb4a6fb219",
5
5
  "meta.json": "e187074ca194ceaf969a3e2f9a85a0be42e7935de316817f309f6c9bee4eb952",
6
6
  "types/index.d.ts": "35f6ca4fa77c28ecad363920b444f27ab72f0fe49e82eb20e42824c312ac689b",
7
7
  "rules/argo-appset-single-project.ts": "afa9f310753aa2d475f35012b13135b2dfaebed2a35d44edbe185ebc07673674",
@@ -78,5 +78,5 @@
78
78
  "skills/chant-k8s-argo.md": "24c9a85b78a2fc5c6657424baac9cc6d6caff6f47605b8146b2c0082133181cf",
79
79
  "skills/chant-k8s-flux.md": "9670efc2e9854bd14686b5adeb707396b9030a4dcaee6529b30abf56efe2c50c"
80
80
  },
81
- "composite": "566471956199707bc69ad19d793706b60714f184d892766cd87baeb733d9a17c"
81
+ "composite": "f5e35cdbe53dd0ac219939997b071b587016e33c66c06c41169146f547e79650"
82
82
  }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Kubernetes discovery's type names as k8s lexicon kinds (#4521).
3
+ *
4
+ * behold#1029 lists a cluster through API discovery and LIST, and names each
5
+ * object's type by group, version and kind: `apps/v1/Deployment`, or
6
+ * `v1/Pod` for the core group. The lexicon's kinds are
7
+ * `K8s::<Group>::<Kind>`, the group's segment from the one rule every other
8
+ * path uses (./group-namespace.ts, as `gvkToTypeName` applies it). The
9
+ * version is not part of the kind.
10
+ *
11
+ * A listed object is the whole manifest. The deep reader compares it without
12
+ * `apiVersion` and `kind`, so those two are dropped before the hooks run.
13
+ */
14
+ import type { ListedTypeMapping } from "@intentius/chant/lifecycle/type-listing";
15
+ /** `apps/v1/Deployment` or `v1/Pod` as its group, version and kind. */
16
+ export declare function parseListedGvk(listedType: string): {
17
+ group: string;
18
+ version: string;
19
+ kind: string;
20
+ } | undefined;
21
+ /** `apiVersion` (`apps/v1`, `v1`) and kind as the listed type behold's lister writes. */
22
+ export declare function k8sListedTypeFor(apiVersion: string, kind: string): string;
23
+ /** The kind the group rule gives, before any check that the lexicon has it. */
24
+ export declare function k8sKindByRule(listedType: string): string | undefined;
25
+ /**
26
+ * The k8s kind for a discovery type, or undefined. The rule's answer must be
27
+ * a kind the lexicon generated; with nothing generated the rule's answer
28
+ * stands, as the lexicon's own discovery sweep does.
29
+ */
30
+ export declare function k8sKindForListedType(listedType: string, kinds?: ReadonlySet<string> | null): string | undefined;
31
+ /** A listed object in the tree the deep reader compares. */
32
+ export declare function k8sObservedTree(properties: Record<string, unknown>): Record<string, unknown>;
33
+ export declare const k8sListedTypes: ListedTypeMapping;
34
+ //# sourceMappingURL=listed-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listed-types.d.ts","sourceRoot":"","sources":["../src/listed-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAIjF,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAK/G;AAED,yFAAyF;AACzF,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIpE;AAYD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAuB,GAAG,MAAM,GAAG,SAAS,CAKjI;AAED,4DAA4D;AAC5D,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG5F;AAED,eAAO,MAAM,cAAc,EAAE,iBAI5B,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { operationTable } from "./api/operation-surface.js";
2
+ import { namespaceSegmentForGroup } from "./group-namespace.js";
3
+ /** `apps/v1/Deployment` or `v1/Pod` as its group, version and kind. */
4
+ export function parseListedGvk(listedType) {
5
+ const parts = listedType.split("/");
6
+ if (parts.length === 2 && parts[0] && parts[1])
7
+ return { group: "", version: parts[0], kind: parts[1] };
8
+ if (parts.length === 3 && parts[0] && parts[1] && parts[2])
9
+ return { group: parts[0], version: parts[1], kind: parts[2] };
10
+ return undefined;
11
+ }
12
+ /** `apiVersion` (`apps/v1`, `v1`) and kind as the listed type behold's lister writes. */
13
+ export function k8sListedTypeFor(apiVersion, kind) {
14
+ return `${apiVersion}/${kind}`;
15
+ }
16
+ /** The kind the group rule gives, before any check that the lexicon has it. */
17
+ export function k8sKindByRule(listedType) {
18
+ const gvk = parseListedGvk(listedType);
19
+ if (!gvk)
20
+ return undefined;
21
+ return `K8s::${namespaceSegmentForGroup(gvk.group)}::${gvk.kind}`;
22
+ }
23
+ let cachedKinds;
24
+ /** The entity types of the generated operation surface, or null in a checkout that has not generated. */
25
+ function generatedKinds() {
26
+ if (cachedKinds !== undefined)
27
+ return cachedKinds;
28
+ const table = operationTable();
29
+ cachedKinds = Object.keys(table).length > 0 ? new Set(Object.keys(table)) : null;
30
+ return cachedKinds;
31
+ }
32
+ /**
33
+ * The k8s kind for a discovery type, or undefined. The rule's answer must be
34
+ * a kind the lexicon generated; with nothing generated the rule's answer
35
+ * stands, as the lexicon's own discovery sweep does.
36
+ */
37
+ export function k8sKindForListedType(listedType, kinds = generatedKinds()) {
38
+ const kind = k8sKindByRule(listedType);
39
+ if (kind === undefined)
40
+ return undefined;
41
+ if (kinds && !kinds.has(kind))
42
+ return undefined;
43
+ return kind;
44
+ }
45
+ /** A listed object in the tree the deep reader compares. */
46
+ export function k8sObservedTree(properties) {
47
+ const { apiVersion: _apiVersion, kind: _kind, ...rest } = properties;
48
+ return rest;
49
+ }
50
+ export const k8sListedTypes = {
51
+ substrate: "kubernetes",
52
+ kindFor: (listedType) => k8sKindForListedType(listedType),
53
+ observedTree: (properties) => k8sObservedTree(properties),
54
+ };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k8s",
3
- "version": "0.124.52",
3
+ "version": "0.124.55",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "K8s",
6
6
  "intrinsics": [],