@intentius/chant-lexicon-k8s 0.124.52 → 0.124.54
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/components/kubectl-apply.d.ts.map +1 -1
- package/dist/components/kubectl-apply.js +37 -0
- package/dist/integrity.json +2 -2
- package/dist/listed-types.d.ts +34 -0
- package/dist/listed-types.d.ts.map +1 -0
- package/dist/listed-types.js +54 -0
- package/dist/manifest.json +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +7 -0
- package/dist/reference-catalog.d.ts +3 -0
- package/dist/reference-catalog.d.ts.map +1 -0
- package/dist/reference-catalog.js +138 -0
- package/package.json +5 -5
- package/src/components/kubectl-apply.test.ts +26 -0
- package/src/components/kubectl-apply.ts +37 -0
- package/src/listed-types.test.ts +76 -0
- package/src/listed-types.ts +70 -0
- package/src/plugin.ts +9 -0
- package/src/reference-catalog.test.ts +173 -0
- package/src/reference-catalog.ts +157 -0
- package/src/testdata/indexed/listing.json +67 -0
|
@@ -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,EA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C1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACnD;AAED,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,8GAA8G;IAC9G,KAAK,EAAE,MAAM,CAAC;CACf;AA4CD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAoB/J;AAUD;;;uCAGuC;AACvC,wBAAgB,4BAA4B,CAC1C,KAAK,CAAC,EAAE,OAAO,EACf,IAAI,CAAC,EAAE,cAAc,EACrB,MAAM,CAAC,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE,UAAU,GACpB,UAAU,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAwJpD;AAED,eAAO,MAAM,sBAAsB,oDAAiC,CAAC"}
|
|
@@ -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_;
|
package/dist/integrity.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"algorithm": "sha256",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"manifest.json": "
|
|
4
|
+
"manifest.json": "eae38679a1e122b4035fbfc82e0ddc3be5b43ee409bf91d2d3b698125386a727",
|
|
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": "
|
|
81
|
+
"composite": "edfc26a4ad39415e44c3eefa79a160540722b87e3d857db56d5c71737a2efa7c"
|
|
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
|
+
};
|
package/dist/manifest.json
CHANGED
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAqC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAqC,MAAM,0BAA0B,CAAC;AAmCjG,eAAO,MAAM,SAAS,EAAE,aAqwBvB,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -23,6 +23,8 @@ import { k8sHover } from "./lsp/hover.js";
|
|
|
23
23
|
import { K8sParser } from "./import/parser.js";
|
|
24
24
|
import { K8sGenerator } from "./import/generator.js";
|
|
25
25
|
import { k8sDeepNormalizationHooks } from "./deep-observe-hooks.js";
|
|
26
|
+
import { k8sListedTypes } from "./listed-types.js";
|
|
27
|
+
import { k8sReferenceCatalog } from "./reference-catalog.js";
|
|
26
28
|
import { LABEL_OWNERSHIP_KEYS } from "@intentius/chant/ownership";
|
|
27
29
|
import { k8sConfigSchema } from "./config-schema.js";
|
|
28
30
|
import { renderKustomizeRoots } from "./kustomize/root.js";
|
|
@@ -754,4 +756,9 @@ const { deployment, service, serviceMonitor, prometheusRule } = MonitoredService
|
|
|
754
756
|
return observeResourcesDeepK8s(options);
|
|
755
757
|
},
|
|
756
758
|
deepNormalizationHooks: k8sDeepNormalizationHooks,
|
|
759
|
+
// Cloud inventory type names to kinds, for an indexed resource (#4521).
|
|
760
|
+
listedTypes: k8sListedTypes,
|
|
761
|
+
// How its resources reference each other, for chant's catalog pass over an
|
|
762
|
+
// index and a declared graph (#4535; behold#1005 retires behold's matcher on it).
|
|
763
|
+
referenceCatalog: k8sReferenceCatalog,
|
|
757
764
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-catalog.d.ts","sourceRoot":"","sources":["../src/reference-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,gBAAgB,EAAW,MAAM,6BAA6B,CAAC;AA4J3F,eAAO,MAAM,mBAAmB,EAAE,gBAAuC,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kubernetes reference catalog (#4535): how Kubernetes objects name each
|
|
3
|
+
* other, so chant's catalog pass (`reconstructIndexedEdges`, #4522) draws
|
|
4
|
+
* their edges over an index and over a declared graph, and behold can retire
|
|
5
|
+
* its name matcher (behold#1005).
|
|
6
|
+
*
|
|
7
|
+
* ## Shape and scope
|
|
8
|
+
*
|
|
9
|
+
* The paths are the manifest's own (`metadata`, `spec`), which is the tree a
|
|
10
|
+
* listed object becomes once `apiVersion` and `kind` are dropped
|
|
11
|
+
* (./listed-types.ts `k8sObservedTree`) and the shape the lexicon's declared
|
|
12
|
+
* props have. Every target is identified by `metadata.name`.
|
|
13
|
+
*
|
|
14
|
+
* A name is unique only inside its namespace. Over an index a namespaced
|
|
15
|
+
* object's location is its namespace (behold#1025), so the scoped join key
|
|
16
|
+
* (behold#1023's ruling) keeps a `serviceAccountName: default` inside its own
|
|
17
|
+
* namespace, and a namespaced holder also reaches cluster-scoped objects (a
|
|
18
|
+
* `Namespace`, a `ClusterRole`, a `StorageClass`). A declared graph is one
|
|
19
|
+
* scope, so two `default` service accounts in two namespaces make that
|
|
20
|
+
* reference ambiguous there, and it draws no edge.
|
|
21
|
+
*
|
|
22
|
+
* ## Multi-kind fields
|
|
23
|
+
*
|
|
24
|
+
* A field that can name one of several kinds (`scaleTargetRef`, `roleRef`,
|
|
25
|
+
* a binding's `subjects`, an owner reference) has one rule per kind, each
|
|
26
|
+
* `optional`, so a value that names a node of another kind is not dangling
|
|
27
|
+
* under the rules it does not match.
|
|
28
|
+
*
|
|
29
|
+
* ## Values that may name a cloud resource
|
|
30
|
+
*
|
|
31
|
+
* A container's env var value can be the literal name of a bucket it uses
|
|
32
|
+
* (behold#166's case: `ASSET_BUCKET` set to the bucket's `BucketName`). The
|
|
33
|
+
* env-value rules join such a value to an `AWS::S3::Bucket` of that name, and
|
|
34
|
+
* are `optional`, since most env values name nothing. Over an index the
|
|
35
|
+
* cluster and the AWS account are two scopes, so the join only draws on a
|
|
36
|
+
* declared graph (one scope), which is where behold's matcher drew it.
|
|
37
|
+
*
|
|
38
|
+
* ## What this does not do
|
|
39
|
+
*
|
|
40
|
+
* - Label selectors. A Service selects pods by labels, and the standard keys
|
|
41
|
+
* (`app.kubernetes.io/name`) contain dots, which `readPath` reads as path
|
|
42
|
+
* separators. Only the bare `app` label is matched: a Service's
|
|
43
|
+
* `spec.selector.app` to a workload whose pod template carries the same
|
|
44
|
+
* `app` label. behold's own k8s pass (src/k8s-edges.ts) still joins full
|
|
45
|
+
* selectors on behold's side.
|
|
46
|
+
* - Annotations, for the same reason (`eks.amazonaws.com/role-arn`).
|
|
47
|
+
*/
|
|
48
|
+
/** Workload kinds and the path to their pod spec. */
|
|
49
|
+
const POD_SPECS = [
|
|
50
|
+
["K8s::Core::Pod", "spec"],
|
|
51
|
+
["K8s::Apps::Deployment", "spec.template.spec"],
|
|
52
|
+
["K8s::Apps::StatefulSet", "spec.template.spec"],
|
|
53
|
+
["K8s::Apps::DaemonSet", "spec.template.spec"],
|
|
54
|
+
["K8s::Apps::ReplicaSet", "spec.template.spec"],
|
|
55
|
+
["K8s::Batch::Job", "spec.template.spec"],
|
|
56
|
+
["K8s::Batch::CronJob", "spec.jobTemplate.spec.template.spec"],
|
|
57
|
+
];
|
|
58
|
+
/** Kinds that sit in a namespace, so `metadata.namespace` places them. */
|
|
59
|
+
const NAMESPACED_KINDS = [
|
|
60
|
+
...POD_SPECS.map(([kind]) => kind),
|
|
61
|
+
"K8s::Core::Service",
|
|
62
|
+
"K8s::Core::ConfigMap",
|
|
63
|
+
"K8s::Core::Secret",
|
|
64
|
+
"K8s::Core::ServiceAccount",
|
|
65
|
+
"K8s::Core::PersistentVolumeClaim",
|
|
66
|
+
"K8s::Networking::Ingress",
|
|
67
|
+
"K8s::Networking::NetworkPolicy",
|
|
68
|
+
"K8s::Autoscaling::HorizontalPodAutoscaler",
|
|
69
|
+
"K8s::Policy::PodDisruptionBudget",
|
|
70
|
+
"K8s::Rbac::Role",
|
|
71
|
+
"K8s::Rbac::RoleBinding",
|
|
72
|
+
];
|
|
73
|
+
/** Kinds other objects name by `metadata.name`. */
|
|
74
|
+
const NAMED_KINDS = [
|
|
75
|
+
...NAMESPACED_KINDS,
|
|
76
|
+
"K8s::Core::Namespace",
|
|
77
|
+
"K8s::Core::PersistentVolume",
|
|
78
|
+
"K8s::Networking::IngressClass",
|
|
79
|
+
"K8s::Storage::StorageClass",
|
|
80
|
+
"K8s::Rbac::ClusterRole",
|
|
81
|
+
];
|
|
82
|
+
/** Workloads whose pod template a Service's `app` selector can match. */
|
|
83
|
+
const SELECTED_WORKLOADS = ["K8s::Apps::Deployment", "K8s::Apps::StatefulSet", "K8s::Apps::DaemonSet"];
|
|
84
|
+
const identities = NAMED_KINDS.map((kind) => ({
|
|
85
|
+
kind,
|
|
86
|
+
ids: SELECTED_WORKLOADS.includes(kind) ? ["metadata.name", "spec.template.metadata.labels.app"] : ["metadata.name"],
|
|
87
|
+
}));
|
|
88
|
+
const ref = (from, path, targetKind, label, relation = "reference") => ({ from, path, targetKind, relation, label });
|
|
89
|
+
const anyOf = (from, path, targetKinds, label) => targetKinds.map((targetKind) => ({ from, path, targetKind, relation: "reference", label, optional: true }));
|
|
90
|
+
/** What a pod spec names: its service account, mounted config and secrets, claims, pull secrets. */
|
|
91
|
+
function podSpecRules(kind, p) {
|
|
92
|
+
const containers = [`${p}.containers[]`, `${p}.initContainers[]`];
|
|
93
|
+
return [
|
|
94
|
+
ref(kind, `${p}.serviceAccountName`, "K8s::Core::ServiceAccount", "runs as"),
|
|
95
|
+
ref(kind, `${p}.volumes[].configMap.name`, "K8s::Core::ConfigMap", "mounts"),
|
|
96
|
+
ref(kind, `${p}.volumes[].secret.secretName`, "K8s::Core::Secret", "mounts"),
|
|
97
|
+
ref(kind, `${p}.volumes[].persistentVolumeClaim.claimName`, "K8s::Core::PersistentVolumeClaim", "mounts"),
|
|
98
|
+
ref(kind, `${p}.volumes[].projected.sources[].configMap.name`, "K8s::Core::ConfigMap", "mounts"),
|
|
99
|
+
ref(kind, `${p}.volumes[].projected.sources[].secret.name`, "K8s::Core::Secret", "mounts"),
|
|
100
|
+
ref(kind, `${p}.imagePullSecrets[].name`, "K8s::Core::Secret", "pulls with"),
|
|
101
|
+
...containers.flatMap((c) => [
|
|
102
|
+
ref(kind, `${c}.envFrom[].configMapRef.name`, "K8s::Core::ConfigMap", "env from"),
|
|
103
|
+
ref(kind, `${c}.envFrom[].secretRef.name`, "K8s::Core::Secret", "env from"),
|
|
104
|
+
ref(kind, `${c}.env[].valueFrom.configMapKeyRef.name`, "K8s::Core::ConfigMap", "env from"),
|
|
105
|
+
ref(kind, `${c}.env[].valueFrom.secretKeyRef.name`, "K8s::Core::Secret", "env from"),
|
|
106
|
+
]),
|
|
107
|
+
// behold#166: an env var whose value is a bucket's literal name.
|
|
108
|
+
{ from: kind, path: `${p}.containers[].env[].value`, targetKind: "AWS::S3::Bucket", relation: "reference", label: "uses bucket", optional: true },
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
const refs = [
|
|
112
|
+
// ── containment: the namespace an object is in ──
|
|
113
|
+
...NAMESPACED_KINDS.map((kind) => ref(kind, "metadata.namespace", "K8s::Core::Namespace", "in namespace", "containment")),
|
|
114
|
+
// ── owner references, by name inside the namespace ──
|
|
115
|
+
...anyOf("K8s::Core::Pod", "metadata.ownerReferences[].name", ["K8s::Apps::ReplicaSet", "K8s::Apps::StatefulSet", "K8s::Apps::DaemonSet", "K8s::Batch::Job"], "owned by"),
|
|
116
|
+
...anyOf("K8s::Apps::ReplicaSet", "metadata.ownerReferences[].name", ["K8s::Apps::Deployment"], "owned by"),
|
|
117
|
+
...anyOf("K8s::Batch::Job", "metadata.ownerReferences[].name", ["K8s::Batch::CronJob"], "owned by"),
|
|
118
|
+
// ── pod specs ──
|
|
119
|
+
...POD_SPECS.flatMap(([kind, p]) => podSpecRules(kind, p)),
|
|
120
|
+
// ── services and ingress ──
|
|
121
|
+
...anyOf("K8s::Core::Service", "spec.selector.app", SELECTED_WORKLOADS, "selects"),
|
|
122
|
+
ref("K8s::Networking::Ingress", "spec.rules[].http.paths[].backend.service.name", "K8s::Core::Service", "routes to"),
|
|
123
|
+
ref("K8s::Networking::Ingress", "spec.defaultBackend.service.name", "K8s::Core::Service", "routes to"),
|
|
124
|
+
ref("K8s::Networking::Ingress", "spec.tls[].secretName", "K8s::Core::Secret", "tls"),
|
|
125
|
+
ref("K8s::Networking::Ingress", "spec.ingressClassName", "K8s::Networking::IngressClass", "class"),
|
|
126
|
+
// ── scaling, storage, RBAC ──
|
|
127
|
+
...anyOf("K8s::Autoscaling::HorizontalPodAutoscaler", "spec.scaleTargetRef.name", ["K8s::Apps::Deployment", "K8s::Apps::StatefulSet", "K8s::Apps::ReplicaSet"], "scales"),
|
|
128
|
+
ref("K8s::Core::PersistentVolumeClaim", "spec.volumeName", "K8s::Core::PersistentVolume", "bound to"),
|
|
129
|
+
ref("K8s::Core::PersistentVolumeClaim", "spec.storageClassName", "K8s::Storage::StorageClass", "class"),
|
|
130
|
+
ref("K8s::Core::PersistentVolume", "spec.storageClassName", "K8s::Storage::StorageClass", "class"),
|
|
131
|
+
...anyOf("K8s::Rbac::RoleBinding", "roleRef.name", ["K8s::Rbac::Role", "K8s::Rbac::ClusterRole"], "binds"),
|
|
132
|
+
...anyOf("K8s::Rbac::RoleBinding", "subjects[].name", ["K8s::Core::ServiceAccount"], "grants"),
|
|
133
|
+
...anyOf("K8s::Rbac::ClusterRoleBinding", "roleRef.name", ["K8s::Rbac::ClusterRole"], "binds"),
|
|
134
|
+
...anyOf("K8s::Rbac::ClusterRoleBinding", "subjects[].name", ["K8s::Core::ServiceAccount"], "grants"),
|
|
135
|
+
ref("K8s::Core::ServiceAccount", "secrets[].name", "K8s::Core::Secret", "token"),
|
|
136
|
+
ref("K8s::Core::ServiceAccount", "imagePullSecrets[].name", "K8s::Core::Secret", "pulls with"),
|
|
137
|
+
];
|
|
138
|
+
export const k8sReferenceCatalog = { identities, refs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-k8s",
|
|
3
|
-
"version": "0.124.
|
|
3
|
+
"version": "0.124.54",
|
|
4
4
|
"description": "Kubernetes lexicon for chant — declarative IaC in TypeScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -74,13 +74,13 @@
|
|
|
74
74
|
"build": "../../scripts/tsc7.sh -p tsconfig.build.json --sourceMap false && tsc-alias -p tsconfig.build.json && cp src/generated/index.d.ts dist/generated/index.d.d.ts"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@intentius/chant-lexicon-otel": "^0.124.
|
|
78
|
-
"@intentius/chant-lexicon-prometheus": "^0.124.
|
|
77
|
+
"@intentius/chant-lexicon-otel": "^0.124.54",
|
|
78
|
+
"@intentius/chant-lexicon-prometheus": "^0.124.54",
|
|
79
79
|
"js-yaml": "^4.3.1",
|
|
80
80
|
"@types/js-yaml": "^4.0.9"
|
|
81
81
|
},
|
|
82
82
|
"optionalDependencies": {
|
|
83
|
-
"@intentius/chant-k8s-client": "^0.124.
|
|
83
|
+
"@intentius/chant-k8s-client": "^0.124.54"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@intentius/chant": "*",
|
|
@@ -88,6 +88,6 @@
|
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
90
|
"zod": "^4.3.6",
|
|
91
|
-
"@intentius/chant": "^0.124.
|
|
91
|
+
"@intentius/chant": "^0.124.54"
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -318,6 +318,32 @@ describe("kubectl-apply plan: a server-side dry-run diff (#3998)", () => {
|
|
|
318
318
|
await cap.run({ env: "prod", component: "api", plans: { other: { kind: "kubectl-apply-plan", planDigest: "sha256:x", documents: [] } } }, { manifest: "k8s.yaml", stack: "web" });
|
|
319
319
|
expect(applied).toEqual([{ manifest: "k8s.yaml", environment: "prod", stack: "web" }]);
|
|
320
320
|
});
|
|
321
|
+
|
|
322
|
+
test("inputs waiting on another component read nothing and leave a hole (#4467)", async () => {
|
|
323
|
+
const cap = createKubectlApplyCapability(
|
|
324
|
+
noApply,
|
|
325
|
+
() => {
|
|
326
|
+
throw new Error("no read expected");
|
|
327
|
+
},
|
|
328
|
+
async () => {
|
|
329
|
+
throw new Error("no dry run expected");
|
|
330
|
+
},
|
|
331
|
+
async () => {
|
|
332
|
+
throw new Error("no live read expected");
|
|
333
|
+
},
|
|
334
|
+
);
|
|
335
|
+
const ctx = { env: "prod", component: "api", unresolvedInputs: ["network", "cluster"] };
|
|
336
|
+
const input = { manifest: undefined as unknown as string, stack: "web", outputs: { host: { object: "Service/prod/web", field: "spec.clusterIP" } } };
|
|
337
|
+
const planned = await cap.plan!(ctx, input);
|
|
338
|
+
expect(planned.member).toBe("web");
|
|
339
|
+
expect(planned.artifact).toBeUndefined();
|
|
340
|
+
expect(planned.outputs).toBeUndefined();
|
|
341
|
+
expect(planned.changeSet!.entries).toEqual([]);
|
|
342
|
+
expect(planned.changeSet!.member.holes).toEqual([{ address: "web", type: "kubectl-apply", reason: "inputs from cluster, network; re-checked on apply" }]);
|
|
343
|
+
expect(isPlanDigest(planned.planDigest)).toBe(true);
|
|
344
|
+
const other = await cap.plan!({ ...ctx, unresolvedInputs: ["network"] }, input);
|
|
345
|
+
expect(other.planDigest).not.toBe(planned.planDigest);
|
|
346
|
+
});
|
|
321
347
|
});
|
|
322
348
|
|
|
323
349
|
describe("kubectl-apply outputs: the fields a step names (#3999)", () => {
|
|
@@ -259,6 +259,37 @@ function dryRunDigest(
|
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
+
/**
|
|
263
|
+
* The plan of a step whose inputs wait on other components (#4467): one hole
|
|
264
|
+
* naming them, no artifact, and a digest over the environment, the member,
|
|
265
|
+
* the input and the unresolved names.
|
|
266
|
+
*/
|
|
267
|
+
function unresolvedPlan(ctx: DeployContext, input: KubectlApplyInput, member: string, unresolved: string[]): CapabilityPlan {
|
|
268
|
+
const planDigest = computePlanDigest("kubectl-apply-plan", {
|
|
269
|
+
env: ctx.env,
|
|
270
|
+
member,
|
|
271
|
+
manifest: input.manifest ?? null,
|
|
272
|
+
context: input.context ?? null,
|
|
273
|
+
delete: input.delete ?? "never",
|
|
274
|
+
unresolved,
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
member,
|
|
278
|
+
planDigest,
|
|
279
|
+
changeSet: {
|
|
280
|
+
member: {
|
|
281
|
+
member,
|
|
282
|
+
lexicon: "k8s",
|
|
283
|
+
planner: "chant",
|
|
284
|
+
status: "planned",
|
|
285
|
+
planDigest,
|
|
286
|
+
holes: [{ address: member, type: "kubectl-apply", reason: `inputs from ${unresolved.join(", ")}; re-checked on apply` }],
|
|
287
|
+
},
|
|
288
|
+
entries: [],
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
262
293
|
export interface KubectlApplyInput {
|
|
263
294
|
/** Path to a manifest file, or a directory of them. */
|
|
264
295
|
manifest: string;
|
|
@@ -464,10 +495,16 @@ export function createKubectlApplyCapability(
|
|
|
464
495
|
* would apply, release attributes set, server-side applied with
|
|
465
496
|
* `dryRun=All` as the same field manager, each compared with its live
|
|
466
497
|
* object. The member is the step's `stack`, or the component.
|
|
498
|
+
*
|
|
499
|
+
* A step whose inputs wait on another component's outputs (#4467) reads
|
|
500
|
+
* nothing and dry-runs nothing: its manifest or context may be one of
|
|
501
|
+
* them, so the member gets one hole and no artifact, as `gcp-apply` does.
|
|
467
502
|
*/
|
|
468
503
|
async plan(ctx: DeployContext, stepInput: KubectlApplyInput): Promise<CapabilityPlan> {
|
|
469
504
|
const input = narrowedInput(ctx, stepInput);
|
|
470
505
|
const member = input.stack ?? ctx.component;
|
|
506
|
+
const unresolved = [...(ctx.unresolvedInputs ?? [])].sort();
|
|
507
|
+
if (unresolved.length > 0) return unresolvedPlan(ctx, input, member, unresolved);
|
|
471
508
|
const read_ = (read ?? (await activities()).readManifestDocuments)(input.manifest);
|
|
472
509
|
const targets = ctx.targets && ctx.targets.length > 0 ? ctx.targets : undefined;
|
|
473
510
|
const documents = targets ? targetedDocuments(member, input.manifest, read_, targets) : read_;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4521 on the k8s lexicon: discovery's group/version/kind mapped to kinds,
|
|
3
|
+
* and a fixture listing typed into nodes through the k8s hooks.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { describe, expect, it } from "vitest";
|
|
8
|
+
import { typeListing, type ListingLexicon, type ListingResult } from "@intentius/chant/lifecycle/type-listing";
|
|
9
|
+
import { MASKED } from "@intentius/chant/deep-observation";
|
|
10
|
+
import { operationTable } from "./api/operation-surface";
|
|
11
|
+
import { k8sKindForListedType, k8sListedTypeFor } from "./listed-types";
|
|
12
|
+
import { k8sPlugin } from "./plugin";
|
|
13
|
+
|
|
14
|
+
const here = import.meta.dirname;
|
|
15
|
+
const surface = JSON.parse(readFileSync(join(here, "..", "surface.snapshot.json"), "utf-8")) as {
|
|
16
|
+
entries: Record<string, { kind: string; resourceType: string }>;
|
|
17
|
+
};
|
|
18
|
+
const KINDS: ReadonlySet<string> = new Set(
|
|
19
|
+
Object.values(surface.entries).filter((e) => e.kind === "resource").map((e) => e.resourceType),
|
|
20
|
+
);
|
|
21
|
+
const listing = JSON.parse(readFileSync(join(here, "testdata", "indexed", "listing.json"), "utf-8")) as ListingResult;
|
|
22
|
+
const hasGenerated = existsSync(join(here, "generated", "operations.json"));
|
|
23
|
+
|
|
24
|
+
const k8s: ListingLexicon = {
|
|
25
|
+
name: k8sPlugin.name,
|
|
26
|
+
deepNormalizationHooks: k8sPlugin.deepNormalizationHooks,
|
|
27
|
+
listedTypes: { ...k8sPlugin.listedTypes!, kindFor: (t) => k8sKindForListedType(t, KINDS) },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe("discovery types to k8s kinds", () => {
|
|
31
|
+
it("maps group/version/kind through the shared group rule; the version is not part of the kind", () => {
|
|
32
|
+
expect(k8sKindForListedType("v1/Pod", KINDS)).toBe("K8s::Core::Pod");
|
|
33
|
+
expect(k8sKindForListedType("apps/v1/Deployment", KINDS)).toBe("K8s::Apps::Deployment");
|
|
34
|
+
expect(k8sKindForListedType("apps/v1beta2/Deployment", KINDS)).toBe("K8s::Apps::Deployment");
|
|
35
|
+
expect(k8sKindForListedType("networking.k8s.io/v1/Ingress", KINDS)).toBe("K8s::Networking::Ingress");
|
|
36
|
+
expect(k8sKindForListedType("rbac.authorization.k8s.io/v1/ClusterRole", KINDS)).toBe("K8s::Rbac::ClusterRole");
|
|
37
|
+
expect(k8sKindForListedType("kustomize.toolkit.fluxcd.io/v1/Kustomization", KINDS)).toBe("K8s::Flux::Kustomization");
|
|
38
|
+
expect(k8sKindForListedType("argoproj.io/v1alpha1/Application", KINDS)).toBe("K8s::Argo::Application");
|
|
39
|
+
expect(k8sKindForListedType("widgets.example.com/v1alpha1/Widget", KINDS)).toBeUndefined();
|
|
40
|
+
expect(k8sKindForListedType("Deployment", KINDS)).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it.skipIf(!hasGenerated)("every kind of the generated operation surface maps back from its apiVersion and kind", () => {
|
|
44
|
+
const table = operationTable();
|
|
45
|
+
const kinds = new Set(Object.keys(table));
|
|
46
|
+
const missing = Object.values(table).filter((d) => k8sKindForListedType(k8sListedTypeFor(d.apiVersion, d.kind), kinds) !== d.entityType);
|
|
47
|
+
expect(missing.map((d) => d.entityType)).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("the k8s fixture listing as typed nodes", () => {
|
|
52
|
+
const doc = typeListing(listing, [k8s]);
|
|
53
|
+
|
|
54
|
+
it("produces typed nodes, and keeps the unmapped custom resource as an unknown-kind node", () => {
|
|
55
|
+
expect(doc.graph.nodes.map((n) => [n.nativeId, n.kind, n.lexicon, n.unmappedKind ?? false])).toEqual([
|
|
56
|
+
["flux-system/apps", "K8s::Flux::Kustomization", "k8s", false],
|
|
57
|
+
["shop/web", "K8s::Apps::Deployment", "k8s", false],
|
|
58
|
+
["shop/db-credentials", "K8s::Core::Secret", "k8s", false],
|
|
59
|
+
["shop/w1", "widgets.example.com/v1alpha1/Widget", "kubernetes", true],
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("drops apiVersion and kind, and prunes what the k8s hooks prune", () => {
|
|
64
|
+
const web = doc.graph.nodes.find((n) => n.nativeId === "shop/web")!;
|
|
65
|
+
expect(web.attrs.apiVersion).toBeUndefined();
|
|
66
|
+
expect(web.attrs.kind).toBeUndefined();
|
|
67
|
+
expect(web.attrs.status).toBeUndefined();
|
|
68
|
+
expect((web.attrs.metadata as Record<string, unknown>).uid).toBeUndefined();
|
|
69
|
+
expect(web.attrs.spec).toEqual({ replicas: 2, selector: { matchLabels: { app: "web" } } });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("masks a Secret's data whatever its keys are called", () => {
|
|
73
|
+
const secret = doc.graph.nodes.find((n) => n.kind === "K8s::Core::Secret")!;
|
|
74
|
+
expect(secret.attrs.data).toEqual({ "app.conf": MASKED });
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import { operationTable } from "./api/operation-surface";
|
|
16
|
+
import { namespaceSegmentForGroup } from "./group-namespace";
|
|
17
|
+
|
|
18
|
+
/** `apps/v1/Deployment` or `v1/Pod` as its group, version and kind. */
|
|
19
|
+
export function parseListedGvk(listedType: string): { group: string; version: string; kind: string } | undefined {
|
|
20
|
+
const parts = listedType.split("/");
|
|
21
|
+
if (parts.length === 2 && parts[0] && parts[1]) return { group: "", version: parts[0], kind: parts[1] };
|
|
22
|
+
if (parts.length === 3 && parts[0] && parts[1] && parts[2]) return { group: parts[0], version: parts[1], kind: parts[2] };
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** `apiVersion` (`apps/v1`, `v1`) and kind as the listed type behold's lister writes. */
|
|
27
|
+
export function k8sListedTypeFor(apiVersion: string, kind: string): string {
|
|
28
|
+
return `${apiVersion}/${kind}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The kind the group rule gives, before any check that the lexicon has it. */
|
|
32
|
+
export function k8sKindByRule(listedType: string): string | undefined {
|
|
33
|
+
const gvk = parseListedGvk(listedType);
|
|
34
|
+
if (!gvk) return undefined;
|
|
35
|
+
return `K8s::${namespaceSegmentForGroup(gvk.group)}::${gvk.kind}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let cachedKinds: ReadonlySet<string> | null | undefined;
|
|
39
|
+
|
|
40
|
+
/** The entity types of the generated operation surface, or null in a checkout that has not generated. */
|
|
41
|
+
function generatedKinds(): ReadonlySet<string> | null {
|
|
42
|
+
if (cachedKinds !== undefined) return cachedKinds;
|
|
43
|
+
const table = operationTable();
|
|
44
|
+
cachedKinds = Object.keys(table).length > 0 ? new Set(Object.keys(table)) : null;
|
|
45
|
+
return cachedKinds;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The k8s kind for a discovery type, or undefined. The rule's answer must be
|
|
50
|
+
* a kind the lexicon generated; with nothing generated the rule's answer
|
|
51
|
+
* stands, as the lexicon's own discovery sweep does.
|
|
52
|
+
*/
|
|
53
|
+
export function k8sKindForListedType(listedType: string, kinds: ReadonlySet<string> | null = generatedKinds()): string | undefined {
|
|
54
|
+
const kind = k8sKindByRule(listedType);
|
|
55
|
+
if (kind === undefined) return undefined;
|
|
56
|
+
if (kinds && !kinds.has(kind)) return undefined;
|
|
57
|
+
return kind;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A listed object in the tree the deep reader compares. */
|
|
61
|
+
export function k8sObservedTree(properties: Record<string, unknown>): Record<string, unknown> {
|
|
62
|
+
const { apiVersion: _apiVersion, kind: _kind, ...rest } = properties;
|
|
63
|
+
return rest;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const k8sListedTypes: ListedTypeMapping = {
|
|
67
|
+
substrate: "kubernetes",
|
|
68
|
+
kindFor: (listedType) => k8sKindForListedType(listedType),
|
|
69
|
+
observedTree: (properties) => k8sObservedTree(properties),
|
|
70
|
+
};
|
package/src/plugin.ts
CHANGED
|
@@ -29,6 +29,8 @@ import { k8sHover } from "./lsp/hover";
|
|
|
29
29
|
import { K8sParser } from "./import/parser";
|
|
30
30
|
import { K8sGenerator } from "./import/generator";
|
|
31
31
|
import { k8sDeepNormalizationHooks } from "./deep-observe-hooks";
|
|
32
|
+
import { k8sListedTypes } from "./listed-types";
|
|
33
|
+
import { k8sReferenceCatalog } from "./reference-catalog";
|
|
32
34
|
import { LABEL_OWNERSHIP_KEYS } from "@intentius/chant/ownership";
|
|
33
35
|
import { k8sConfigSchema } from "./config-schema";
|
|
34
36
|
import type { K8sChantConfig } from "./config";
|
|
@@ -805,4 +807,11 @@ const { deployment, service, serviceMonitor, prometheusRule } = MonitoredService
|
|
|
805
807
|
},
|
|
806
808
|
|
|
807
809
|
deepNormalizationHooks: k8sDeepNormalizationHooks,
|
|
810
|
+
|
|
811
|
+
// Cloud inventory type names to kinds, for an indexed resource (#4521).
|
|
812
|
+
listedTypes: k8sListedTypes,
|
|
813
|
+
|
|
814
|
+
// How its resources reference each other, for chant's catalog pass over an
|
|
815
|
+
// index and a declared graph (#4535; behold#1005 retires behold's matcher on it).
|
|
816
|
+
referenceCatalog: k8sReferenceCatalog,
|
|
808
817
|
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4535: the k8s reference catalog. Each rule draws its edge on a fixture of
|
|
3
|
+
* its own, the catalog keeps behold#1023's ruling (typed rules, no edge on
|
|
4
|
+
* ambiguity, scoped join keys: a namespace is a scope over an index), and
|
|
5
|
+
* behold#166's case, a Deployment's env var naming a bucket, is joined.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from "vitest";
|
|
8
|
+
import type { IRNode } from "@intentius/chant/graph-ir";
|
|
9
|
+
import { reconstructIndexedEdges, refRuleId, type ReferenceCatalog } from "@intentius/chant/graph-refs";
|
|
10
|
+
import { k8sReferenceCatalog } from "./reference-catalog";
|
|
11
|
+
import { k8sPlugin } from "./plugin";
|
|
12
|
+
|
|
13
|
+
const LEXICON = "k8s";
|
|
14
|
+
|
|
15
|
+
/** attrs with `value` written at a catalog path (`a.b`, `arr[].c`). */
|
|
16
|
+
function atPath(path: string, value: string): Record<string, unknown> {
|
|
17
|
+
const parts = path.split(".");
|
|
18
|
+
const build = (i: number): unknown => {
|
|
19
|
+
if (i === parts.length) return value;
|
|
20
|
+
const part = parts[i];
|
|
21
|
+
const isArr = part.endsWith("[]");
|
|
22
|
+
const inner = build(i + 1);
|
|
23
|
+
return { [isArr ? part.slice(0, -2) : part]: isArr ? [inner] : inner };
|
|
24
|
+
};
|
|
25
|
+
return build(0) as Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A node of `kind` named `value` by the catalog's first identity path for it, else by its native id. */
|
|
29
|
+
function target(catalog: ReferenceCatalog, kind: string, id: string, value: string): IRNode {
|
|
30
|
+
const path = catalog.identities.find((r) => r.kind === kind)?.ids[0];
|
|
31
|
+
const lexicon = kind.startsWith("AWS::") ? "aws" : LEXICON;
|
|
32
|
+
return path ? { id, kind, lexicon, attrs: atPath(path, value) } : { id, kind, lexicon, attrs: {}, nativeId: value };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const node = (id: string, kind: string, attrs: Record<string, unknown>, location?: string): IRNode => ({ id, kind, lexicon: LEXICON, attrs, ...(location ? { location } : {}) });
|
|
36
|
+
|
|
37
|
+
/** An index's scope: a namespaced object's location is its namespace, a cluster-scoped one's is `cluster`. */
|
|
38
|
+
const clusterScope = (n: IRNode) => ({ account: "kubernetes/k3d-demo", ...(n.location && n.location !== "cluster" ? { region: n.location } : {}) });
|
|
39
|
+
|
|
40
|
+
const derive = (nodes: IRNode[], scope: (n: IRNode) => { account: string; region?: string } = () => ({ account: "declared" }), catalogs = [{ lexicon: LEXICON, catalog: k8sReferenceCatalog }]) =>
|
|
41
|
+
reconstructIndexedEdges(nodes, catalogs, scope);
|
|
42
|
+
|
|
43
|
+
describe("k8s reference catalog", () => {
|
|
44
|
+
it("is the plugin's referenceCatalog", () => {
|
|
45
|
+
expect(k8sPlugin.referenceCatalog).toBe(k8sReferenceCatalog);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("names a target kind on every rule (behold#1023's ruling)", () => {
|
|
49
|
+
expect(k8sReferenceCatalog.refs.filter((r) => !(r.targetKind ?? r.indexedTargetKind))).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("has no two rules for one holder kind, path and target kind", () => {
|
|
53
|
+
const keys = k8sReferenceCatalog.refs.map((r) => `${r.from}|${r.path}|${r.targetKind}`);
|
|
54
|
+
expect(keys.filter((k, i) => keys.indexOf(k) !== i)).toEqual([]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("each rule draws its edge", () => {
|
|
58
|
+
for (const [i, rule] of k8sReferenceCatalog.refs.entries()) {
|
|
59
|
+
const to = rule.targetKind ?? rule.indexedTargetKind!;
|
|
60
|
+
it(`${rule.from} ${rule.path} -> ${to}`, () => {
|
|
61
|
+
const value = `target-name-${i}`;
|
|
62
|
+
const holder = node(`holder-${i}`, rule.from, atPath(rule.path, value));
|
|
63
|
+
const out = derive([holder, target(k8sReferenceCatalog, to, `target-${i}`, value)]);
|
|
64
|
+
const edge = out.edges.find((e) => e.from === holder.id && e.to === `target-${i}`);
|
|
65
|
+
expect(edge?.rule).toBe(refRuleId(LEXICON, rule.from, rule.path));
|
|
66
|
+
expect(edge?.relation).toBe(rule.relation);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("an app in one namespace, as an index lists it", () => {
|
|
72
|
+
const nodes: IRNode[] = [
|
|
73
|
+
node("ns/shop", "K8s::Core::Namespace", { metadata: { name: "shop" } }, "cluster"),
|
|
74
|
+
node("shop/sa/web", "K8s::Core::ServiceAccount", { metadata: { name: "web", namespace: "shop" } }, "shop"),
|
|
75
|
+
node("shop/cm/web-config", "K8s::Core::ConfigMap", { metadata: { name: "web-config", namespace: "shop" } }, "shop"),
|
|
76
|
+
node("shop/secret/web-tls", "K8s::Core::Secret", { metadata: { name: "web-tls", namespace: "shop" } }, "shop"),
|
|
77
|
+
node(
|
|
78
|
+
"shop/deploy/web",
|
|
79
|
+
"K8s::Apps::Deployment",
|
|
80
|
+
{
|
|
81
|
+
metadata: { name: "web", namespace: "shop" },
|
|
82
|
+
spec: {
|
|
83
|
+
template: {
|
|
84
|
+
metadata: { labels: { app: "web" } },
|
|
85
|
+
spec: { serviceAccountName: "web", containers: [{ name: "web", envFrom: [{ configMapRef: { name: "web-config" } }] }] },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
"shop",
|
|
90
|
+
),
|
|
91
|
+
node("shop/svc/web", "K8s::Core::Service", { metadata: { name: "web-svc", namespace: "shop" }, spec: { selector: { app: "web" } } }, "shop"),
|
|
92
|
+
node(
|
|
93
|
+
"shop/ing/web",
|
|
94
|
+
"K8s::Networking::Ingress",
|
|
95
|
+
{ metadata: { name: "web", namespace: "shop" }, spec: { tls: [{ secretName: "web-tls" }], rules: [{ http: { paths: [{ backend: { service: { name: "web-svc" } } }] } }] } },
|
|
96
|
+
"shop",
|
|
97
|
+
),
|
|
98
|
+
];
|
|
99
|
+
const out = derive(nodes, clusterScope);
|
|
100
|
+
|
|
101
|
+
it("draws the app's topology", () => {
|
|
102
|
+
expect(out.edges.filter((e) => e.relation === "reference").map((e) => `${e.from} -> ${e.to} [${e.viaAttr}]`)).toEqual([
|
|
103
|
+
"shop/deploy/web -> shop/cm/web-config [spec]",
|
|
104
|
+
"shop/deploy/web -> shop/sa/web [spec]",
|
|
105
|
+
"shop/ing/web -> shop/secret/web-tls [spec]",
|
|
106
|
+
"shop/ing/web -> shop/svc/web [spec]",
|
|
107
|
+
"shop/svc/web -> shop/deploy/web [spec]",
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("places every namespaced object in its namespace, across the namespace-to-cluster scope", () => {
|
|
112
|
+
expect(out.containment.map((c) => c.child).sort()).toEqual(nodes.filter((n) => n.location === "shop").map((n) => n.id).sort());
|
|
113
|
+
expect(new Set(out.containment.map((c) => c.parent))).toEqual(new Set(["ns/shop"]));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("leaves nothing ambiguous or dangling", () => {
|
|
117
|
+
expect(out.ambiguous).toEqual([]);
|
|
118
|
+
expect(out.dangling).toEqual([]);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("keeps a `default` service account inside its own namespace over an index", () => {
|
|
123
|
+
const nodes: IRNode[] = [
|
|
124
|
+
node("a/sa/default", "K8s::Core::ServiceAccount", { metadata: { name: "default", namespace: "a" } }, "a"),
|
|
125
|
+
node("b/sa/default", "K8s::Core::ServiceAccount", { metadata: { name: "default", namespace: "b" } }, "b"),
|
|
126
|
+
node("a/pod/x", "K8s::Core::Pod", { metadata: { name: "x", namespace: "a" }, spec: { serviceAccountName: "default" } }, "a"),
|
|
127
|
+
];
|
|
128
|
+
expect(derive(nodes, clusterScope).edges.filter((e) => e.relation === "reference").map((e) => `${e.from} -> ${e.to}`)).toEqual(["a/pod/x -> a/sa/default"]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("draws no edge on a declared graph (one scope) where two namespaces share the name, and records both", () => {
|
|
132
|
+
const nodes: IRNode[] = [
|
|
133
|
+
node("sa-a", "K8s::Core::ServiceAccount", { metadata: { name: "default", namespace: "a" } }),
|
|
134
|
+
node("sa-b", "K8s::Core::ServiceAccount", { metadata: { name: "default", namespace: "b" } }),
|
|
135
|
+
node("pod", "K8s::Core::Pod", { metadata: { name: "x", namespace: "a" }, spec: { serviceAccountName: "default" } }),
|
|
136
|
+
];
|
|
137
|
+
const out = derive(nodes);
|
|
138
|
+
expect(out.edges.filter((e) => e.viaAttr === "spec")).toEqual([]);
|
|
139
|
+
expect(out.ambiguous.map((a) => a.candidates)).toEqual([["sa-a", "sa-b"]]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe("behold#166: a Deployment's env var naming a bucket", () => {
|
|
143
|
+
const deployment = node("assets-api", "K8s::Apps::Deployment", {
|
|
144
|
+
metadata: { name: "assets-api" },
|
|
145
|
+
spec: { template: { spec: { containers: [{ name: "api", env: [{ name: "ASSET_BUCKET", value: "loom-assets-1a2b3c" }, { name: "LOG_LEVEL", value: "info" }] }] } } },
|
|
146
|
+
});
|
|
147
|
+
const bucket: IRNode = { id: "AssetBucket", kind: "AWS::S3::Bucket", lexicon: "aws", attrs: { BucketName: "loom-assets-1a2b3c" } };
|
|
148
|
+
// The aws catalog's bucket identity is what names it; an inline copy keeps this test inside the k8s package.
|
|
149
|
+
const aws: ReferenceCatalog = { identities: [{ kind: "AWS::S3::Bucket", ids: ["BucketName"] }], refs: [] };
|
|
150
|
+
const out = derive([deployment, bucket], undefined, [
|
|
151
|
+
{ lexicon: "aws", catalog: aws },
|
|
152
|
+
{ lexicon: LEXICON, catalog: k8sReferenceCatalog },
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
it("joins the env value to the bucket", () => {
|
|
156
|
+
expect(out.edges.map((e) => `${e.from} -> ${e.to} (${e.rule})`)).toEqual([
|
|
157
|
+
"assets-api -> AssetBucket (k8s:K8s::Apps::Deployment:spec.template.spec.containers[].env[].value)",
|
|
158
|
+
]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("reports no other env value as dangling", () => {
|
|
162
|
+
expect(out.dangling).toEqual([]);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("does not join across substrates over an index, where the cluster and the account are two scopes", () => {
|
|
166
|
+
const scoped = derive([deployment, bucket], (n) => ({ account: n.lexicon === "aws" ? "aws/000000000000" : "kubernetes/k3d-demo" }), [
|
|
167
|
+
{ lexicon: "aws", catalog: aws },
|
|
168
|
+
{ lexicon: LEXICON, catalog: k8sReferenceCatalog },
|
|
169
|
+
]);
|
|
170
|
+
expect(scoped.edges).toEqual([]);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { IdentityRule, ReferenceCatalog, RefRule } from "@intentius/chant/graph-refs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Kubernetes reference catalog (#4535): how Kubernetes objects name each
|
|
5
|
+
* other, so chant's catalog pass (`reconstructIndexedEdges`, #4522) draws
|
|
6
|
+
* their edges over an index and over a declared graph, and behold can retire
|
|
7
|
+
* its name matcher (behold#1005).
|
|
8
|
+
*
|
|
9
|
+
* ## Shape and scope
|
|
10
|
+
*
|
|
11
|
+
* The paths are the manifest's own (`metadata`, `spec`), which is the tree a
|
|
12
|
+
* listed object becomes once `apiVersion` and `kind` are dropped
|
|
13
|
+
* (./listed-types.ts `k8sObservedTree`) and the shape the lexicon's declared
|
|
14
|
+
* props have. Every target is identified by `metadata.name`.
|
|
15
|
+
*
|
|
16
|
+
* A name is unique only inside its namespace. Over an index a namespaced
|
|
17
|
+
* object's location is its namespace (behold#1025), so the scoped join key
|
|
18
|
+
* (behold#1023's ruling) keeps a `serviceAccountName: default` inside its own
|
|
19
|
+
* namespace, and a namespaced holder also reaches cluster-scoped objects (a
|
|
20
|
+
* `Namespace`, a `ClusterRole`, a `StorageClass`). A declared graph is one
|
|
21
|
+
* scope, so two `default` service accounts in two namespaces make that
|
|
22
|
+
* reference ambiguous there, and it draws no edge.
|
|
23
|
+
*
|
|
24
|
+
* ## Multi-kind fields
|
|
25
|
+
*
|
|
26
|
+
* A field that can name one of several kinds (`scaleTargetRef`, `roleRef`,
|
|
27
|
+
* a binding's `subjects`, an owner reference) has one rule per kind, each
|
|
28
|
+
* `optional`, so a value that names a node of another kind is not dangling
|
|
29
|
+
* under the rules it does not match.
|
|
30
|
+
*
|
|
31
|
+
* ## Values that may name a cloud resource
|
|
32
|
+
*
|
|
33
|
+
* A container's env var value can be the literal name of a bucket it uses
|
|
34
|
+
* (behold#166's case: `ASSET_BUCKET` set to the bucket's `BucketName`). The
|
|
35
|
+
* env-value rules join such a value to an `AWS::S3::Bucket` of that name, and
|
|
36
|
+
* are `optional`, since most env values name nothing. Over an index the
|
|
37
|
+
* cluster and the AWS account are two scopes, so the join only draws on a
|
|
38
|
+
* declared graph (one scope), which is where behold's matcher drew it.
|
|
39
|
+
*
|
|
40
|
+
* ## What this does not do
|
|
41
|
+
*
|
|
42
|
+
* - Label selectors. A Service selects pods by labels, and the standard keys
|
|
43
|
+
* (`app.kubernetes.io/name`) contain dots, which `readPath` reads as path
|
|
44
|
+
* separators. Only the bare `app` label is matched: a Service's
|
|
45
|
+
* `spec.selector.app` to a workload whose pod template carries the same
|
|
46
|
+
* `app` label. behold's own k8s pass (src/k8s-edges.ts) still joins full
|
|
47
|
+
* selectors on behold's side.
|
|
48
|
+
* - Annotations, for the same reason (`eks.amazonaws.com/role-arn`).
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/** Workload kinds and the path to their pod spec. */
|
|
52
|
+
const POD_SPECS: ReadonlyArray<readonly [kind: string, podSpec: string]> = [
|
|
53
|
+
["K8s::Core::Pod", "spec"],
|
|
54
|
+
["K8s::Apps::Deployment", "spec.template.spec"],
|
|
55
|
+
["K8s::Apps::StatefulSet", "spec.template.spec"],
|
|
56
|
+
["K8s::Apps::DaemonSet", "spec.template.spec"],
|
|
57
|
+
["K8s::Apps::ReplicaSet", "spec.template.spec"],
|
|
58
|
+
["K8s::Batch::Job", "spec.template.spec"],
|
|
59
|
+
["K8s::Batch::CronJob", "spec.jobTemplate.spec.template.spec"],
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
/** Kinds that sit in a namespace, so `metadata.namespace` places them. */
|
|
63
|
+
const NAMESPACED_KINDS = [
|
|
64
|
+
...POD_SPECS.map(([kind]) => kind),
|
|
65
|
+
"K8s::Core::Service",
|
|
66
|
+
"K8s::Core::ConfigMap",
|
|
67
|
+
"K8s::Core::Secret",
|
|
68
|
+
"K8s::Core::ServiceAccount",
|
|
69
|
+
"K8s::Core::PersistentVolumeClaim",
|
|
70
|
+
"K8s::Networking::Ingress",
|
|
71
|
+
"K8s::Networking::NetworkPolicy",
|
|
72
|
+
"K8s::Autoscaling::HorizontalPodAutoscaler",
|
|
73
|
+
"K8s::Policy::PodDisruptionBudget",
|
|
74
|
+
"K8s::Rbac::Role",
|
|
75
|
+
"K8s::Rbac::RoleBinding",
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
/** Kinds other objects name by `metadata.name`. */
|
|
79
|
+
const NAMED_KINDS = [
|
|
80
|
+
...NAMESPACED_KINDS,
|
|
81
|
+
"K8s::Core::Namespace",
|
|
82
|
+
"K8s::Core::PersistentVolume",
|
|
83
|
+
"K8s::Networking::IngressClass",
|
|
84
|
+
"K8s::Storage::StorageClass",
|
|
85
|
+
"K8s::Rbac::ClusterRole",
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
/** Workloads whose pod template a Service's `app` selector can match. */
|
|
89
|
+
const SELECTED_WORKLOADS = ["K8s::Apps::Deployment", "K8s::Apps::StatefulSet", "K8s::Apps::DaemonSet"];
|
|
90
|
+
|
|
91
|
+
const identities: IdentityRule[] = NAMED_KINDS.map((kind) => ({
|
|
92
|
+
kind,
|
|
93
|
+
ids: SELECTED_WORKLOADS.includes(kind) ? ["metadata.name", "spec.template.metadata.labels.app"] : ["metadata.name"],
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
type Rel = RefRule["relation"];
|
|
97
|
+
|
|
98
|
+
const ref = (from: string, path: string, targetKind: string, label: string, relation: Rel = "reference"): RefRule => ({ from, path, targetKind, relation, label });
|
|
99
|
+
|
|
100
|
+
const anyOf = (from: string, path: string, targetKinds: readonly string[], label: string): RefRule[] =>
|
|
101
|
+
targetKinds.map((targetKind) => ({ from, path, targetKind, relation: "reference" as const, label, optional: true }));
|
|
102
|
+
|
|
103
|
+
/** What a pod spec names: its service account, mounted config and secrets, claims, pull secrets. */
|
|
104
|
+
function podSpecRules(kind: string, p: string): RefRule[] {
|
|
105
|
+
const containers = [`${p}.containers[]`, `${p}.initContainers[]`];
|
|
106
|
+
return [
|
|
107
|
+
ref(kind, `${p}.serviceAccountName`, "K8s::Core::ServiceAccount", "runs as"),
|
|
108
|
+
ref(kind, `${p}.volumes[].configMap.name`, "K8s::Core::ConfigMap", "mounts"),
|
|
109
|
+
ref(kind, `${p}.volumes[].secret.secretName`, "K8s::Core::Secret", "mounts"),
|
|
110
|
+
ref(kind, `${p}.volumes[].persistentVolumeClaim.claimName`, "K8s::Core::PersistentVolumeClaim", "mounts"),
|
|
111
|
+
ref(kind, `${p}.volumes[].projected.sources[].configMap.name`, "K8s::Core::ConfigMap", "mounts"),
|
|
112
|
+
ref(kind, `${p}.volumes[].projected.sources[].secret.name`, "K8s::Core::Secret", "mounts"),
|
|
113
|
+
ref(kind, `${p}.imagePullSecrets[].name`, "K8s::Core::Secret", "pulls with"),
|
|
114
|
+
...containers.flatMap((c) => [
|
|
115
|
+
ref(kind, `${c}.envFrom[].configMapRef.name`, "K8s::Core::ConfigMap", "env from"),
|
|
116
|
+
ref(kind, `${c}.envFrom[].secretRef.name`, "K8s::Core::Secret", "env from"),
|
|
117
|
+
ref(kind, `${c}.env[].valueFrom.configMapKeyRef.name`, "K8s::Core::ConfigMap", "env from"),
|
|
118
|
+
ref(kind, `${c}.env[].valueFrom.secretKeyRef.name`, "K8s::Core::Secret", "env from"),
|
|
119
|
+
]),
|
|
120
|
+
// behold#166: an env var whose value is a bucket's literal name.
|
|
121
|
+
{ from: kind, path: `${p}.containers[].env[].value`, targetKind: "AWS::S3::Bucket", relation: "reference", label: "uses bucket", optional: true },
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const refs: RefRule[] = [
|
|
126
|
+
// ── containment: the namespace an object is in ──
|
|
127
|
+
...NAMESPACED_KINDS.map((kind) => ref(kind, "metadata.namespace", "K8s::Core::Namespace", "in namespace", "containment")),
|
|
128
|
+
|
|
129
|
+
// ── owner references, by name inside the namespace ──
|
|
130
|
+
...anyOf("K8s::Core::Pod", "metadata.ownerReferences[].name", ["K8s::Apps::ReplicaSet", "K8s::Apps::StatefulSet", "K8s::Apps::DaemonSet", "K8s::Batch::Job"], "owned by"),
|
|
131
|
+
...anyOf("K8s::Apps::ReplicaSet", "metadata.ownerReferences[].name", ["K8s::Apps::Deployment"], "owned by"),
|
|
132
|
+
...anyOf("K8s::Batch::Job", "metadata.ownerReferences[].name", ["K8s::Batch::CronJob"], "owned by"),
|
|
133
|
+
|
|
134
|
+
// ── pod specs ──
|
|
135
|
+
...POD_SPECS.flatMap(([kind, p]) => podSpecRules(kind, p)),
|
|
136
|
+
|
|
137
|
+
// ── services and ingress ──
|
|
138
|
+
...anyOf("K8s::Core::Service", "spec.selector.app", SELECTED_WORKLOADS, "selects"),
|
|
139
|
+
ref("K8s::Networking::Ingress", "spec.rules[].http.paths[].backend.service.name", "K8s::Core::Service", "routes to"),
|
|
140
|
+
ref("K8s::Networking::Ingress", "spec.defaultBackend.service.name", "K8s::Core::Service", "routes to"),
|
|
141
|
+
ref("K8s::Networking::Ingress", "spec.tls[].secretName", "K8s::Core::Secret", "tls"),
|
|
142
|
+
ref("K8s::Networking::Ingress", "spec.ingressClassName", "K8s::Networking::IngressClass", "class"),
|
|
143
|
+
|
|
144
|
+
// ── scaling, storage, RBAC ──
|
|
145
|
+
...anyOf("K8s::Autoscaling::HorizontalPodAutoscaler", "spec.scaleTargetRef.name", ["K8s::Apps::Deployment", "K8s::Apps::StatefulSet", "K8s::Apps::ReplicaSet"], "scales"),
|
|
146
|
+
ref("K8s::Core::PersistentVolumeClaim", "spec.volumeName", "K8s::Core::PersistentVolume", "bound to"),
|
|
147
|
+
ref("K8s::Core::PersistentVolumeClaim", "spec.storageClassName", "K8s::Storage::StorageClass", "class"),
|
|
148
|
+
ref("K8s::Core::PersistentVolume", "spec.storageClassName", "K8s::Storage::StorageClass", "class"),
|
|
149
|
+
...anyOf("K8s::Rbac::RoleBinding", "roleRef.name", ["K8s::Rbac::Role", "K8s::Rbac::ClusterRole"], "binds"),
|
|
150
|
+
...anyOf("K8s::Rbac::RoleBinding", "subjects[].name", ["K8s::Core::ServiceAccount"], "grants"),
|
|
151
|
+
...anyOf("K8s::Rbac::ClusterRoleBinding", "roleRef.name", ["K8s::Rbac::ClusterRole"], "binds"),
|
|
152
|
+
...anyOf("K8s::Rbac::ClusterRoleBinding", "subjects[].name", ["K8s::Core::ServiceAccount"], "grants"),
|
|
153
|
+
ref("K8s::Core::ServiceAccount", "secrets[].name", "K8s::Core::Secret", "token"),
|
|
154
|
+
ref("K8s::Core::ServiceAccount", "imagePullSecrets[].name", "K8s::Core::Secret", "pulls with"),
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
export const k8sReferenceCatalog: ReferenceCatalog = { identities, refs };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"listing": "v1",
|
|
3
|
+
"source": { "name": "behold-lister", "version": "0.0.0-fixture" },
|
|
4
|
+
"scope": { "substrate": "kubernetes", "scopeId": "kind-dev", "locations": "*", "types": "*" },
|
|
5
|
+
"startedAt": "2026-10-26T09:00:00.000Z",
|
|
6
|
+
"completedAt": "2026-10-26T09:00:02.000Z",
|
|
7
|
+
"resources": [
|
|
8
|
+
{
|
|
9
|
+
"listedType": "apps/v1/Deployment",
|
|
10
|
+
"location": "shop",
|
|
11
|
+
"nativeId": "shop/web",
|
|
12
|
+
"cloudIds": [{ "kind": "k8s-uid", "value": "5f1c2a8e-0000-4000-8000-000000000001" }],
|
|
13
|
+
"tags": { "app": "web", "app.kubernetes.io/managed-by": "chant" },
|
|
14
|
+
"properties": {
|
|
15
|
+
"apiVersion": "apps/v1",
|
|
16
|
+
"kind": "Deployment",
|
|
17
|
+
"metadata": {
|
|
18
|
+
"name": "web",
|
|
19
|
+
"namespace": "shop",
|
|
20
|
+
"uid": "5f1c2a8e-0000-4000-8000-000000000001",
|
|
21
|
+
"resourceVersion": "4711",
|
|
22
|
+
"generation": 3,
|
|
23
|
+
"creationTimestamp": "2026-10-20T00:00:00Z",
|
|
24
|
+
"labels": { "app": "web", "app.kubernetes.io/managed-by": "chant" }
|
|
25
|
+
},
|
|
26
|
+
"spec": { "replicas": 2, "selector": { "matchLabels": { "app": "web" } } },
|
|
27
|
+
"status": { "readyReplicas": 2 }
|
|
28
|
+
},
|
|
29
|
+
"observedAt": "2026-10-26T09:00:01.000Z"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"listedType": "v1/Secret",
|
|
33
|
+
"location": "shop",
|
|
34
|
+
"nativeId": "shop/db-credentials",
|
|
35
|
+
"cloudIds": [{ "kind": "k8s-uid", "value": "5f1c2a8e-0000-4000-8000-000000000002" }],
|
|
36
|
+
"tags": {},
|
|
37
|
+
"properties": {
|
|
38
|
+
"apiVersion": "v1",
|
|
39
|
+
"kind": "Secret",
|
|
40
|
+
"metadata": { "name": "db-credentials", "namespace": "shop" },
|
|
41
|
+
"type": "Opaque",
|
|
42
|
+
"data": { "app.conf": "<masked>" }
|
|
43
|
+
},
|
|
44
|
+
"observedAt": "2026-10-26T09:00:01.000Z"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"listedType": "kustomize.toolkit.fluxcd.io/v1/Kustomization",
|
|
48
|
+
"location": "flux-system",
|
|
49
|
+
"nativeId": "flux-system/apps",
|
|
50
|
+
"cloudIds": [{ "kind": "k8s-uid", "value": "5f1c2a8e-0000-4000-8000-000000000003" }],
|
|
51
|
+
"tags": {},
|
|
52
|
+
"properties": { "apiVersion": "kustomize.toolkit.fluxcd.io/v1", "kind": "Kustomization", "metadata": { "name": "apps", "namespace": "flux-system" }, "spec": { "path": "./apps", "prune": true } },
|
|
53
|
+
"observedAt": "2026-10-26T09:00:01.000Z"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"listedType": "widgets.example.com/v1alpha1/Widget",
|
|
57
|
+
"location": "shop",
|
|
58
|
+
"nativeId": "shop/w1",
|
|
59
|
+
"cloudIds": [{ "kind": "k8s-uid", "value": "5f1c2a8e-0000-4000-8000-000000000004" }],
|
|
60
|
+
"tags": {},
|
|
61
|
+
"properties": { "apiVersion": "widgets.example.com/v1alpha1", "kind": "Widget", "metadata": { "name": "w1", "namespace": "shop" }, "spec": { "size": 3 } },
|
|
62
|
+
"observedAt": "2026-10-26T09:00:01.000Z"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"coverage": [{ "listedType": "*", "location": "*", "verdict": "listed" }],
|
|
66
|
+
"notes": [{ "code": "default-types", "message": "events and leases were left out of types \"*\"" }]
|
|
67
|
+
}
|