The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import * as Kubernetes from "@alchemy.run/kubernetes"; |
| 3 | import { |
| 4 | HelmError, |
| 5 | parseRenderedManifests, |
| 6 | renderHelmChart, |
| 7 | } from "@alchemy.run/kubernetes/internal/helm"; |
| 8 | import { describe as suite, expect, layer } from "@alchemy.run/test"; |
| 9 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 10 | import * as Core from "@alchemy.run/test/Core"; |
| 11 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 12 | import * as Drift from "alchemy/Drift"; |
| 13 | import * as Provider from "alchemy/Provider"; |
| 14 | import * as Effect from "effect/Effect"; |
| 15 | import * as FileSystem from "effect/FileSystem"; |
| 16 | import * as Layer from "effect/Layer"; |
| 17 | import * as Path from "effect/Path"; |
| 18 | import * as Redacted from "effect/Redacted"; |
| 19 | import * as Result from "effect/Result"; |
| 20 | import { |
| 21 | destroyKindStack, |
| 22 | KindTestCluster, |
| 23 | kubectl, |
| 24 | kubectlGet, |
| 25 | type KindCluster, |
| 26 | } from "./fixtures/kind.ts"; |
| 27 | |
| 28 | const testOptions = { providers: Layer.mergeAll(AWS.providers(), Kubernetes.providers()) }; |
| 29 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 30 | |
| 31 | // Rendering shells out to the local helm CLI (like Docker for image |
| 32 | // builds) — `helm` must be installed on the machine running this suite. |
| 33 | const chartDir = `${import.meta.dirname}/fixtures/chart`; |
| 34 | |
| 35 | const describe = layer(NodeServices.layer); |
| 36 | |
| 37 | const expectValuesFileGone = (secret: string) => |
| 38 | Effect.gen(function* () { |
| 39 | const fs = yield* FileSystem.FileSystem; |
| 40 | const path = yield* Path.Path; |
| 41 | const probe = yield* fs.makeTempDirectory({ prefix: "alchemy-helm-probe-" }); |
| 42 | const tmp = path.dirname(probe); |
| 43 | yield* fs.remove(probe, { recursive: true }); |
| 44 | const entries = yield* fs.readDirectory(tmp); |
| 45 | for (const entry of entries) { |
| 46 | if (!entry.startsWith("alchemy-helm-")) continue; |
| 47 | const valuesFile = path.join(tmp, entry, "values.json"); |
| 48 | if (!(yield* fs.exists(valuesFile))) continue; |
| 49 | expect(yield* fs.readFileString(valuesFile)).not.toContain(secret); |
| 50 | } |
| 51 | }); |
| 52 | |
| 53 | describe("renderHelmChart (local fixture)", (it) => { |
| 54 | it.effect( |
| 55 | "renders values, release name, and namespace", |
| 56 | () => |
| 57 | Effect.gen(function* () { |
| 58 | const objects = yield* renderHelmChart({ |
| 59 | chart: chartDir, |
| 60 | releaseName: "probe", |
| 61 | namespace: "demo", |
| 62 | values: { message: "hello-from-values" }, |
| 63 | }); |
| 64 | expect(objects).toHaveLength(1); |
| 65 | const configMap = objects[0]! as unknown as { |
| 66 | kind: string; |
| 67 | metadata: { name: string }; |
| 68 | data: Record<string, string>; |
| 69 | }; |
| 70 | expect(configMap.kind).toBe("ConfigMap"); |
| 71 | expect(configMap.metadata.name).toBe("probe-config"); |
| 72 | expect(configMap.data.message).toBe("hello-from-values"); |
| 73 | expect(configMap.data.release).toBe("probe"); |
| 74 | expect(configMap.data.namespace).toBe("demo"); |
| 75 | }), |
| 76 | { tags: ["provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 77 | ); |
| 78 | |
| 79 | it.effect( |
| 80 | "unwraps Redacted values before writing the values file", |
| 81 | () => |
| 82 | Effect.gen(function* () { |
| 83 | const secret = "helm-values-sentinel"; |
| 84 | const objects = yield* renderHelmChart({ |
| 85 | chart: chartDir, |
| 86 | releaseName: "probe", |
| 87 | namespace: "demo", |
| 88 | values: { message: Redacted.make(secret) }, |
| 89 | }); |
| 90 | const configMap = objects[0] as unknown as { data: { message: string } }; |
| 91 | expect(configMap.data.message).toBe(secret); |
| 92 | expect(configMap.data.message).not.toBe("<redacted>"); |
| 93 | yield* expectValuesFileGone(secret); |
| 94 | }), |
| 95 | { tags: ["provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 96 | ); |
| 97 | |
| 98 | it.effect( |
| 99 | "values toggle conditional templates on and off", |
| 100 | () => |
| 101 | Effect.gen(function* () { |
| 102 | const withoutSecond = yield* renderHelmChart({ |
| 103 | chart: chartDir, |
| 104 | releaseName: "probe", |
| 105 | namespace: "demo", |
| 106 | }); |
| 107 | expect(withoutSecond).toHaveLength(1); |
| 108 | |
| 109 | const withSecond = yield* renderHelmChart({ |
| 110 | chart: chartDir, |
| 111 | releaseName: "probe", |
| 112 | namespace: "demo", |
| 113 | values: { secondConfigMap: { enabled: true } }, |
| 114 | }); |
| 115 | expect(withSecond).toHaveLength(2); |
| 116 | expect(withSecond.map((object) => object.metadata.name).sort()).toEqual([ |
| 117 | "probe-config", |
| 118 | "probe-second", |
| 119 | ]); |
| 120 | }), |
| 121 | { tags: ["provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 122 | ); |
| 123 | |
| 124 | // Regression for #1312: the fixture chart ships a `helm.sh/hook: pre-delete` |
| 125 | // Job. HelmChart has no Helm release and no hook lifecycle, so the hook |
| 126 | // must never enter the managed-object graph (where it would be created and |
| 127 | // reconciled like an ordinary workload on every deploy). |
| 128 | it.effect( |
| 129 | "excludes Helm lifecycle hooks from the render", |
| 130 | () => |
| 131 | Effect.gen(function* () { |
| 132 | const objects = yield* renderHelmChart({ |
| 133 | chart: chartDir, |
| 134 | releaseName: "probe", |
| 135 | namespace: "demo", |
| 136 | }); |
| 137 | expect(objects.map((object) => object.kind)).not.toContain("Job"); |
| 138 | expect(objects.map((object) => object.metadata.name)).toEqual(["probe-config"]); |
| 139 | }), |
| 140 | { tags: ["provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 141 | ); |
| 142 | |
| 143 | it.effect( |
| 144 | "scrubs Redacted values from helm stderr", |
| 145 | () => |
| 146 | Effect.gen(function* () { |
| 147 | const secret = "helm-stderr-sentinel"; |
| 148 | const result = yield* Effect.result( |
| 149 | renderHelmChart({ |
| 150 | chart: chartDir, |
| 151 | releaseName: "probe", |
| 152 | namespace: "demo", |
| 153 | values: { message: Redacted.make(secret), fail: true }, |
| 154 | }), |
| 155 | ); |
| 156 | expect(Result.isFailure(result)).toBe(true); |
| 157 | if (Result.isFailure(result)) { |
| 158 | expect(result.failure._tag).toBe("HelmError"); |
| 159 | expect(result.failure.message).not.toContain(secret); |
| 160 | expect(result.failure.message).toContain("<redacted>"); |
| 161 | } |
| 162 | yield* expectValuesFileGone(secret); |
| 163 | }), |
| 164 | { tags: ["provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 165 | ); |
| 166 | |
| 167 | it.effect( |
| 168 | "a bad chart reference fails with a typed HelmError", |
| 169 | () => |
| 170 | Effect.gen(function* () { |
| 171 | const result = yield* Effect.result( |
| 172 | renderHelmChart({ |
| 173 | chart: `${chartDir}-does-not-exist`, |
| 174 | releaseName: "probe", |
| 175 | namespace: "demo", |
| 176 | }), |
| 177 | ); |
| 178 | expect(Result.isFailure(result)).toBe(true); |
| 179 | if (Result.isFailure(result)) { |
| 180 | expect(result.failure._tag).toBe("HelmError"); |
| 181 | } |
| 182 | }), |
| 183 | { tags: ["provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 184 | ); |
| 185 | }); |
| 186 | |
| 187 | describe("parseRenderedManifests", (it) => { |
| 188 | it.effect( |
| 189 | "ignores Helm OCI pull metadata", |
| 190 | () => |
| 191 | Effect.gen(function* () { |
| 192 | const objects = yield* parseRenderedManifests( |
| 193 | "oci://registry.example.test/charts/example", |
| 194 | `Pulled: registry.example.test/charts/example:1.2.3 |
| 195 | Digest: sha256:0123456789abcdef |
| 196 | --- |
| 197 | apiVersion: v1 |
| 198 | kind: ConfigMap |
| 199 | metadata: |
| 200 | name: example |
| 201 | `, |
| 202 | ); |
| 203 | |
| 204 | expect(objects).toHaveLength(1); |
| 205 | expect(objects[0]?.kind).toBe("ConfigMap"); |
| 206 | expect(objects[0]?.metadata.name).toBe("example"); |
| 207 | }), |
| 208 | { tags: ["unit", "provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 209 | ); |
| 210 | |
| 211 | it.effect( |
| 212 | "excludes helm.sh/hook-annotated objects (#1312)", |
| 213 | () => |
| 214 | Effect.gen(function* () { |
| 215 | const objects = yield* parseRenderedManifests( |
| 216 | "example", |
| 217 | `apiVersion: v1 |
| 218 | kind: ConfigMap |
| 219 | metadata: |
| 220 | name: ordinary |
| 221 | --- |
| 222 | apiVersion: batch/v1 |
| 223 | kind: Job |
| 224 | metadata: |
| 225 | name: uninstall-hook |
| 226 | annotations: |
| 227 | helm.sh/hook: pre-delete |
| 228 | --- |
| 229 | apiVersion: v1 |
| 230 | kind: Pod |
| 231 | metadata: |
| 232 | name: smoke-test |
| 233 | annotations: |
| 234 | "helm.sh/hook": test |
| 235 | `, |
| 236 | ); |
| 237 | |
| 238 | expect(objects.map((object) => object.metadata.name)).toEqual(["ordinary"]); |
| 239 | }), |
| 240 | { tags: ["unit", "provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 241 | ); |
| 242 | |
| 243 | it.effect( |
| 244 | "rejects pull-shaped metadata for non-OCI charts", |
| 245 | () => |
| 246 | Effect.gen(function* () { |
| 247 | const result = yield* Effect.result( |
| 248 | parseRenderedManifests( |
| 249 | "example", |
| 250 | `Pulled: registry.example.test/charts/example:1.2.3 |
| 251 | Digest: sha256:0123456789abcdef |
| 252 | `, |
| 253 | ), |
| 254 | ); |
| 255 | |
| 256 | expect(Result.isFailure(result)).toBe(true); |
| 257 | if (Result.isFailure(result)) { |
| 258 | expect(result.failure._tag).toBe("HelmError"); |
| 259 | } |
| 260 | }), |
| 261 | { tags: ["unit", "provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 262 | ); |
| 263 | |
| 264 | it.effect( |
| 265 | "rejects pull metadata that is not the leading OCI preamble", |
| 266 | () => |
| 267 | Effect.gen(function* () { |
| 268 | const result = yield* Effect.result( |
| 269 | parseRenderedManifests( |
| 270 | "oci://registry.example.test/charts/example", |
| 271 | `apiVersion: v1 |
| 272 | kind: ConfigMap |
| 273 | metadata: |
| 274 | name: example |
| 275 | --- |
| 276 | Pulled: registry.example.test/charts/example:1.2.3 |
| 277 | Digest: sha256:0123456789abcdef |
| 278 | `, |
| 279 | ), |
| 280 | ); |
| 281 | |
| 282 | expect(Result.isFailure(result)).toBe(true); |
| 283 | if (Result.isFailure(result)) { |
| 284 | expect(result.failure._tag).toBe("HelmError"); |
| 285 | } |
| 286 | }), |
| 287 | { tags: ["unit", "provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 288 | ); |
| 289 | |
| 290 | const parserTags = [ |
| 291 | "unit", |
| 292 | "provider:kubernetes", |
| 293 | "provider:kubernetes:helmchart", |
| 294 | "local", |
| 295 | ] as const; |
| 296 | |
| 297 | const expectScrubbedMessage = ( |
| 298 | result: Result.Result<unknown, { message: string }>, |
| 299 | secret: string, |
| 300 | includes: string, |
| 301 | ) => { |
| 302 | expect(Result.isFailure(result)).toBe(true); |
| 303 | if (!Result.isFailure(result)) return; |
| 304 | expect(result.failure.message).toContain(includes); |
| 305 | expect(result.failure.message).toContain("<redacted>"); |
| 306 | expect(result.failure.message).not.toContain(secret); |
| 307 | }; |
| 308 | |
| 309 | const expectScrubbedHelmError = (failure: unknown, secret: string) => { |
| 310 | expect(failure).toBeInstanceOf(HelmError); |
| 311 | if (!(failure instanceof HelmError)) return; |
| 312 | expect(failure.message).toContain("<redacted>"); |
| 313 | expect(failure.message).not.toContain(secret); |
| 314 | }; |
| 315 | |
| 316 | it.effect( |
| 317 | "leaves credentials in successfully parsed objects", |
| 318 | () => |
| 319 | Effect.gen(function* () { |
| 320 | const secret = "helm-kept-secret"; |
| 321 | const objects = yield* parseRenderedManifests( |
| 322 | "example", |
| 323 | `apiVersion: v1 |
| 324 | kind: ConfigMap |
| 325 | metadata: |
| 326 | name: example |
| 327 | data: |
| 328 | token: ${secret} |
| 329 | `, |
| 330 | [secret], |
| 331 | ); |
| 332 | const configMap = objects[0] as { data?: { token?: string } }; |
| 333 | expect(configMap.data?.token).toBe(secret); |
| 334 | }), |
| 335 | { tags: parserTags }, |
| 336 | ); |
| 337 | |
| 338 | it.effect( |
| 339 | "scrubs credentials from invalid rendered documents", |
| 340 | () => |
| 341 | Effect.gen(function* () { |
| 342 | const secret = "helm-object-secret"; |
| 343 | expectScrubbedMessage( |
| 344 | yield* Effect.result(parseRenderedManifests("example", `${secret}\n`, [secret])), |
| 345 | secret, |
| 346 | "non-object", |
| 347 | ); |
| 348 | const missingVersion = yield* Effect.result( |
| 349 | parseRenderedManifests( |
| 350 | "example", |
| 351 | `kind: ConfigMap |
| 352 | data: |
| 353 | token: ${secret} |
| 354 | `, |
| 355 | [secret], |
| 356 | ), |
| 357 | ); |
| 358 | expectScrubbedMessage(missingVersion, secret, "without apiVersion/kind"); |
| 359 | if (Result.isFailure(missingVersion)) { |
| 360 | expect(missingVersion.failure.message).toContain("ConfigMap"); |
| 361 | } |
| 362 | expectScrubbedMessage( |
| 363 | yield* Effect.result( |
| 364 | parseRenderedManifests( |
| 365 | "example", |
| 366 | `apiVersion: v1 |
| 367 | kind: ${secret} |
| 368 | metadata: {} |
| 369 | `, |
| 370 | [secret], |
| 371 | ), |
| 372 | ), |
| 373 | secret, |
| 374 | "without metadata.name", |
| 375 | ); |
| 376 | }), |
| 377 | { tags: parserTags }, |
| 378 | ); |
| 379 | |
| 380 | it.effect( |
| 381 | "scrubs a credential that crosses the diagnostic truncation boundary", |
| 382 | () => |
| 383 | Effect.gen(function* () { |
| 384 | // JSON is {"token":"<secret>"}; the secret starts at index 10 and |
| 385 | // continues past the 200-character snippet, so slicing first would |
| 386 | // leave a prefix that replaceAll cannot match. |
| 387 | const secret = `boundary-secret-${"Z".repeat(240)}`; |
| 388 | const result = yield* Effect.result( |
| 389 | parseRenderedManifests("example", `token: ${secret}\n`, [secret]), |
| 390 | ); |
| 391 | expect(Result.isFailure(result)).toBe(true); |
| 392 | if (Result.isFailure(result)) { |
| 393 | expect(result.failure.message).toContain("without apiVersion/kind"); |
| 394 | expect(result.failure.message).toContain("<redacted>"); |
| 395 | expect(result.failure.message).not.toContain(secret); |
| 396 | expect(result.failure.message).not.toContain(secret.slice(0, 40)); |
| 397 | expect(result.failure.message).not.toContain(secret.slice(20, 80)); |
| 398 | } |
| 399 | }), |
| 400 | { tags: parserTags }, |
| 401 | ); |
| 402 | |
| 403 | it.effect( |
| 404 | "returns a typed error for malformed YAML without the credential", |
| 405 | () => |
| 406 | Effect.gen(function* () { |
| 407 | const secret = "helm-yaml-secret"; |
| 408 | const parsed = yield* Effect.result( |
| 409 | parseRenderedManifests("example", `token: "${secret}\n`, [secret]), |
| 410 | ); |
| 411 | expect(Result.isFailure(parsed)).toBe(true); |
| 412 | if (Result.isFailure(parsed)) { |
| 413 | expectScrubbedHelmError(parsed.failure, secret); |
| 414 | expect(parsed.failure.message).toContain("Failed to parse"); |
| 415 | } |
| 416 | |
| 417 | const alias = "helm-alias-secret"; |
| 418 | const thrown = yield* Effect.result( |
| 419 | parseRenderedManifests("example", `*${alias}\n`, [alias]), |
| 420 | ); |
| 421 | expect(Result.isFailure(thrown)).toBe(true); |
| 422 | if (Result.isFailure(thrown)) { |
| 423 | expectScrubbedHelmError(thrown.failure, alias); |
| 424 | expect(thrown.failure.message).toContain("Failed to parse"); |
| 425 | } |
| 426 | }), |
| 427 | { tags: parserTags }, |
| 428 | ); |
| 429 | }); |
| 430 | |
| 431 | // Ungated probe: chart objects live in-cluster with no cloud-side |
| 432 | // enumeration attributing them to alchemy, so `list()` is intentionally |
| 433 | // empty. Proves the provider is registered and its record type-checks; the |
| 434 | // live apply path rides the gated Deployment E2E cluster |
| 435 | // (Deployment.test.ts). |
| 436 | test.provider( |
| 437 | "list returns an empty array (in-cluster objects)", |
| 438 | () => |
| 439 | Effect.gen(function* () { |
| 440 | const provider = yield* Provider.findProvider(Kubernetes.HelmChart); |
| 441 | const all = yield* provider.list(); |
| 442 | expect(Array.isArray(all)).toBe(true); |
| 443 | expect(all).toEqual([]); |
| 444 | }), |
| 445 | { tags: ["provider:aws", "provider:kubernetes", "provider:kubernetes:helmchart", "local"] }, |
| 446 | ); |
| 447 | |
| 448 | const kindStack = Core.scratchStack(testOptions, "KubernetesHelmChartKind"); |
| 449 | |
| 450 | // Creates a real kind cluster (~30s); needs Docker, kind, kubectl, and helm. |
| 451 | suite( |
| 452 | "Kubernetes HelmChart on kind", |
| 453 | { |
| 454 | tags: [ |
| 455 | "provider:kubernetes", |
| 456 | "provider:kubernetes:helmchart", |
| 457 | "provider:kubernetes:localcluster", |
| 458 | "live", |
| 459 | ], |
| 460 | }, |
| 461 | () => { |
| 462 | let cluster: KindCluster; |
| 463 | const ns = ["--namespace", "default"]; |
| 464 | const readConfigMap = (name: string, namespace = "default") => |
| 465 | kubectlGet(cluster, ["configmap", name, "--namespace", namespace]); |
| 466 | |
| 467 | beforeAll( |
| 468 | Effect.gen(function* () { |
| 469 | yield* kindStack.destroy(); |
| 470 | cluster = yield* kindStack.deploy(KindTestCluster("helm", 5063)); |
| 471 | }), |
| 472 | { timeout: 300_000 }, |
| 473 | ); |
| 474 | |
| 475 | afterAll.skipIf(!!process.env.NO_DESTROY)( |
| 476 | Effect.suspend(() => destroyKindStack(kindStack, cluster)), |
| 477 | { timeout: 180_000 }, |
| 478 | ); |
| 479 | |
| 480 | test.provider( |
| 481 | "Redacted values reach the cluster unwrapped and drift tracks the release's objects", |
| 482 | (stack) => |
| 483 | Effect.gen(function* () { |
| 484 | yield* stack.destroy(); |
| 485 | const secret = "helm-live-sentinel"; |
| 486 | const chart = (id: string, values: Record<string, unknown>) => |
| 487 | Kubernetes.HelmChart(id, { |
| 488 | cluster: cluster.connection, |
| 489 | chart: chartDir, |
| 490 | releaseName: id.toLowerCase(), |
| 491 | values, |
| 492 | }); |
| 493 | yield* stack.deploy( |
| 494 | Effect.all([ |
| 495 | chart("Steady", { message: Redacted.make(secret) }), |
| 496 | chart("Annotated", { message: "annotated" }), |
| 497 | chart("Edited", { message: "declared" }), |
| 498 | chart("Pruned", { message: "pruned", secondConfigMap: { enabled: true } }), |
| 499 | ]), |
| 500 | ); |
| 501 | |
| 502 | // The values file carried the plaintext, not the placeholder. |
| 503 | const steady = yield* readConfigMap("steady-config"); |
| 504 | expect(steady.data.message).toBe(secret); |
| 505 | expect(yield* readConfigMap("pruned-second")).toBeDefined(); |
| 506 | |
| 507 | const detect = Drift.detect({ name: stack.name, stage: stack.stage }); |
| 508 | const baseline = yield* detect; |
| 509 | for (const id of ["Steady", "Annotated", "Edited", "Pruned"]) { |
| 510 | expect({ id, action: baseline.resources[id]?.action }).toEqual({ |
| 511 | id, |
| 512 | action: "unchanged", |
| 513 | }); |
| 514 | } |
| 515 | |
| 516 | // An undeclared annotation is not drift; a declared data edit and a |
| 517 | // deleted chart object are. |
| 518 | yield* kubectl(cluster, [ |
| 519 | "annotate", |
| 520 | "configmap", |
| 521 | "annotated-config", |
| 522 | "example.com/owner=someone-else", |
| 523 | ...ns, |
| 524 | ]); |
| 525 | yield* kubectl(cluster, [ |
| 526 | "patch", |
| 527 | "configmap", |
| 528 | "edited-config", |
| 529 | "--type", |
| 530 | "merge", |
| 531 | "-p", |
| 532 | JSON.stringify({ data: { message: "edited" } }), |
| 533 | ...ns, |
| 534 | ]); |
| 535 | yield* kubectl(cluster, ["delete", "configmap", "pruned-second", ...ns]); |
| 536 | const steadyVersion = steady.metadata.resourceVersion; |
| 537 | |
| 538 | const after = yield* detect; |
| 539 | expect(after.resources.Steady?.action).toBe("unchanged"); |
| 540 | expect(after.resources.Annotated?.action).toBe("unchanged"); |
| 541 | expect(after.resources.Edited?.action).toBe("drifted"); |
| 542 | expect(after.resources.Pruned?.action).toBe("drifted"); |
| 543 | // Drift reads are GETs: the untouched object was not written. |
| 544 | expect((yield* readConfigMap("steady-config")).metadata.resourceVersion).toBe( |
| 545 | steadyVersion, |
| 546 | ); |
| 547 | |
| 548 | yield* stack.destroy(); |
| 549 | for (const name of [ |
| 550 | "steady-config", |
| 551 | "annotated-config", |
| 552 | "edited-config", |
| 553 | "pruned-config", |
| 554 | ]) { |
| 555 | expect(yield* readConfigMap(name)).toBe(undefined); |
| 556 | } |
| 557 | }), |
| 558 | { timeout: 180_000 }, |
| 559 | ); |
| 560 | |
| 561 | test.provider( |
| 562 | "turning createNamespace off releases the Namespace and prunes dropped objects", |
| 563 | (stack) => |
| 564 | Effect.gen(function* () { |
| 565 | yield* stack.destroy(); |
| 566 | const namespace = "alchemy-helm-shared"; |
| 567 | const release = (createNamespace: boolean, second: boolean) => |
| 568 | Kubernetes.HelmChart("Shared", { |
| 569 | cluster: cluster.connection, |
| 570 | chart: chartDir, |
| 571 | releaseName: "shared", |
| 572 | namespace, |
| 573 | createNamespace, |
| 574 | values: { message: "shared", secondConfigMap: { enabled: second } }, |
| 575 | }); |
| 576 | |
| 577 | const created = yield* stack.deploy(release(true, true)); |
| 578 | expect(created.objects.map((object) => object.kind).sort()).toEqual([ |
| 579 | "ConfigMap", |
| 580 | "ConfigMap", |
| 581 | "Namespace", |
| 582 | ]); |
| 583 | expect(yield* readConfigMap("shared-second", namespace)).toBeDefined(); |
| 584 | |
| 585 | const released = yield* stack.deploy(release(false, false)); |
| 586 | expect(released.objects.map((object) => object.name)).toEqual(["shared-config"]); |
| 587 | // The dropped chart object is deleted; the released Namespace stays. |
| 588 | expect(yield* readConfigMap("shared-second", namespace)).toBe(undefined); |
| 589 | expect(yield* readConfigMap("shared-config", namespace)).toBeDefined(); |
| 590 | expect(yield* kubectlGet(cluster, ["namespace", namespace])).toBeDefined(); |
| 591 | |
| 592 | yield* stack.destroy(); |
| 593 | expect(yield* readConfigMap("shared-config", namespace)).toBe(undefined); |
| 594 | // No longer tracked, so destroy leaves it; clean it up out of band. |
| 595 | expect(yield* kubectlGet(cluster, ["namespace", namespace])).toBeDefined(); |
| 596 | yield* kubectl(cluster, ["delete", "namespace", namespace, "--wait=false"]); |
| 597 | }), |
| 598 | { timeout: 180_000 }, |
| 599 | ); |
| 600 | }, |
| 601 | ); |