hammerkit 2.1.0-next.9 → 2.2.0-next.1
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/dashboard/assets/{graph-canvas-BFnEN5i0.js → graph-canvas-D6GMgkoe.js} +1 -1
- package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
- package/dist/dashboard/assets/{index-Dt3ITvRO.css → index-DP3_hKOe.css} +1 -1
- package/dist/dashboard/index.html +2 -2
- package/dist/executer/archive-task-entry.js +1 -1
- package/dist/executer/deadline.js +63 -10
- package/dist/executer/event-cache.js +5 -1
- package/dist/executer/execute-work-task.js +15 -3
- package/dist/executer/runner-commands.js +36 -0
- package/dist/file/get-file-context.js +4 -7
- package/dist/harness/connect.js +12 -8
- package/dist/harness/reconnect.js +141 -0
- package/dist/harness/sandbox-client.js +242 -33
- package/dist/harness/service-tools.js +36 -3
- package/dist/kubernetes/cluster-state.js +48 -14
- package/dist/kubernetes/ensure-persistent-data.js +15 -4
- package/dist/kubernetes/follow-pod-logs.js +8 -5
- package/dist/kubernetes/kept-claims.js +26 -5
- package/dist/kubernetes/resources.js +5 -1
- package/dist/kubernetes/sandbox-runner.js +526 -156
- package/dist/kubernetes/store-kubernetes-data.js +18 -3
- package/dist/kubernetes/sync-changes.js +463 -0
- package/dist/kubernetes/volumes.js +23 -1
- package/dist/optimizer/get-work-cache-stats.js +7 -0
- package/dist/planner/work-item-status.js +12 -2
- package/dist/planner/work-runtime-aggregate.js +1 -0
- package/dist/planner/work-runtime-docker.js +9 -5
- package/dist/planner/work-runtime-kubernetes.js +277 -55
- package/dist/planner/work-runtime-local.js +8 -4
- package/dist/remote/annotations.js +29 -3
- package/dist/remote/bundle.js +6 -8
- package/dist/remote/collect-bundle.js +3 -2
- package/dist/remote/device-login.js +4 -1
- package/dist/remote/remote-commands.js +16 -7
- package/dist/remote/remote-work-commands.js +265 -72
- package/dist/remote/server-client.js +38 -40
- package/dist/server/artifacts-api.js +56 -0
- package/dist/server/definitions-api.js +62 -8
- package/dist/server/endpoints.js +52 -32
- package/dist/server/executor.js +117 -30
- package/dist/server/http.js +4 -1
- package/dist/server/keep-artifacts.js +230 -0
- package/dist/server/kubernetes-backend.js +186 -59
- package/dist/server/kubernetes-sandbox-storage.js +83 -22
- package/dist/server/overview.js +67 -9
- package/dist/server/paging.js +167 -0
- package/dist/server/plan.js +8 -1
- package/dist/server/public-paths.js +52 -0
- package/dist/server/run-access.js +24 -0
- package/dist/server/run-artifacts.js +171 -0
- package/dist/server/run-logs.js +25 -1
- package/dist/server/run-request.js +63 -1
- package/dist/server/run-retry.js +6 -0
- package/dist/server/run-worker.js +267 -33
- package/dist/server/runs.js +527 -99
- package/dist/server/sandbox-files.js +9 -8
- package/dist/server/sandbox-follow.js +54 -0
- package/dist/server/sandbox-storage.js +38 -1
- package/dist/server/sandbox-sync.js +392 -0
- package/dist/server/sandboxes-api.js +54 -8
- package/dist/server/sandboxes.js +19 -0
- package/dist/server/server-config.js +14 -0
- package/dist/server/server.js +189 -46
- package/dist/server/service-runs.js +41 -8
- package/dist/server/task-order.js +56 -0
- package/dist/utils/project-path.js +20 -0
- package/dist/utils/tar-files.js +52 -0
- package/dist/utils/tar.js +37 -1
- package/package.json +1 -1
- package/dist/dashboard/assets/index-CE5PSB3y.js +0 -23
|
@@ -15,10 +15,13 @@ const log_1 = require("../log");
|
|
|
15
15
|
const network_policy_1 = require("../kubernetes/network-policy");
|
|
16
16
|
const network_gate_1 = require("../kubernetes/network-gate");
|
|
17
17
|
const sleep_1 = require("../utils/sleep");
|
|
18
|
+
const kubernetes_sandbox_storage_1 = require("./kubernetes-sandbox-storage");
|
|
19
|
+
const sandbox_runner_1 = require("../kubernetes/sandbox-runner");
|
|
18
20
|
const version_1 = require("../version");
|
|
19
21
|
const executor_1 = require("./executor");
|
|
20
22
|
const kept_claims_1 = require("../kubernetes/kept-claims");
|
|
21
23
|
const units_1 = require("../utils/units");
|
|
24
|
+
const runs_1 = require("./runs");
|
|
22
25
|
const server_config_1 = require("./server-config");
|
|
23
26
|
// the name of the quota and limit range the server keeps in a caller's namespace
|
|
24
27
|
const POLICY_NAME = 'hammerkit';
|
|
@@ -270,8 +273,11 @@ class KubernetesExecutor {
|
|
|
270
273
|
// per caller namespace, what changes objects of the whole namespace: its setup, the
|
|
271
274
|
// removal of what a stopped server left, the sweeps of kept claims. The last one waiting.
|
|
272
275
|
this.queues = new Map();
|
|
273
|
-
// per caller namespace, the runs that execute in it
|
|
274
|
-
//
|
|
276
|
+
// per caller namespace, the runs that execute in it: by run label, the volume scope of the
|
|
277
|
+
// kept claims they mount, if any. Every run that executes is here, not only those that mount
|
|
278
|
+
// kept claims: a tidy of the namespace (after a release that failed, or the first after a
|
|
279
|
+
// restart) leaves the objects of all of them, a resumed run's too once it no longer counts
|
|
280
|
+
// as resuming
|
|
275
281
|
this.active = new Map();
|
|
276
282
|
// per caller namespace, when its kept claims are next looked at
|
|
277
283
|
this.sweeps = new Map();
|
|
@@ -285,6 +291,9 @@ class KubernetesExecutor {
|
|
|
285
291
|
this.serviceRuns = new Map();
|
|
286
292
|
this.serviceRunsSwept = false;
|
|
287
293
|
this.asleep = new Set();
|
|
294
|
+
// the runs whose execution got its place on the cluster, until it ended: their release
|
|
295
|
+
// removes what they made
|
|
296
|
+
this.placed = new Set();
|
|
288
297
|
this.access = getClusterAccess(config.backend, processEnvs);
|
|
289
298
|
this.instance = (0, kubernetes_instance_1.createKubernetesInstances)({
|
|
290
299
|
type: 'kubernetes',
|
|
@@ -316,6 +325,7 @@ class KubernetesExecutor {
|
|
|
316
325
|
log: options.log,
|
|
317
326
|
});
|
|
318
327
|
}
|
|
328
|
+
this.resuming = new ResumingRuns(config.backend.namespacePrefix, (run) => this.namespaceOf(run));
|
|
319
329
|
this.host = new executor_1.HostExecutor({ ...options, placement: this.placement() });
|
|
320
330
|
}
|
|
321
331
|
// what the namespaces of the server's callers and service runs request and use
|
|
@@ -345,13 +355,61 @@ class KubernetesExecutor {
|
|
|
345
355
|
});
|
|
346
356
|
}
|
|
347
357
|
async execute(run, context) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
358
|
+
// what a run that resumes left is this execution's from now: the end of a run that got its
|
|
359
|
+
// place on the cluster (release) removes it, the end of one that did not removes it here
|
|
360
|
+
const left = this.resuming.has(run);
|
|
361
|
+
try {
|
|
362
|
+
await this.executeOn(run, context);
|
|
363
|
+
}
|
|
364
|
+
finally {
|
|
365
|
+
const placed = this.placed.delete(run.id);
|
|
366
|
+
if (left && !placed && !(0, runs_1.isDetached)(context)) {
|
|
367
|
+
// the run executed: its process removed its commands when it ended
|
|
368
|
+
await this.removeLeft(run, false);
|
|
351
369
|
}
|
|
352
|
-
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// What a run left on the cluster, that no release removes
|
|
373
|
+
async removeLeft(run, commands = true) {
|
|
374
|
+
const say = (text) => this.log?.(`run=${run.id} ${text}`);
|
|
375
|
+
this.resuming.forget(run);
|
|
376
|
+
try {
|
|
377
|
+
if (!run.up) {
|
|
378
|
+
const namespace = getCallerNamespace(this.config.backend.namespacePrefix, run.owner);
|
|
379
|
+
if (commands) {
|
|
380
|
+
await this.removeRunCommands(run, namespace, say);
|
|
381
|
+
}
|
|
382
|
+
await this.removeRun(run, namespace, say);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
// a namespace is kept only for a run that has one from start to end
|
|
386
|
+
const namespace = this.namespaceOf(run);
|
|
387
|
+
this.asleep.delete(namespace);
|
|
388
|
+
await this.enqueue(namespace, () => this.removeServiceRun(namespace, say));
|
|
389
|
+
}
|
|
390
|
+
catch (e) {
|
|
391
|
+
say(`what the run left could not be removed: ${(0, log_1.getErrorMessage)(e)}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
// What the commands of a run on a sandbox left in its runner: they ran on over the restart
|
|
395
|
+
// for the run to take them up again, which it no longer does. Another run may be on the
|
|
396
|
+
// sandbox by now, so only the run's own commands are killed.
|
|
397
|
+
async removeRunCommands(run, namespace, say) {
|
|
398
|
+
if (run.source.type !== 'sandbox' || !this.config.backend.sandboxes.runner) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
await (0, sandbox_runner_1.removeRunCommands)(this.instance, namespace, (0, kubernetes_sandbox_storage_1.getSandboxNames)(run.source.id).label, run.id, {
|
|
402
|
+
clean: false,
|
|
403
|
+
}).catch((e) => say(`what the commands of the run left in the sandbox could not be removed: ${(0, log_1.getErrorMessage)(e)}`));
|
|
404
|
+
}
|
|
405
|
+
async executeOn(run, context) {
|
|
406
|
+
if (run.up) {
|
|
407
|
+
// in a namespace of its own, apart from the caller's runs and their claims, from a branch
|
|
408
|
+
// or from the files of a sandbox (copied, see HostExecutor.execute)
|
|
353
409
|
return this.host.execute(run, context);
|
|
354
410
|
}
|
|
411
|
+
// it executes: its objects are kept from a tidy as those of any run that executes
|
|
412
|
+
this.resuming.forget(run);
|
|
355
413
|
const namespace = getCallerNamespace(this.config.backend.namespacePrefix, run.owner);
|
|
356
414
|
const label = (0, job_placement_1.getRunLabelValue)(run.id);
|
|
357
415
|
let runs = this.active.get(namespace);
|
|
@@ -359,9 +417,7 @@ class KubernetesExecutor {
|
|
|
359
417
|
runs = new Map();
|
|
360
418
|
this.active.set(namespace, runs);
|
|
361
419
|
}
|
|
362
|
-
|
|
363
|
-
runs.set(label, getVolumeScope(run));
|
|
364
|
-
}
|
|
420
|
+
runs.set(label, this.holds(run) ? getVolumeScope(run) : undefined);
|
|
365
421
|
// the caller is promised its share while the run executes
|
|
366
422
|
this.quotas?.enter(namespace, run.id);
|
|
367
423
|
try {
|
|
@@ -372,11 +428,19 @@ class KubernetesExecutor {
|
|
|
372
428
|
if (runs.size === 0 && this.active.get(namespace) === runs) {
|
|
373
429
|
this.active.delete(namespace);
|
|
374
430
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
431
|
+
// a run the next server resumes still has its Jobs, under the quota it had
|
|
432
|
+
if (!(0, runs_1.isDetached)(context)) {
|
|
433
|
+
await this.quotas
|
|
434
|
+
?.leave(namespace, run.id)
|
|
435
|
+
.catch((e) => this.log?.(`the quotas could not be worked out again: ${(0, log_1.getErrorMessage)(e)}`));
|
|
436
|
+
}
|
|
378
437
|
}
|
|
379
438
|
}
|
|
439
|
+
// The changed files of a sandbox for the services of a service run here: they are synced in
|
|
440
|
+
// place, nothing of the run moves (see RunExecutor.syncFiles)
|
|
441
|
+
syncFiles(run, changes) {
|
|
442
|
+
return !!run.up && this.host.syncChildFiles(run.id, changes);
|
|
443
|
+
}
|
|
380
444
|
// A service run moves to another commit in its namespace: unchanged services stay, the
|
|
381
445
|
// others roll to their new pods (see kubernetesServiceRuntime)
|
|
382
446
|
movesBeside(run) {
|
|
@@ -390,25 +454,32 @@ class KubernetesExecutor {
|
|
|
390
454
|
}
|
|
391
455
|
/**
|
|
392
456
|
* A service run that slept with its volumes ended without waking: its namespace goes, with
|
|
393
|
-
* the claims in it.
|
|
457
|
+
* the claims in it. A run that resumed after a restart ended: what an execution before the
|
|
458
|
+
* restart left goes, as no execution may have removed it (one cancelled in the queue).
|
|
394
459
|
*/
|
|
395
460
|
async forget(run) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
// a namespace is kept only for a run that has one from start to end
|
|
400
|
-
const namespace = getServiceRunNamespace(this.config.backend.namespacePrefix, run.id);
|
|
401
|
-
this.asleep.delete(namespace);
|
|
402
|
-
await this.enqueue(namespace, () => this.removeServiceRun(namespace, (text) => this.log?.(`run=${run.id} ${text}`)));
|
|
461
|
+
// the commands of a run are left only when it was restored and never executed again
|
|
462
|
+
await this.removeLeft(run, this.resuming.has(run));
|
|
403
463
|
}
|
|
404
464
|
/**
|
|
405
|
-
* The
|
|
406
|
-
* without what runs in them (a server that stopped without
|
|
407
|
-
* it)
|
|
465
|
+
* The runs of a previous start that are not over: the service runs that sleep with their
|
|
466
|
+
* volumes, whose namespaces stay without what runs in them (a server that stopped without
|
|
467
|
+
* putting the run to sleep left it), and the runs that resume (queued), whose Jobs and
|
|
468
|
+
* services stay where they are until they execute again or end. The namespaces of any other
|
|
469
|
+
* service run go.
|
|
408
470
|
*/
|
|
409
471
|
restored(runs) {
|
|
472
|
+
for (const run of runs.filter((candidate) => candidate.state === 'queued')) {
|
|
473
|
+
try {
|
|
474
|
+
this.resuming.add(run, this.holds(run) ? getVolumeScope(run) : undefined);
|
|
475
|
+
}
|
|
476
|
+
catch (e) {
|
|
477
|
+
// its objects are not kept from a sweep, the run does not start for nothing
|
|
478
|
+
this.log?.(`what run ${run.id} left on the cluster is not kept for it: ${(0, log_1.getErrorMessage)(e)}`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
410
481
|
if (this.keepServiceRuns) {
|
|
411
|
-
for (const run of runs.filter((candidate) => candidate.up)) {
|
|
482
|
+
for (const run of runs.filter((candidate) => candidate.up && candidate.state !== 'queued')) {
|
|
412
483
|
const namespace = getServiceRunNamespace(this.config.backend.namespacePrefix, run.id);
|
|
413
484
|
this.asleep.add(namespace);
|
|
414
485
|
this.enqueue(namespace, () => removeRunObjects(this.instance, namespace, job_placement_1.RUN_LABEL, RELEASE_TIMEOUT, { claims: false })).catch((e) => this.log?.(`what runs in the namespace ${namespace} of run ${run.id} could not be removed: ${(0, log_1.getErrorMessage)(e)}`));
|
|
@@ -479,8 +550,12 @@ class KubernetesExecutor {
|
|
|
479
550
|
if (this.keep === 0) {
|
|
480
551
|
return new Set();
|
|
481
552
|
}
|
|
482
|
-
return new Set([
|
|
483
|
-
.
|
|
553
|
+
return new Set([
|
|
554
|
+
...(this.active.get(namespace) ?? new Map()).entries(),
|
|
555
|
+
// a run that resumes mounts them again
|
|
556
|
+
...this.resuming.scopes(namespace),
|
|
557
|
+
]
|
|
558
|
+
.filter(([label, scope]) => label !== except && scope !== undefined)
|
|
484
559
|
.map(([, scope]) => scope));
|
|
485
560
|
}
|
|
486
561
|
// What changes objects of a whole namespace happens one at a time, not what its runs do
|
|
@@ -506,6 +581,9 @@ class KubernetesExecutor {
|
|
|
506
581
|
}
|
|
507
582
|
this.serviceRuns.set(namespace, (this.serviceRuns.get(namespace) ?? 0) + 1);
|
|
508
583
|
this.asleep.delete(namespace);
|
|
584
|
+
// its execution holds the namespace now, and its release removes it
|
|
585
|
+
this.resuming.forget(run);
|
|
586
|
+
this.placed.add(run.id);
|
|
509
587
|
this.sweepServiceRuns();
|
|
510
588
|
const up = run.up;
|
|
511
589
|
// after what a stop of its sleep left in it went (see restored)
|
|
@@ -524,7 +602,7 @@ class KubernetesExecutor {
|
|
|
524
602
|
// its pods take room the callers can't borrow
|
|
525
603
|
await this.quotas?.serviceRun(namespace, this.config.runs.up.quota ?? this.config.backend.quota);
|
|
526
604
|
context.emit({ type: 'log', task: 'hammerkit', stream: 'stdout', text: `runs in the namespace ${namespace}` });
|
|
527
|
-
return { kubernetes: this.environmentOf(run, namespace), env: this.access.env };
|
|
605
|
+
return { kubernetes: this.environmentOf(run, namespace, context), env: this.access.env };
|
|
528
606
|
}
|
|
529
607
|
const label = (0, job_placement_1.getRunLabelValue)(run.id);
|
|
530
608
|
let capabilitiesProblem;
|
|
@@ -537,7 +615,9 @@ class KubernetesExecutor {
|
|
|
537
615
|
// release failed: the objects of a run that does not execute. One that starts
|
|
538
616
|
// after this waits for it here before it makes any.
|
|
539
617
|
if (!this.tidy.has(namespace)) {
|
|
540
|
-
const running = [
|
|
618
|
+
const running = [
|
|
619
|
+
...new Set([label, ...(this.active.get(namespace)?.keys() ?? []), ...this.resuming.labels(namespace)]),
|
|
620
|
+
];
|
|
541
621
|
await removeRunObjects(this.instance, namespace, `${job_placement_1.RUN_LABEL},${job_placement_1.RUN_LABEL} notin (${running.join(',')})`, RELEASE_TIMEOUT);
|
|
542
622
|
this.tidy.add(namespace);
|
|
543
623
|
}
|
|
@@ -557,8 +637,9 @@ class KubernetesExecutor {
|
|
|
557
637
|
// tasks run
|
|
558
638
|
await this.quotas?.apply(namespace);
|
|
559
639
|
context.emit({ type: 'log', task: 'hammerkit', stream: 'stdout', text: `runs in the namespace ${namespace}` });
|
|
640
|
+
this.placed.add(run.id);
|
|
560
641
|
return {
|
|
561
|
-
kubernetes: this.environmentOf(run, namespace, work, capabilitiesProblem),
|
|
642
|
+
kubernetes: this.environmentOf(run, namespace, context, work, capabilitiesProblem),
|
|
562
643
|
env: this.access.env,
|
|
563
644
|
};
|
|
564
645
|
},
|
|
@@ -599,40 +680,35 @@ class KubernetesExecutor {
|
|
|
599
680
|
}
|
|
600
681
|
return;
|
|
601
682
|
}
|
|
602
|
-
|
|
603
|
-
const selector = `${job_placement_1.RUN_LABEL}=${(0, job_placement_1.getRunLabelValue)(run.id)}`;
|
|
604
|
-
await removeRunObjects(this.instance, namespace, selector, RELEASE_TIMEOUT);
|
|
605
|
-
}
|
|
606
|
-
catch (e) {
|
|
607
|
-
// the next run removes what is left
|
|
608
|
-
this.tidy.delete(namespace);
|
|
609
|
-
context.emit({
|
|
610
|
-
type: 'log',
|
|
611
|
-
task: 'hammerkit',
|
|
612
|
-
stream: 'stderr',
|
|
613
|
-
text: `what the run made in ${namespace} could not be removed: ${(0, log_1.getErrorMessage)(e)}`,
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
if (this.keep > 0) {
|
|
617
|
-
try {
|
|
618
|
-
await (0, kept_claims_1.expireKeptClaims)(this.instance, namespace, (0, job_placement_1.getRunLabelValue)(run.id), new Date(Date.now() + this.keep));
|
|
619
|
-
}
|
|
620
|
-
catch (e) {
|
|
621
|
-
// without an expiry, the next look at the namespace removes them
|
|
622
|
-
context.emit({
|
|
623
|
-
type: 'log',
|
|
624
|
-
task: 'hammerkit',
|
|
625
|
-
stream: 'stderr',
|
|
626
|
-
text: `the claims the run kept in ${namespace} could not be given their expiry: ${(0, log_1.getErrorMessage)(e)}`,
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
this.sweepLater(namespace, this.keep);
|
|
630
|
-
}
|
|
683
|
+
await this.removeRun(run, namespace, (text) => context.emit({ type: 'log', task: 'hammerkit', stream: 'stderr', text }));
|
|
631
684
|
},
|
|
632
685
|
};
|
|
633
686
|
}
|
|
687
|
+
// The end of a run of tasks: what it made in the caller's namespace goes, but for the claims
|
|
688
|
+
// it keeps, which expire from now
|
|
689
|
+
async removeRun(run, namespace, say) {
|
|
690
|
+
try {
|
|
691
|
+
const selector = `${job_placement_1.RUN_LABEL}=${(0, job_placement_1.getRunLabelValue)(run.id)}`;
|
|
692
|
+
await removeRunObjects(this.instance, namespace, selector, RELEASE_TIMEOUT);
|
|
693
|
+
}
|
|
694
|
+
catch (e) {
|
|
695
|
+
// the next run removes what is left
|
|
696
|
+
this.tidy.delete(namespace);
|
|
697
|
+
say(`what the run made in ${namespace} could not be removed: ${(0, log_1.getErrorMessage)(e)}`);
|
|
698
|
+
}
|
|
699
|
+
if (this.keep > 0) {
|
|
700
|
+
try {
|
|
701
|
+
await (0, kept_claims_1.expireKeptClaims)(this.instance, namespace, (0, job_placement_1.getRunLabelValue)(run.id), new Date(Date.now() + this.keep));
|
|
702
|
+
}
|
|
703
|
+
catch (e) {
|
|
704
|
+
// without an expiry, the next look at the namespace removes them
|
|
705
|
+
say(`the claims the run kept in ${namespace} could not be given their expiry: ${(0, log_1.getErrorMessage)(e)}`);
|
|
706
|
+
}
|
|
707
|
+
this.sweepLater(namespace, this.keep);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
634
710
|
// The cluster as the process of a run sees it: the namespace its tasks and services go in.
|
|
635
|
-
environmentOf(run, namespace, work, capabilitiesProblem) {
|
|
711
|
+
environmentOf(run, namespace, context, work, capabilitiesProblem) {
|
|
636
712
|
const backend = this.config.backend;
|
|
637
713
|
const openGate = (0, network_gate_1.getOpenNetworkGate)(backend);
|
|
638
714
|
return {
|
|
@@ -656,6 +732,8 @@ class KubernetesExecutor {
|
|
|
656
732
|
...(this.keep > 0 && !run.up ? { volumeScope: getVolumeScope(run) } : {}),
|
|
657
733
|
...(run.up ? { serviceRun: true } : {}),
|
|
658
734
|
...(openGate ? { openGate } : {}),
|
|
735
|
+
// what the execution before a restart left, its tasks and services take over
|
|
736
|
+
...(context.resumed ? { resumed: { logs: context.resumed.logs } } : {}),
|
|
659
737
|
...(backend.capabilities
|
|
660
738
|
? {
|
|
661
739
|
capabilities: {
|
|
@@ -686,6 +764,7 @@ class KubernetesExecutor {
|
|
|
686
764
|
isCallerNamespace(this.config.backend.namespacePrefix, name) &&
|
|
687
765
|
!this.serviceRuns.has(name) &&
|
|
688
766
|
!this.asleep.has(name) &&
|
|
767
|
+
!this.resuming.keeps(name) &&
|
|
689
768
|
!namespace.metadata?.deletionTimestamp) {
|
|
690
769
|
this.log?.(`removing the namespace ${name} of a service run from before the server started`);
|
|
691
770
|
await removeServiceRunNamespace(this.instance, name, 0);
|
|
@@ -747,6 +826,54 @@ class KubernetesExecutor {
|
|
|
747
826
|
}
|
|
748
827
|
}
|
|
749
828
|
exports.KubernetesExecutor = KubernetesExecutor;
|
|
829
|
+
// What the runs that resume after a restart left on the cluster, which the sweeps leave: the
|
|
830
|
+
// namespaces of service runs, and per caller namespace the runs by run label, with the volume
|
|
831
|
+
// scope of the kept claims they mount
|
|
832
|
+
class ResumingRuns {
|
|
833
|
+
constructor(prefix, namespaceOf) {
|
|
834
|
+
this.prefix = prefix;
|
|
835
|
+
this.namespaceOf = namespaceOf;
|
|
836
|
+
this.serviceRuns = new Set();
|
|
837
|
+
this.runs = new Map();
|
|
838
|
+
}
|
|
839
|
+
add(run, scope) {
|
|
840
|
+
if (run.up) {
|
|
841
|
+
this.serviceRuns.add(this.namespaceOf(run));
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const namespace = getCallerNamespace(this.prefix, run.owner);
|
|
845
|
+
const runs = this.runs.get(namespace) ?? new Map();
|
|
846
|
+
runs.set((0, job_placement_1.getRunLabelValue)(run.id), scope);
|
|
847
|
+
this.runs.set(namespace, runs);
|
|
848
|
+
}
|
|
849
|
+
has(run) {
|
|
850
|
+
return run.up
|
|
851
|
+
? this.serviceRuns.has(this.namespaceOf(run))
|
|
852
|
+
: !!this.runs.get(getCallerNamespace(this.prefix, run.owner))?.has((0, job_placement_1.getRunLabelValue)(run.id));
|
|
853
|
+
}
|
|
854
|
+
forget(run) {
|
|
855
|
+
if (run.up) {
|
|
856
|
+
this.serviceRuns.delete(this.namespaceOf(run));
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
const namespace = getCallerNamespace(this.prefix, run.owner);
|
|
860
|
+
const runs = this.runs.get(namespace);
|
|
861
|
+
runs?.delete((0, job_placement_1.getRunLabelValue)(run.id));
|
|
862
|
+
if (runs?.size === 0) {
|
|
863
|
+
this.runs.delete(namespace);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
// whether the namespace of a service run is kept for it
|
|
867
|
+
keeps(namespace) {
|
|
868
|
+
return this.serviceRuns.has(namespace);
|
|
869
|
+
}
|
|
870
|
+
labels(namespace) {
|
|
871
|
+
return [...(this.runs.get(namespace)?.keys() ?? [])];
|
|
872
|
+
}
|
|
873
|
+
scopes(namespace) {
|
|
874
|
+
return [...(this.runs.get(namespace)?.entries() ?? [])];
|
|
875
|
+
}
|
|
876
|
+
}
|
|
750
877
|
const ENFORCE_LABEL = 'pod-security.kubernetes.io/enforce';
|
|
751
878
|
const AUDIT_LABEL = 'pod-security.kubernetes.io/audit';
|
|
752
879
|
/**
|
|
@@ -55,6 +55,8 @@ const UNSCHEDULABLE_MS = 10000;
|
|
|
55
55
|
// how long a pod may take to start, its image pull included
|
|
56
56
|
const POD_START_MS = 5 * 60 * 1000;
|
|
57
57
|
const REQUEST_TIMEOUT_MS = 5 * 60 * 1000;
|
|
58
|
+
// how long a pod of the files may take to be deleted, before the requests that wait for it go on
|
|
59
|
+
const POD_REMOVE_MS = 2 * 60 * 1000;
|
|
58
60
|
const FETCH_TIMEOUT_MS = 10 * 60 * 1000;
|
|
59
61
|
// an answer is read into memory up to this; a diff is up to 64 MiB, as JSON a bit more
|
|
60
62
|
const MAX_ANSWER_BYTES = 160 * 1024 * 1024;
|
|
@@ -110,6 +112,8 @@ class KubernetesSandboxStorage {
|
|
|
110
112
|
// one request at a time per sandbox, as a host has it: the objects `state` writes are
|
|
111
113
|
// pruned again in the pod, which must not meet another request that still needs them
|
|
112
114
|
this.queues = new Map();
|
|
115
|
+
// per sandbox, the pod that is being taken away: until it is gone no pod of the sandbox starts
|
|
116
|
+
this.leaving = new Map();
|
|
113
117
|
this.backend = config.backend;
|
|
114
118
|
const access = (0, kubernetes_backend_1.getClusterAccess)(config.backend, env);
|
|
115
119
|
this.instance =
|
|
@@ -311,7 +315,8 @@ class KubernetesSandboxStorage {
|
|
|
311
315
|
const names = getSandboxNames(key.id);
|
|
312
316
|
const namespace = this.namespaces.name(key.owner);
|
|
313
317
|
const pod = await this.usePod(key);
|
|
314
|
-
pod
|
|
318
|
+
// the pod counts this run only once the copy is over: until then the pod is a request
|
|
319
|
+
// under way, which a pod that makes way for another run waits for (makeWayForRun)
|
|
315
320
|
const leave = () => {
|
|
316
321
|
pod.runs--;
|
|
317
322
|
this.leavePod(key, pod);
|
|
@@ -325,12 +330,13 @@ class KubernetesSandboxStorage {
|
|
|
325
330
|
await (0, promises_1.mkdir)(into, { recursive: true });
|
|
326
331
|
await this.copyOut(key, ['tar', 'cf', '-', '-C', `${CLAIM_PATH}/${key.id}/files`, '.'], into,
|
|
327
332
|
// what the run plans with: files, directories and links, nothing outside of it
|
|
328
|
-
(_path, type) => ['File', 'OldFile', 'ContiguousFile', 'Directory', 'SymbolicLink'].includes(type), AbortSignal.timeout(FETCH_TIMEOUT_MS));
|
|
333
|
+
(_path, type) => ['File', 'OldFile', 'ContiguousFile', 'Directory', 'SymbolicLink'].includes(type), AbortSignal.timeout(FETCH_TIMEOUT_MS), pod);
|
|
329
334
|
}
|
|
330
335
|
catch (e) {
|
|
331
|
-
|
|
336
|
+
this.leavePod(key, pod);
|
|
332
337
|
throw e;
|
|
333
338
|
}
|
|
339
|
+
pod.runs++;
|
|
334
340
|
const watching = new AbortController();
|
|
335
341
|
void this.makeWayForRun(key, pod, watching.signal);
|
|
336
342
|
return {
|
|
@@ -376,16 +382,14 @@ class KubernetesSandboxStorage {
|
|
|
376
382
|
condition.reason === 'Unschedulable' &&
|
|
377
383
|
Date.now() - new Date(condition.lastTransitionTime ?? Date.now()).getTime() >= UNSCHEDULABLE_MS));
|
|
378
384
|
if (stuck && !signal.aborted && this.pods.get(key.id) === pod) {
|
|
379
|
-
// requests under way are answered first; the next one starts a pod next to the run's
|
|
380
|
-
this
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
pod.movedAside = true;
|
|
388
|
-
await this.deletePod(pod.namespace, pod.name, 'Orphan');
|
|
385
|
+
// requests under way are answered first; the next one starts a pod next to the run's,
|
|
386
|
+
// once this one is gone: it has the name of this one, and would be the one deleted
|
|
387
|
+
await this.retire(key.id, pod, () => pod.runs, async () => {
|
|
388
|
+
// what it owns stays for the run (the egress proxies of its tasks) and goes
|
|
389
|
+
// when the run released it
|
|
390
|
+
await this.deletePod(pod.namespace, pod.name, 'Orphan', pod.uid);
|
|
391
|
+
pod.movedAside = true;
|
|
392
|
+
});
|
|
389
393
|
return;
|
|
390
394
|
}
|
|
391
395
|
}
|
|
@@ -396,7 +400,9 @@ class KubernetesSandboxStorage {
|
|
|
396
400
|
}
|
|
397
401
|
// What a tar in the pod writes, extracted into `into`: the entries `keep` takes, up to
|
|
398
402
|
// the bytes a sandbox may take.
|
|
399
|
-
async copyOut(key, command, into, keep, signal
|
|
403
|
+
async copyOut(key, command, into, keep, signal,
|
|
404
|
+
// the pod a caller holds already: asking for one again would wait for a pod that goes
|
|
405
|
+
held) {
|
|
400
406
|
let bytes = 0;
|
|
401
407
|
const extract = (0, tar_1.extract)({
|
|
402
408
|
cwd: into,
|
|
@@ -416,7 +422,12 @@ class KubernetesSandboxStorage {
|
|
|
416
422
|
});
|
|
417
423
|
extracted.catch(() => undefined);
|
|
418
424
|
counted.pipe(extract);
|
|
419
|
-
|
|
425
|
+
if (held) {
|
|
426
|
+
await this.exec(held, command, null, counted, signal);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
await this.withPod(key, (pod) => this.exec(pod, command, null, counted, signal));
|
|
430
|
+
}
|
|
420
431
|
counted.end();
|
|
421
432
|
await extracted;
|
|
422
433
|
}
|
|
@@ -569,6 +580,10 @@ class KubernetesSandboxStorage {
|
|
|
569
580
|
}
|
|
570
581
|
// The running pod of the sandbox's files, which stays until `leavePod`.
|
|
571
582
|
async usePod(key) {
|
|
583
|
+
// a pod that goes (stopPod, makeWayForRun) has the name the next one gets
|
|
584
|
+
while (this.leaving.has(key.id)) {
|
|
585
|
+
await this.leaving.get(key.id);
|
|
586
|
+
}
|
|
572
587
|
let pod = this.pods.get(key.id);
|
|
573
588
|
if (pod?.started !== undefined && pod.busy === 0 && Date.now() - pod.started > POD_RENEW_MS) {
|
|
574
589
|
// nothing uses it and its deadline nears: a new one, before a run needs it for long
|
|
@@ -620,34 +635,80 @@ class KubernetesSandboxStorage {
|
|
|
620
635
|
}
|
|
621
636
|
// Takes the pod of the sandbox's files down, once the requests under way are answered.
|
|
622
637
|
async stopPod(key, namespace = this.namespaces.name(key.owner)) {
|
|
623
|
-
|
|
638
|
+
// no await between the last look at `leaving` and `retire`, which sets it
|
|
639
|
+
while (this.leaving.has(key.id)) {
|
|
640
|
+
await this.leaving.get(key.id);
|
|
641
|
+
}
|
|
642
|
+
await this.retire(key.id, this.pods.get(key.id), () => 0, () => this.deletePod(namespace, getSandboxNames(key.id).pod));
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Takes `pod` (if there is one) out of use, waits until no more than `keep()` of its users are
|
|
646
|
+
* left (the requests under way are answered, the runs that hold it stay) and then runs
|
|
647
|
+
* `remove`, for at most POD_REMOVE_MS. A pod after it has the same name, so none starts
|
|
648
|
+
* (usePod) before this is over: it would take the pod that goes, or be deleted by its name.
|
|
649
|
+
*/
|
|
650
|
+
async retire(id, pod, keep, remove) {
|
|
624
651
|
if (pod) {
|
|
625
|
-
this.pods.
|
|
652
|
+
if (this.pods.get(id) === pod) {
|
|
653
|
+
this.pods.delete(id);
|
|
654
|
+
}
|
|
626
655
|
clearTimeout(pod.idle);
|
|
627
|
-
|
|
656
|
+
}
|
|
657
|
+
const gone = (async () => {
|
|
658
|
+
for (let i = 0; pod && pod.busy > keep() && i < REQUEST_TIMEOUT_MS / 100; i++) {
|
|
628
659
|
await (0, sleep_1.sleep)(100);
|
|
629
660
|
}
|
|
661
|
+
let timer;
|
|
662
|
+
try {
|
|
663
|
+
await Promise.race([
|
|
664
|
+
remove(),
|
|
665
|
+
new Promise((_resolve, reject) => {
|
|
666
|
+
timer = setTimeout(() => reject(new Error('the pod of the sandbox did not go in time')), POD_REMOVE_MS);
|
|
667
|
+
}),
|
|
668
|
+
]);
|
|
669
|
+
}
|
|
670
|
+
finally {
|
|
671
|
+
clearTimeout(timer);
|
|
672
|
+
}
|
|
673
|
+
})();
|
|
674
|
+
// a remove that is stuck must not hold the requests of the sandbox: `leaving` always settles
|
|
675
|
+
const settled = gone.catch(() => undefined);
|
|
676
|
+
this.leaving.set(id, settled);
|
|
677
|
+
try {
|
|
678
|
+
await gone;
|
|
679
|
+
}
|
|
680
|
+
finally {
|
|
681
|
+
await settled;
|
|
682
|
+
if (this.leaving.get(id) === settled) {
|
|
683
|
+
this.leaving.delete(id);
|
|
684
|
+
}
|
|
630
685
|
}
|
|
631
|
-
await this.deletePod(namespace, getSandboxNames(key.id).pod);
|
|
632
686
|
}
|
|
633
|
-
|
|
687
|
+
// Deletes a pod and waits until it is gone. With its `uid` only that pod goes: one that has
|
|
688
|
+
// the name now is another, which a late delete must not remove.
|
|
689
|
+
async deletePod(namespace, name, propagationPolicy, uid) {
|
|
634
690
|
try {
|
|
635
691
|
await this.instance.coreApi.deleteNamespacedPod({
|
|
636
692
|
name,
|
|
637
693
|
namespace,
|
|
638
694
|
gracePeriodSeconds: 0,
|
|
639
695
|
...(propagationPolicy ? { propagationPolicy } : {}),
|
|
696
|
+
...(uid ? { body: { preconditions: { uid } } } : {}),
|
|
640
697
|
});
|
|
641
698
|
}
|
|
642
699
|
catch (e) {
|
|
643
|
-
|
|
700
|
+
// 409: the precondition failed, the pod of that uid is gone
|
|
701
|
+
if ((0, apply_1.statusCodeOf)(e) === 404 || (uid && (0, apply_1.statusCodeOf)(e) === 409)) {
|
|
644
702
|
return;
|
|
645
703
|
}
|
|
646
704
|
throw e;
|
|
647
705
|
}
|
|
648
706
|
for (let attempt = 0; attempt < 120; attempt++) {
|
|
649
707
|
try {
|
|
650
|
-
await this.instance.coreApi.readNamespacedPod({ name, namespace });
|
|
708
|
+
const found = await this.instance.coreApi.readNamespacedPod({ name, namespace });
|
|
709
|
+
if (uid && found.metadata?.uid !== uid) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
651
712
|
}
|
|
652
713
|
catch (e) {
|
|
653
714
|
if ((0, apply_1.statusCodeOf)(e) === 404) {
|