@intentius/chant-lexicon-k8s 0.124.97 → 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-paths.d.ts","sourceRoot":"","sources":["../src/application-paths.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,QAAQ,EAAe,MAAM,6BAA6B,CAAC;AA8DzE,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,EAAE,QAAQ,EAK1C,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 { APPLICATION } from "./application-set.js";
|
|
28
|
+
import { HELM_REFERENCES_KEY } from "./helm-references.js";
|
|
29
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30
|
+
const str = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
31
|
+
/** A path from the repository's root, normalized, or undefined when it is absolute or leaves the root. */
|
|
32
|
+
function repoPath(path) {
|
|
33
|
+
if (path.startsWith("/"))
|
|
34
|
+
return undefined;
|
|
35
|
+
const norm = posix.normalize(path).replace(/\/+$/, "");
|
|
36
|
+
if (norm === ".." || norm.startsWith("../"))
|
|
37
|
+
return undefined;
|
|
38
|
+
return norm === "." ? "" : norm;
|
|
39
|
+
}
|
|
40
|
+
/** The value files of one source, as repository paths. */
|
|
41
|
+
function valueFiles(source, sources, stamped) {
|
|
42
|
+
const helm = isObject(source.helm) ? source.helm : undefined;
|
|
43
|
+
if (stamped)
|
|
44
|
+
return [];
|
|
45
|
+
if (!helm || helm.ignoreMissingValueFiles === true || !Array.isArray(helm.valueFiles))
|
|
46
|
+
return [];
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const raw of helm.valueFiles) {
|
|
49
|
+
const file = str(raw);
|
|
50
|
+
if (!file || /^[a-z][a-z0-9+.-]*:\/\//i.test(file))
|
|
51
|
+
continue;
|
|
52
|
+
if (file.startsWith("$")) {
|
|
53
|
+
const slash = file.indexOf("/");
|
|
54
|
+
if (slash === -1)
|
|
55
|
+
continue;
|
|
56
|
+
const ref = file.slice(1, slash);
|
|
57
|
+
const repo = str(sources.find((s) => s.ref === ref)?.repoURL);
|
|
58
|
+
const value = repoPath(file.slice(slash + 1));
|
|
59
|
+
if (repo && value !== undefined)
|
|
60
|
+
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)
|
|
66
|
+
continue;
|
|
67
|
+
const value = repoPath(posix.join(base, file));
|
|
68
|
+
if (value !== undefined)
|
|
69
|
+
out.push({ value, repo, type: "file" });
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
function sourcePath(source) {
|
|
74
|
+
const repo = str(source.repoURL);
|
|
75
|
+
const path = str(source.path);
|
|
76
|
+
if (!repo || !path || source.chart !== undefined)
|
|
77
|
+
return [];
|
|
78
|
+
const value = repoPath(path);
|
|
79
|
+
return value === undefined ? [] : [{ value, repo, type: "dir" }];
|
|
80
|
+
}
|
|
81
|
+
const specOf = (node) => (isObject(node.attrs.spec) ? node.attrs.spec : {});
|
|
82
|
+
const multi = (node) => {
|
|
83
|
+
const sources = specOf(node).sources;
|
|
84
|
+
return Array.isArray(sources) ? sources.filter(isObject) : [];
|
|
85
|
+
};
|
|
86
|
+
const single = (node) => (isObject(specOf(node).source) ? [specOf(node).source] : []);
|
|
87
|
+
/** Whether the k8s reader stamped the node's charts and values files for the helm rule (#5100). */
|
|
88
|
+
const stampedByHelm = (node) => isObject(node.attrs[HELM_REFERENCES_KEY]);
|
|
89
|
+
/** The path rules of an Application, one per field. */
|
|
90
|
+
export const applicationPathRules = [
|
|
91
|
+
{ from: APPLICATION, path: "spec.source.path", label: "deploys from", read: (n) => single(n).flatMap(sourcePath) },
|
|
92
|
+
{ from: APPLICATION, path: "spec.sources[].path", label: "deploys from", read: (n) => multi(n).flatMap(sourcePath) },
|
|
93
|
+
{ from: APPLICATION, path: "spec.source.helm.valueFiles[]", label: "values from", read: (n) => single(n).flatMap((s) => valueFiles(s, [s], stampedByHelm(n))) },
|
|
94
|
+
{ from: APPLICATION, path: "spec.sources[].helm.valueFiles[]", label: "values from", read: (n) => multi(n).flatMap((s, _i, all) => valueFiles(s, all, stampedByHelm(n))) },
|
|
95
|
+
];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argo CD ApplicationSets as the graph reads them (#5102).
|
|
3
|
+
*
|
|
4
|
+
* An ApplicationSet does not name its paths and clusters. Its generators
|
|
5
|
+
* yield parameter sets, and its template turns each set into an Application.
|
|
6
|
+
* {@link generateApplications} expands two generators whose inputs are
|
|
7
|
+
* literals in the repo:
|
|
8
|
+
*
|
|
9
|
+
* - `list`: one parameter set per entry of `elements`.
|
|
10
|
+
* - `clusters`: one per Argo CD cluster Secret in the graph that the
|
|
11
|
+
* generator's `selector` selects (`matchLabels`, and `matchExpressions`
|
|
12
|
+
* with `In`, `NotIn`, `Exists` and `DoesNotExist`), with the generator's
|
|
13
|
+
* `values` merged in under `values`. A generator with no selector also
|
|
14
|
+
* selects the cluster Argo CD runs in (`in-cluster`) when no Secret
|
|
15
|
+
* registers it. The parameters are `name`, `nameNormalized`, `server`,
|
|
16
|
+
* `metadata.labels.<key>` and `metadata.annotations.<key>`.
|
|
17
|
+
*
|
|
18
|
+
* Each parameter set is substituted into the template, with a generator's own
|
|
19
|
+
* `template` merged over it, in the form the ApplicationSet uses: `{{name}}`
|
|
20
|
+
* by default, `{{ .name }}` with `goTemplate: true`. The Go form reads a field
|
|
21
|
+
* (`.metadata.labels.cloud`) and `index` with literal keys; any other
|
|
22
|
+
* function or pipeline, and a field the parameters do not have, is reported
|
|
23
|
+
* and that element is not expanded. A generated Application sits in the
|
|
24
|
+
* ApplicationSet's namespace, as Argo CD creates it there.
|
|
25
|
+
*
|
|
26
|
+
* Other generators (`git`, `matrix`, `merge`, `scmProvider`, `pullRequest`,
|
|
27
|
+
* `clusterDecisionResource`, `plugin`), `elementsYaml`, a generator's
|
|
28
|
+
* post-selector and `templatePatch` are not expanded, and each is reported.
|
|
29
|
+
* Pure.
|
|
30
|
+
*/
|
|
31
|
+
import type { IRNode } from "@intentius/chant/graph-ir";
|
|
32
|
+
import type { Generated } from "@intentius/chant/graph-refs";
|
|
33
|
+
type Doc = Record<string, unknown>;
|
|
34
|
+
/** The kind of the node an ApplicationSet makes, and of the cluster registrations a `clusters` generator reads. */
|
|
35
|
+
export declare const APPLICATION = "K8s::Argo::Application";
|
|
36
|
+
export declare const APPLICATION_SET = "K8s::Argo::ApplicationSet";
|
|
37
|
+
/** Nested parameters as `a.b.c` keys, scalars as strings. */
|
|
38
|
+
export declare function flattenParams(params: Doc, prefix?: string, out?: Record<string, string>): Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* The Applications an ApplicationSet node generates from its `list` and
|
|
41
|
+
* `clusters` generators, given every node the pass reads (the cluster
|
|
42
|
+
* Secrets among them), and a line for each thing it did not expand.
|
|
43
|
+
*/
|
|
44
|
+
export declare function generateApplications(holder: IRNode, nodes: readonly IRNode[]): Generated;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=application-set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-set.d.ts","sourceRoot":"","sources":["../src/application-set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,6BAA6B,CAAC;AAG5E,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAKnC,mHAAmH;AACnH,eAAO,MAAM,WAAW,2BAA2B,CAAC;AACpD,eAAO,MAAM,eAAe,8BAA8B,CAAC;AAgG3D,6DAA6D;AAC7D,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,SAAK,EAAE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOhH;AAkFD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAuGxF"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { stampGeneratedApplication } from "./helm-references.js";
|
|
2
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3
|
+
const str = (v) => (typeof v === "string" ? v : undefined);
|
|
4
|
+
/** The kind of the node an ApplicationSet makes, and of the cluster registrations a `clusters` generator reads. */
|
|
5
|
+
export const APPLICATION = "K8s::Argo::Application";
|
|
6
|
+
export const APPLICATION_SET = "K8s::Argo::ApplicationSet";
|
|
7
|
+
const SECRET = "K8s::Core::Secret";
|
|
8
|
+
/** The cluster Argo CD runs in, as the `clusters` generator yields it when no Secret registers it. */
|
|
9
|
+
const IN_CLUSTER = { name: "in-cluster", server: "https://kubernetes.default.svc" };
|
|
10
|
+
/** Generators this module reads. Every other key of a generator entry is one it does not. */
|
|
11
|
+
const EXPANDED = new Set(["list", "clusters"]);
|
|
12
|
+
/** A template that did not render, and why. */
|
|
13
|
+
class Unsupported extends Error {
|
|
14
|
+
}
|
|
15
|
+
// ── substitution ──────────────────────────────────────────────────────────
|
|
16
|
+
/** A field path of the Go form, `.a.b.c`, as its steps. */
|
|
17
|
+
const FIELD = /^(?:\.[A-Za-z_][A-Za-z0-9_]*)+$/;
|
|
18
|
+
/** A literal Go string, as `index` takes its keys. */
|
|
19
|
+
const QUOTED = /^"(?:[^"\\]|\\.)*"$/;
|
|
20
|
+
function lookup(params, steps, written) {
|
|
21
|
+
let cur = params;
|
|
22
|
+
for (const step of steps) {
|
|
23
|
+
if (!isObject(cur) || !(step in cur))
|
|
24
|
+
throw new Unsupported(`the parameters have no ${written}`);
|
|
25
|
+
cur = cur[step];
|
|
26
|
+
}
|
|
27
|
+
if (typeof cur === "string")
|
|
28
|
+
return cur;
|
|
29
|
+
if (typeof cur === "number" || typeof cur === "boolean")
|
|
30
|
+
return String(cur);
|
|
31
|
+
throw new Unsupported(`${written} is not a string`);
|
|
32
|
+
}
|
|
33
|
+
/** The value of one Go template action: a field, or `index` of a field with literal keys. */
|
|
34
|
+
function goAction(expr, params) {
|
|
35
|
+
if (FIELD.test(expr))
|
|
36
|
+
return lookup(params, expr.slice(1).split("."), expr);
|
|
37
|
+
const words = expr.split(/\s+/);
|
|
38
|
+
if (words[0] === "index" && words.length >= 3 && (words[1] === "." || FIELD.test(words[1])) && words.slice(2).every((w) => QUOTED.test(w))) {
|
|
39
|
+
const base = words[1] === "." ? [] : words[1].slice(1).split(".");
|
|
40
|
+
return lookup(params, [...base, ...words.slice(2).map((w) => JSON.parse(w))], expr);
|
|
41
|
+
}
|
|
42
|
+
throw new Unsupported(`{{ ${expr} }} uses a function or form the graph does not expand`);
|
|
43
|
+
}
|
|
44
|
+
/** Substitute one string in the Go form. `{{-` and `-}}` trim the space beside them, as in Go. */
|
|
45
|
+
function renderGo(text, params) {
|
|
46
|
+
let out = "";
|
|
47
|
+
let i = 0;
|
|
48
|
+
while (i < text.length) {
|
|
49
|
+
const open = text.indexOf("{{", i);
|
|
50
|
+
if (open === -1) {
|
|
51
|
+
out += text.slice(i);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
const close = text.indexOf("}}", open + 2);
|
|
55
|
+
if (close === -1)
|
|
56
|
+
throw new Unsupported(`"${text}" opens an action it does not close`);
|
|
57
|
+
let before = text.slice(i, open);
|
|
58
|
+
let inner = text.slice(open + 2, close);
|
|
59
|
+
if (/^-\s/.test(inner)) {
|
|
60
|
+
before = before.replace(/\s+$/, "");
|
|
61
|
+
inner = inner.slice(1);
|
|
62
|
+
}
|
|
63
|
+
let next = close + 2;
|
|
64
|
+
if (/\s-$/.test(inner)) {
|
|
65
|
+
inner = inner.slice(0, -1);
|
|
66
|
+
while (next < text.length && /\s/.test(text[next]))
|
|
67
|
+
next++;
|
|
68
|
+
}
|
|
69
|
+
const expr = inner.trim();
|
|
70
|
+
if (expr.startsWith("/*")) {
|
|
71
|
+
out += before;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
out += before + goAction(expr, params);
|
|
75
|
+
}
|
|
76
|
+
i = next;
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/** Substitute one string in the default form, `{{name}}`, against flattened parameters. */
|
|
81
|
+
function renderPlain(text, flat) {
|
|
82
|
+
return text.replace(/\{\{([^{}]*)\}\}/g, (_m, inner) => {
|
|
83
|
+
const key = inner.trim();
|
|
84
|
+
if (!(key in flat))
|
|
85
|
+
throw new Unsupported(`the parameters have no ${key} for {{${inner}}}`);
|
|
86
|
+
return flat[key];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Every string in a tree, keys included, substituted. */
|
|
90
|
+
function renderTree(value, one) {
|
|
91
|
+
if (typeof value === "string")
|
|
92
|
+
return value.includes("{{") ? one(value) : value;
|
|
93
|
+
if (Array.isArray(value))
|
|
94
|
+
return value.map((v) => renderTree(v, one));
|
|
95
|
+
if (isObject(value)) {
|
|
96
|
+
const out = {};
|
|
97
|
+
for (const [k, v] of Object.entries(value))
|
|
98
|
+
out[k.includes("{{") ? one(k) : k] = renderTree(v, one);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
/** Nested parameters as `a.b.c` keys, scalars as strings. */
|
|
104
|
+
export function flattenParams(params, prefix = "", out = {}) {
|
|
105
|
+
for (const [k, v] of Object.entries(params)) {
|
|
106
|
+
const key = prefix ? `${prefix}.${k}` : k;
|
|
107
|
+
if (isObject(v))
|
|
108
|
+
flattenParams(v, key, out);
|
|
109
|
+
else if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
110
|
+
out[key] = String(v);
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
/** A generator's own `template` over the ApplicationSet's: maps merge key by key, anything else is replaced. */
|
|
115
|
+
function merge(base, over) {
|
|
116
|
+
if (!isObject(base) || !isObject(over))
|
|
117
|
+
return over === undefined ? base : over;
|
|
118
|
+
const out = { ...base };
|
|
119
|
+
for (const [k, v] of Object.entries(over))
|
|
120
|
+
out[k] = merge(base[k], v);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
const labelsOf = (node) => {
|
|
124
|
+
const labels = isObject(node.attrs.metadata) ? node.attrs.metadata.labels : undefined;
|
|
125
|
+
return isObject(labels) ? Object.fromEntries(Object.entries(labels).filter(([, v]) => typeof v === "string")) : {};
|
|
126
|
+
};
|
|
127
|
+
/** Whether a label selector selects `labels`, or why it cannot be read. */
|
|
128
|
+
function selects(selector, labels) {
|
|
129
|
+
const matchLabels = isObject(selector.matchLabels) ? selector.matchLabels : {};
|
|
130
|
+
for (const [k, v] of Object.entries(matchLabels))
|
|
131
|
+
if (labels[k] !== String(v))
|
|
132
|
+
return false;
|
|
133
|
+
const expressions = Array.isArray(selector.matchExpressions) ? selector.matchExpressions : [];
|
|
134
|
+
for (const e of expressions) {
|
|
135
|
+
if (!isObject(e) || typeof e.key !== "string")
|
|
136
|
+
throw new Unsupported("a matchExpressions entry has no key");
|
|
137
|
+
const values = Array.isArray(e.values) ? e.values.map(String) : [];
|
|
138
|
+
const has = e.key in labels;
|
|
139
|
+
switch (e.operator) {
|
|
140
|
+
case "In":
|
|
141
|
+
if (!has || !values.includes(labels[e.key]))
|
|
142
|
+
return false;
|
|
143
|
+
break;
|
|
144
|
+
case "NotIn":
|
|
145
|
+
if (has && values.includes(labels[e.key]))
|
|
146
|
+
return false;
|
|
147
|
+
break;
|
|
148
|
+
case "Exists":
|
|
149
|
+
if (!has)
|
|
150
|
+
return false;
|
|
151
|
+
break;
|
|
152
|
+
case "DoesNotExist":
|
|
153
|
+
if (has)
|
|
154
|
+
return false;
|
|
155
|
+
break;
|
|
156
|
+
default:
|
|
157
|
+
throw new Unsupported(`matchExpressions operator ${String(e.operator)} is not one the graph reads`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
/** `name` as Argo CD normalizes it for `nameNormalized`: lower case, with any character a resource name cannot hold made `-`. */
|
|
163
|
+
const normalizeName = (name) => name.toLowerCase().replace(/[^a-z0-9.-]/g, "-");
|
|
164
|
+
function clusterParams(name, server, node) {
|
|
165
|
+
const metadata = node && isObject(node.attrs.metadata) ? node.attrs.metadata : {};
|
|
166
|
+
const annotations = isObject(metadata.annotations) ? metadata.annotations : {};
|
|
167
|
+
return {
|
|
168
|
+
params: { name, nameNormalized: normalizeName(name), server, metadata: { labels: node ? labelsOf(node) : {}, annotations: { ...annotations } } },
|
|
169
|
+
...(node ? { node } : {}),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/** The clusters a `clusters` generator selects, by Secret name. */
|
|
173
|
+
function selectedClusters(generator, nodes) {
|
|
174
|
+
const selector = isObject(generator.selector) ? generator.selector : {};
|
|
175
|
+
const secrets = nodes.filter((n) => n.kind === SECRET && isObject(n.attrs.argoCluster));
|
|
176
|
+
const out = [];
|
|
177
|
+
for (const node of secrets) {
|
|
178
|
+
const cluster = node.attrs.argoCluster;
|
|
179
|
+
const name = str(cluster.name);
|
|
180
|
+
const server = str(cluster.server);
|
|
181
|
+
if (name === undefined || server === undefined)
|
|
182
|
+
continue;
|
|
183
|
+
if (selects(selector, labelsOf(node)))
|
|
184
|
+
out.push(clusterParams(name, server, node));
|
|
185
|
+
}
|
|
186
|
+
const empty = !isObject(generator.selector) || (Object.keys(selector.matchLabels ?? {}).length === 0 && (!Array.isArray(selector.matchExpressions) || selector.matchExpressions.length === 0));
|
|
187
|
+
if (empty && !out.some((c) => c.params.server === IN_CLUSTER.server))
|
|
188
|
+
out.push(clusterParams(IN_CLUSTER.name, IN_CLUSTER.server));
|
|
189
|
+
return out.sort((a, b) => String(a.params.name).localeCompare(String(b.params.name)) || (a.node?.id ?? "").localeCompare(b.node?.id ?? ""));
|
|
190
|
+
}
|
|
191
|
+
// ── expansion ─────────────────────────────────────────────────────────────
|
|
192
|
+
/**
|
|
193
|
+
* The Applications an ApplicationSet node generates from its `list` and
|
|
194
|
+
* `clusters` generators, given every node the pass reads (the cluster
|
|
195
|
+
* Secrets among them), and a line for each thing it did not expand.
|
|
196
|
+
*/
|
|
197
|
+
export function generateApplications(holder, nodes) {
|
|
198
|
+
const out = { nodes: [], notExpanded: [] };
|
|
199
|
+
const spec = isObject(holder.attrs.spec) ? holder.attrs.spec : {};
|
|
200
|
+
if (spec.templatePatch !== undefined) {
|
|
201
|
+
out.notExpanded.push("templatePatch is not expanded, so no Application is generated");
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
const go = spec.goTemplate === true;
|
|
205
|
+
const namespace = isObject(holder.attrs.metadata) ? str(holder.attrs.metadata.namespace) : undefined;
|
|
206
|
+
const generators = Array.isArray(spec.generators) ? spec.generators : [];
|
|
207
|
+
const seen = new Set();
|
|
208
|
+
generators.forEach((generator, i) => {
|
|
209
|
+
const at = `generators[${i}]`;
|
|
210
|
+
if (!isObject(generator))
|
|
211
|
+
return;
|
|
212
|
+
const types = Object.keys(generator).filter((k) => k !== "selector");
|
|
213
|
+
const type = types[0];
|
|
214
|
+
if (types.length !== 1) {
|
|
215
|
+
out.notExpanded.push(`${at} names ${types.length === 0 ? "no generator" : `several generators (${types.join(", ")})`}, and is not expanded`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!EXPANDED.has(type)) {
|
|
219
|
+
out.notExpanded.push(`${at}: the ${type} generator is not expanded`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (generator.selector !== undefined) {
|
|
223
|
+
out.notExpanded.push(`${at}: a generator's post-selector is not expanded`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const body = isObject(generator[type]) ? generator[type] : {};
|
|
227
|
+
const template = merge(spec.template, body.template);
|
|
228
|
+
let sets;
|
|
229
|
+
if (type === "list") {
|
|
230
|
+
if (body.elementsYaml !== undefined) {
|
|
231
|
+
out.notExpanded.push(`${at}: list elementsYaml is not expanded`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const elements = Array.isArray(body.elements) ? body.elements : [];
|
|
235
|
+
sets = elements.map((e) => ({ params: isObject(e) ? e : {} }));
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
if (body.flatList === true) {
|
|
239
|
+
out.notExpanded.push(`${at}: a clusters generator with flatList is not expanded`);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
sets = selectedClusters(body, nodes);
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
out.notExpanded.push(`${at}: ${err.message}, so the generator is not expanded`);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const values = isObject(body.values) ? body.values : undefined;
|
|
250
|
+
if (values) {
|
|
251
|
+
const withValues = [];
|
|
252
|
+
for (const set of sets) {
|
|
253
|
+
try {
|
|
254
|
+
const one = go ? (s) => renderGo(s, set.params) : (s) => renderPlain(s, flattenParams(set.params));
|
|
255
|
+
withValues.push({ ...set, params: { ...set.params, values: renderTree(values, one) } });
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
out.notExpanded.push(`${at} cluster ${String(set.params.name)}: values: ${err.message}; not expanded`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
sets = withValues;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
sets.forEach((set, j) => {
|
|
265
|
+
const which = type === "clusters" ? `${at} cluster ${String(set.params.name)}` : `${at} element ${j}`;
|
|
266
|
+
const flat = flattenParams(set.params);
|
|
267
|
+
let rendered;
|
|
268
|
+
try {
|
|
269
|
+
rendered = renderTree(template, go ? (s) => renderGo(s, set.params) : (s) => renderPlain(s, flat));
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
out.notExpanded.push(`${which}: ${err.message}; not expanded`);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const app = isObject(rendered) ? rendered : {};
|
|
276
|
+
const metadata = { ...(isObject(app.metadata) ? app.metadata : {}) };
|
|
277
|
+
const name = str(metadata.name);
|
|
278
|
+
if (!name) {
|
|
279
|
+
out.notExpanded.push(`${which}: the template gives no metadata.name; not expanded`);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (seen.has(name)) {
|
|
283
|
+
out.notExpanded.push(`${which}: Application ${name} is generated twice; the second is not expanded`);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
seen.add(name);
|
|
287
|
+
delete metadata.namespace;
|
|
288
|
+
if (namespace !== undefined)
|
|
289
|
+
metadata.namespace = namespace;
|
|
290
|
+
const node = {
|
|
291
|
+
key: name,
|
|
292
|
+
kind: APPLICATION,
|
|
293
|
+
// Stamped as the reader stamps an Application written by hand, so its charts and values files join the Helm graph (#5094).
|
|
294
|
+
attrs: stampGeneratedApplication({ apiVersion: str(holder.attrs.apiVersion) ?? "argoproj.io/v1alpha1", kind: "Application", metadata, spec: isObject(app.spec) ? app.spec : {} }),
|
|
295
|
+
generator: type,
|
|
296
|
+
params: flat,
|
|
297
|
+
...(set.node ? { cluster: set.node } : {}),
|
|
298
|
+
};
|
|
299
|
+
out.nodes.push(node);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argo CD cluster Secrets as the graph reads them (#5101).
|
|
3
|
+
*
|
|
4
|
+
* A cluster Secret is a Secret labelled `argocd.argoproj.io/secret-type:
|
|
5
|
+
* cluster`. Its `name` and `server` say which cluster it registers, and they
|
|
6
|
+
* are what an Application's destination and a Terraform cluster resource are
|
|
7
|
+
* joined on. They sit in `stringData`, or base64 in `data`.
|
|
8
|
+
*
|
|
9
|
+
* The rest of the Secret is the cluster's credentials: a bearer token, a CA
|
|
10
|
+
* bundle. No graph read needs them, so {@link clusterSecretView} drops them
|
|
11
|
+
* when a member reads a manifest directory.
|
|
12
|
+
*/
|
|
13
|
+
import type { DeclaredCatalogNode } from "@intentius/chant/graph-refs";
|
|
14
|
+
import type { IRNode } from "@intentius/chant/graph-ir";
|
|
15
|
+
type Doc = Record<string, unknown>;
|
|
16
|
+
/** Whether a manifest document is a Secret labelled as an Argo CD cluster registration. */
|
|
17
|
+
export declare function isClusterSecretDocument(doc: Doc): boolean;
|
|
18
|
+
/** The `name` and `server` a cluster Secret registers, as the ones it sets. */
|
|
19
|
+
export declare function clusterSecretJoin(secret: Doc): {
|
|
20
|
+
name?: string;
|
|
21
|
+
server?: string;
|
|
22
|
+
};
|
|
23
|
+
/** A cluster Secret document cut down to its metadata and the `name` and `server` in `stringData`. */
|
|
24
|
+
export declare function clusterSecretView(doc: Doc): Doc;
|
|
25
|
+
/**
|
|
26
|
+
* The node the catalog reads for a declared node of the k8s lexicon: a
|
|
27
|
+
* cluster Secret with its `name` and `server` under `argoCluster`, decoded,
|
|
28
|
+
* and nothing else of its `data`. Any other node is read as it is. Only a
|
|
29
|
+
* cluster Secret has that path, so a Secret that happens to carry a
|
|
30
|
+
* `stringData.name` is not read as a cluster registration.
|
|
31
|
+
*/
|
|
32
|
+
export declare function k8sDeclaredNode(node: IRNode): DeclaredCatalogNode | undefined;
|
|
33
|
+
/** Whether a node is an Argo CD cluster Secret: what a member's `runsOn` joins to the cluster resource. */
|
|
34
|
+
export declare function registersCluster(node: IRNode): boolean;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=cluster-secret.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cluster-secret.d.ts","sourceRoot":"","sources":["../src/cluster-secret.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAGxD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AASnC,2FAA2F;AAC3F,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAEzD;AAYD,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAIjF;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAQ/C;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAK7E;AAED,2GAA2G;AAC3G,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CLUSTER_SECRET_TYPE_LABEL } from "./lint/post-synth/argo-helpers.js";
|
|
2
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3
|
+
/** Whether the labels of an object mark an Argo CD cluster Secret. */
|
|
4
|
+
function labelled(metadata) {
|
|
5
|
+
return isObject(metadata) && isObject(metadata.labels) && metadata.labels[CLUSTER_SECRET_TYPE_LABEL] === "cluster";
|
|
6
|
+
}
|
|
7
|
+
/** Whether a manifest document is a Secret labelled as an Argo CD cluster registration. */
|
|
8
|
+
export function isClusterSecretDocument(doc) {
|
|
9
|
+
return doc.kind === "Secret" && typeof doc.apiVersion === "string" && !doc.apiVersion.includes("/") && labelled(doc.metadata);
|
|
10
|
+
}
|
|
11
|
+
/** A string field of a cluster Secret: `stringData` when set, else `data` decoded from base64. */
|
|
12
|
+
function field(secret, key) {
|
|
13
|
+
const plain = isObject(secret.stringData) ? secret.stringData[key] : undefined;
|
|
14
|
+
if (typeof plain === "string")
|
|
15
|
+
return plain;
|
|
16
|
+
const encoded = isObject(secret.data) ? secret.data[key] : undefined;
|
|
17
|
+
if (typeof encoded !== "string")
|
|
18
|
+
return undefined;
|
|
19
|
+
const text = Buffer.from(encoded, "base64").toString("utf-8");
|
|
20
|
+
return text.includes("\uFFFD") ? undefined : text;
|
|
21
|
+
}
|
|
22
|
+
/** The `name` and `server` a cluster Secret registers, as the ones it sets. */
|
|
23
|
+
export function clusterSecretJoin(secret) {
|
|
24
|
+
const name = field(secret, "name");
|
|
25
|
+
const server = field(secret, "server");
|
|
26
|
+
return { ...(name !== undefined ? { name } : {}), ...(server !== undefined ? { server } : {}) };
|
|
27
|
+
}
|
|
28
|
+
/** A cluster Secret document cut down to its metadata and the `name` and `server` in `stringData`. */
|
|
29
|
+
export function clusterSecretView(doc) {
|
|
30
|
+
return {
|
|
31
|
+
apiVersion: doc.apiVersion,
|
|
32
|
+
kind: doc.kind,
|
|
33
|
+
metadata: doc.metadata,
|
|
34
|
+
...(doc.type !== undefined ? { type: doc.type } : {}),
|
|
35
|
+
stringData: clusterSecretJoin(doc),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The node the catalog reads for a declared node of the k8s lexicon: a
|
|
40
|
+
* cluster Secret with its `name` and `server` under `argoCluster`, decoded,
|
|
41
|
+
* and nothing else of its `data`. Any other node is read as it is. Only a
|
|
42
|
+
* cluster Secret has that path, so a Secret that happens to carry a
|
|
43
|
+
* `stringData.name` is not read as a cluster registration.
|
|
44
|
+
*/
|
|
45
|
+
export function k8sDeclaredNode(node) {
|
|
46
|
+
if (node.kind !== "K8s::Core::Secret" || !labelled(node.attrs.metadata))
|
|
47
|
+
return undefined;
|
|
48
|
+
const { name, server } = clusterSecretJoin(node.attrs);
|
|
49
|
+
const { data: _data, stringData: _stringData, ...rest } = node.attrs;
|
|
50
|
+
return { kind: node.kind, attrs: { ...rest, argoCluster: { ...(name !== undefined ? { name } : {}), ...(server !== undefined ? { server } : {}) } }, nonLiteral: 0 };
|
|
51
|
+
}
|
|
52
|
+
/** Whether a node is an Argo CD cluster Secret: what a member's `runsOn` joins to the cluster resource. */
|
|
53
|
+
export function registersCluster(node) {
|
|
54
|
+
return node.kind === "K8s::Core::Secret" && labelled(node.attrs.metadata);
|
|
55
|
+
}
|
|
@@ -62,6 +62,12 @@ export interface KustomizeApplyInput {
|
|
|
62
62
|
context?: string;
|
|
63
63
|
/** Same delete vocabulary as kubectl-apply; default `never`. */
|
|
64
64
|
delete?: "never" | "owned-only";
|
|
65
|
+
/** Render a kustomization that has `helmCharts` (`--enable-helm`, #5112). Default off. */
|
|
66
|
+
enableHelm?: boolean;
|
|
67
|
+
/** The `helm` binary for `--helm-command`. */
|
|
68
|
+
helmCommand?: string;
|
|
69
|
+
/** Let kustomize pull a chart that is not in the chart home (network). Default off. */
|
|
70
|
+
fetchCharts?: boolean;
|
|
65
71
|
}
|
|
66
72
|
/** Factory with injectable renderer + applier, so tests assert the render
|
|
67
73
|
* command and the exact applier delegation without kustomize or a cluster. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kustomize-apply.d.ts","sourceRoot":"","sources":["../../src/components/kustomize-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAEL,aAAa,EAEb,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,CAAC;AAE/C,+EAA+E;AAC/E,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,UAAU,WAAW;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,OAAO,CAAC;CAC/C;AAED,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAErE,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"kustomize-apply.d.ts","sourceRoot":"","sources":["../../src/components/kustomize-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAEL,aAAa,EAEb,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,CAAC;AAE/C,+EAA+E;AAC/E,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,UAAU,WAAW;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,OAAO,CAAC;CAC/C;AAED,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAErE,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAChC,0FAA0F;IAC1F,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uFAAuF;IACvF,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;8EAC8E;AAC9E,wBAAgB,8BAA8B,CAC5C,GAAG,GAAE,eAAwC,EAC7C,KAAK,CAAC,EAAE,OAAO,GACd,UAAU,CAAC,mBAAmB,EAAE,qBAAqB,CAAC,CAmBxD;AAED,eAAO,MAAM,wBAAwB,wDAAmC,CAAC"}
|
|
@@ -9,7 +9,7 @@ export function createKustomizeApplyCapability(run = defaultKustomizeRunner, app
|
|
|
9
9
|
// undo of its own — same posture as kubectl-apply.
|
|
10
10
|
rollbackPolicy: "needs-opt-out",
|
|
11
11
|
async run(ctx, input) {
|
|
12
|
-
const documents = await renderKustomizeDocuments(input.dir, run);
|
|
12
|
+
const documents = await renderKustomizeDocuments(input.dir, run, { enableHelm: input.enableHelm, helmCommand: input.helmCommand, fetchCharts: input.fetchCharts });
|
|
13
13
|
const applier = apply ?? (await import("../op/activities/kubectl.js")).applyManifest;
|
|
14
14
|
return applier({
|
|
15
15
|
manifest: `kustomize:${input.dir}`,
|
package/dist/config-schema.d.ts
CHANGED
|
@@ -120,6 +120,9 @@ export declare const k8sConfigSchema: z.ZodObject<{
|
|
|
120
120
|
merge: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
121
121
|
jsonPatch: z.ZodOptional<z.ZodNever>;
|
|
122
122
|
}, z.core.$strict>]>>>;
|
|
123
|
+
enableHelm: z.ZodOptional<z.ZodBoolean>;
|
|
124
|
+
helmCommand: z.ZodOptional<z.ZodString>;
|
|
125
|
+
fetchCharts: z.ZodOptional<z.ZodBoolean>;
|
|
123
126
|
}, z.core.$strict>]>>>;
|
|
124
127
|
}, z.core.$strict>>;
|
|
125
128
|
member: z.ZodOptional<z.ZodObject<{
|
|
@@ -127,9 +130,14 @@ export declare const k8sConfigSchema: z.ZodObject<{
|
|
|
127
130
|
"argo-app": "argo-app";
|
|
128
131
|
"flux-kustomization": "flux-kustomization";
|
|
129
132
|
kustomize: "kustomize";
|
|
133
|
+
manifests: "manifests";
|
|
130
134
|
}>;
|
|
131
135
|
dir: z.ZodString;
|
|
132
136
|
label: z.ZodOptional<z.ZodString>;
|
|
137
|
+
enableHelm: z.ZodOptional<z.ZodBoolean>;
|
|
138
|
+
helmCommand: z.ZodOptional<z.ZodString>;
|
|
139
|
+
fetchCharts: z.ZodOptional<z.ZodBoolean>;
|
|
140
|
+
workspace: z.ZodOptional<z.ZodString>;
|
|
133
141
|
}, z.core.$strict>>;
|
|
134
142
|
receipts: z.ZodOptional<z.ZodObject<{
|
|
135
143
|
namespace: z.ZodOptional<z.ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-schema.d.ts","sourceRoot":"","sources":["../src/config-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,uBAAuB;;kBAElC,CAAC;AAIH,+DAA+D;AAC/D,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;4BAgBpC,CAAC;AAkBH,yFAAyF;AACzF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAG9B,CAAC;AAEH,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"config-schema.d.ts","sourceRoot":"","sources":["../src/config-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,eAAO,MAAM,uBAAuB;;kBAElC,CAAC;AAIH,+DAA+D;AAC/D,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;4BAgBpC,CAAC;AAkBH,yFAAyF;AACzF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAG9B,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA2B1B,CAAC;AAEH,OAAO,QAAQ,yBAAyB,CAAC;IACvC,UAAU,WAAW;QACnB,GAAG,CAAC,EAAE,cAAc,CAAC;KACtB;CACF;AAED,iEAAiE;AACjE,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;AAEjE;;;GAGG;AACH,KAAK,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,SAAS,cAAc,GAChF,cAAc,SAAS,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,GACpD,IAAI,GACJ,KAAK,GACP,KAAK,CAAC;AACV,MAAM,MAAM,0BAA0B,GAAG,sBAAsB,CAAC"}
|
package/dist/config-schema.js
CHANGED
|
@@ -59,15 +59,19 @@ export const k8sConfigSchema = z.strictObject({
|
|
|
59
59
|
kustomize: z
|
|
60
60
|
.strictObject({
|
|
61
61
|
roots: z
|
|
62
|
-
.array(z.union([z.string(), z.strictObject({ path: z.string(), patches: z.array(renderedPatchSchema).optional() })]))
|
|
62
|
+
.array(z.union([z.string(), z.strictObject({ path: z.string(), patches: z.array(renderedPatchSchema).optional(), enableHelm: z.boolean().optional(), helmCommand: z.string().optional(), fetchCharts: z.boolean().optional() })]))
|
|
63
63
|
.optional(),
|
|
64
64
|
})
|
|
65
65
|
.optional(),
|
|
66
66
|
member: z
|
|
67
67
|
.strictObject({
|
|
68
|
-
kind: z.enum(["kustomize", "argo-app", "flux-kustomization"]),
|
|
68
|
+
kind: z.enum(["kustomize", "argo-app", "flux-kustomization", "manifests"]),
|
|
69
69
|
dir: z.string().min(1),
|
|
70
70
|
label: z.string().optional(),
|
|
71
|
+
enableHelm: z.boolean().optional(),
|
|
72
|
+
helmCommand: z.string().optional(),
|
|
73
|
+
fetchCharts: z.boolean().optional(),
|
|
74
|
+
workspace: z.string().optional(),
|
|
71
75
|
})
|
|
72
76
|
.optional(),
|
|
73
77
|
receipts: z
|