diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a70bd81ef..9b8d237888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This file records changes to what chant prints or writes for a plain project, th ## Unreleased +- [#5096](https://github.com/INTENTIUS/chant/issues/5096) The k8s lexicon supplies a `manifests` workspace kind (precedence 305, below every other kind that reads YAML): a directory of plain Kubernetes manifests is a member, with a node for every document that has an `apiVersion` and a `kind`, custom resources included. A directory no other kind claimed that holds such files is now a `manifests` member in `chant workspace init` and `chant workspace graph`, where it was left out before. The `argo-app` kind also reads `ApplicationSet` and `AppProject` documents and claims a directory that holds only those. A YAML file that does not parse is a warning that names it. +- [#5070](https://github.com/INTENTIUS/chant/issues/5070) `chant import` of a Kubernetes manifest checks that `@intentius/chant-lexicon-k8s` exports a class for each kind before it writes one. A kind with no class (a custom resource whose CRD the lexicon does not ship, such as `ExternalSecret` or `ManagedCertificate`) is written as `k8sManifest({ apiVersion, kind, ... })`, which builds and comes back as the manifest it was, and the import prints one warning per kind naming `k8s.crds` and `chant generate`. Before, it wrote `new ExternalSecret(...)` and an import of a name the lexicon does not export, so the build failed to load the module while the import exited 0. A kind whose name is another group's class (`Kustomization` of `kustomize.config.k8s.io`, which is not Flux's) is untyped now too, where it was written as the other group's class. A kind with a class is written as before. - [#5060](https://github.com/INTENTIUS/chant/issues/5060) In a product's workflow (`runIf`) with `beforeMerge` and a spec `control`, the Op waves control job runs again. It used to need the last wave's record jobs and sit inside the product's push `runIf`, so it could never run. It now runs on the default branch's push run, outside the product's `runIf`, after the jobs `firstWaveNeeds` names, and tells the control repo the waves applied at `github.sha` or `$CI_COMMIT_SHA`, adding up no outcomes. GitHub, Forgejo and GitLab. Without `beforeMerge`, or without `runIf`, the job renders as before. Floor: `OP_WAVES_CONTROL_BEFORE_MERGE_FLOOR`. - [#5061](https://github.com/INTENTIUS/chant/issues/5061) With `wavesBeforeMerge` and the product plan's `reach`, and no `locks: "plan"`, the comment job (GitHub, Forgejo) and the note poll (GitLab, `chantNoteRuns`) answer `/ lock` on an open pull request by taking the locks of what the reach line prints at stage `apply` in `_locks/.json`, without applying, refused with the holder named while another open pull request holds one, and `/ unlock` by releasing the pull request's locks. Both reply, run none of the change's code, and are refused for a fork or a commenter without write access. The product plan takes `reach` without `locks: "plan"` under `wavesBeforeMerge`, and then writes no reach lock job. With `locks: "plan"`, or without `wavesBeforeMerge` and `reach`, nothing changes. Floor: `WAVES_BEFORE_MERGE_LOCKS_FLOOR`. - [#5056](https://github.com/INTENTIUS/chant/issues/5056) `approvals.remainder` resumes the waves terragucci's own records resume. The terraform step gives a live choudoufu root planned through `live-plan-set` its `resourceDigests`, from the set's plan, as the `plan -out` path does, so the applied line names its changes; before, such a wave never resumed as a remainder. Those digests also reach a pull request's recorded plans, so `approvals.preview` compares a live root resource by resource, as it does a `plan -out` root. The remainder's cover leaves out the cost member `(monthly cost)` on both sides, since it digests the wave's monthly change, which moves once part of the wave applied; every change is still compared. Floor: `OP_WAVES_REMAINDER_PARITY_FLOOR`. diff --git a/docs/src/content/docs/cli/audit.mdx b/docs/src/content/docs/cli/audit.mdx index faec1dbca4..7ba4529fa6 100644 --- a/docs/src/content/docs/cli/audit.mdx +++ b/docs/src/content/docs/cli/audit.mdx @@ -205,7 +205,7 @@ For tooling, `--format json` emits a **versioned** envelope (stable contract). T "snapshot": { "target": "...", "host": "github.com", "repo": "owner/repo", "commit": "…", "files": ["..."], "generatedAt": "…", "toolVersion": "0.7.0" }, "summary": { "total": 0, "quickWin": 0, "needsReview": 0, "reportOnly": 0, "errors": 0, "warnings": 0, "infos": 0, "security": 0, "correctness": 0, "bestPractice": 0 }, "findings": [ - { "checkId": "GHA033", "severity": "warning", "message": "…", "file": "…", "entity": "…", "lexicon": "github", + { "checkId": "GHA033", "severity": "warning", "message": "…", "file": "…", "entity": "…", "identity": "…", "lexicon": "github", "tier": "merge-worthy", "fixKind": "deterministic", "category": "security", "title": "…", "remediation": "…", "authority": [{ "name": "…", "url": "…" }], "lineage": [{ "tool": "zizmor", "rule": "excessive-permissions", "url": "…", "relation": "equivalent" }], @@ -221,6 +221,8 @@ For tooling, `--format json` emits a **versioned** envelope (stable contract). T - The `snapshot` anchors findings to an exact commit for reproducibility. - `status` is `"ok"` when at least one lexicon ran, `"no-lexicons"` when none could (see [Prerequisites](#prerequisites)). Check it before trusting an empty `findings`. An optional `unclaimed` list names files that wanted a lexicon that is not installed. - An optional `truncated` object (`limit`, `flag`) means the local walk stopped at its file limit, so `findings` covers only part of the tree (see [Scan limits](#scan-limits)). +- An optional `skipped` list names each lexicon whose files were found but not read because an optional parser is not installed (today, `@cdktn/hcl2json` for Terraform). Each entry has `lexicon`, `reason` (`"parser-not-installed"`), `package`, `install` and `paths`, the audited directories it could not read. A lexicon in `skipped` has no findings because it was not read, not because it is clean, so a consumer that treats an empty lexicon as clean should check this list first. The same sentence is printed on stderr, and text reports lead with it as a note. +- `identity` names a finding across runs, so a base and a head can be compared without reading messages. It is built from the rule, the file, the object's name or address, the finding's place in the object (for a container finding, the kind and the container's index) and, for a secret, the value's fingerprint. It does not use the message or the line. Renaming a container inside a Deployment leaves the identity alone; renaming the Deployment changes it. A finding with no further locator is told apart from others on the same object by its order. An aliased Terraform provider is keyed by its alias. - `lineage` credits the open-source tools whose rules check the same condition, with the upstream rule id and how the two relate. It is credit, not authority, and is empty for a rule with no known counterpart. The [audit rules reference](/chant/lint-rules/audit-rules/#prior-art) lists every tool credited. - For maximum stability, use `--format sarif`, an industry-standard format versioned independently of chant. @@ -229,6 +231,7 @@ For tooling, `--format json` emits a **versioned** envelope (stable contract). T `--format sarif` emits a [SARIF 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html) document, the interchange format most CI platforms and code-review surfaces (GitHub code scanning, GitLab, Azure DevOps, many SAST/IDE viewers) render as inline, file-and-line annotations instead of scraped text: - Each `run.tool.driver.rules[]` entry carries the finding's `helpUri` (the same authority citation as the other formats) plus a `help.text` with the catalog's remediation guidance, and a `properties.category`/`properties.dimension` pair (`security`, `correctness`, or `best-practice`) for rule-level triage. A rule with prior art also carries `properties.priorArt`, the same `lineage` entries the JSON report emits. +- Each `run.results[]` entry carries the same `identity` as the JSON report, as `partialFingerprints["chantFindingIdentity/v1"]`. - Each `run.results[]` entry carries `properties.tier` (`merge-worthy` or `report-only`) alongside the standard `ruleId`, `level`, `message`, and `locations` (file + line, when known). - Secrets findings (`SEC001`–`SEC010`) redact the same as every other format — a result's `message.text` never carries the matched value, only the rule id, kind, location, and fingerprint. - `--agents` emits the same property bag under a `chant audit --agents` driver name, so one consumer can triage both. Its rules' `helpUri` points at the rule's own entry in the audit rules reference rather than an external authority, since an `AGT` finding is about a local file. diff --git a/docs/src/content/docs/cli/workspace-graph.mdx b/docs/src/content/docs/cli/workspace-graph.mdx index 1f7f1feb9f..98fbe76beb 100644 --- a/docs/src/content/docs/cli/workspace-graph.mdx +++ b/docs/src/content/docs/cli/workspace-graph.mdx @@ -9,6 +9,7 @@ title: "chant workspace graph" ``` chant workspace graph [dir] [--at ] [--detail 0..3] [-o ] [--member ] [--kind ] [--env ] [--capability-view] [--no-cache] [--dry-run] chant workspace graph [dir] --live --env [--overlay] [--traffic ] [--detail 0..3] [-o ] [--member ] [--kind ] +chant workspace graph --discover [--at ] [--detail 0..3] [-o ] [--member ] [--env ] [--no-cache] [--dry-run] chant workspace graph [dir] --composites [--at ] [-o ] [--member ] [--env ] chant workspace graph [dir] --intent [--at ] [--kind ...] [--follow-squash] [--forge-issues] [--json] chant workspace graph [dir] --intent --record [--at ] [--kind ...] [--follow-squash] [--forge-issues] [--json] @@ -20,22 +21,100 @@ chant workspace graph [dir] --intent --record [--at ] [--kind --discover` reads a directory that has no `chant.workspace.json` ([#5095](https://github.com/INTENTIUS/chant/issues/5095)). The kinds' probes find the members, and from there the read is a declared read, with its [reader projects](#description) and [member cache](#the-member-cache), printing the same document. Nothing is written inside ``. + +The walk starts at `` and visits every directory below it except `node_modules` and those whose names start with a dot, such as `.git`. Symbolic links to directories are not followed. Each directory is resolved by probe and [precedence](/chant/reference/workspace-kinds/#kinds-from-a-package), as a declared member's kind is checked. A directory that some kind claims becomes a member, unless one of these holds: + +- Two or more kinds claim it at the same highest precedence. This is a `tie`, and the directory is not read; a declaration that names its kind reads it. +- A `.tf` file anywhere under `` calls it through a local `source` in a `module` block, one that starts with `./` or `../`. Such a `module` is read with each root that calls it, since a terraform member's reader project has `` as its `moduleRoot`. A source that leaves `` is not followed. +- The directory sits inside another member's directory. Members don't nest, so this `inside-member` directory is not read, except inside the root member `.` ([placement](/chant/reference/workspace-declaration/#placement)). + +The kinds are the built-in ones and those of every `@intentius` package that publishes a `./workspace-kinds` file and is installed beside the running chant: in the `node_modules/@intentius` of chant's own directory or a directory above it, the nearest copy of each package winning. A `node_modules` inside `` supplies no kinds, so discovery loads no package that the directory carries. To read with the terraform and k8s kinds, install their lexicons next to chant. + +Member names are built from each directory's path relative to ``, so they stay the same from one revision to the next. The path is lowercased and each run of characters a name can't hold becomes one `-`: `infra/net` gives `infra-net`, and `` itself gives `root`. When the result is longer than 40 characters, or two directories would share it (`a/b` and `a-b`), it is cut short and ends in `-` and the first six hex digits of the SHA-256 of the path, which still depends on the path alone. The workspace takes ``'s base name, rewritten by the same rule. + +`--member`, `--detail`, `--env`, `--live`, `--no-cache`, `-o` and `--dry-run` work as they do for a declared read, and `--member` takes the discovered names. `--at ` discovers the members in the commit's tree under ``, which must sit in a git repository, and reads them at that commit. `--discover` takes none of `--composites`, `--intent` and `--kind`. When `` holds a `chant.workspace.json` or `.jsonc` itself, that declaration is read as without `--discover`, and the document has no `discovered` list. A declaration in a directory above `` is not read. + +A discovered document carries one more top-level field, `discovered`. It lists every directory some kind claims, sorted by `dir`, with what became of it: + +```json +"discovered": [ + { "dir": "argo", "member": "argo", "kind": "argo-app", "source": "@intentius/chant-lexicon-k8s", + "probe": { "anyDocument": { "in": ["*.yaml", "*.yml"], "match": [{ "/apiVersion": ["argoproj.io/*"], "/kind": ["Application"] }] } }, + "outcome": "member", "claims": [{ "kind": "argo-app", "precedence": 360, "source": "@intentius/chant-lexicon-k8s" }], "note": null }, + { "dir": "db", "member": null, "kind": null, "source": null, "probe": null, "outcome": "tie", + "claims": [{ "kind": "flyway", "precedence": 300, "source": "@intentius/chant-lexicon-sql" }, { "kind": "golang-migrate", "precedence": 300, "source": "@intentius/chant-lexicon-sql" }], + "note": "kinds flyway and golang-migrate claim it at precedence 300; name its kind in a declaration to read it" }, + { "dir": "infra/modules/vpc", "member": null, "kind": "terraform", "source": "@intentius/chant-lexicon-terraform", "probe": { "anyFile": ["*.tf"] }, + "outcome": "module", "claims": [{ "kind": "terraform", "precedence": 400, "source": "@intentius/chant-lexicon-terraform" }], + "note": "called as a module through a local source by infra/net" }, + { "dir": "infra/net", "member": "infra-net", "kind": "terraform", "source": "@intentius/chant-lexicon-terraform", "probe": { "anyFile": ["*.tf"] }, + "outcome": "member", "claims": [{ "kind": "terraform", "precedence": 400, "source": "@intentius/chant-lexicon-terraform" }], "note": null } +] +``` + +`dir` is relative to ``, `.` for `` itself. `member` is the member's name when `outcome` is `member`, and `null` otherwise. `kind`, `source` and `probe` describe the kind the precedence order picks, with the probe as its kinds file states it, and are `null` for a tie. `outcome` is one of `member`, `tie`, `module` and `inside-member`, a closed list. `claims` holds every kind whose probe claims the directory, highest precedence first. `note` says in one line why a directory is not a member. The members themselves are listed in `members` as in any graph document, with the discovered `dir` and `kind`. + ## Composition Every node id becomes `/`. Member names can't contain `/`, and `::` keeps its meaning for stacks inside a member, as in `app/web::Bucket`. Edge ends and `$ref` values in attributes are rewritten the same way, as are `compositeInstance`, `runtimeOwner`, `instanceOf` and the nodes of exports and imports. Each node and edge also gains a `member` field. `groups.byMember` maps each member to its node ids. A lexicon or a composite type means the same thing in every member, so `byLexicon` and `byComposite` keep their keys and merge the ids across members. The keys of `byStack`, `byContainer`, `byWave` and `byPipeline` name things inside one member, and they are prefixed with the member too. -CI members keep what [`chant graph`](/chant/cli/graph/) reports for them ([#3910](https://github.com/INTENTIUS/chant/issues/3910), [#3922](https://github.com/INTENTIUS/chant/issues/3922)). An edge keeps its `kind` (`ref`, `needs`, `calls`, `triggers`, `includes` or `extends`) and its `crossPipeline` flag. `groups.byPipeline` maps each workflow or pipeline, as `/`, to the prefixed ids of the nodes it runs. A member's references that name no node of its graph, such as a `needs:` on a job no workflow declares or a `uses:` of another repository's workflow, go on the top-level `dangling` list. Each entry is the member's own `{ from, kind, path, value, crossPipeline? }` with `from` prefixed and a `member` field, sorted by `from`, `path` and `value`. The list is absent when no member has one. Edges between members are still drawn only through [links](#links). +CI members keep what [`chant graph`](/chant/cli/graph/) reports for them ([#3910](https://github.com/INTENTIUS/chant/issues/3910), [#3922](https://github.com/INTENTIUS/chant/issues/3922)). An edge keeps its `kind` (`ref`, `needs`, `calls`, `triggers`, `includes` or `extends`) and its `crossPipeline` flag. `groups.byPipeline` maps each workflow or pipeline, as `/`, to the prefixed ids of the nodes it runs. A member's references that name no node of its graph, such as a `needs:` on a job no workflow declares or a `uses:` of another repository's workflow, go on the top-level `dangling` list. Each entry is the member's own `{ from, kind, path, value, crossPipeline? }` with `from` prefixed and a `member` field, sorted by `from`, `path` and `value`. The list is absent when no member has one. Edges between members are drawn through [links](#links) and by the [reference catalog](#derived-edges). The `links` section holds the [member links](#links), followed by the [record links](#record-links) when `--kind` names a record kind. The `records` section lists the records of that kind, and it is empty without `--kind`. +## Derived edges + +Each lexicon's reference catalog says how its resources name each other: a Deployment's `serviceAccountName` names a ServiceAccount, a subnet's `vpc_id` names a VPC. `chant workspace graph` runs the catalog of every lexicon in the graph over the composed nodes, so a reference joins nodes of two members ([#5097](https://github.com/INTENTIUS/chant/issues/5097)). It is the pass `chant graph --live` and cloud indexes run (`reconstructIndexedEdges`, [#4522](https://github.com/INTENTIUS/chant/issues/4522)), and every join is exact: a value is matched against the values that identify a node of the kind the rule names, never against a near name. + +The rules read nested attributes (`spec`, `metadata`, a terraform block's arguments), which only `--detail 3` prints, so the pass reads each member at `--detail 3` whatever tier the document is printed at. At `--detail 1` and `0` each edge, dangling holder and candidate moves to the node it is drawn as, its composite or its member's stack node, and an edge that falls inside one node is dropped. The pass does not run with `--live`, where each member's own chant runs its catalog on the account it read. + +What it finds goes in four places: + +| Field | What it holds | +|---|---| +| `edges[]` | An edge with `origin: "derived"`, the `rule` that drew it, `relation` (`reference` or `containment`), `grain: "property"` and `member`, the holder's member. A pair the declared graph already joins gets no second edge. | +| `dangling[]` | A reference that names no node, as `{ from, kind: "ref", path, value, member, rule, targetKind? }`. A missing edge is never read as no relation. | +| `ambiguous[]` | A reference that names more than one node, as `{ from, member, rule, path, value, candidates }`. No edge is drawn. Absent when there are none. | +| `catalog` | `lexicons`, whose catalogs ran; `members`, whose nodes the pass read; `rules`, each rule the document names by id with its `lexicon`, `from`, `path`, `relation`, `targetKinds` and `label`; and `nonLiteral`, by node id, the arguments the pass could not read because their value is not literal. | + +A rule id is `::`, such as `k8s:K8s::Apps::Deployment:spec.template.spec.serviceAccountName`. One id can stand for several rules of one path, one per target kind, which is why `targetKinds` is a list. + +```json +{ + "edges": [ + { "from": "app/web", "to": "rbac/runner", "kind": "ref", "viaAttr": "spec", "grain": "property", + "origin": "derived", "rule": "k8s:K8s::Apps::Deployment:spec.template.spec.serviceAccountName", + "relation": "reference", "member": "app" } + ], + "catalog": { + "lexicons": ["k8s", "terraform"], + "members": ["app", "infra", "rbac"], + "rules": { + "k8s:K8s::Apps::Deployment:spec.template.spec.serviceAccountName": { + "lexicon": "k8s", "from": "K8s::Apps::Deployment", "path": "spec.template.spec.serviceAccountName", + "relation": "reference", "targetKinds": ["K8s::Core::ServiceAccount"], "label": "runs as" + } + }, + "nonLiteral": { "infra/infra/google_service_account.runner": 1 } + } +} +``` + +Every node sits in one workspace scope, and a node of a kind its catalog scopes also sits in the scope it names. A Kubernetes object's names are unique inside its namespace, so a holder in a namespace matches the nodes of that namespace in any member, and every node with no namespace, such as a cluster-scoped object or a cloud resource. A namespaced object that names no namespace is matched only inside its own member, since chant cannot tell where it will be applied. One Namespace declared by two members makes every object in it ambiguous to its namespace rule, and draws no containment edge. + +A terraform block is read as its provider type with its literal arguments ([`declaredNode`](/chant/lexicon-authoring/observation-contract/#live-graph-edges-referencecatalog--enrichliveattrs)). An argument holding an interpolation is left out and counted in `nonLiteral`; one that names another block already draws its declared edge. + ## Nested workspaces A member of kind `workspace` holds its own declaration. The outer workspace reads it read-only, through the nested workspace's own command ([#2551](https://github.com/INTENTIUS/chant/issues/2551), [ws-007](https://github.com/INTENTIUS/chant/blob/main/docs/design/decisions/ws-007-nesting.md), [ws-071](https://github.com/INTENTIUS/chant/blob/main/docs/design/decisions/ws-071-nested-reads.md)). chant runs `chant workspace graph` in the nested root, which hands itself to the nested workspace's own chant when it has one, as at any root. The outer read passes on `--at`, `--env`, `--live`, `--overlay`, `--traffic`, `--detail` and `--no-cache`, and nothing that writes. The answer must be a graph document of a contract this chant reads. @@ -526,7 +605,8 @@ A trace over one region may take at most twice as long as [`chant workspace stat | Option | Effect | |---|---| -| `dir` | Where the walk up to the declaration starts. | +| `dir` | Where the walk up to the declaration starts. With `--discover`, the directory whose members are discovered. | +| `--discover` | Find the members by the kinds' probes when `dir` has no declaration, and write nothing inside it. See [discovering members](#discovering-members). | | `--at ` | Read the declaration at a commit, and each member's graph from its source at that commit. The tree is exported to a temporary directory and each member runs there under the toolchain installed now. See [what `--at` reads](/chant/reference/workspace-read-contract/#identity-and-revisions). | | `-o, --output ` | Write the document to a file. | | `--member ` | Compose only these members. Repeatable, and a comma list works too. | diff --git a/docs/src/content/docs/lexicon-authoring/observation-contract.mdx b/docs/src/content/docs/lexicon-authoring/observation-contract.mdx index ef2400896a..befe3ce614 100644 --- a/docs/src/content/docs/lexicon-authoring/observation-contract.mdx +++ b/docs/src/content/docs/lexicon-authoring/observation-contract.mdx @@ -547,6 +547,26 @@ export const myReferenceCatalog: ReferenceCatalog = { A reference whose target isn't in the observed set is reported as dangling and never drawn as a wrong edge. +A path step is a key. `[]` after a step reads every element of a list, and a key that holds dots or slashes is quoted as a JSON string in brackets: `metadata.annotations["eks.amazonaws.com/role-arn"]`, `spec.selector["app.kubernetes.io/name"]` ([#5097](https://github.com/INTENTIUS/chant/issues/5097)). + +### On a declared workspace graph + +[`chant workspace graph`](/chant/cli/workspace-graph/#derived-edges) runs the same catalog over the composed declared graph, across members ([#5097](https://github.com/INTENTIUS/chant/issues/5097)). Two optional fields shape what it reads there: + +- `scopes`, a list of `{ kind, path }`: a node of `kind` has names unique only inside the scope the value at `path` names. The k8s catalog lists each namespaced kind with `metadata.namespace`. +- `declaredNode(node)`, a pure function giving the node the rules read when the declared node is not shaped like them, as `{ kind, attrs, nonLiteral }`. The terraform catalog gives a `Terraform::Resource` its provider type as `kind` and its literal arguments as `attrs`, and counts the arguments it left out. + +### Adding a rule + +A rule is one entry in `refs`, in the lexicon's `reference-catalog.ts`: + +```typescript +{ from: "K8s::Core::ServiceAccount", path: 'metadata.annotations["iam.gke.io/gcp-service-account"]', + targetKind: "google_service_account", relation: "reference", label: "acts as" } +``` + +Its id, `::`, is what each edge it draws and each dangling or ambiguous entry it records carries as `rule`, and what `catalog.rules` describes, so a reader picks it up with no change on its side. The target kind needs an identity rule for the value the path holds, unless the value is a node id. A field that can name one of several kinds gets one rule per kind, each `optional`, so a value naming a node of one kind is not dangling under the others. A rule whose path is a value that is only sometimes a reference (an env var) is `optional` too. Each catalog's test suite checks that every rule draws its edge on a fixture of its own. + ### When `describeResources` is too thin: `enrichLiveAttrs` Edge reconstruction only works if the observed nodes actually carry those reference attributes. Some observation APIs return thin metadata; AWS `describe-stack-resources` gives stack outputs and no per-resource references. Then implement `enrichLiveAttrs` to source richer attributes for graphing: diff --git a/docs/src/content/docs/lexicon-authoring/overview.mdx b/docs/src/content/docs/lexicon-authoring/overview.mdx index 98a2d2cc32..8e7d245b24 100644 --- a/docs/src/content/docs/lexicon-authoring/overview.mdx +++ b/docs/src/content/docs/lexicon-authoring/overview.mdx @@ -138,7 +138,7 @@ best-known readers. | `executeTeardown()` | `TeardownExecution` | Delete the handed-over teardown candidates, one outcome per candidate (deleted / failed / not-prunable / retained with reason) — core retries failures once | | `listArtifacts()` | `Record` | Runtime artifacts rather than 1:1 resources — Helm releases, Docker containers | | `ownershipChannel` | `OwnershipChannel` | Where this lexicon can stamp and read chant's ownership marker, per read path | -| `referenceCatalog` | `ReferenceCatalog` | How observed resources reference each other, so `chant graph --live` can rebuild edges from a bag of nodes | +| `referenceCatalog` | `ReferenceCatalog` | How resources reference each other, so `chant graph --live` can rebuild edges from a bag of nodes and `chant workspace graph` can draw them across members | | `listedTypes` | `ListedTypeMapping` | How a cloud inventory API's type names map to this lexicon's kinds, so an indexed resource becomes a typed node and its properties go through `deepNormalizationHooks` | | `indexIdentity` | `IndexIdentity` | The identifier a declaration's props spell (aws: the CloudFormation `primaryIdentifier`; k8s: `/` at its namespace, matched by kind), so a declared entity that was never deployed can be matched to an indexed resource | | `indexImport` | `IndexImportCodegen` | How an indexed resource is written as source for `chant import --index`: the import IR for one node, a value that names another imported node as a reference, and a masked value as a parameter. Core passes the IR to `templateGenerator`. A lexicon without it reports its indexed nodes as unsupported | diff --git a/docs/src/content/docs/reference/workspace-kinds.mdx b/docs/src/content/docs/reference/workspace-kinds.mdx index cbfa23a0b5..924dd7d541 100644 --- a/docs/src/content/docs/reference/workspace-kinds.mdx +++ b/docs/src/content/docs/reference/workspace-kinds.mdx @@ -496,17 +496,18 @@ The file also holds a SHA-256 digest of the migration files it ran, and for Flyw ## Platform kinds -Seven kinds cover the files a platform repository holds besides Terraform ([#3179](https://github.com/INTENTIUS/chant/issues/3179)). Each is data in the kinds file of the package that knows the substrate. All seven have a `graph` block, so [`chant workspace graph`](/chant/cli/workspace-graph/) draws their members (see [below](#how-the-platform-kinds-are-read)). +Eight kinds cover the files a platform repository holds besides Terraform ([#3179](https://github.com/INTENTIUS/chant/issues/3179)). Each is data in the kinds file of the package that knows the substrate. All eight have a `graph` block, so [`chant workspace graph`](/chant/cli/workspace-graph/) draws their members (see [below](#how-the-platform-kinds-are-read)). | Kind | Package | Precedence | Probe | |---|---|---|---| -| `argo-app` | `@intentius/chant-lexicon-k8s` | 360 | a YAML file with `apiVersion: argoproj.io/*` and `kind: Application` | +| `argo-app` | `@intentius/chant-lexicon-k8s` | 360 | a YAML file with `apiVersion: argoproj.io/*` and `kind: Application`, `ApplicationSet` or `AppProject` | | `flux-kustomization` | `@intentius/chant-lexicon-k8s` | 350 | a YAML file with `apiVersion: kustomize.toolkit.fluxcd.io/*` and `kind: Kustomization`. kustomize's own `kustomization.yaml` uses another apiVersion and isn't claimed | | `kustomize` | `@intentius/chant-lexicon-k8s` | 340 | `kustomization.yaml`, `kustomization.yml` or `Kustomization` | | `helm-chart` | `@intentius/chant-lexicon-helm` | 330 | `Chart.yaml`, which the kind also checks (`apiVersion`, `name`, `version`) | | `cloudformation` | `@intentius/chant-lexicon-aws` | 320 | a `.yaml`, `.yml`, `.json` or `.template` file with `AWSTemplateFormatVersion` or `Resources` at its top. YAML short-form tags such as `!Ref` are allowed | | `cdk` | `@intentius/chant-lexicon-aws` | 315 | `cdk.json`, which the kind also checks (`app`) | | `pulumi` | `@intentius/chant-lexicon-pulumi` | 310 | `Pulumi.yaml`, which the kind also checks (`name`, `runtime`). The kind was in `@intentius/chant-lexicon-terraform` until [#4453](https://github.com/INTENTIUS/chant/issues/4453); a workspace that reads Pulumi members pins the pulumi lexicon | +| `manifests` | `@intentius/chant-lexicon-k8s` | 305 | a YAML file with an `apiVersion` and a `kind`, whatever their values. Every kind above outranks it, so a directory with a `kustomization.yaml`, a `Chart.yaml` or an Argo CD document goes to that kind | [`chant workspace init`](/chant/cli/workspace-init/) proposes these kinds, and pins the packages, when the packages are installed at the root. @@ -514,8 +515,9 @@ Seven kinds cover the files a platform repository holds besides Terraform ([#317 | Kind | What the graph holds | Needs | |---|---|---| -| `argo-app` | an `Application` per document, as a node | nothing; the manifests are read as data | +| `argo-app` | an `Application`, `ApplicationSet` or `AppProject` per document, as a node | nothing; the manifests are read as data | | `flux-kustomization` | a Flux `Kustomization` per document, as a node | nothing | +| `manifests` | a node per document with an `apiVersion` and a `kind`, including custom resources the k8s lexicon has no class for, with its `spec` at `--detail 3`. A file that does not parse, or holds `{{ ... }}` template syntax, is named in the member's warnings and the other files are still read. A directory that a `kustomization.yaml` in the workspace lists in `resources` is left to the kustomize member (`coveredBy` on `meta.k8sMember`), so its objects are not drawn twice | nothing | | `cloudformation` | a node per resource; an edge per `Ref`, `Fn::GetAtt`, `Fn::Sub` reference and `DependsOn` between resources of the template | nothing | | `kustomize` | the objects `kustomize build` renders, as nodes | `kustomize`, or `kubectl` | | `helm-chart` | the objects `helm template` renders, as nodes | `helm` | diff --git a/lexicons/k8s/docs/pages/importing-yaml.mdx b/lexicons/k8s/docs/pages/importing-yaml.mdx index 3d2fca1a3e..0912c7a7f3 100644 --- a/lexicons/k8s/docs/pages/importing-yaml.mdx +++ b/lexicons/k8s/docs/pages/importing-yaml.mdx @@ -20,6 +20,10 @@ Input YAML → parse → generate TypeScript → export typed resources The importer reads multi-document YAML, identifies each resource’s `apiVersion` and `kind`, and generates the corresponding typed constructor call. The output is a valid `.k8s.ts` file you can immediately build with `chant build`. +## Kinds the lexicon has no class for + +The importer writes a typed class only when `@intentius/chant-lexicon-k8s` exports one for that group and kind. For any other kind, such as the custom resources of an operator whose CRD the lexicon does not ship, it writes the manifest as `k8sManifest({ apiVersion, kind, ... })`. That source builds, and the build writes the manifest back as it was. The import prints one warning per kind. To get a typed class, list the CRD under `k8s.crds` in `chant.config.ts` and run `chant generate`, as described in [CRD-generated classes](/chant/lexicons/k8s/crd-classes/). + ## Collector configs, rule groups, Alertmanager configs and dashboards inside manifests `chant import` hands content that another lexicon owns to that lexicon, when it is installed: diff --git a/lexicons/k8s/src/config-schema.ts b/lexicons/k8s/src/config-schema.ts index 0b03ff02a9..9f28004d7d 100644 --- a/lexicons/k8s/src/config-schema.ts +++ b/lexicons/k8s/src/config-schema.ts @@ -75,9 +75,10 @@ export const k8sConfigSchema = z.strictObject({ .optional(), member: z .strictObject({ - kind: z.enum(["kustomize", "argo-app", "flux-kustomization"]), + kind: z.enum(["kustomize", "argo-app", "flux-kustomization", "manifests"]), dir: z.string().min(1), label: z.string().optional(), + workspace: z.string().optional(), }) .optional(), receipts: z diff --git a/lexicons/k8s/src/config.ts b/lexicons/k8s/src/config.ts index 116c5d7cbe..2851be3996 100644 --- a/lexicons/k8s/src/config.ts +++ b/lexicons/k8s/src/config.ts @@ -124,7 +124,7 @@ export interface K8sChantConfig { /** * One workspace member read into the graph (#3179). `chant workspace graph` * writes this into the reader project it makes for a member of kind - * `kustomize`, `argo-app` or `flux-kustomization`; it is not meant to be + * `kustomize`, `argo-app`, `flux-kustomization` or `manifests`; it is not meant to be * written by hand. `dir` is the member's directory, absolute; `label` names * the entities (`