| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Kubernetes from "@/Kubernetes"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { |
| 5 | JOB_MARKER_BODY, |
| 6 | JOB_MARKER_KEY, |
| 7 | SmokeBucket, |
| 8 | SmokeCluster, |
| 9 | SmokeNamespace, |
| 10 | smokeResources, |
| 11 | } from "./smoke-resources.ts"; |
| 12 | |
| 13 | /** |
| 14 | * Inline-effect one-shot `Kubernetes.Job`: writes the marker object through |
| 15 | * a `GCP.Storage.WriteBucket` binding granted to the Job's KSA Workload |
| 16 | * Identity principal, then exits. Kubernetes runs it as soon as it is |
| 17 | * applied; a fresh bucket grant may take a moment to propagate, so the pod |
| 18 | * retries under the Job's backoff. |
| 19 | */ |
| 20 | export default Kubernetes.Job( |
| 21 | "GkeSmokeJob", |
| 22 | Effect.gen(function* () { |
| 23 | const cluster = yield* SmokeCluster; |
| 24 | const ns = yield* SmokeNamespace; |
| 25 | return { |
| 26 | cluster, |
| 27 | main: import.meta.url, |
| 28 | namespace: ns.name, |
| 29 | backoffLimit: 6, |
| 30 | resources: smokeResources, |
| 31 | }; |
| 32 | }), |
| 33 | Effect.gen(function* () { |
| 34 | const bucket = yield* GCP.Storage.WriteBucket(SmokeBucket); |
| 35 | return { |
| 36 | run: Effect.gen(function* () { |
| 37 | yield* bucket.put(JOB_MARKER_KEY, JOB_MARKER_BODY, { |
| 38 | contentType: "text/plain", |
| 39 | }); |
| 40 | yield* Effect.log(`wrote ${JOB_MARKER_KEY}`); |
| 41 | }).pipe(Effect.orDie), |
| 42 | }; |
| 43 | }).pipe(Effect.provide(GCP.Storage.WriteBucketHttp)), |
| 44 | ); |