@intentius/chant-lexicon-k8s 0.100.0 → 0.102.0
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/actions/apps.d.ts +4 -4
- package/dist/actions/apps.d.ts.map +1 -1
- package/dist/actions/core.d.ts +5 -5
- package/dist/actions/core.d.ts.map +1 -1
- package/dist/actions/networking.d.ts.map +1 -1
- package/dist/codegen/generate-typescript.d.ts +2 -2
- package/dist/codegen/generate-typescript.d.ts.map +1 -1
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/naming.d.ts.map +1 -1
- package/dist/codegen/versions.d.ts.map +1 -1
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/composites/catalog.d.ts.map +1 -1
- package/dist/composites/cockroachdb-cluster.d.ts +2 -2
- package/dist/composites/gke-otel-collector.d.ts.map +1 -1
- package/dist/composites/index.d.ts +1 -0
- package/dist/composites/index.d.ts.map +1 -1
- package/dist/composites/otel-collector-agent.d.ts +24 -2
- package/dist/composites/otel-collector-agent.d.ts.map +1 -1
- package/dist/composites/otel-collector-gateway.d.ts +37 -52
- package/dist/composites/otel-collector-gateway.d.ts.map +1 -1
- package/dist/composites/otel-collector-node.d.ts +88 -0
- package/dist/composites/otel-collector-node.d.ts.map +1 -0
- package/dist/composites/otel-collector-rbac.d.ts +74 -0
- package/dist/composites/otel-collector-rbac.d.ts.map +1 -0
- package/dist/composites/otel-collector-shape.d.ts +7 -0
- package/dist/composites/otel-collector-shape.d.ts.map +1 -1
- package/dist/composites/otel-collector.d.ts +17 -21
- package/dist/composites/otel-collector.d.ts.map +1 -1
- package/dist/composites/ray-cluster.d.ts +6 -6
- package/dist/composites/ray-job.d.ts +5 -5
- package/dist/composites/ray-service.d.ts +6 -6
- package/dist/crd/crd-sources.d.ts.map +1 -1
- package/dist/crd/loader.d.ts.map +1 -1
- package/dist/crd/oci-chart.d.ts +50 -0
- package/dist/crd/oci-chart.d.ts.map +1 -0
- package/dist/crd/types.d.ts +5 -0
- package/dist/crd/types.d.ts.map +1 -1
- package/dist/effect-receipt-row.d.ts.map +1 -1
- package/dist/generated/index.d.ts +752 -729
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/import/embedded.d.ts +4 -2
- package/dist/import/embedded.d.ts.map +1 -1
- package/dist/import/generator.d.ts.map +1 -1
- package/dist/import/live-export.d.ts +5 -0
- package/dist/import/live-export.d.ts.map +1 -1
- package/dist/import/parser.d.ts.map +1 -1
- package/dist/import/testdata/embedded/fixtures.d.ts +6 -0
- package/dist/import/testdata/embedded/fixtures.d.ts.map +1 -1
- package/dist/integrity.json +8 -6
- package/dist/lint/audit-catalog.d.ts.map +1 -1
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/lint/post-synth/otel-placement-helpers.d.ts +5 -1
- package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
- package/dist/lint/post-synth/wk8604.d.ts +19 -0
- package/dist/lint/post-synth/wk8604.d.ts.map +1 -0
- package/dist/lint/post-synth/wk8605.d.ts +23 -0
- package/dist/lint/post-synth/wk8605.d.ts.map +1 -0
- package/dist/manifest.json +1 -1
- package/dist/meta.json +156 -17
- package/dist/okf/index.md +5 -0
- package/dist/okf/rules/WK8604.md +11 -0
- package/dist/okf/rules/WK8605.md +11 -0
- package/dist/okf/types/APIGroup.md +3 -3
- package/dist/okf/types/APIGroupList.md +1 -1
- package/dist/okf/types/APIResourceList.md +1 -1
- package/dist/okf/types/APIService.md +1 -1
- package/dist/okf/types/APIServiceList.md +2 -2
- package/dist/okf/types/APIVersions.md +1 -1
- package/dist/okf/types/BatchJob.md +1 -1
- package/dist/okf/types/CSIDriver.md +1 -1
- package/dist/okf/types/CSIDriverList.md +2 -2
- package/dist/okf/types/CSINode.md +1 -1
- package/dist/okf/types/CSINodeList.md +2 -2
- package/dist/okf/types/CSIStorageCapacity.md +2 -2
- package/dist/okf/types/CSIStorageCapacityList.md +2 -2
- package/dist/okf/types/CertificateSigningRequest.md +1 -1
- package/dist/okf/types/CertificateSigningRequestList.md +2 -2
- package/dist/okf/types/ClusterRole.md +1 -1
- package/dist/okf/types/ClusterRoleBindingList.md +2 -2
- package/dist/okf/types/ClusterRoleList.md +2 -2
- package/dist/okf/types/ClusterTrustBundle.md +1 -1
- package/dist/okf/types/ClusterTrustBundleList.md +2 -2
- package/dist/okf/types/ComponentStatus.md +1 -1
- package/dist/okf/types/ComponentStatusList.md +2 -2
- package/dist/okf/types/ConfigMapList.md +2 -2
- package/dist/okf/types/ControllerRevisionList.md +2 -2
- package/dist/okf/types/CoreEventList.md +2 -2
- package/dist/okf/types/CronJob.md +1 -1
- package/dist/okf/types/CronJobList.md +2 -2
- package/dist/okf/types/CustomResourceDefinition.md +1 -1
- package/dist/okf/types/CustomResourceDefinitionList.md +2 -2
- package/dist/okf/types/DaemonSet.md +1 -1
- package/dist/okf/types/DaemonSetList.md +2 -2
- package/dist/okf/types/DeleteOptions.md +1 -1
- package/dist/okf/types/Deploy.md +1 -1
- package/dist/okf/types/DeploymentList.md +2 -2
- package/dist/okf/types/DeviceClass.md +1 -1
- package/dist/okf/types/DeviceClassList.md +2 -2
- package/dist/okf/types/DeviceTaintRule.md +1 -1
- package/dist/okf/types/DeviceTaintRuleList.md +2 -2
- package/dist/okf/types/EndpointSlice.md +2 -2
- package/dist/okf/types/EndpointSliceList.md +2 -2
- package/dist/okf/types/Endpoints.md +1 -1
- package/dist/okf/types/EndpointsList.md +2 -2
- package/dist/okf/types/Event.md +2 -2
- package/dist/okf/types/EventsEvent.md +2 -2
- package/dist/okf/types/EventsEventList.md +2 -2
- package/dist/okf/types/Eviction.md +1 -1
- package/dist/okf/types/FlowSchema.md +1 -1
- package/dist/okf/types/FlowSchemaList.md +2 -2
- package/dist/okf/types/GrafanaDashboard.md +14 -0
- package/dist/okf/types/GrafanaDatasource.md +14 -0
- package/dist/okf/types/GrafanaFolder.md +14 -0
- package/dist/okf/types/HorizontalPodAutoscaler.md +1 -1
- package/dist/okf/types/HorizontalPodAutoscalerList.md +2 -2
- package/dist/okf/types/IPAddress.md +1 -1
- package/dist/okf/types/IPAddressList.md +2 -2
- package/dist/okf/types/Ing.md +1 -1
- package/dist/okf/types/IngressClass.md +1 -1
- package/dist/okf/types/IngressClassList.md +2 -2
- package/dist/okf/types/IngressList.md +2 -2
- package/dist/okf/types/JobList.md +2 -2
- package/dist/okf/types/Lease.md +1 -1
- package/dist/okf/types/LeaseCandidate.md +1 -1
- package/dist/okf/types/LeaseCandidateList.md +2 -2
- package/dist/okf/types/LeaseList.md +2 -2
- package/dist/okf/types/LimitRange.md +1 -1
- package/dist/okf/types/LimitRangeList.md +2 -2
- package/dist/okf/types/LocalSubjectAccessReview.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicy.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicyBinding.md +1 -1
- package/dist/okf/types/MutatingAdmissionPolicyBindingList.md +2 -2
- package/dist/okf/types/MutatingAdmissionPolicyList.md +2 -2
- package/dist/okf/types/MutatingWebhookConfiguration.md +1 -1
- package/dist/okf/types/MutatingWebhookConfigurationList.md +2 -2
- package/dist/okf/types/Namespace.md +1 -1
- package/dist/okf/types/NamespaceList.md +2 -2
- package/dist/okf/types/NetPol.md +1 -1
- package/dist/okf/types/NetworkPolicyList.md +2 -2
- package/dist/okf/types/Node.md +1 -1
- package/dist/okf/types/NodeList.md +2 -2
- package/dist/okf/types/PersistentVolume.md +1 -1
- package/dist/okf/types/PersistentVolumeClaimList.md +2 -2
- package/dist/okf/types/PersistentVolumeList.md +2 -2
- package/dist/okf/types/PodCertificateRequest.md +1 -1
- package/dist/okf/types/PodCertificateRequestList.md +2 -2
- package/dist/okf/types/PodDisruptionBudgetList.md +2 -2
- package/dist/okf/types/PodList.md +2 -2
- package/dist/okf/types/PodTemplateList.md +2 -2
- package/dist/okf/types/PriorityClassList.md +2 -2
- package/dist/okf/types/PriorityLevelConfiguration.md +1 -1
- package/dist/okf/types/PriorityLevelConfigurationList.md +2 -2
- package/dist/okf/types/ReplicaSet.md +1 -1
- package/dist/okf/types/ReplicaSetList.md +2 -2
- package/dist/okf/types/ReplicationController.md +1 -1
- package/dist/okf/types/ReplicationControllerList.md +2 -2
- package/dist/okf/types/ResourceClaim.md +1 -1
- package/dist/okf/types/ResourceClaimList.md +2 -2
- package/dist/okf/types/ResourceClaimTemplate.md +1 -1
- package/dist/okf/types/ResourceClaimTemplateList.md +2 -2
- package/dist/okf/types/ResourceQuota.md +1 -1
- package/dist/okf/types/ResourceQuotaList.md +2 -2
- package/dist/okf/types/ResourceSlice.md +1 -1
- package/dist/okf/types/ResourceSliceList.md +2 -2
- package/dist/okf/types/RoleBindingList.md +2 -2
- package/dist/okf/types/RoleList.md +2 -2
- package/dist/okf/types/RuntimeClass.md +2 -2
- package/dist/okf/types/RuntimeClassList.md +2 -2
- package/dist/okf/types/Scale.md +1 -1
- package/dist/okf/types/SecretList.md +2 -2
- package/dist/okf/types/SelfSubjectAccessReview.md +1 -1
- package/dist/okf/types/SelfSubjectRulesReview.md +1 -1
- package/dist/okf/types/Service.md +1 -1
- package/dist/okf/types/ServiceAccountList.md +2 -2
- package/dist/okf/types/ServiceCIDR.md +1 -1
- package/dist/okf/types/ServiceCIDRList.md +2 -2
- package/dist/okf/types/ServiceList.md +2 -2
- package/dist/okf/types/StatefulSet.md +1 -1
- package/dist/okf/types/StatefulSetList.md +2 -2
- package/dist/okf/types/Status.md +2 -2
- package/dist/okf/types/StorageClass.md +1 -1
- package/dist/okf/types/StorageClassList.md +2 -2
- package/dist/okf/types/StorageVersionMigration.md +1 -1
- package/dist/okf/types/StorageVersionMigrationList.md +2 -2
- package/dist/okf/types/SubjectAccessReview.md +1 -1
- package/dist/okf/types/TokenRequest.md +1 -1
- package/dist/okf/types/TokenReview.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicy.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicyBinding.md +1 -1
- package/dist/okf/types/ValidatingAdmissionPolicyBindingList.md +2 -2
- package/dist/okf/types/ValidatingAdmissionPolicyList.md +2 -2
- package/dist/okf/types/ValidatingWebhookConfiguration.md +1 -1
- package/dist/okf/types/ValidatingWebhookConfigurationList.md +2 -2
- package/dist/okf/types/VolumeAttachment.md +1 -1
- package/dist/okf/types/VolumeAttachmentList.md +2 -2
- package/dist/okf/types/VolumeAttributesClassList.md +2 -2
- package/dist/op/activities/argo.d.ts.map +1 -1
- package/dist/op/activities/index.d.ts +3 -3
- package/dist/op/activities/index.d.ts.map +1 -1
- package/dist/op/activities/wait-for-ready.d.ts.map +1 -1
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/rules/otel-placement-helpers.ts +7 -11
- package/dist/rules/wk8604.ts +29 -0
- package/dist/rules/wk8605.ts +131 -0
- package/dist/skills/chant-k8s.md +1 -1
- package/dist/spec/parse.d.ts +27 -0
- package/dist/spec/parse.d.ts.map +1 -1
- package/dist/types/index.d.ts +5360 -972
- package/dist/variables.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/codegen/declarations.test.ts +118 -0
- package/src/codegen/generate-typescript.ts +69 -4
- package/src/codegen/generate.ts +15 -6
- package/src/composites/__snapshots__/gke-otel-collector.snapshot.test.ts.snap +2 -68
- package/src/composites/catalog.ts +12 -0
- package/src/composites/gke-otel-collector.snapshot.test.ts +3 -1
- package/src/composites/gke-otel-collector.ts +13 -2
- package/src/composites/index.ts +1 -0
- package/src/composites/otel-collector-agent.ts +45 -11
- package/src/composites/otel-collector-gateway.test.ts +102 -5
- package/src/composites/otel-collector-gateway.ts +96 -18
- package/src/composites/otel-collector-node.test.ts +174 -0
- package/src/composites/otel-collector-node.ts +213 -0
- package/src/composites/otel-collector-rbac.test.ts +114 -0
- package/src/composites/otel-collector-rbac.ts +144 -0
- package/src/composites/otel-collector-shape.ts +19 -0
- package/src/composites/otel-collector.ts +40 -35
- package/src/crd/crd-sources.ts +26 -0
- package/src/crd/loader.test.ts +9 -1
- package/src/crd/loader.ts +26 -3
- package/src/crd/oci-chart.test.ts +149 -0
- package/src/crd/oci-chart.ts +178 -0
- package/src/crd/types.ts +5 -0
- package/src/generated/index.d.ts +5360 -972
- package/src/generated/index.ts +23 -0
- package/src/generated/lexicon-k8s.json +156 -17
- package/src/generated/operations.json +48 -0
- package/src/import/embedded-live.test.ts +180 -0
- package/src/import/embedded-roundtrip.test.ts +73 -7
- package/src/import/embedded-types.e2e.test.ts +3 -1
- package/src/import/embedded.test.ts +64 -0
- package/src/import/embedded.ts +31 -2
- package/src/import/generator.test.ts +19 -0
- package/src/import/generator.ts +20 -2
- package/src/import/live-export.ts +10 -2
- package/src/import/testdata/embedded/README.md +4 -1
- package/src/import/testdata/embedded/alertmanager-configmap.yaml +91 -0
- package/src/import/testdata/embedded/fixtures.ts +18 -0
- package/src/import/testdata/embedded/grafana-operator-dashboard.yaml +363 -0
- package/src/import/testdata/embedded/grafana-v2-dashboard-configmap.yaml +851 -0
- package/src/lint/audit-catalog.ts +2 -0
- package/src/lint/post-synth/index.ts +4 -0
- package/src/lint/post-synth/otel-placement-helpers.ts +7 -11
- package/src/lint/post-synth/otel-placement.test.ts +35 -0
- package/src/lint/post-synth/post-synth.test.ts +3 -3
- package/src/lint/post-synth/wk8604.ts +29 -0
- package/src/lint/post-synth/wk8605.test.ts +141 -0
- package/src/lint/post-synth/wk8605.ts +131 -0
- package/src/skills/chant-k8s.md +1 -1
- package/src/spec/parse.test.ts +118 -0
- package/src/spec/parse.ts +250 -29
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What `chant import` generates for manifests with embedded content (#2962
|
|
2
|
+
* What `chant import` generates for manifests with embedded content (#2962,
|
|
3
|
+
* #3031)
|
|
3
4
|
* type-checks: the k8s module that references the owners' declarations, and
|
|
4
5
|
* the owners' modules. Compiling takes longer than the unit-test budget
|
|
5
6
|
* allows, so this runs with the e2e tests.
|
|
@@ -31,6 +32,7 @@ describe("the source generated for embedded content type-checks", () => {
|
|
|
31
32
|
"node-exporter-prometheusrule.yaml",
|
|
32
33
|
"grafana-dashboard-configmap.yaml",
|
|
33
34
|
"agent-observability.yaml",
|
|
35
|
+
"alertmanager-configmap.yaml",
|
|
34
36
|
])("%s", async (fixture) => {
|
|
35
37
|
const imported = await importManifest(read(fixture));
|
|
36
38
|
try {
|
|
@@ -107,6 +107,70 @@ describe("k8s import offers embedded content (#2962)", () => {
|
|
|
107
107
|
const [main] = new K8sGenerator().generate(ir);
|
|
108
108
|
expect(main.content).not.toContain("import { render");
|
|
109
109
|
});
|
|
110
|
+
|
|
111
|
+
test("a GrafanaDashboard's spec.json is offered as text, and replaced by the owner's reference (#3015)", () => {
|
|
112
|
+
const seen: EmbeddedContent[] = [];
|
|
113
|
+
const embedded = new EmbeddedImports([{ lexicon: "acme", importer: claimAll(seen) }]);
|
|
114
|
+
const ir = new K8sParser().parse(
|
|
115
|
+
`
|
|
116
|
+
apiVersion: grafana.integreatly.org/v1beta1
|
|
117
|
+
kind: GrafanaDashboard
|
|
118
|
+
metadata:
|
|
119
|
+
name: api
|
|
120
|
+
spec:
|
|
121
|
+
instanceSelector:
|
|
122
|
+
matchLabels:
|
|
123
|
+
dashboards: grafana
|
|
124
|
+
folderRef: grafana-folder-services
|
|
125
|
+
json: '{"title": "API", "panels": [], "schemaVersion": 41}'
|
|
126
|
+
---
|
|
127
|
+
apiVersion: grafana.integreatly.org/v1beta1
|
|
128
|
+
kind: GrafanaDashboard
|
|
129
|
+
metadata:
|
|
130
|
+
name: remote
|
|
131
|
+
spec:
|
|
132
|
+
instanceSelector: {}
|
|
133
|
+
url: https://grafana.com/api/dashboards/1860/revisions/37/download
|
|
134
|
+
`,
|
|
135
|
+
{ embedded },
|
|
136
|
+
);
|
|
137
|
+
expect(seen.map((c) => [c.location, c.directory, c.text, c.expectedOwner?.lexicon])).toEqual([
|
|
138
|
+
["GrafanaDashboard api spec.json", "api", '{"title": "API", "panels": [], "schemaVersion": 41}', "grafana"],
|
|
139
|
+
]);
|
|
140
|
+
const [main] = new K8sGenerator().generate(ir);
|
|
141
|
+
expect(main.content).toContain("json: render(thing),");
|
|
142
|
+
expect(main.content).toContain('folderRef: "grafana-folder-services",');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("an alertmanager.yml and a v2 dashboard name their expected owners (#3031)", () => {
|
|
146
|
+
const embedded = new EmbeddedImports([]);
|
|
147
|
+
new K8sParser().parse(
|
|
148
|
+
`
|
|
149
|
+
apiVersion: v1
|
|
150
|
+
kind: ConfigMap
|
|
151
|
+
metadata:
|
|
152
|
+
name: alertmanager
|
|
153
|
+
data:
|
|
154
|
+
alertmanager.yml: |
|
|
155
|
+
route:
|
|
156
|
+
receiver: team
|
|
157
|
+
receivers:
|
|
158
|
+
- name: team
|
|
159
|
+
---
|
|
160
|
+
apiVersion: v1
|
|
161
|
+
kind: ConfigMap
|
|
162
|
+
metadata:
|
|
163
|
+
name: dashboards-v2
|
|
164
|
+
data:
|
|
165
|
+
checkout.json: '{"apiVersion": "dashboard.grafana.app/v2beta1", "kind": "Dashboard", "spec": {"elements": {}, "layout": {}}}'
|
|
166
|
+
`,
|
|
167
|
+
{ embedded },
|
|
168
|
+
);
|
|
169
|
+
expect(embedded.offered.map((c) => c.expectedOwner)).toEqual([
|
|
170
|
+
{ lexicon: "prometheus", what: "an Alertmanager config" },
|
|
171
|
+
{ lexicon: "grafana", what: "a Grafana dashboard" },
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
110
174
|
});
|
|
111
175
|
|
|
112
176
|
describe("the k8s generator's imports", () => {
|
package/src/import/embedded.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* The parser offers two kinds of place to core's embedded-content resolver:
|
|
6
6
|
*
|
|
7
7
|
* - every `data` value of a ConfigMap, as text (a collector's `config.yaml`,
|
|
8
|
-
* a Prometheus rule file, a Grafana dashboard's
|
|
8
|
+
* a Prometheus rule file, an `alertmanager.yml`, a Grafana dashboard's
|
|
9
|
+
* JSON);
|
|
9
10
|
* - a `monitoring.coreos.com` PrometheusRule's `spec.groups`, as the rule file
|
|
10
|
-
* `{ groups }` those groups would make
|
|
11
|
+
* `{ groups }` those groups would make;
|
|
12
|
+
* - a Grafana Operator `GrafanaDashboard`'s `spec.json`, as text (#3015).
|
|
11
13
|
*
|
|
12
14
|
* Which lexicon imports the content is decided by core at run time, from the
|
|
13
15
|
* lexicons that register an `embeddedImporters()`; this module names none of
|
|
@@ -35,10 +37,19 @@ function hintFor(key: string, doc: unknown, labels: Record<string, string>): Emb
|
|
|
35
37
|
if (Array.isArray(doc.panels) && (GRAFANA_DASHBOARD_LABEL in labels || key.endsWith(".json"))) {
|
|
36
38
|
return { lexicon: "grafana", what: "a Grafana dashboard" };
|
|
37
39
|
}
|
|
40
|
+
const v2Dashboard =
|
|
41
|
+
(doc.kind === "Dashboard" && typeof doc.apiVersion === "string" && doc.apiVersion.startsWith("dashboard.grafana.app/")) ||
|
|
42
|
+
(isObject(doc.elements) && isObject(doc.layout));
|
|
43
|
+
if (v2Dashboard && (GRAFANA_DASHBOARD_LABEL in labels || key.endsWith(".json"))) {
|
|
44
|
+
return { lexicon: "grafana", what: "a Grafana dashboard" };
|
|
45
|
+
}
|
|
38
46
|
if (isObject(doc.service) && isObject(doc.service.pipelines)) {
|
|
39
47
|
return { lexicon: "otel", what: "an OpenTelemetry Collector config" };
|
|
40
48
|
}
|
|
41
49
|
if (looksLikeRuleGroups(doc.groups)) return { lexicon: "prometheus", what: "a Prometheus rule file" };
|
|
50
|
+
if ((isObject(doc.route) || Array.isArray(doc.receivers)) && !("apiVersion" in doc) && !("kind" in doc)) {
|
|
51
|
+
return { lexicon: "prometheus", what: "an Alertmanager config" };
|
|
52
|
+
}
|
|
42
53
|
return undefined;
|
|
43
54
|
}
|
|
44
55
|
|
|
@@ -87,6 +98,24 @@ export function delegateEmbedded(
|
|
|
87
98
|
return;
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
if (type === "K8s::Grafana::GrafanaDashboard" && isObject(properties.spec) && typeof properties.spec.json === "string") {
|
|
102
|
+
const text = properties.spec.json;
|
|
103
|
+
const doc = embeddedDocument(text);
|
|
104
|
+
if (!isObject(doc)) return;
|
|
105
|
+
const ref = embedded.resolve({
|
|
106
|
+
host: "k8s",
|
|
107
|
+
hostType: type,
|
|
108
|
+
location: `GrafanaDashboard ${name} spec.json`,
|
|
109
|
+
directory: name,
|
|
110
|
+
text,
|
|
111
|
+
document: doc,
|
|
112
|
+
labels,
|
|
113
|
+
expectedOwner: { lexicon: "grafana", what: "a Grafana dashboard" },
|
|
114
|
+
});
|
|
115
|
+
if (ref) properties.spec = { ...properties.spec, json: ref };
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
90
119
|
if (type === "K8s::Monitoring::PrometheusRule" && isObject(properties.spec) && Array.isArray(properties.spec.groups)) {
|
|
91
120
|
const groups = properties.spec.groups;
|
|
92
121
|
const ref = embedded.resolve({
|
|
@@ -112,6 +112,25 @@ describe("K8sGenerator", () => {
|
|
|
112
112
|
expect(files[0].content).toContain("ServicePort");
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
+
// chant #3093 — the property classes carry their members, so a Role's
|
|
116
|
+
// rules built as IngressRules would no longer type-check.
|
|
117
|
+
test("a Role's rules use the PolicyRule constructor, an Ingress's the IngressRule one", () => {
|
|
118
|
+
const files = generator.generate(makeIR([
|
|
119
|
+
{
|
|
120
|
+
logicalId: "role",
|
|
121
|
+
type: "K8s::Rbac::Role",
|
|
122
|
+
properties: { metadata: { name: "r" }, rules: [{ apiGroups: [""], resources: ["pods"], verbs: ["get"] }] },
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
logicalId: "clusterRole",
|
|
126
|
+
type: "K8s::Rbac::ClusterRole",
|
|
127
|
+
properties: { metadata: { name: "cr" }, rules: [{ apiGroups: [""], resources: ["nodes"], verbs: ["list"] }] },
|
|
128
|
+
},
|
|
129
|
+
]));
|
|
130
|
+
expect(files[0].content).toContain("new PolicyRule(");
|
|
131
|
+
expect(files[0].content).not.toContain("IngressRule");
|
|
132
|
+
});
|
|
133
|
+
|
|
115
134
|
test("handles empty IR", () => {
|
|
116
135
|
const ir = makeIR([]);
|
|
117
136
|
const files = generator.generate(ir);
|
package/src/import/generator.ts
CHANGED
|
@@ -107,6 +107,23 @@ const SERVICE_PORT_TYPES = new Set([
|
|
|
107
107
|
"K8s::Core::Service",
|
|
108
108
|
]);
|
|
109
109
|
|
|
110
|
+
/**
|
|
111
|
+
* A Role's and a ClusterRole's top-level `rules` are PolicyRules, not the
|
|
112
|
+
* IngressRules {@link PROPERTY_CONSTRUCTORS} maps `rules` to. Since the
|
|
113
|
+
* property classes carry their members (chant #3093), an IngressRule built
|
|
114
|
+
* from `apiGroups`/`verbs` no longer type-checks.
|
|
115
|
+
*/
|
|
116
|
+
const POLICY_RULE_TYPES = new Set([
|
|
117
|
+
"K8s::Rbac::Role",
|
|
118
|
+
"K8s::Rbac::ClusterRole",
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
/** The constructor for `key` on a resource of `parentType`. */
|
|
122
|
+
function constructorFor(key: string, parentType: string): string | undefined {
|
|
123
|
+
if (key === "rules" && POLICY_RULE_TYPES.has(parentType)) return "PolicyRule";
|
|
124
|
+
return PROPERTY_CONSTRUCTORS[key];
|
|
125
|
+
}
|
|
126
|
+
|
|
110
127
|
/**
|
|
111
128
|
* Generate TypeScript source code from a Kubernetes IR.
|
|
112
129
|
*/
|
|
@@ -132,6 +149,7 @@ export class K8sGenerator implements TypeScriptGenerator {
|
|
|
132
149
|
...usedConstructors,
|
|
133
150
|
...Object.values(PROPERTY_CONSTRUCTORS),
|
|
134
151
|
"ServicePort",
|
|
152
|
+
"PolicyRule",
|
|
135
153
|
...ir.resources.map((r) => r.logicalId),
|
|
136
154
|
]);
|
|
137
155
|
|
|
@@ -197,7 +215,7 @@ export class K8sGenerator implements TypeScriptGenerator {
|
|
|
197
215
|
continue;
|
|
198
216
|
}
|
|
199
217
|
|
|
200
|
-
const constructor =
|
|
218
|
+
const constructor = constructorFor(key, parentType);
|
|
201
219
|
if (!constructor) continue;
|
|
202
220
|
|
|
203
221
|
if (Array.isArray(value)) {
|
|
@@ -243,7 +261,7 @@ export class K8sGenerator implements TypeScriptGenerator {
|
|
|
243
261
|
}
|
|
244
262
|
|
|
245
263
|
// Check if this key maps to a property constructor
|
|
246
|
-
const constructor =
|
|
264
|
+
const constructor = constructorFor(key, parentType);
|
|
247
265
|
if (constructor) {
|
|
248
266
|
// Array of constructors (containers, volumes, ports, env, etc.)
|
|
249
267
|
if (Array.isArray(value)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExportedTemplate, ResourceSelector } from "@intentius/chant/lexicon";
|
|
2
2
|
import { hasOwnershipMarker, LABEL_OWNERSHIP_KEYS } from "@intentius/chant/ownership";
|
|
3
|
+
import type { ParseContext, TemplateIR } from "@intentius/chant/import/parser";
|
|
3
4
|
import { K8sParser } from "./parser";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -52,6 +53,11 @@ export function stripServerFields(obj: Record<string, unknown>): Record<string,
|
|
|
52
53
|
* `items` of a `kubectl get -o json` List). Reuses the import K8sParser by
|
|
53
54
|
* feeding it the cleaned objects as JSON documents — JSON is valid YAML, so no
|
|
54
55
|
* separate serializer is needed. Pure: all I/O stays in the caller.
|
|
56
|
+
*
|
|
57
|
+
* The result's `reparse(context)` parses the same objects again with a
|
|
58
|
+
* `ParseContext`, so `chant import --from` hands embedded content (a
|
|
59
|
+
* collector config in a ConfigMap, a PrometheusRule's groups) to the lexicon
|
|
60
|
+
* that owns it, as file import does (#2995).
|
|
55
61
|
*/
|
|
56
62
|
export function buildExportFromObjects(
|
|
57
63
|
objects: unknown[],
|
|
@@ -70,9 +76,11 @@ export function buildExportFromObjects(
|
|
|
70
76
|
.map((o) => (opts.verbatim ? o : stripServerFields(o)));
|
|
71
77
|
|
|
72
78
|
const content = cleaned.map((o) => JSON.stringify(o, null, 2)).join("\n---\n");
|
|
73
|
-
const
|
|
79
|
+
const parse = (context?: ParseContext): TemplateIR => select(new K8sParser().parse(content, context), opts.selector);
|
|
80
|
+
return { ...parse(), reparse: (context) => parse(context) };
|
|
81
|
+
}
|
|
74
82
|
|
|
75
|
-
|
|
83
|
+
function select(ir: TemplateIR, selector: ResourceSelector | undefined): TemplateIR {
|
|
76
84
|
if (!selector || (selector.type === undefined && selector.name === undefined)) {
|
|
77
85
|
return ir;
|
|
78
86
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Embedded-content import fixtures
|
|
2
2
|
|
|
3
3
|
Manifests that hold another lexicon's content, for `embedded-roundtrip.test.ts`
|
|
4
|
-
and `embedded-types.e2e.test.ts` (#2962).
|
|
4
|
+
`embedded-live.test.ts` and `embedded-types.e2e.test.ts` (#2962, #3031).
|
|
5
5
|
|
|
6
6
|
| File | Source |
|
|
7
7
|
|---|---|
|
|
@@ -9,3 +9,6 @@ and `embedded-types.e2e.test.ts` (#2962).
|
|
|
9
9
|
| `node-exporter-prometheusrule.yaml` | prometheus-operator/kube-prometheus `v0.19.0`, `manifests/nodeExporter-prometheusRule.yaml`, unchanged. |
|
|
10
10
|
| `grafana-dashboard-configmap.yaml` | prometheus-operator/kube-prometheus `v0.19.0`, `manifests/grafana-dashboardDefinitions.yaml`: the `grafana-dashboard-alertmanager-overview` item of that ConfigMapList, written as a ConfigMap of its own with the Grafana sidecar's `grafana_dashboard: "1"` label added, re-serialized by js-yaml. The dashboard JSON is unchanged. |
|
|
11
11
|
| `agent-observability.yaml` | `chant build src --lexicon k8s` of `examples/agent-observability` as of #2954: collector ConfigMaps from the k8s collector composites, Prometheus's `rules.yml` from `ruleFileYaml`, and the Grafana dashboard, datasource and provider ConfigMaps from `GrafanaConfigMaps` (`@intentius/chant-lexicon-grafana/k8s`). |
|
|
12
|
+
| `alertmanager-configmap.yaml` | prometheus-community/helm-charts at `8d235acbefe2d95f1b1365fafdf07279ae05176f`, chart alertmanager 2.0.1 (Alertmanager v0.34.1), Apache-2.0: `helm template alertmanager alertmanager --repo https://prometheus-community.github.io/helm-charts --version 2.0.1 --namespace monitoring --show-only templates/configmap.yaml`, with `config:` set to Alertmanager's own `doc/examples/simple.yml` at v0.34.1 (Apache-2.0; vendored in the prometheus lexicon as `src/import/testdata/upstream/alertmanager-simple.yml`) plus the chart's `enabled: true`. The rendered output is unchanged, apart from the leading `---`. |
|
|
13
|
+
| `grafana-v2-dashboard-configmap.yaml` | The grafana lexicon's `test/fixtures/exports/grafana-13.2.2/checkout.v2-resource.json` (Grafana 13.2.2's "V2 Resource" export, provenance in that directory's README), written as the `checkout.json` value of a ConfigMap with the Grafana sidecar's `grafana_dashboard: "1"` label, serialized by js-yaml. The dashboard JSON is unchanged. |
|
|
14
|
+
| `grafana-operator-dashboard.yaml` | The dashboard JSON of `grafana-dashboard-configmap.yaml`, unchanged, as the `spec.json` of a Grafana Operator `GrafanaDashboard` (`grafana.integreatly.org/v1beta1`, Grafana Operator v5.25.0) with an `instanceSelector`, a `folder` and a `resyncPeriod`, serialized by js-yaml (#3015). |
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Source: alertmanager/templates/configmap.yaml
|
|
2
|
+
apiVersion: v1
|
|
3
|
+
kind: ConfigMap
|
|
4
|
+
metadata:
|
|
5
|
+
name: alertmanager
|
|
6
|
+
labels:
|
|
7
|
+
helm.sh/chart: alertmanager-2.0.1
|
|
8
|
+
app.kubernetes.io/name: alertmanager
|
|
9
|
+
app.kubernetes.io/instance: alertmanager
|
|
10
|
+
app.kubernetes.io/version: "v0.34.1"
|
|
11
|
+
app.kubernetes.io/managed-by: Helm
|
|
12
|
+
namespace: monitoring
|
|
13
|
+
data:
|
|
14
|
+
alertmanager.yml: |
|
|
15
|
+
global:
|
|
16
|
+
smtp_auth_password: password
|
|
17
|
+
smtp_auth_username: alertmanager
|
|
18
|
+
smtp_from: alertmanager@example.org
|
|
19
|
+
smtp_smarthost: localhost:25
|
|
20
|
+
inhibit_rules:
|
|
21
|
+
- equal:
|
|
22
|
+
- alertname
|
|
23
|
+
- cluster
|
|
24
|
+
- service
|
|
25
|
+
source_matchers:
|
|
26
|
+
- severity="critical"
|
|
27
|
+
target_matchers:
|
|
28
|
+
- severity="warning"
|
|
29
|
+
receivers:
|
|
30
|
+
- email_configs:
|
|
31
|
+
- to: team-X+alerts@example.org
|
|
32
|
+
name: team-X-mails
|
|
33
|
+
- email_configs:
|
|
34
|
+
- to: team-X+alerts-critical@example.org
|
|
35
|
+
name: team-X-pager
|
|
36
|
+
pagerduty_configs:
|
|
37
|
+
- service_key: <team-X-key>
|
|
38
|
+
- email_configs:
|
|
39
|
+
- to: team-Y+alerts@example.org
|
|
40
|
+
name: team-Y-mails
|
|
41
|
+
- name: team-Y-pager
|
|
42
|
+
pagerduty_configs:
|
|
43
|
+
- service_key: <team-Y-key>
|
|
44
|
+
- name: team-DB-pager
|
|
45
|
+
pagerduty_configs:
|
|
46
|
+
- service_key: <team-DB-key>
|
|
47
|
+
route:
|
|
48
|
+
group_by:
|
|
49
|
+
- alertname
|
|
50
|
+
- cluster
|
|
51
|
+
- service
|
|
52
|
+
group_interval: 5m
|
|
53
|
+
group_wait: 30s
|
|
54
|
+
receiver: team-X-mails
|
|
55
|
+
repeat_interval: 3h
|
|
56
|
+
routes:
|
|
57
|
+
- matchers:
|
|
58
|
+
- service=~"foo1|foo2|baz"
|
|
59
|
+
receiver: team-X-mails
|
|
60
|
+
routes:
|
|
61
|
+
- matchers:
|
|
62
|
+
- severity="critical"
|
|
63
|
+
receiver: team-X-pager
|
|
64
|
+
- matchers:
|
|
65
|
+
- service="files"
|
|
66
|
+
receiver: team-Y-mails
|
|
67
|
+
routes:
|
|
68
|
+
- matchers:
|
|
69
|
+
- severity="critical"
|
|
70
|
+
receiver: team-Y-pager
|
|
71
|
+
- group_by:
|
|
72
|
+
- alertname
|
|
73
|
+
- cluster
|
|
74
|
+
- database
|
|
75
|
+
matchers:
|
|
76
|
+
- service="database"
|
|
77
|
+
receiver: team-DB-pager
|
|
78
|
+
routes:
|
|
79
|
+
- continue: true
|
|
80
|
+
matchers:
|
|
81
|
+
- owner="team-X"
|
|
82
|
+
receiver: team-X-pager
|
|
83
|
+
- matchers:
|
|
84
|
+
- owner="team-Y"
|
|
85
|
+
receiver: team-Y-pager
|
|
86
|
+
templates:
|
|
87
|
+
- /etc/alertmanager/template/*.tmpl
|
|
88
|
+
tracing:
|
|
89
|
+
endpoint: localhost:4317
|
|
90
|
+
insecure: true
|
|
91
|
+
sampling_fraction: 1
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "fs";
|
|
9
9
|
import { join, relative, resolve } from "path";
|
|
10
10
|
import { importCommand, type ImportResult } from "@intentius/chant/cli/commands/import";
|
|
11
|
+
import { parsePrometheusYaml } from "@intentius/chant-lexicon-prometheus/import/parser";
|
|
11
12
|
|
|
12
13
|
export const pkgDir = resolve(import.meta.dirname, "../../../..");
|
|
13
14
|
export const repoRoot = resolve(pkgDir, "../..");
|
|
@@ -51,3 +52,20 @@ export async function importManifest(yaml: string, options: { detect?: boolean }
|
|
|
51
52
|
export function removeDir(dir: string): void {
|
|
52
53
|
rmSync(dir, { recursive: true, force: true });
|
|
53
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* An alertmanager.yml as the prometheus importer reads it, receivers and
|
|
58
|
+
* time intervals sorted by name (the serializer sorts them): what an
|
|
59
|
+
* imported ConfigMap's `alertmanager.yml` must give back (#3031).
|
|
60
|
+
*/
|
|
61
|
+
export function alertmanagerConfig(text: string): Record<string, unknown> {
|
|
62
|
+
const parsed = parsePrometheusYaml(text);
|
|
63
|
+
if (parsed.kind !== "alertmanager") throw new Error("not an alertmanager.yml");
|
|
64
|
+
const byName = (a: { name: string }, b: { name: string }) => a.name.localeCompare(b.name);
|
|
65
|
+
const { receivers, time_intervals, ...rest } = parsed.config;
|
|
66
|
+
return {
|
|
67
|
+
...rest,
|
|
68
|
+
...(receivers ? { receivers: [...receivers].sort(byName) } : {}),
|
|
69
|
+
...(time_intervals ? { time_intervals: [...time_intervals].sort(byName) } : {}),
|
|
70
|
+
};
|
|
71
|
+
}
|