@caelo-cms/provisioning 0.11.21 → 0.12.2
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.
- package/dist/adapter.d.ts +6 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/agent-db.js +137 -9
- package/dist/bootstrap-token.d.ts +4 -3
- package/dist/bootstrap-token.d.ts.map +1 -1
- package/dist/bootstrap-token.js.map +1 -1
- package/dist/cli-routing.d.ts.map +1 -1
- package/dist/cli-routing.js +5 -0
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/converge-job-gcp.d.ts +1 -16
- package/dist/converge-job-gcp.d.ts.map +1 -1
- package/dist/converge-job-gcp.js +10 -97
- package/dist/converge-job-gcp.js.map +1 -1
- package/dist/converge-job.d.ts +7 -46
- package/dist/converge-job.d.ts.map +1 -1
- package/dist/converge-job.js +22 -57
- package/dist/converge-job.js.map +1 -1
- package/dist/gateway-armor.d.ts.map +1 -1
- package/dist/gateway-armor.js +11 -3
- package/dist/gateway-armor.js.map +1 -1
- package/dist/gcp-names.d.ts +2 -0
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +4 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +14 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/job-handover-gcp.d.ts +40 -0
- package/dist/job-handover-gcp.d.ts.map +1 -0
- package/dist/job-handover-gcp.js +108 -0
- package/dist/job-handover-gcp.js.map +1 -0
- package/dist/job-handover.d.ts +141 -0
- package/dist/job-handover.d.ts.map +1 -0
- package/dist/job-handover.js +141 -0
- package/dist/job-handover.js.map +1 -0
- package/dist/owner-setup-token.d.ts +52 -0
- package/dist/owner-setup-token.d.ts.map +1 -0
- package/dist/owner-setup-token.js +111 -0
- package/dist/owner-setup-token.js.map +1 -0
- package/dist/project-status.d.ts +33 -0
- package/dist/project-status.d.ts.map +1 -1
- package/dist/project-status.js +116 -26
- package/dist/project-status.js.map +1 -1
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +9 -5
- package/dist/stack-converge.js.map +1 -1
- package/dist/static-security-headers.d.ts +6 -0
- package/dist/static-security-headers.d.ts.map +1 -1
- package/dist/static-security-headers.js +11 -1
- package/dist/static-security-headers.js.map +1 -1
- package/dist/upgrader-assess.d.ts +30 -3
- package/dist/upgrader-assess.d.ts.map +1 -1
- package/dist/upgrader-assess.js +77 -24
- package/dist/upgrader-assess.js.map +1 -1
- package/dist/upgrader-gcp.d.ts +4 -2
- package/dist/upgrader-gcp.d.ts.map +1 -1
- package/dist/upgrader-gcp.js +16 -3
- package/dist/upgrader-gcp.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts +14 -3
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +40 -6
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-job.d.ts +51 -9
- package/dist/upgrader-job.d.ts.map +1 -1
- package/dist/upgrader-job.js +92 -37
- package/dist/upgrader-job.js.map +1 -1
- package/dist/upgrader-setup.d.ts +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +5 -2
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +11 -1
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp-pulumi.d.ts +0 -13
- package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
- package/dist/wizards/gcp-pulumi.js +0 -12
- package/dist/wizards/gcp-pulumi.js.map +1 -1
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +21 -50
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter.ts +6 -1
- package/src/bootstrap-token.ts +4 -3
- package/src/caddy-redirects.docker.test.ts +5 -0
- package/src/cli-routing.test.ts +1 -1
- package/src/cli-routing.ts +6 -0
- package/src/cli.ts +4 -0
- package/src/converge-job-gcp.test.ts +1 -40
- package/src/converge-job-gcp.ts +10 -100
- package/src/converge-job.test.ts +9 -3
- package/src/converge-job.ts +33 -115
- package/src/gateway-armor.ts +14 -3
- package/src/gateway-edge.test.ts +16 -1
- package/src/gcp-names.ts +4 -0
- package/src/gcp-url-map.test.ts +2 -0
- package/src/index.ts +3 -0
- package/src/infra-contract.test.ts +4 -3
- package/src/infra-contract.ts +14 -1
- package/src/job-handover-gcp.test.ts +129 -0
- package/src/job-handover-gcp.ts +135 -0
- package/src/job-handover.ts +259 -0
- package/src/owner-setup-token.test.ts +195 -0
- package/src/owner-setup-token.ts +138 -0
- package/src/project-status.test.ts +112 -3
- package/src/project-status.ts +141 -17
- package/src/stack-converge.ts +12 -5
- package/src/static-security-headers.test.ts +16 -0
- package/src/static-security-headers.ts +12 -1
- package/src/upgrader-assess.test.ts +75 -1
- package/src/upgrader-assess.ts +121 -57
- package/src/upgrader-gcp.ts +19 -5
- package/src/upgrader-iam-preflight.test.ts +28 -1
- package/src/upgrader-iam-preflight.ts +46 -6
- package/src/upgrader-job.test.ts +365 -31
- package/src/upgrader-job.ts +177 -53
- package/src/upgrader-setup.test.ts +17 -0
- package/src/upgrader-setup.ts +5 -2
- package/src/url-map-redirects-access.test.ts +1 -1
- package/src/wizards/gcp-install-job.ts +10 -1
- package/src/wizards/gcp-pulumi.ts +0 -18
- package/src/wizards/gcp.ts +24 -61
- package/stacks/aws/README.md +4 -2
- package/stacks/aws/index.ts +4 -8
- package/stacks/azure/README.md +4 -2
- package/stacks/azure/index.ts +4 -8
- package/stacks/gcp/README.md +6 -3
- package/stacks/gcp/index.ts +7 -8
- package/stacks/gcp-firebase/index.ts +4 -6
package/src/upgrader-job.test.ts
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* The upgrader job (upgrader-job.ts) against fakes: an in-memory request
|
|
5
5
|
* queue, a fake gcloud for a healthy gcp-firebase install, a fake signed
|
|
6
|
-
* manifest and health probe. Checks the
|
|
7
|
-
*
|
|
8
|
-
* the
|
|
6
|
+
* manifest and health probe. Checks the two stages (#1029: stage 1 moves the
|
|
7
|
+
* job onto the target's image, stage 2 does everything else), the order
|
|
8
|
+
* (backup before migrations), what lands on the timeline, and how each
|
|
9
|
+
* failure ends the request.
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
import { describe, expect, it } from "bun:test";
|
|
@@ -13,6 +14,7 @@ import type { StoredUpdatePolicy } from "@caelo-cms/shared";
|
|
|
13
14
|
import type { GcloudResult } from "./gcloud.js";
|
|
14
15
|
import type { GcloudRunner } from "./gcloud-retry.js";
|
|
15
16
|
import type { InstallMetadata } from "./install-state.js";
|
|
17
|
+
import type { JobClaim } from "./job-handover.js";
|
|
16
18
|
import type { ReleaseManifest, ReleaseManifestResult } from "./release-manifest.js";
|
|
17
19
|
import { StateLockHeldError } from "./state-store.js";
|
|
18
20
|
import {
|
|
@@ -34,8 +36,8 @@ import {
|
|
|
34
36
|
runUpgraderJob,
|
|
35
37
|
type UpdateEnd,
|
|
36
38
|
type UpdateFacts,
|
|
37
|
-
type UpdateQueue,
|
|
38
39
|
type UpgraderJobDeps,
|
|
40
|
+
type UpgraderQueue,
|
|
39
41
|
} from "./upgrader-job.js";
|
|
40
42
|
|
|
41
43
|
const ok = (stdout = ""): GcloudResult => ({ ok: true, stdout, stderr: "", exitCode: 0 });
|
|
@@ -206,12 +208,19 @@ function fakeGcloud(events: string[], overrides: [RegExp, Answer][] = []) {
|
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
/** An in-memory queue holding one pending request. */
|
|
209
|
-
function memoryQueue(request: ClaimedUpdate | null) {
|
|
211
|
+
function memoryQueue(request: ClaimedUpdate | null, over: Partial<JobClaim> = {}) {
|
|
210
212
|
const events: { phase: string; level: string; message: string }[] = [];
|
|
211
213
|
const facts: UpdateFacts[] = [];
|
|
214
|
+
const handovers: { from: string | null; to: string | null }[] = [];
|
|
215
|
+
let handedOver = true;
|
|
212
216
|
let end: UpdateEnd | null = null;
|
|
213
|
-
const queue:
|
|
214
|
-
|
|
217
|
+
const queue: UpgraderQueue = {
|
|
218
|
+
claimUpgrade: async (execution) =>
|
|
219
|
+
request ? { request, resume: false, execution, ...over } : null,
|
|
220
|
+
handover: async (_id, from, to) => {
|
|
221
|
+
handovers.push({ from, to });
|
|
222
|
+
return handedOver;
|
|
223
|
+
},
|
|
215
224
|
event: async (_id, phase, level, message) => {
|
|
216
225
|
events.push({ phase, level, message });
|
|
217
226
|
},
|
|
@@ -223,7 +232,16 @@ function memoryQueue(request: ClaimedUpdate | null) {
|
|
|
223
232
|
return true;
|
|
224
233
|
},
|
|
225
234
|
};
|
|
226
|
-
return {
|
|
235
|
+
return {
|
|
236
|
+
queue,
|
|
237
|
+
events,
|
|
238
|
+
facts,
|
|
239
|
+
handovers,
|
|
240
|
+
refuseHandover: () => {
|
|
241
|
+
handedOver = false;
|
|
242
|
+
},
|
|
243
|
+
end: () => end,
|
|
244
|
+
};
|
|
227
245
|
}
|
|
228
246
|
|
|
229
247
|
function healthProbe(order: string[], deep: HealthOutcome): HealthProbe {
|
|
@@ -262,6 +280,15 @@ function setup(
|
|
|
262
280
|
iamWithheld?: Record<string, readonly string[]>;
|
|
263
281
|
/** A resource IAM cannot be asked about. */
|
|
264
282
|
iamError?: string;
|
|
283
|
+
/** The release this image belongs to; default the target's (stage 2). */
|
|
284
|
+
ownVersion?: string;
|
|
285
|
+
/** The image this run executes; default the target's ops image. */
|
|
286
|
+
ownDigest?: string | null;
|
|
287
|
+
claim?: Partial<JobClaim>;
|
|
288
|
+
imageSigned?: boolean;
|
|
289
|
+
pointError?: string;
|
|
290
|
+
startError?: string;
|
|
291
|
+
executionState?: "running" | "ended" | "unreadable";
|
|
265
292
|
} = {},
|
|
266
293
|
) {
|
|
267
294
|
const order: string[] = [];
|
|
@@ -272,7 +299,7 @@ function setup(
|
|
|
272
299
|
policy: POLICY,
|
|
273
300
|
...opts.request,
|
|
274
301
|
};
|
|
275
|
-
const q = memoryQueue(request);
|
|
302
|
+
const q = memoryQueue(request, opts.claim);
|
|
276
303
|
const written: InstallMetadata[] = [];
|
|
277
304
|
const deps: UpgraderJobDeps = {
|
|
278
305
|
queue: q.queue,
|
|
@@ -282,6 +309,27 @@ function setup(
|
|
|
282
309
|
region: "europe-west1",
|
|
283
310
|
env: "production",
|
|
284
311
|
execution: "caelo-production-upgrader-x1",
|
|
312
|
+
ownVersion: opts.ownVersion ?? request.targetVersion,
|
|
313
|
+
verifyImage: async (slug, digest) => {
|
|
314
|
+
order.push(`cosign ${slug}@${digest}`);
|
|
315
|
+
return opts.imageSigned ?? true;
|
|
316
|
+
},
|
|
317
|
+
ownImageDigest: async () => (opts.ownDigest === undefined ? D("c") : opts.ownDigest),
|
|
318
|
+
pointJobAt: async (digest) => {
|
|
319
|
+
order.push(`point job at ${digest}`);
|
|
320
|
+
return opts.pointError ? { ok: false, error: opts.pointError } : { ok: true };
|
|
321
|
+
},
|
|
322
|
+
startJob: async () => {
|
|
323
|
+
order.push("start job");
|
|
324
|
+
return opts.startError
|
|
325
|
+
? { ok: false, error: opts.startError }
|
|
326
|
+
: { ok: true, execution: "caelo-production-upgrader-x2" };
|
|
327
|
+
},
|
|
328
|
+
executionState: async (execution) => {
|
|
329
|
+
order.push(`state of ${execution}`);
|
|
330
|
+
if (opts.executionState === "unreadable") throw new Error("Cloud Run answered 503");
|
|
331
|
+
return opts.executionState === "running" ? "running" : "failed";
|
|
332
|
+
},
|
|
285
333
|
iam: fakeIam(order, opts.iamWithheld ?? {}, opts.iamError),
|
|
286
334
|
fetchManifest: async (v) => {
|
|
287
335
|
order.push(`manifest ${v}`);
|
|
@@ -371,7 +419,7 @@ describe("runUpgraderJob", () => {
|
|
|
371
419
|
expect(r).toEqual({ exitCode: 0, requestId: null, status: null });
|
|
372
420
|
});
|
|
373
421
|
|
|
374
|
-
it("happy path: verify, backup, migrate, roll, health, record
|
|
422
|
+
it("happy path: verify, backup, migrate, roll, health, record — in that order", async () => {
|
|
375
423
|
const { deps, order, q, written } = setup();
|
|
376
424
|
const r = await runUpgraderJob(deps);
|
|
377
425
|
expect(r).toEqual({ exitCode: 0, requestId: "req-1", status: "succeeded" });
|
|
@@ -380,14 +428,11 @@ describe("runUpgraderJob", () => {
|
|
|
380
428
|
const migrate = step(order, /^migrate .*admin@sha256:a{64}/);
|
|
381
429
|
const roll = step(order, /^gcloud run services update caelo-production-admin-aaa/);
|
|
382
430
|
const deep = step(order, /^health deep/);
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
);
|
|
387
|
-
expect(
|
|
388
|
-
expect(
|
|
389
|
-
manifest < backup && backup < migrate && migrate < roll && roll < deep && deep < self,
|
|
390
|
-
).toBe(true);
|
|
431
|
+
expect([manifest, backup, migrate, roll, deep].every((i) => i >= 0)).toBe(true);
|
|
432
|
+
expect(manifest < backup && backup < migrate && migrate < roll && roll < deep).toBe(true);
|
|
433
|
+
// Stage 2 runs the target's image already: the job stays where it is.
|
|
434
|
+
expect(order.some((l) => /jobs update caelo-production-upgrader/.test(l))).toBe(false);
|
|
435
|
+
expect(order).not.toContain("start job");
|
|
391
436
|
// Images come from the signed manifest, pinned by digest, from the fixed mirror.
|
|
392
437
|
expect(
|
|
393
438
|
order.some((l) =>
|
|
@@ -419,7 +464,6 @@ describe("runUpgraderJob", () => {
|
|
|
419
464
|
"roll",
|
|
420
465
|
"health",
|
|
421
466
|
"record",
|
|
422
|
-
"self-update",
|
|
423
467
|
"finish",
|
|
424
468
|
]);
|
|
425
469
|
});
|
|
@@ -620,7 +664,7 @@ describe("runUpgraderJob", () => {
|
|
|
620
664
|
it("retries recording the end, and fails the run when it cannot", async () => {
|
|
621
665
|
const { deps, q } = setup();
|
|
622
666
|
let calls = 0;
|
|
623
|
-
const flaky:
|
|
667
|
+
const flaky: UpgraderQueue = {
|
|
624
668
|
...q.queue,
|
|
625
669
|
finish: async (id, end) => {
|
|
626
670
|
calls += 1;
|
|
@@ -634,7 +678,7 @@ describe("runUpgraderJob", () => {
|
|
|
634
678
|
});
|
|
635
679
|
expect(calls).toBe(3);
|
|
636
680
|
|
|
637
|
-
const dead:
|
|
681
|
+
const dead: UpgraderQueue = {
|
|
638
682
|
...q.queue,
|
|
639
683
|
finish: async () => {
|
|
640
684
|
throw new Error("database gone");
|
|
@@ -1192,9 +1236,8 @@ describe("runUpgraderJob", () => {
|
|
|
1192
1236
|
expect(q.end()?.codes).toEqual(["record"]);
|
|
1193
1237
|
expect(q.end()?.reason).toContain("0.11.0 serves");
|
|
1194
1238
|
expect(q.events.some((e) => e.phase === "record" && e.level === "error")).toBe(true);
|
|
1195
|
-
// The new release keeps serving: no rollback
|
|
1239
|
+
// The new release keeps serving: no rollback.
|
|
1196
1240
|
expect(order.some((l) => /--to-revisions/.test(l))).toBe(false);
|
|
1197
|
-
expect(order.some((l) => /jobs update caelo-production-upgrader/.test(l))).toBe(false);
|
|
1198
1241
|
});
|
|
1199
1242
|
|
|
1200
1243
|
it("a failed backup stops before migrations", async () => {
|
|
@@ -1228,14 +1271,6 @@ describe("runUpgraderJob", () => {
|
|
|
1228
1271
|
expect(q.events.some((e) => e.phase === "rollback")).toBe(true);
|
|
1229
1272
|
});
|
|
1230
1273
|
|
|
1231
|
-
it("a failed self-update only warns", async () => {
|
|
1232
|
-
const { deps, q } = setup({
|
|
1233
|
-
gcloud: [[/^run jobs update caelo-production-upgrader/, fail("denied")]],
|
|
1234
|
-
});
|
|
1235
|
-
expect((await runUpgraderJob(deps)).status).toBe("succeeded");
|
|
1236
|
-
expect(q.events.some((e) => e.phase === "self-update" && e.level === "warn")).toBe(true);
|
|
1237
|
-
});
|
|
1238
|
-
|
|
1239
1274
|
it("an unexpected throw ends the request as failed", async () => {
|
|
1240
1275
|
const { deps, q } = setup();
|
|
1241
1276
|
const r = await runUpgraderJob({
|
|
@@ -1248,3 +1283,302 @@ describe("runUpgraderJob", () => {
|
|
|
1248
1283
|
expect(q.end()?.reason).toContain("kaboom");
|
|
1249
1284
|
});
|
|
1250
1285
|
});
|
|
1286
|
+
|
|
1287
|
+
describe("runUpgraderJob — stage 1 (#1029: the image of an earlier release)", () => {
|
|
1288
|
+
const STAGE1 = { ownVersion: "0.10.45", ownDigest: D("e") };
|
|
1289
|
+
const WRITES =
|
|
1290
|
+
/sql backups create|services update|^migrate|jobs update|run jobs execute|lock|point job/;
|
|
1291
|
+
|
|
1292
|
+
it("verifies, moves the job onto the target's image, releases the request, starts it", async () => {
|
|
1293
|
+
const { deps, order, q, written } = setup(STAGE1);
|
|
1294
|
+
const r = await runUpgraderJob(deps);
|
|
1295
|
+
expect(r).toEqual({ exitCode: 0, requestId: "req-1", status: null });
|
|
1296
|
+
const seq = ["manifest 0.11.0", `cosign ops@${D("c")}`, "lock", `point job at ${D("c")}`];
|
|
1297
|
+
const at = [...seq, "unlock", "start job"].map((l) => order.indexOf(l));
|
|
1298
|
+
expect(at.every((i) => i >= 0)).toBe(true);
|
|
1299
|
+
expect([...at].sort((a, b) => a - b)).toEqual(at);
|
|
1300
|
+
// Released to no run, from this one, before the next exists.
|
|
1301
|
+
expect(q.handovers).toEqual([{ from: "caelo-production-upgrader-x1", to: null }]);
|
|
1302
|
+
expect(q.end()).toBeNull();
|
|
1303
|
+
expect(q.events.at(-1)?.message).toContain("caelo-production-upgrader-x2");
|
|
1304
|
+
expect(q.facts).toContainEqual(expect.objectContaining({ opsDigest: D("c") }));
|
|
1305
|
+
expect(written).toEqual([]);
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
it("assesses and rolls nothing: the serving images are not even read", async () => {
|
|
1309
|
+
// The #1025 shape: the installed code's drift check would stop this.
|
|
1310
|
+
const { deps, order } = setup({
|
|
1311
|
+
...STAGE1,
|
|
1312
|
+
meta: { ...META, imageDigests: { admin: D("7"), gateway: D("8") } },
|
|
1313
|
+
});
|
|
1314
|
+
await runUpgraderJob(deps);
|
|
1315
|
+
expect(order.some((l) => /run services|run revisions|sql |^migrate|health/.test(l))).toBe(
|
|
1316
|
+
false,
|
|
1317
|
+
);
|
|
1318
|
+
expect(order).toContain("start job");
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
it("a bug in the installed assessment stays behind: only the gate of stage 1 applies", async () => {
|
|
1322
|
+
// minFromVersion is the target's assessment, in the target's code.
|
|
1323
|
+
const { deps, order } = setup({
|
|
1324
|
+
...STAGE1,
|
|
1325
|
+
manifest: { ok: true, manifest: { ...MANIFEST, minFromVersion: "0.10.99" } },
|
|
1326
|
+
});
|
|
1327
|
+
await runUpgraderJob(deps);
|
|
1328
|
+
expect(order).toContain("start job");
|
|
1329
|
+
});
|
|
1330
|
+
|
|
1331
|
+
it("asks IAM only for the job's rights on itself", async () => {
|
|
1332
|
+
const { deps, order } = setup(STAGE1);
|
|
1333
|
+
await runUpgraderJob(deps);
|
|
1334
|
+
const asked = order.filter((l) => l.startsWith("iam "));
|
|
1335
|
+
expect(asked).toEqual([
|
|
1336
|
+
"iam projects/acme/locations/europe-west1/jobs/caelo-production-upgrader",
|
|
1337
|
+
"iam projects/acme",
|
|
1338
|
+
"iam projects/acme/serviceAccounts/caelo-production-upgrader@acme.iam.gserviceaccount.com",
|
|
1339
|
+
]);
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
it("missing rights on itself end needs-Cloud-Shell; the job does not move", async () => {
|
|
1343
|
+
const { deps, order, q } = setup({
|
|
1344
|
+
...STAGE1,
|
|
1345
|
+
iamWithheld: { "projects/acme": ["run.jobs.run"] },
|
|
1346
|
+
});
|
|
1347
|
+
expect((await runUpgraderJob(deps)).status).toBe("needs_cloud_shell");
|
|
1348
|
+
expect(q.end()?.codes).toEqual(["iam-preflight"]);
|
|
1349
|
+
expect(q.end()?.reason).toContain("run.jobs.run");
|
|
1350
|
+
expect(order.some((l) => WRITES.test(l))).toBe(false);
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
it("adversarial: a request for an older signed release never moves the job", async () => {
|
|
1354
|
+
const { deps, order, q } = setup({
|
|
1355
|
+
...STAGE1,
|
|
1356
|
+
request: { targetVersion: "0.10.40" },
|
|
1357
|
+
manifests: { "0.10.40": manifestOf("0.10.40", D("a"), D("b")) },
|
|
1358
|
+
});
|
|
1359
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1360
|
+
expect(q.end()?.codes).toEqual(["not-newer"]);
|
|
1361
|
+
expect(order.some((l) => WRITES.test(l))).toBe(false);
|
|
1362
|
+
expect(q.handovers).toEqual([]);
|
|
1363
|
+
});
|
|
1364
|
+
|
|
1365
|
+
it("adversarial: a bad manifest signature never moves the job", async () => {
|
|
1366
|
+
const { deps, order, q } = setup({
|
|
1367
|
+
...STAGE1,
|
|
1368
|
+
manifest: { ok: false, error: { code: "signature", message: "bad identity" } },
|
|
1369
|
+
});
|
|
1370
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1371
|
+
expect(q.end()?.codes).toEqual(["signature"]);
|
|
1372
|
+
expect(order.some((l) => WRITES.test(l))).toBe(false);
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
it("adversarial: an ops image without Caelo's signature never moves the job", async () => {
|
|
1376
|
+
const { deps, order, q } = setup({ ...STAGE1, imageSigned: false });
|
|
1377
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1378
|
+
expect(q.end()?.codes).toEqual(["signature"]);
|
|
1379
|
+
expect(order.some((l) => WRITES.test(l))).toBe(false);
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
it("an automatic request the policy does not allow never moves the job", async () => {
|
|
1383
|
+
const { deps, order, q } = setup({ ...STAGE1, request: { trigger: "auto" } });
|
|
1384
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1385
|
+
expect(q.end()?.codes).toEqual(["policy"]);
|
|
1386
|
+
expect(order.some((l) => WRITES.test(l))).toBe(false);
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
it("an infrastructure change stays with the converge job", async () => {
|
|
1390
|
+
const { deps, order, q } = setup({ ...STAGE1, meta: { ...META, infraContractVersion: 1 } });
|
|
1391
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "needs_cloud_shell" });
|
|
1392
|
+
expect(q.end()?.codes).toEqual(["infra-contract"]);
|
|
1393
|
+
expect(order.some((l) => WRITES.test(l))).toBe(false);
|
|
1394
|
+
});
|
|
1395
|
+
|
|
1396
|
+
it("the same release as install.json names still hands over: the records may be stale", async () => {
|
|
1397
|
+
const { deps, order } = setup({ ...STAGE1, meta: { ...META, releaseVersion: "0.11.0" } });
|
|
1398
|
+
await runUpgraderJob(deps);
|
|
1399
|
+
expect(order).toContain("start job");
|
|
1400
|
+
});
|
|
1401
|
+
|
|
1402
|
+
it("a job left ahead of the install by a failed update still moves to the target", async () => {
|
|
1403
|
+
const { deps, order } = setup({ ...STAGE1, ownVersion: "0.12.0" });
|
|
1404
|
+
await runUpgraderJob(deps);
|
|
1405
|
+
expect(order).toContain(`point job at ${D("c")}`);
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
it("the state lock held: nothing moves, and it says so", async () => {
|
|
1409
|
+
const { deps, order, q } = setup({ ...STAGE1, locked: true });
|
|
1410
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "failed" });
|
|
1411
|
+
expect(q.end()?.codes).toEqual(["state-locked"]);
|
|
1412
|
+
expect(order.some((l) => l.startsWith("point job"))).toBe(false);
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
it("a job that cannot be moved fails the request, and releases the lock", async () => {
|
|
1416
|
+
const { deps, order, q } = setup({ ...STAGE1, pointError: "denied" });
|
|
1417
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "failed" });
|
|
1418
|
+
expect(q.end()?.codes).toEqual(["handover"]);
|
|
1419
|
+
expect(order).toContain("unlock");
|
|
1420
|
+
expect(q.handovers).toEqual([]);
|
|
1421
|
+
});
|
|
1422
|
+
|
|
1423
|
+
it("a stage 2 that cannot be started fails the request; nothing on the site changed", async () => {
|
|
1424
|
+
const { deps, q } = setup({ ...STAGE1, startError: "quota" });
|
|
1425
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "failed" });
|
|
1426
|
+
expect(q.end()?.codes).toEqual(["handover"]);
|
|
1427
|
+
// The job already moved, so "nothing was changed" would not be true.
|
|
1428
|
+
expect(q.end()?.reason).toContain("Nothing on the site was changed");
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
it("a job update that throws still releases the lock", async () => {
|
|
1432
|
+
const { deps, order, q } = setup(STAGE1);
|
|
1433
|
+
const r = await runUpgraderJob({
|
|
1434
|
+
...deps,
|
|
1435
|
+
pointJobAt: async () => {
|
|
1436
|
+
throw new Error("gcloud vanished");
|
|
1437
|
+
},
|
|
1438
|
+
});
|
|
1439
|
+
expect(r).toMatchObject({ status: "failed" });
|
|
1440
|
+
expect(q.end()?.codes).toEqual(["internal"]);
|
|
1441
|
+
expect(order).toContain("unlock");
|
|
1442
|
+
});
|
|
1443
|
+
|
|
1444
|
+
it("a request that moved on before the release is left alone", async () => {
|
|
1445
|
+
const { deps, order, q } = setup(STAGE1);
|
|
1446
|
+
q.refuseHandover();
|
|
1447
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ exitCode: 0, status: null });
|
|
1448
|
+
expect(order).not.toContain("start job");
|
|
1449
|
+
expect(q.end()).toBeNull();
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
it("regression: a target image that reports another version cannot hand over for ever", async () => {
|
|
1453
|
+
const { deps, order, q } = setup({ ownVersion: "0.10.45", ownDigest: D("c") });
|
|
1454
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1455
|
+
expect(q.end()?.codes).toEqual(["ops-image"]);
|
|
1456
|
+
expect(order).not.toContain("start job");
|
|
1457
|
+
});
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1460
|
+
describe("runUpgraderJob — stage 2 (#1029: the target's own image)", () => {
|
|
1461
|
+
it("takes over the request stage 1 released, then runs the whole update", async () => {
|
|
1462
|
+
const { deps, order, q } = setup({ claim: { resume: true, execution: null } });
|
|
1463
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "succeeded" });
|
|
1464
|
+
// Nobody was named, so there is no run to wait for.
|
|
1465
|
+
expect(order.some((l) => l.startsWith("state of"))).toBe(false);
|
|
1466
|
+
expect(q.handovers).toEqual([{ from: null, to: "caelo-production-upgrader-x1" }]);
|
|
1467
|
+
expect(q.events.some((e) => e.message.includes("own upgrader took over"))).toBe(true);
|
|
1468
|
+
expect(order.some((l) => /sql backups create/.test(l))).toBe(true);
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
it("stage 1 → hand-over → stage 2, end to end over one request", async () => {
|
|
1472
|
+
let claim: JobClaim | null = null;
|
|
1473
|
+
const first = setup({ ownVersion: "0.10.45", ownDigest: D("e") });
|
|
1474
|
+
const request = (await first.deps.queue.claimUpgrade("caelo-production-upgrader-x1"))?.request;
|
|
1475
|
+
const stage1 = await runUpgraderJob({
|
|
1476
|
+
...first.deps,
|
|
1477
|
+
startJob: async () => {
|
|
1478
|
+
claim = { request: request as ClaimedUpdate, resume: true, execution: null };
|
|
1479
|
+
return { ok: true, execution: "caelo-production-upgrader-x2" };
|
|
1480
|
+
},
|
|
1481
|
+
});
|
|
1482
|
+
expect(stage1.status).toBeNull();
|
|
1483
|
+
expect(claim).not.toBeNull();
|
|
1484
|
+
|
|
1485
|
+
const second = setup({ claim: claim as unknown as JobClaim });
|
|
1486
|
+
const stage2 = await runUpgraderJob({
|
|
1487
|
+
...second.deps,
|
|
1488
|
+
execution: "caelo-production-upgrader-x2",
|
|
1489
|
+
});
|
|
1490
|
+
expect(stage2.status).toBe("succeeded");
|
|
1491
|
+
expect(second.q.end()?.status).toBe("succeeded");
|
|
1492
|
+
expect(second.written.at(-1)).toMatchObject({ releaseVersion: "0.11.0" });
|
|
1493
|
+
});
|
|
1494
|
+
|
|
1495
|
+
it("adversarial: an image the manifest does not sign changes nothing", async () => {
|
|
1496
|
+
const { deps, order, q, written } = setup({ ownDigest: D("9") });
|
|
1497
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1498
|
+
expect(q.end()?.codes).toEqual(["ops-image"]);
|
|
1499
|
+
expect(order.some((l) => /sql backups create|services update|^migrate|^lock/.test(l))).toBe(
|
|
1500
|
+
false,
|
|
1501
|
+
);
|
|
1502
|
+
expect(written).toEqual([]);
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1505
|
+
it("an unreadable own image is refused, never assumed right", async () => {
|
|
1506
|
+
const { deps, q } = setup({ ownDigest: null });
|
|
1507
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1508
|
+
expect(q.end()?.codes).toEqual(["ops-image"]);
|
|
1509
|
+
});
|
|
1510
|
+
|
|
1511
|
+
it("the platform form of the image, which Cloud Run records, is the signed image (#1025)", async () => {
|
|
1512
|
+
const { deps } = setup({
|
|
1513
|
+
ownDigest: P("c"),
|
|
1514
|
+
manifest: {
|
|
1515
|
+
ok: true,
|
|
1516
|
+
manifest: {
|
|
1517
|
+
...MANIFEST,
|
|
1518
|
+
platformDigests: { admin: P("a"), gateway: P("b"), ops: P("c") },
|
|
1519
|
+
},
|
|
1520
|
+
},
|
|
1521
|
+
});
|
|
1522
|
+
expect((await runUpgraderJob(deps)).status).toBe("succeeded");
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
it("the policy is judged again here, from the policy this claim read", async () => {
|
|
1526
|
+
const { deps, q } = setup({ request: { trigger: "auto" } });
|
|
1527
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "refused" });
|
|
1528
|
+
expect(q.end()?.codes).toEqual(["policy"]);
|
|
1529
|
+
});
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
describe("runUpgraderJob — a run that died (#1029)", () => {
|
|
1533
|
+
const dead = { resume: true, execution: "caelo-production-upgrader-x0" };
|
|
1534
|
+
|
|
1535
|
+
it("waits while the named run lives; two runs at once never happen", async () => {
|
|
1536
|
+
const { deps, order, q } = setup({ claim: dead, executionState: "running" });
|
|
1537
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ exitCode: 0, status: null });
|
|
1538
|
+
expect(q.handovers).toEqual([]);
|
|
1539
|
+
expect(q.end()).toBeNull();
|
|
1540
|
+
expect(order.some((l) => /sql backups create/.test(l))).toBe(false);
|
|
1541
|
+
});
|
|
1542
|
+
|
|
1543
|
+
it("regression: Cloud Run not answering never ends a run that may be alive", async () => {
|
|
1544
|
+
const { deps, order, q } = setup({ claim: dead, executionState: "unreadable" });
|
|
1545
|
+
expect(await runUpgraderJob(deps)).toEqual({
|
|
1546
|
+
exitCode: 1,
|
|
1547
|
+
requestId: "req-1",
|
|
1548
|
+
status: null,
|
|
1549
|
+
});
|
|
1550
|
+
expect(q.end()).toBeNull();
|
|
1551
|
+
expect(q.handovers).toEqual([]);
|
|
1552
|
+
expect(order.some((l) => /run services/.test(l))).toBe(false);
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
it("adopts the request once Cloud Run says that run ended, and starts over from its checks", async () => {
|
|
1556
|
+
const { deps, q } = setup({ claim: dead });
|
|
1557
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ status: "succeeded" });
|
|
1558
|
+
expect(q.handovers).toEqual([
|
|
1559
|
+
{ from: "caelo-production-upgrader-x0", to: "caelo-production-upgrader-x1" },
|
|
1560
|
+
]);
|
|
1561
|
+
expect(q.events.some((e) => e.message.startsWith("Continuing the update"))).toBe(true);
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
it("a stage 1 that died before it moved the job is continued by an earlier-release run", async () => {
|
|
1565
|
+
const { deps, order } = setup({ claim: dead, ownVersion: "0.10.45", ownDigest: D("e") });
|
|
1566
|
+
await runUpgraderJob(deps);
|
|
1567
|
+
expect(order).toContain("start job");
|
|
1568
|
+
});
|
|
1569
|
+
|
|
1570
|
+
it("two adopters: the loser does nothing", async () => {
|
|
1571
|
+
const { deps, order, q } = setup({ claim: dead });
|
|
1572
|
+
q.refuseHandover();
|
|
1573
|
+
expect(await runUpgraderJob(deps)).toMatchObject({ exitCode: 0, status: null });
|
|
1574
|
+
expect(order.some((l) => /run services/.test(l))).toBe(false);
|
|
1575
|
+
expect(q.end()).toBeNull();
|
|
1576
|
+
});
|
|
1577
|
+
|
|
1578
|
+
it("outside Cloud Run a running request is never adopted", async () => {
|
|
1579
|
+
const { deps, q } = setup({ claim: { resume: true, execution: null } });
|
|
1580
|
+
const r = await runUpgraderJob({ ...deps, execution: null });
|
|
1581
|
+
expect(r).toMatchObject({ exitCode: 0, status: null });
|
|
1582
|
+
expect(q.handovers).toEqual([]);
|
|
1583
|
+
});
|
|
1584
|
+
});
|