@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.
- package/dist/components/kubectl-apply.d.ts.map +1 -1
- package/dist/components/kubectl-apply.js +37 -0
- package/dist/import/generator.d.ts +7 -0
- package/dist/import/generator.d.ts.map +1 -1
- package/dist/import/generator.js +45 -2
- package/dist/index-identity.d.ts +51 -0
- package/dist/index-identity.d.ts.map +1 -0
- package/dist/index-identity.js +78 -0
- package/dist/index-import.d.ts +20 -0
- package/dist/index-import.d.ts.map +1 -0
- package/dist/index-import.js +170 -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 +15 -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/import/generator.ts +44 -2
- package/src/index-identity.ts +119 -0
- package/src/index-import.test.ts +244 -0
- package/src/index-import.ts +181 -0
- package/src/listed-types.test.ts +76 -0
- package/src/listed-types.ts +70 -0
- package/src/plugin.ts +19 -0
- package/src/reference-catalog.test.ts +173 -0
- package/src/reference-catalog.ts +157 -0
- package/src/testdata/indexed/listing.json +67 -0
|
@@ -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
|
+
}
|