| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as gkeonprem from "@distilled.cloud/gcp/gkeonprem_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { |
| 9 | bareMetalControlPlane, |
| 10 | bareMetalLoadBalancer, |
| 11 | bareMetalNetwork, |
| 12 | bareMetalStorage, |
| 13 | missingBareMetalCluster, |
| 14 | missingMembership, |
| 15 | currentProject, |
| 16 | bareMetalAdminMembership, |
| 17 | runBareMetalLifecycle, |
| 18 | } from "./common.ts"; |
| 19 | |
| 20 | const { test } = Test.make({ providers: GCP.providers() }); |
| 21 | |
| 22 | const logLevel = Effect.provideService( |
| 23 | MinimumLogLevel, |
| 24 | process.env.DEBUG ? "Debug" : "Info", |
| 25 | ); |
| 26 | |
| 27 | const waitUntilGone = (name: string) => |
| 28 | gkeonprem |
| 29 | .getProjectsLocationsBareMetalClustersBareMetalNodePools({ name }) |
| 30 | .pipe( |
| 31 | Effect.as("found" as const), |
| 32 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 33 | Effect.repeat({ |
| 34 | schedule: Schedule.spaced("2 seconds"), |
| 35 | until: (status) => status === "gone", |
| 36 | times: 10, |
| 37 | }), |
| 38 | ); |
| 39 | |
| 40 | test.provider( |
| 41 | "getProjectsLocationsBareMetalClustersBareMetalNodePools on a missing pool fails with a typed tag", |
| 42 | (stack) => |
| 43 | Effect.gen(function* () { |
| 44 | const project = yield* currentProject; |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | |
| 48 | const error = yield* Effect.flip( |
| 49 | gkeonprem.getProjectsLocationsBareMetalClustersBareMetalNodePools({ |
| 50 | name: `${missingBareMetalCluster(project)}/bareMetalNodePools/alchemy-missing-pool`, |
| 51 | }), |
| 52 | ); |
| 53 | expect(error._tag).toEqual("NotFound"); |
| 54 | |
| 55 | yield* stack.destroy(); |
| 56 | }).pipe(logLevel), |
| 57 | { tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], timeout: 90_000 }, |
| 58 | ); |
| 59 | |
| 60 | test.provider.skipIf(runBareMetalLifecycle)( |
| 61 | "create under a missing cluster is rejected with a typed tag", |
| 62 | (stack) => |
| 63 | Effect.gen(function* () { |
| 64 | const project = yield* currentProject; |
| 65 | |
| 66 | yield* stack.destroy(); |
| 67 | |
| 68 | const error = yield* Effect.flip( |
| 69 | stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | return yield* GCP.GKEOnPrem.BareMetalClustersBareMetalNodePool( |
| 72 | "Workers", |
| 73 | { |
| 74 | bareMetalCluster: missingBareMetalCluster(project), |
| 75 | nodePoolConfig: { |
| 76 | nodeConfigs: [{ nodeIp: "10.200.0.11" }], |
| 77 | }, |
| 78 | displayName: "alchemy-test-bmnp", |
| 79 | labels: { env: "test" }, |
| 80 | }, |
| 81 | ); |
| 82 | }), |
| 83 | ), |
| 84 | ); |
| 85 | expect(error._tag).toEqual("NotFound"); |
| 86 | |
| 87 | yield* stack.destroy(); |
| 88 | }).pipe(logLevel), |
| 89 | { tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], timeout: 90_000 }, |
| 90 | ); |
| 91 | |
| 92 | test.provider.skipIf(!runBareMetalLifecycle)( |
| 93 | "create, update, and delete a bare metal node pool", |
| 94 | (stack) => |
| 95 | Effect.gen(function* () { |
| 96 | const project = yield* currentProject; |
| 97 | |
| 98 | yield* stack.destroy(); |
| 99 | |
| 100 | const created = yield* stack.deploy( |
| 101 | Effect.gen(function* () { |
| 102 | const cluster = yield* GCP.GKEOnPrem.BareMetalCluster("Workload", { |
| 103 | adminClusterMembership: |
| 104 | bareMetalAdminMembership ?? missingMembership(project), |
| 105 | bareMetalVersion: "1.28.0-gke.1", |
| 106 | controlPlane: bareMetalControlPlane, |
| 107 | storage: bareMetalStorage, |
| 108 | networkConfig: bareMetalNetwork, |
| 109 | loadBalancer: bareMetalLoadBalancer, |
| 110 | description: "node pool parent", |
| 111 | }); |
| 112 | const pool = yield* GCP.GKEOnPrem.BareMetalClustersBareMetalNodePool( |
| 113 | "Workers", |
| 114 | { |
| 115 | bareMetalCluster: cluster.name, |
| 116 | nodePoolConfig: { |
| 117 | nodeConfigs: [{ nodeIp: "10.200.0.11" }], |
| 118 | }, |
| 119 | displayName: "alchemy-test-bmnp", |
| 120 | labels: { env: "test" }, |
| 121 | }, |
| 122 | ); |
| 123 | return { cluster, pool }; |
| 124 | }), |
| 125 | ); |
| 126 | |
| 127 | expect(created.pool.name).toContain("/bareMetalNodePools/"); |
| 128 | expect(created.pool.bareMetalCluster).toEqual(created.cluster.name); |
| 129 | expect(created.pool.displayName).toEqual("alchemy-test-bmnp"); |
| 130 | |
| 131 | const fetched = |
| 132 | yield* gkeonprem.getProjectsLocationsBareMetalClustersBareMetalNodePools( |
| 133 | { name: created.pool.name }, |
| 134 | ); |
| 135 | expect(fetched.name).toEqual(created.pool.name); |
| 136 | expect(fetched.displayName).toContain("alchemy-id="); |
| 137 | expect(fetched.annotations?.["alchemy-id"]).toBeDefined(); |
| 138 | |
| 139 | const updated = yield* stack.deploy( |
| 140 | Effect.gen(function* () { |
| 141 | const cluster = yield* GCP.GKEOnPrem.BareMetalCluster("Workload", { |
| 142 | bareMetalClusterId: created.cluster.bareMetalClusterId, |
| 143 | location: created.cluster.location, |
| 144 | adminClusterMembership: |
| 145 | created.cluster.adminClusterMembership ?? |
| 146 | bareMetalAdminMembership ?? |
| 147 | missingMembership(project), |
| 148 | bareMetalVersion: |
| 149 | created.cluster.bareMetalVersion ?? "1.28.0-gke.1", |
| 150 | controlPlane: created.cluster.controlPlane ?? bareMetalControlPlane, |
| 151 | storage: created.cluster.storage ?? bareMetalStorage, |
| 152 | networkConfig: created.cluster.networkConfig ?? bareMetalNetwork, |
| 153 | loadBalancer: created.cluster.loadBalancer ?? bareMetalLoadBalancer, |
| 154 | description: "node pool parent", |
| 155 | }); |
| 156 | const pool = yield* GCP.GKEOnPrem.BareMetalClustersBareMetalNodePool( |
| 157 | "Workers", |
| 158 | { |
| 159 | bareMetalNodePoolId: created.pool.bareMetalNodePoolId, |
| 160 | bareMetalCluster: cluster.name, |
| 161 | nodePoolConfig: { |
| 162 | nodeConfigs: [ |
| 163 | { nodeIp: "10.200.0.11" }, |
| 164 | { nodeIp: "10.200.0.12" }, |
| 165 | ], |
| 166 | }, |
| 167 | displayName: "alchemy-test-bmnp-v2", |
| 168 | }, |
| 169 | ); |
| 170 | return { cluster, pool }; |
| 171 | }), |
| 172 | ); |
| 173 | |
| 174 | expect(updated.pool.displayName).toEqual("alchemy-test-bmnp-v2"); |
| 175 | expect(updated.pool.bareMetalNodePoolId).toEqual( |
| 176 | created.pool.bareMetalNodePoolId, |
| 177 | ); |
| 178 | |
| 179 | yield* stack.destroy(); |
| 180 | yield* waitUntilGone(created.pool.name); |
| 181 | }).pipe(logLevel), |
| 182 | { |
| 183 | tags: ["provider:gcp", "provider:gcp:gkeonprem", "live"], |
| 184 | timeout: 120_000, |
| 185 | }, |
| 186 | ); |