@intentius/chant-lexicon-k8s 0.106.1 → 0.106.3

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.
@@ -12,7 +12,8 @@
12
12
  * - a Grafana Operator `GrafanaDashboard`'s `spec.json`, as text (#3015);
13
13
  * - the alerting content of the Grafana Operator's `GrafanaAlertRuleGroup`
14
14
  * (`spec.rules`), `GrafanaContactPoint` (`spec.receivers`),
15
- * `GrafanaNotificationPolicy` (`spec.route`), `GrafanaMuteTiming`
15
+ * `GrafanaNotificationPolicy` (`spec.route`), `GrafanaNotificationPolicyRoute`
16
+ * (the whole `spec`, offered as `route`), `GrafanaMuteTiming`
16
17
  * (`spec.time_intervals`) and `GrafanaNotificationTemplate`
17
18
  * (`spec.template`), each with the whole `spec` as the document so the
18
19
  * owner can read the fields beside it (#3538).
@@ -1 +1 @@
1
- {"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../src/import/embedded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAmB,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAOjG,6HAA6H;AAC7H,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AA0C3D;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,QAAQ,EAAE,uBAAuB,GAChC,IAAI,CA8EN"}
1
+ {"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../src/import/embedded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAmB,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAOjG,6HAA6H;AAC7H,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AA0C3D;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,QAAQ,EAAE,uBAAuB,GAChC,IAAI,CA8FN"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "74ae82ff1fe4bc497ab0864037e34e4ab8d7bbc04604ab161df147058c540a2d",
4
+ "manifest.json": "6e188f229fb2742f0f0c6bf190920077d5fb7dd0404dda0767c925dc4066f511",
5
5
  "meta.json": "88e6b03f6f72fd9ba74d4e5899e529875cb1dcb90581943a786efd66e58d137e",
6
6
  "types/index.d.ts": "f4e2eabdd2792eb17086e5de919710b5db3a05057ec2c1b3c64da03dfb60b80b",
7
7
  "rules/argo-appset-single-project.ts": "afa9f310753aa2d475f35012b13135b2dfaebed2a35d44edbe185ebc07673674",
@@ -71,5 +71,5 @@
71
71
  "skills/chant-k8s-argo.md": "24c9a85b78a2fc5c6657424baac9cc6d6caff6f47605b8146b2c0082133181cf",
72
72
  "skills/chant-k8s-flux.md": "9670efc2e9854bd14686b5adeb707396b9030a4dcaee6529b30abf56efe2c50c"
73
73
  },
74
- "composite": "2018da8b6b57050838bb301fead913b01073570c7fe6a97c6d210bd3cba6fb35"
74
+ "composite": "1150cfec19abb6cdb07173ae6ba12675a85c495f3f2ce2e770f824acf2981b3f"
75
75
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k8s",
3
- "version": "0.106.1",
3
+ "version": "0.106.3",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "K8s",
6
6
  "intrinsics": [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-k8s",
3
- "version": "0.106.1",
3
+ "version": "0.106.3",
4
4
  "description": "Kubernetes lexicon for chant — declarative IaC in TypeScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -78,7 +78,7 @@
78
78
  "@types/js-yaml": "^4.0.9"
79
79
  },
80
80
  "optionalDependencies": {
81
- "@intentius/chant-k8s-client": "^0.106.1"
81
+ "@intentius/chant-k8s-client": "^0.106.3"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@intentius/chant": "*",
@@ -86,7 +86,7 @@
86
86
  },
87
87
  "peerDependencies": {
88
88
  "zod": "^4.3.6",
89
- "@intentius/chant": "^0.106.1",
89
+ "@intentius/chant": "^0.106.3",
90
90
  "typescript": "^5.9.3"
91
91
  }
92
92
  }
@@ -229,6 +229,7 @@ describe("manifest -> TypeScript -> manifest, with embedded content imported by
229
229
  "grafana-dashboard-slo-support-agent-runs",
230
230
  "otel-agent-config",
231
231
  "otel-gateway-config",
232
+ "prometheus-config-prometheus",
232
233
  "prometheus-config-rules",
233
234
  ]);
234
235
  // The rule group an Slo() built comes back as that Slo, referenced by its rules.
