@intentius/chant-lexicon-k8s 0.124.96 → 0.124.98
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/application-paths.d.ts +4 -0
- package/dist/application-paths.d.ts.map +1 -0
- package/dist/application-paths.js +95 -0
- package/dist/application-set.d.ts +46 -0
- package/dist/application-set.d.ts.map +1 -0
- package/dist/application-set.js +303 -0
- package/dist/cluster-secret.d.ts +36 -0
- package/dist/cluster-secret.d.ts.map +1 -0
- package/dist/cluster-secret.js +55 -0
- package/dist/components/kustomize-apply.d.ts +6 -0
- package/dist/components/kustomize-apply.d.ts.map +1 -1
- package/dist/components/kustomize-apply.js +1 -1
- package/dist/config-schema.d.ts +8 -0
- package/dist/config-schema.d.ts.map +1 -1
- package/dist/config-schema.js +6 -2
- package/dist/config.d.ts +26 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/helm-references.d.ts +113 -0
- package/dist/helm-references.d.ts.map +1 -0
- package/dist/helm-references.js +389 -0
- package/dist/import/generator.d.ts +11 -2
- package/dist/import/generator.d.ts.map +1 -1
- package/dist/import/generator.js +37 -55
- package/dist/import/parser.d.ts.map +1 -1
- package/dist/import/parser.js +34 -5
- package/dist/import/typed-classes.d.ts +57 -0
- package/dist/import/typed-classes.d.ts.map +1 -0
- package/dist/import/typed-classes.js +126 -0
- package/dist/integrity.json +41 -41
- package/dist/kustomize/render.d.ts +41 -2
- package/dist/kustomize/render.d.ts.map +1 -1
- package/dist/kustomize/render.js +114 -7
- package/dist/kustomize/root.d.ts +3 -3
- package/dist/kustomize/root.d.ts.map +1 -1
- package/dist/kustomize/root.js +6 -1
- package/dist/lint/post-synth/argo-helpers.d.ts +3 -0
- package/dist/lint/post-synth/argo-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/argo-helpers.js +8 -2
- package/dist/lint/post-synth/argo002.d.ts.map +1 -1
- package/dist/lint/post-synth/argo002.js +2 -1
- package/dist/lint/post-synth/argo003.d.ts.map +1 -1
- package/dist/lint/post-synth/argo003.js +2 -1
- package/dist/lint/post-synth/argo005.d.ts.map +1 -1
- package/dist/lint/post-synth/argo005.js +36 -9
- package/dist/lint/post-synth/crd-schema-helpers.d.ts +1 -1
- package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/crd-schema-helpers.js +3 -3
- package/dist/lint/post-synth/flux002.d.ts.map +1 -1
- package/dist/lint/post-synth/flux002.js +2 -1
- package/dist/lint/post-synth/flux003.d.ts.map +1 -1
- package/dist/lint/post-synth/flux003.js +2 -1
- package/dist/lint/post-synth/k8s-helpers.d.ts +32 -0
- package/dist/lint/post-synth/k8s-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/k8s-helpers.js +57 -10
- package/dist/lint/post-synth/wk8005.d.ts +9 -0
- package/dist/lint/post-synth/wk8005.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8005.js +53 -3
- package/dist/lint/post-synth/wk8006.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8006.js +4 -2
- package/dist/lint/post-synth/wk8041.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8041.js +3 -2
- package/dist/lint/post-synth/wk8042.js +2 -2
- package/dist/lint/post-synth/wk8101.js +2 -2
- package/dist/lint/post-synth/wk8102.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8102.js +7 -3
- package/dist/lint/post-synth/wk8103.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8103.js +3 -2
- package/dist/lint/post-synth/wk8104.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8104.js +3 -2
- package/dist/lint/post-synth/wk8105.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8105.js +3 -2
- package/dist/lint/post-synth/wk8201.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8201.js +3 -2
- package/dist/lint/post-synth/wk8202.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8202.js +3 -2
- package/dist/lint/post-synth/wk8203.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8203.js +3 -2
- package/dist/lint/post-synth/wk8204.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8204.js +5 -2
- package/dist/lint/post-synth/wk8205.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8205.js +3 -2
- package/dist/lint/post-synth/wk8207.js +2 -2
- package/dist/lint/post-synth/wk8208.js +2 -2
- package/dist/lint/post-synth/wk8209.js +2 -2
- package/dist/lint/post-synth/wk8301.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8301.js +3 -2
- package/dist/lint/post-synth/wk8302.js +2 -2
- package/dist/lint/post-synth/wk8303.js +2 -2
- package/dist/lint/post-synth/wk8304.js +2 -2
- package/dist/lint/post-synth/wk8305.js +2 -2
- package/dist/lint/post-synth/wk8306.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8306.js +3 -2
- package/dist/lint/post-synth/wk8401.js +2 -2
- package/dist/lint/post-synth/wk8402.js +2 -2
- package/dist/lint/post-synth/wk8403.js +2 -2
- package/dist/lint/post-synth/wk8404.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8404.js +2 -2
- package/dist/lint/post-synth/wk8405.js +2 -2
- package/dist/lint/post-synth/wk8406.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8406.js +3 -2
- package/dist/lint/post-synth/wk8407.js +2 -2
- package/dist/lint/post-synth/wk8503.js +2 -2
- package/dist/manifest.json +1 -1
- package/dist/reference-catalog.d.ts +3 -1
- package/dist/reference-catalog.d.ts.map +1 -1
- package/dist/reference-catalog.js +283 -15
- package/dist/rules/argo-helpers.ts +9 -2
- package/dist/rules/argo002.ts +2 -1
- package/dist/rules/argo003.ts +2 -1
- package/dist/rules/argo005.ts +36 -10
- package/dist/rules/crd-schema-helpers.ts +3 -3
- package/dist/rules/flux002.ts +2 -1
- package/dist/rules/flux003.ts +2 -1
- package/dist/rules/k8s-helpers.ts +56 -11
- package/dist/rules/wk8005.ts +56 -3
- package/dist/rules/wk8006.ts +4 -2
- package/dist/rules/wk8041.ts +3 -2
- package/dist/rules/wk8042.ts +2 -2
- package/dist/rules/wk8101.ts +2 -2
- package/dist/rules/wk8102.ts +7 -3
- package/dist/rules/wk8103.ts +3 -2
- package/dist/rules/wk8104.ts +3 -2
- package/dist/rules/wk8105.ts +3 -2
- package/dist/rules/wk8201.ts +3 -2
- package/dist/rules/wk8202.ts +3 -2
- package/dist/rules/wk8203.ts +3 -2
- package/dist/rules/wk8204.ts +5 -2
- package/dist/rules/wk8205.ts +3 -2
- package/dist/rules/wk8207.ts +2 -2
- package/dist/rules/wk8208.ts +2 -2
- package/dist/rules/wk8209.ts +2 -2
- package/dist/rules/wk8301.ts +3 -2
- package/dist/rules/wk8302.ts +2 -2
- package/dist/rules/wk8303.ts +2 -2
- package/dist/rules/wk8304.ts +2 -2
- package/dist/rules/wk8305.ts +2 -2
- package/dist/rules/wk8306.ts +3 -2
- package/dist/rules/wk8401.ts +2 -2
- package/dist/rules/wk8402.ts +2 -2
- package/dist/rules/wk8403.ts +2 -2
- package/dist/rules/wk8404.ts +2 -1
- package/dist/rules/wk8405.ts +2 -2
- package/dist/rules/wk8406.ts +3 -2
- package/dist/rules/wk8407.ts +2 -2
- package/dist/rules/wk8503.ts +2 -2
- package/dist/workspace-member.d.ts +15 -3
- package/dist/workspace-member.d.ts.map +1 -1
- package/dist/workspace-member.js +151 -21
- package/package.json +5 -5
- package/src/application-paths.ts +96 -0
- package/src/application-set.test.ts +130 -0
- package/src/application-set.ts +336 -0
- package/src/cluster-secret.test.ts +117 -0
- package/src/cluster-secret.ts +76 -0
- package/src/components/kustomize-apply.ts +7 -1
- package/src/config-schema.ts +6 -2
- package/src/config.ts +24 -4
- package/src/helm-references.test.ts +149 -0
- package/src/helm-references.ts +425 -0
- package/src/import/generator.test.ts +57 -0
- package/src/import/generator.ts +35 -61
- package/src/import/parser.test.ts +59 -0
- package/src/import/parser.ts +38 -5
- package/src/import/roundtrip-build.test.ts +91 -0
- package/src/import/typed-classes.ts +168 -0
- package/src/kustomize/helm.test.ts +183 -0
- package/src/kustomize/render.ts +142 -6
- package/src/kustomize/root.ts +8 -3
- package/src/lint/post-synth/argo-helpers.ts +9 -2
- package/src/lint/post-synth/argo002.ts +2 -1
- package/src/lint/post-synth/argo003.ts +2 -1
- package/src/lint/post-synth/argo005.ts +36 -10
- package/src/lint/post-synth/audit-identity.test.ts +65 -0
- package/src/lint/post-synth/crd-schema-helpers.ts +3 -3
- package/src/lint/post-synth/flux002.ts +2 -1
- package/src/lint/post-synth/flux003.ts +2 -1
- package/src/lint/post-synth/k8s-helpers.ts +56 -11
- package/src/lint/post-synth/post-synth.test.ts +144 -0
- package/src/lint/post-synth/wk8005.ts +56 -3
- package/src/lint/post-synth/wk8006.ts +4 -2
- package/src/lint/post-synth/wk8041.ts +3 -2
- package/src/lint/post-synth/wk8042.ts +2 -2
- package/src/lint/post-synth/wk8101.ts +2 -2
- package/src/lint/post-synth/wk8102.ts +7 -3
- package/src/lint/post-synth/wk8103.ts +3 -2
- package/src/lint/post-synth/wk8104.ts +3 -2
- package/src/lint/post-synth/wk8105.ts +3 -2
- package/src/lint/post-synth/wk8201.ts +3 -2
- package/src/lint/post-synth/wk8202.ts +3 -2
- package/src/lint/post-synth/wk8203.ts +3 -2
- package/src/lint/post-synth/wk8204.ts +5 -2
- package/src/lint/post-synth/wk8205.ts +3 -2
- package/src/lint/post-synth/wk8207.ts +2 -2
- package/src/lint/post-synth/wk8208.ts +2 -2
- package/src/lint/post-synth/wk8209.ts +2 -2
- package/src/lint/post-synth/wk8301.ts +3 -2
- package/src/lint/post-synth/wk8302.ts +2 -2
- package/src/lint/post-synth/wk8303.ts +2 -2
- package/src/lint/post-synth/wk8304.ts +2 -2
- package/src/lint/post-synth/wk8305.ts +2 -2
- package/src/lint/post-synth/wk8306.ts +3 -2
- package/src/lint/post-synth/wk8401.ts +2 -2
- package/src/lint/post-synth/wk8402.ts +2 -2
- package/src/lint/post-synth/wk8403.ts +2 -2
- package/src/lint/post-synth/wk8404.ts +2 -1
- package/src/lint/post-synth/wk8405.ts +2 -2
- package/src/lint/post-synth/wk8406.ts +3 -2
- package/src/lint/post-synth/wk8407.ts +2 -2
- package/src/lint/post-synth/wk8503.ts +2 -2
- package/src/reference-catalog.test.ts +78 -0
- package/src/reference-catalog.ts +297 -16
- package/src/testdata/helm-chart-missing/kustomization.yaml +8 -0
- package/src/testdata/helm-chart-root/charts/webchart/Chart.yaml +3 -0
- package/src/testdata/helm-chart-root/charts/webchart/templates/configmap.yaml +6 -0
- package/src/testdata/helm-chart-root/charts/webchart/values.yaml +1 -0
- package/src/testdata/helm-chart-root/kustomization.yaml +9 -0
- package/src/testdata/helm-chart-root/values.yaml +1 -0
- package/src/testdata/workspace-members/argo-clusters/clusters.yaml +34 -0
- package/src/testdata/workspace-members/argo-set/all.yaml +43 -0
- package/src/testdata/workspace-members/plain/deploy.yaml +27 -0
- package/src/testdata/workspace-members/plain/es.yaml +15 -0
- package/src/testdata/workspace-members/templated/block.yaml +6 -0
- package/src/testdata/workspace-members/templated/chart-cm.yaml +4 -0
- package/src/testdata/workspace-members/templated/cm.yaml +6 -0
- package/src/workspace-kinds.test.ts +9 -1
- package/src/workspace-member.test.ts +69 -3
- package/src/workspace-member.ts +165 -24
- package/workspace-kinds.json +45 -6
package/dist/workspace-member.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reading a workspace member into the graph (#3179).
|
|
2
|
+
* Reading a workspace member into the graph (#3179, #5096).
|
|
3
3
|
*
|
|
4
4
|
* `chant workspace graph` writes a reader project for a member of kind
|
|
5
|
-
* `kustomize`, `argo-app
|
|
6
|
-
* config (see `workspace-kinds.json`). The k8s plugin's
|
|
7
|
-
* {@link readK8sMember}, and the objects it returns are
|
|
5
|
+
* `kustomize`, `argo-app`, `flux-kustomization` or `manifests`, with
|
|
6
|
+
* `k8s.member` in its config (see `workspace-kinds.json`). The k8s plugin's
|
|
7
|
+
* `buildRoots` hook calls {@link readK8sMember}, and the objects it returns are
|
|
8
|
+
* the member's nodes.
|
|
8
9
|
*
|
|
9
10
|
* - `kustomize` renders the directory through the kustomize runner (`kustomize
|
|
10
11
|
* build`, `kubectl kustomize` fallback). With neither binary installed there
|
|
@@ -12,17 +13,32 @@
|
|
|
12
13
|
* `rendered: false` with the reason. A render the binary ran and refused is
|
|
13
14
|
* not that case and still throws.
|
|
14
15
|
* - `argo-app` and `flux-kustomization` read the directory's YAML files and keep
|
|
15
|
-
* the documents of their
|
|
16
|
+
* the documents of their kinds. No binary is involved.
|
|
17
|
+
* - `manifests` reads the directory's YAML files and keeps every document with
|
|
18
|
+
* a string `apiVersion` and `kind`, whatever the kind, so a custom resource
|
|
19
|
+
* with no lexicon class is a node too. No binary is involved. A directory
|
|
20
|
+
* that a kustomization in the workspace lists in `resources` is not read:
|
|
21
|
+
* the kustomize member has its objects.
|
|
22
|
+
*
|
|
23
|
+
* An Argo CD cluster Secret (a Secret labelled `argocd.argoproj.io/secret-type:
|
|
24
|
+
* cluster`) is kept by the `argo-app` and `manifests` kinds, cut down to its
|
|
25
|
+
* metadata and the `name` and `server` it registers (#5101, ./cluster-secret.ts).
|
|
26
|
+
* Its other data holds the cluster's credentials, which the graph does not carry.
|
|
27
|
+
*
|
|
28
|
+
* A YAML file that does not parse, such as a chart template, is a warning that
|
|
29
|
+
* names the file; the member's other files are still read.
|
|
16
30
|
*/
|
|
17
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
18
|
-
import { basename, join } from "node:path";
|
|
31
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
32
|
+
import { basename, join, relative, resolve } from "node:path";
|
|
19
33
|
import { loadAll } from "js-yaml";
|
|
20
|
-
import { defaultKustomizeRunner, KustomizeBinaryMissingError, renderKustomizeDocuments } from "./kustomize/render.js";
|
|
34
|
+
import { defaultKustomizeRunner, KustomizeBinaryMissingError, KustomizeHelmDisabledError, KustomizeHelmRenderError, renderKustomizeDocuments, } from "./kustomize/render.js";
|
|
21
35
|
import { addRenderedEntity, renderedManifestEntity } from "./kustomize/rendered-entity.js";
|
|
22
|
-
|
|
36
|
+
import { clusterSecretView, isClusterSecretDocument } from "./cluster-secret.js";
|
|
37
|
+
import { kustomizationDocument, readHelmReferences } from "./helm-references.js";
|
|
38
|
+
/** The apiVersion group and kinds each manifest kind is made of. */
|
|
23
39
|
const MANIFEST_KINDS = {
|
|
24
|
-
"argo-app": { group: "argoproj.io",
|
|
25
|
-
"flux-kustomization": { group: "kustomize.toolkit.fluxcd.io",
|
|
40
|
+
"argo-app": { group: "argoproj.io", kinds: ["Application", "ApplicationSet", "AppProject"] },
|
|
41
|
+
"flux-kustomization": { group: "kustomize.toolkit.fluxcd.io", kinds: ["Kustomization"] },
|
|
26
42
|
};
|
|
27
43
|
function objectDocuments(text) {
|
|
28
44
|
const out = [];
|
|
@@ -32,19 +48,107 @@ function objectDocuments(text) {
|
|
|
32
48
|
}
|
|
33
49
|
return out;
|
|
34
50
|
}
|
|
35
|
-
/**
|
|
36
|
-
function
|
|
37
|
-
|
|
51
|
+
/** Whether a mapping anywhere in `value` has a mapping for a key, which js-yaml spells "[object Object]". */
|
|
52
|
+
function hasMappingKey(value) {
|
|
53
|
+
if (Array.isArray(value))
|
|
54
|
+
return value.some(hasMappingKey);
|
|
55
|
+
if (value === null || typeof value !== "object")
|
|
56
|
+
return false;
|
|
57
|
+
return Object.entries(value).some(([k, v]) => k === "[object Object]" || hasMappingKey(v));
|
|
58
|
+
}
|
|
59
|
+
/** The documents of a manifest member's YAML files directly in `dir`, in file-name order, and a warning for each file that does not parse. */
|
|
60
|
+
function manifestDocuments(dir, kind, label) {
|
|
38
61
|
const files = readdirSync(dir).filter((f) => /\.ya?ml$/.test(f)).sort();
|
|
39
62
|
const docs = [];
|
|
63
|
+
const warnings = [];
|
|
40
64
|
for (const file of files) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
let found;
|
|
66
|
+
try {
|
|
67
|
+
found = objectDocuments(readFileSync(join(dir, file), "utf-8"));
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
const reason = (err instanceof Error ? err.message : String(err)).split("\n")[0];
|
|
71
|
+
warnings.push(`${kind} member "${label}": ${file} is not valid YAML and was skipped (${reason})`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// `name: {{ .Values.x }}` is a valid YAML flow mapping, with a mapping for a key, so a template line like it parses. No plain manifest has one.
|
|
75
|
+
if (found.some(hasMappingKey)) {
|
|
76
|
+
warnings.push(`${kind} member "${label}": ${file} holds template syntax ({{ ... }}) and was skipped`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
for (const doc of found) {
|
|
80
|
+
if (typeof doc.apiVersion !== "string" || typeof doc.kind !== "string")
|
|
81
|
+
continue;
|
|
82
|
+
// A cluster Secret registers a cluster with Argo CD, so the Argo member reads it too, cut down to its name and server.
|
|
83
|
+
if (isClusterSecretDocument(doc)) {
|
|
84
|
+
if (kind === "manifests" || kind === "argo-app")
|
|
85
|
+
docs.push(clusterSecretView(doc));
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (kind === "manifests") {
|
|
89
|
+
docs.push(doc);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const want = MANIFEST_KINDS[kind];
|
|
93
|
+
if (doc.apiVersion.startsWith(`${want.group}/`) && want.kinds.includes(doc.kind))
|
|
44
94
|
docs.push(doc);
|
|
45
95
|
}
|
|
46
96
|
}
|
|
47
|
-
return docs;
|
|
97
|
+
return { docs, warnings };
|
|
98
|
+
}
|
|
99
|
+
const SCAN_SKIP = new Set(["node_modules", ".git"]);
|
|
100
|
+
const KUSTOMIZATION_FILES = ["kustomization.yaml", "kustomization.yml", "Kustomization"];
|
|
101
|
+
/** Directories each kustomization under `root` lists in `resources` (or `bases`), absolute, mapped to the kustomization's directory. One scan per root per process. */
|
|
102
|
+
const listedCache = new Map();
|
|
103
|
+
function listedDirectories(root) {
|
|
104
|
+
const cached = listedCache.get(root);
|
|
105
|
+
if (cached)
|
|
106
|
+
return cached;
|
|
107
|
+
const listed = new Map();
|
|
108
|
+
const walk = (dir) => {
|
|
109
|
+
let entries;
|
|
110
|
+
try {
|
|
111
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const file = entries.find((e) => e.isFile() && KUSTOMIZATION_FILES.includes(e.name));
|
|
117
|
+
if (file) {
|
|
118
|
+
try {
|
|
119
|
+
const doc = loadAll(readFileSync(join(dir, file.name), "utf-8"))[0];
|
|
120
|
+
for (const list of [doc?.resources, doc?.bases]) {
|
|
121
|
+
if (!Array.isArray(list))
|
|
122
|
+
continue;
|
|
123
|
+
for (const entry of list) {
|
|
124
|
+
if (typeof entry !== "string" || /^[a-z][a-z0-9+.-]*:/i.test(entry))
|
|
125
|
+
continue;
|
|
126
|
+
const target = resolve(dir, entry);
|
|
127
|
+
if (!listed.has(target) && existsSync(target) && statSync(target).isDirectory())
|
|
128
|
+
listed.set(target, dir);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// A kustomization that does not parse lists nothing here; its own member reports it.
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
for (const e of entries)
|
|
137
|
+
if (e.isDirectory() && !SCAN_SKIP.has(e.name))
|
|
138
|
+
walk(join(dir, e.name));
|
|
139
|
+
};
|
|
140
|
+
walk(root);
|
|
141
|
+
listedCache.set(root, listed);
|
|
142
|
+
return listed;
|
|
143
|
+
}
|
|
144
|
+
const truthy = (v) => v !== undefined && /^(1|true|yes)$/i.test(v.trim());
|
|
145
|
+
/** The Helm settings of a kustomize member: its config, or the environment when the config sets none. */
|
|
146
|
+
export function memberHelmOptions(member, env = process.env) {
|
|
147
|
+
return {
|
|
148
|
+
enableHelm: member.enableHelm ?? truthy(env.CHANT_K8S_ENABLE_HELM),
|
|
149
|
+
helmCommand: member.helmCommand ?? (env.CHANT_K8S_HELM_COMMAND || undefined),
|
|
150
|
+
fetchCharts: member.fetchCharts ?? truthy(env.CHANT_K8S_FETCH_CHARTS),
|
|
151
|
+
};
|
|
48
152
|
}
|
|
49
153
|
export async function readK8sMember(opts) {
|
|
50
154
|
const { member } = opts;
|
|
@@ -56,11 +160,12 @@ export async function readK8sMember(opts) {
|
|
|
56
160
|
let reason;
|
|
57
161
|
if (member.kind === "kustomize") {
|
|
58
162
|
try {
|
|
59
|
-
documents = await renderKustomizeDocuments(member.dir, opts.run ?? defaultKustomizeRunner);
|
|
163
|
+
documents = await renderKustomizeDocuments(member.dir, opts.run ?? defaultKustomizeRunner, memberHelmOptions(member));
|
|
60
164
|
rendered = true;
|
|
61
165
|
}
|
|
62
166
|
catch (err) {
|
|
63
|
-
|
|
167
|
+
// A render Helm kept from happening leaves the member unrendered, not lost: the chart and values nodes read as data below still stand.
|
|
168
|
+
if (!(err instanceof KustomizeBinaryMissingError || err instanceof KustomizeHelmDisabledError || err instanceof KustomizeHelmRenderError))
|
|
64
169
|
throw err;
|
|
65
170
|
documents = [];
|
|
66
171
|
rendered = false;
|
|
@@ -69,8 +174,33 @@ export async function readK8sMember(opts) {
|
|
|
69
174
|
}
|
|
70
175
|
}
|
|
71
176
|
else {
|
|
72
|
-
|
|
177
|
+
const listedBy = member.kind === "manifests" && member.workspace ? listedDirectories(resolve(member.workspace)).get(resolve(member.dir)) : undefined;
|
|
178
|
+
if (listedBy) {
|
|
179
|
+
const coveredBy = relative(resolve(member.workspace), listedBy) || ".";
|
|
180
|
+
return {
|
|
181
|
+
entities,
|
|
182
|
+
warnings,
|
|
183
|
+
report: { kind: member.kind, reason: `listed in resources by the kustomization in ${coveredBy}; its objects are read there`, coveredBy, objects: 0 },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const read = manifestDocuments(member.dir, member.kind, label);
|
|
187
|
+
documents = read.docs;
|
|
188
|
+
warnings.push(...read.warnings);
|
|
189
|
+
}
|
|
190
|
+
// Charts and values files, read as data (#5100), whether or not the member rendered.
|
|
191
|
+
if (member.kind === "kustomize") {
|
|
192
|
+
const own = kustomizationDocument(member.dir, label);
|
|
193
|
+
if (own)
|
|
194
|
+
documents = [own, ...documents];
|
|
73
195
|
}
|
|
196
|
+
documents = readHelmReferences({
|
|
197
|
+
documents,
|
|
198
|
+
ctx: { workspace: resolve(member.workspace ?? member.dir), dir: resolve(member.dir) },
|
|
199
|
+
label,
|
|
200
|
+
entities,
|
|
201
|
+
warnings,
|
|
202
|
+
memberKind: member.kind,
|
|
203
|
+
});
|
|
74
204
|
for (const doc of documents) {
|
|
75
205
|
const entity = renderedManifestEntity(doc, label);
|
|
76
206
|
if (!entity) {
|
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.98",
|
|
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.98",
|
|
78
|
+
"@intentius/chant-lexicon-prometheus": "^0.124.98",
|
|
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.98"
|
|
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.98"
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The repository paths an Argo CD Application names (#5102), for the
|
|
3
|
+
* catalog's path rules: the graph looks for each in the workspace's own
|
|
4
|
+
* repository and lists one that is not there as dangling. A generated
|
|
5
|
+
* Application (./application-set.ts) is read the same way as one written by
|
|
6
|
+
* hand.
|
|
7
|
+
*
|
|
8
|
+
* - `spec.source.path` and `spec.sources[].path`: a directory, from the root
|
|
9
|
+
* of the source's `repoURL`. A source that names a `chart` has no path in
|
|
10
|
+
* a repository.
|
|
11
|
+
* - `helm.valueFiles[]` on either: a file. `$<ref>/<path>` is a path in the
|
|
12
|
+
* repository of the source whose `ref` is `<ref>`. Any other relative value
|
|
13
|
+
* is a path inside the source's `path`, and is read only when the source
|
|
14
|
+
* names one. A URL is not read, and a source with
|
|
15
|
+
* `helm.ignoreMissingValueFiles: true` has none read.
|
|
16
|
+
*
|
|
17
|
+
* The helm rule (#5100, `helmReferences.valuesFiles[]`) owns the values
|
|
18
|
+
* files of every Application stamped with `helmReferences`, so they are
|
|
19
|
+
* not read here and a missing one is dangling once, under that rule. The
|
|
20
|
+
* k8s reader stamps an Application written by hand, and since #5094 the
|
|
21
|
+
* generate rule stamps a generated one the same way.
|
|
22
|
+
*
|
|
23
|
+
* A path that is absolute or climbs out of the repository's root is not
|
|
24
|
+
* read. Pure.
|
|
25
|
+
*/
|
|
26
|
+
import { posix } from "node:path";
|
|
27
|
+
import type { IRNode } from "@intentius/chant/graph-ir";
|
|
28
|
+
import type { PathRule, RepoPathRef } from "@intentius/chant/graph-refs";
|
|
29
|
+
import { APPLICATION } from "./application-set";
|
|
30
|
+
import { HELM_REFERENCES_KEY } from "./helm-references";
|
|
31
|
+
|
|
32
|
+
type Doc = Record<string, unknown>;
|
|
33
|
+
|
|
34
|
+
const isObject = (v: unknown): v is Doc => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
35
|
+
const str = (v: unknown): string | undefined => (typeof v === "string" && v !== "" ? v : undefined);
|
|
36
|
+
|
|
37
|
+
/** A path from the repository's root, normalized, or undefined when it is absolute or leaves the root. */
|
|
38
|
+
function repoPath(path: string): string | undefined {
|
|
39
|
+
if (path.startsWith("/")) return undefined;
|
|
40
|
+
const norm = posix.normalize(path).replace(/\/+$/, "");
|
|
41
|
+
if (norm === ".." || norm.startsWith("../")) return undefined;
|
|
42
|
+
return norm === "." ? "" : norm;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The value files of one source, as repository paths. */
|
|
46
|
+
function valueFiles(source: Doc, sources: readonly Doc[], stamped: boolean): RepoPathRef[] {
|
|
47
|
+
const helm = isObject(source.helm) ? source.helm : undefined;
|
|
48
|
+
if (stamped) return [];
|
|
49
|
+
if (!helm || helm.ignoreMissingValueFiles === true || !Array.isArray(helm.valueFiles)) return [];
|
|
50
|
+
const out: RepoPathRef[] = [];
|
|
51
|
+
for (const raw of helm.valueFiles) {
|
|
52
|
+
const file = str(raw);
|
|
53
|
+
if (!file || /^[a-z][a-z0-9+.-]*:\/\//i.test(file)) continue;
|
|
54
|
+
if (file.startsWith("$")) {
|
|
55
|
+
const slash = file.indexOf("/");
|
|
56
|
+
if (slash === -1) continue;
|
|
57
|
+
const ref = file.slice(1, slash);
|
|
58
|
+
const repo = str(sources.find((s) => s.ref === ref)?.repoURL);
|
|
59
|
+
const value = repoPath(file.slice(slash + 1));
|
|
60
|
+
if (repo && value !== undefined) out.push({ value, repo, type: "file" });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const repo = str(source.repoURL);
|
|
64
|
+
const base = str(source.path);
|
|
65
|
+
if (!repo || !base || source.chart !== undefined) continue;
|
|
66
|
+
const value = repoPath(posix.join(base, file));
|
|
67
|
+
if (value !== undefined) out.push({ value, repo, type: "file" });
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function sourcePath(source: Doc): RepoPathRef[] {
|
|
73
|
+
const repo = str(source.repoURL);
|
|
74
|
+
const path = str(source.path);
|
|
75
|
+
if (!repo || !path || source.chart !== undefined) return [];
|
|
76
|
+
const value = repoPath(path);
|
|
77
|
+
return value === undefined ? [] : [{ value, repo, type: "dir" }];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const specOf = (node: IRNode): Doc => (isObject(node.attrs.spec) ? node.attrs.spec : {});
|
|
81
|
+
const multi = (node: IRNode): Doc[] => {
|
|
82
|
+
const sources = specOf(node).sources;
|
|
83
|
+
return Array.isArray(sources) ? sources.filter(isObject) : [];
|
|
84
|
+
};
|
|
85
|
+
const single = (node: IRNode): Doc[] => (isObject(specOf(node).source) ? [specOf(node).source as Doc] : []);
|
|
86
|
+
|
|
87
|
+
/** Whether the k8s reader stamped the node's charts and values files for the helm rule (#5100). */
|
|
88
|
+
const stampedByHelm = (node: IRNode): boolean => isObject(node.attrs[HELM_REFERENCES_KEY]);
|
|
89
|
+
|
|
90
|
+
/** The path rules of an Application, one per field. */
|
|
91
|
+
export const applicationPathRules: PathRule[] = [
|
|
92
|
+
{ from: APPLICATION, path: "spec.source.path", label: "deploys from", read: (n) => single(n).flatMap(sourcePath) },
|
|
93
|
+
{ from: APPLICATION, path: "spec.sources[].path", label: "deploys from", read: (n) => multi(n).flatMap(sourcePath) },
|
|
94
|
+
{ from: APPLICATION, path: "spec.source.helm.valueFiles[]", label: "values from", read: (n) => single(n).flatMap((s) => valueFiles(s, [s], stampedByHelm(n))) },
|
|
95
|
+
{ from: APPLICATION, path: "spec.sources[].helm.valueFiles[]", label: "values from", read: (n) => multi(n).flatMap((s, _i, all) => valueFiles(s, all, stampedByHelm(n))) },
|
|
96
|
+
];
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import type { IRNode } from "@intentius/chant/graph-ir";
|
|
3
|
+
import { generateApplications } from "./application-set";
|
|
4
|
+
import { applicationPathRules } from "./application-paths";
|
|
5
|
+
|
|
6
|
+
const secret = (name: string, labels: Record<string, string>, server = `https://${name}.example.com`): IRNode => ({
|
|
7
|
+
id: `argo/secret-${name}`,
|
|
8
|
+
kind: "K8s::Core::Secret",
|
|
9
|
+
lexicon: "k8s",
|
|
10
|
+
attrs: { metadata: { name, labels: { "argocd.argoproj.io/secret-type": "cluster", ...labels } }, argoCluster: { name, server } },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const appSet = (spec: Record<string, unknown>, namespace?: string): IRNode => ({
|
|
14
|
+
id: "apps/set",
|
|
15
|
+
kind: "K8s::Argo::ApplicationSet",
|
|
16
|
+
lexicon: "k8s",
|
|
17
|
+
attrs: { apiVersion: "argoproj.io/v1alpha1", kind: "ApplicationSet", metadata: { name: "set", ...(namespace ? { namespace } : {}) }, spec },
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const template = (name: string, path: string, server = "{{ .server }}") => ({ metadata: { name, namespace: "ignored" }, spec: { source: { repoURL: "https://example.com/r.git", path }, destination: { server } } });
|
|
21
|
+
|
|
22
|
+
const CLUSTERS = [secret("gke-a", { cloud: "gke", env: "prod" }), secret("gke-b", { cloud: "gke", env: "dev" }), secret("eks-a", { cloud: "eks", env: "prod" })];
|
|
23
|
+
|
|
24
|
+
describe("generateApplications (#5102)", () => {
|
|
25
|
+
test("matchExpressions select clusters, and the Go form reads labels and values", () => {
|
|
26
|
+
const set = appSet(
|
|
27
|
+
{
|
|
28
|
+
goTemplate: true,
|
|
29
|
+
generators: [
|
|
30
|
+
{
|
|
31
|
+
clusters: {
|
|
32
|
+
selector: { matchExpressions: [{ key: "env", operator: "In", values: ["prod"] }, { key: "cloud", operator: "NotIn", values: ["eks"] }] },
|
|
33
|
+
values: { dir: "envs/{{ .metadata.labels.env }}" },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
template: template("x-{{ .name }}", "{{ .values.dir }}/{{ index .metadata.labels \"cloud\" }}"),
|
|
38
|
+
},
|
|
39
|
+
"argocd",
|
|
40
|
+
);
|
|
41
|
+
const out = generateApplications(set, CLUSTERS);
|
|
42
|
+
expect(out.notExpanded).toEqual([]);
|
|
43
|
+
expect(out.nodes.map((n) => [n.key, (n.attrs.spec as { source: { path: string } }).source.path, n.cluster?.id])).toEqual([["x-gke-a", "envs/prod/gke", "argo/secret-gke-a"]]);
|
|
44
|
+
expect((out.nodes[0].attrs.metadata as { namespace: string }).namespace).toBe("argocd");
|
|
45
|
+
expect(out.nodes[0].params).toMatchObject({ "values.dir": "envs/prod", nameNormalized: "gke-a" });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("a clusters generator with no selector also yields in-cluster when no Secret registers it", () => {
|
|
49
|
+
const out = generateApplications(appSet({ goTemplate: true, generators: [{ clusters: {} }], template: template("x-{{ .name }}", "p") }), CLUSTERS);
|
|
50
|
+
expect(out.nodes.map((n) => n.key)).toEqual(["x-eks-a", "x-gke-a", "x-gke-b", "x-in-cluster"]);
|
|
51
|
+
expect(out.nodes.find((n) => n.key === "x-in-cluster")?.cluster).toBeUndefined();
|
|
52
|
+
const registered = generateApplications(appSet({ goTemplate: true, generators: [{ clusters: {} }], template: template("x-{{ .name }}", "p") }), [secret("local", {}, "https://kubernetes.default.svc")]);
|
|
53
|
+
expect(registered.nodes.map((n) => n.key)).toEqual(["x-local"]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("the default form substitutes flattened list parameters, and a generator's template is merged over the set's", () => {
|
|
57
|
+
const out = generateApplications(
|
|
58
|
+
appSet({
|
|
59
|
+
generators: [{ list: { elements: [{ app: "a", values: { tier: "web" } }], template: { spec: { destination: { name: "c1" } } } } }],
|
|
60
|
+
template: template("{{app}}-{{ values.tier }}", "apps/{{app}}", "https://x"),
|
|
61
|
+
}),
|
|
62
|
+
[],
|
|
63
|
+
);
|
|
64
|
+
expect(out.nodes).toHaveLength(1);
|
|
65
|
+
expect(out.nodes[0].key).toBe("a-web");
|
|
66
|
+
expect(out.nodes[0].attrs.spec).toEqual({ source: { repoURL: "https://example.com/r.git", path: "apps/a" }, destination: { server: "https://x", name: "c1" } });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("an unknown function or field is reported and that element is not expanded", () => {
|
|
70
|
+
const out = generateApplications(
|
|
71
|
+
appSet({ goTemplate: true, generators: [{ list: { elements: [{ name: "a" }, { name: "b", path: "q" }] } }], template: template("{{ .name | upper }}", "p") }),
|
|
72
|
+
[],
|
|
73
|
+
);
|
|
74
|
+
expect(out.nodes).toEqual([]);
|
|
75
|
+
expect(out.notExpanded).toEqual([
|
|
76
|
+
"generators[0] element 0: {{ .name | upper }} uses a function or form the graph does not expand; not expanded",
|
|
77
|
+
"generators[0] element 1: {{ .name | upper }} uses a function or form the graph does not expand; not expanded",
|
|
78
|
+
]);
|
|
79
|
+
const missing = generateApplications(appSet({ goTemplate: true, generators: [{ list: { elements: [{ name: "a" }] } }], template: template("{{ .name }}", "{{ .path }}") }), []);
|
|
80
|
+
expect(missing.notExpanded).toEqual(["generators[0] element 0: the parameters have no .path; not expanded"]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("other generators, a post-selector and templatePatch are noted as not expanded", () => {
|
|
84
|
+
const out = generateApplications(
|
|
85
|
+
appSet({
|
|
86
|
+
generators: [{ git: { repoURL: "r" } }, { matrix: { generators: [] } }, { list: { elements: [] }, selector: { matchLabels: { a: "b" } } }, { list: { elementsYaml: "{{ .x }}" } }],
|
|
87
|
+
template: template("n", "p"),
|
|
88
|
+
}),
|
|
89
|
+
[],
|
|
90
|
+
);
|
|
91
|
+
expect(out.notExpanded).toEqual([
|
|
92
|
+
"generators[0]: the git generator is not expanded",
|
|
93
|
+
"generators[1]: the matrix generator is not expanded",
|
|
94
|
+
"generators[2]: a generator's post-selector is not expanded",
|
|
95
|
+
"generators[3]: list elementsYaml is not expanded",
|
|
96
|
+
]);
|
|
97
|
+
expect(generateApplications(appSet({ templatePatch: "x", generators: [{ list: { elements: [{}] } }], template: template("n", "p") }), []).notExpanded).toEqual([
|
|
98
|
+
"templatePatch is not expanded, so no Application is generated",
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("applicationPathRules (#5102)", () => {
|
|
104
|
+
const app = (spec: Record<string, unknown>): IRNode => ({ id: "a", kind: "K8s::Argo::Application", lexicon: "k8s", attrs: { spec } });
|
|
105
|
+
const read = (n: IRNode) => Object.fromEntries(applicationPathRules.map((r) => [r.path, r.read(n)]).filter(([, v]) => (v as unknown[]).length > 0));
|
|
106
|
+
|
|
107
|
+
test("a single source's path and its value files inside it", () => {
|
|
108
|
+
expect(read(app({ source: { repoURL: "R", path: "./apps/web/", helm: { valueFiles: ["values.yaml", "https://x/v.yaml"] } } }))).toEqual({
|
|
109
|
+
"spec.source.path": [{ value: "apps/web", repo: "R", type: "dir" }],
|
|
110
|
+
"spec.source.helm.valueFiles[]": [{ value: "apps/web/values.yaml", repo: "R", type: "file" }],
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("a chart source's $values file is read in the repository of the source with that ref", () => {
|
|
115
|
+
expect(
|
|
116
|
+
read(app({ sources: [{ repoURL: "https://charts", chart: "c", helm: { valueFiles: ["$values/k/helm/c.yaml", "inside-chart.yaml"] } }, { repoURL: "R", ref: "values" }] })),
|
|
117
|
+
).toEqual({ "spec.sources[].helm.valueFiles[]": [{ value: "k/helm/c.yaml", repo: "R", type: "file" }] });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("an Application the reader stamped for the helm rule has its values files read there, not here", () => {
|
|
121
|
+
const n = app({ source: { repoURL: "R", path: "apps/web", helm: { valueFiles: ["values.yaml"] } } });
|
|
122
|
+
n.attrs.helmReferences = { charts: [], valuesFiles: ["apps/web/values.yaml"] };
|
|
123
|
+
expect(read(n)).toEqual({ "spec.source.path": [{ value: "apps/web", repo: "R", type: "dir" }] });
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("ignoreMissingValueFiles, an absolute path and an escape are not read", () => {
|
|
127
|
+
expect(read(app({ source: { repoURL: "R", path: "../up", helm: { ignoreMissingValueFiles: true, valueFiles: ["v.yaml"] } } }))).toEqual({});
|
|
128
|
+
expect(read(app({ source: { repoURL: "R", path: "/abs" } }))).toEqual({});
|
|
129
|
+
});
|
|
130
|
+
});
|