@@ -12,7 +12,8 @@
12
12
  * - a Grafana Operator `GrafanaDashboard`'s `spec.json`, as text (#3015);
13
13
  * - the alerting content of the Grafana Operator's `GrafanaAlertRuleGroup`
14
14
  * (`spec.rules`), `GrafanaContactPoint` (`spec.receivers`),
15
- * `GrafanaNotificationPolicy` (`spec.route`), `GrafanaMuteTiming`
15
+ * `GrafanaNotificationPolicy` (`spec.route`), `GrafanaNotificationPolicyRoute`
16
+ * (the whole `spec`, offered as `route`), `GrafanaMuteTiming`
16
17
  * (`spec.time_intervals`) and `GrafanaNotificationTemplate`
17
18
  * (`spec.template`), each with the whole `spec` as the document so the
18
19
  * owner can read the fields beside it (#3538).
@@ -131,6 +132,22 @@ export function delegateEmbedded(
131
132
  return;
132
133
  }
133
134
 
135
+ // A GrafanaNotificationPolicyRoute's spec is the route itself, so the whole spec is offered (as `route`) and replaced.
136
+ if (type === "K8s::Grafana::GrafanaNotificationPolicyRoute" && isObject(properties.spec) && typeof properties.spec.receiver === "string") {
137
+ const ref = embedded.resolve({
138
+ host: "k8s",
139
+ hostType: type,
140
+ location: `${kind} ${name} spec`,
141
+ directory: name,
142
+ document: { route: properties.spec },
143
+ select: "route",
144
+ labels,
145
+ expectedOwner: { lexicon: "grafana", what: "a Grafana notification policy route" },
146
+ });
147
+ if (ref) properties.spec = ref as unknown as Record<string, unknown>;
148
+ return;
149
+ }
150
+
134
151
  const alerting = GRAFANA_ALERTING_FIELDS[type];
135
152
  if (alerting && isObject(properties.spec) && properties.spec[alerting.field] !== undefined) {
136
153
  const spec = properties.spec;
@@ -76,12 +76,13 @@ function primary(out: string | SerializerResult | undefined): string {
76
76
  return typeof out === "string" ? out : out.primary;
77
77
  }
78
78
 
79
- function manifest(): string {
79
+ function manifest(policyRoutes = false): string {
80
80
  const instance = GrafanaOperatorResources({
81
81
  entities: entities as never,
82
82
  instanceSelector: { matchLabels: { dashboards: "grafana" } },
83
83
  secretName: "grafana-secrets",
84
84
  namespace: "monitoring",
85
+ policyRoutes,
85
86
  });
86
87
  return primary(k8sSerializer.serialize(expandComposite("grafana", instance)));
87
88
  }
@@ -132,4 +133,26 @@ describe("GrafanaOperatorResources -> chant import -> chant build", () => {
132
133
  removeDir(imported.dir);
133
134
  }
134
135
  });
136
+
137
+ test("a policy route is imported as a declaration and builds back to the same resource, its policy kept as written", async () => {
138
+ const yaml = manifest(true);
139
+ const input = (loadAll(yaml) as Json[]).filter((d) => d);
140
+ const route = find(input, "GrafanaNotificationPolicyRoute");
141
+
142
+ const imported = await importManifest(yaml);
143
+ try {
144
+ expect(imported.result.error).toBeUndefined();
145
+ expect(imported.result.success).toBe(true);
146
+ expect(imported.files["other.ts"]).toContain("operatorRouteSpec(");
147
+ expect(imported.files["grafana-notification-policy-route-1/notifications.ts"]).toContain("new NotificationPolicy(");
148
+
149
+ const result = await build(imported.srcDir, [k8sSerializer, grafanaSerializer]);
150
+ expect(result.errors).toEqual([]);
151
+ const output = (loadAll(primary(result.outputs.get("k8s"))) as Json[]).filter((d) => d);
152
+ expect(find(output, "GrafanaNotificationPolicyRoute")).toEqual(route);
153
+ expect(find(output, "GrafanaNotificationPolicy")).toEqual(find(input, "GrafanaNotificationPolicy"));
154
+ } finally {
155
+ removeDir(imported.dir);
156
+ }
157
+ });
135
158
  });