hammerkit 2.1.0 → 2.2.0-next.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/build.schema.json +126 -28
- package/dist/cache/backends/registry/push-credentials.js +50 -0
- package/dist/cache/backends/registry/registry-client.js +41 -10
- package/dist/cache/backends/registry-cache-backend.js +6 -1
- package/dist/cache/cache-inventory.js +3 -0
- package/dist/cli.js +5 -0
- package/dist/dashboard/assets/graph-canvas-D6GMgkoe.js +8 -0
- package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
- package/dist/dashboard/assets/index-DP3_hKOe.css +2 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/docker/item-network.js +6 -5
- package/dist/docker/remove-orphaned-containers.js +5 -4
- package/dist/environment/replace-env-variables.js +8 -5
- package/dist/environment/run-source-envs.js +2 -1
- package/dist/executer/archive-task-entry.js +1 -1
- package/dist/executer/check-readiness.js +8 -4
- package/dist/executer/docker-healthcheck.js +73 -0
- package/dist/executer/docker-service.js +21 -15
- package/dist/executer/event-cache.js +7 -1
- package/dist/executer/execute-work-task.js +8 -0
- 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 +241 -33
- package/dist/harness/service-tools.js +11 -2
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +62 -14
- package/dist/kubernetes/ensure-persistent-data.js +1 -1
- package/dist/kubernetes/follow-pod-logs.js +8 -5
- package/dist/kubernetes/kept-claims.js +38 -14
- 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/network/healthcheck-request.js +38 -0
- package/dist/optimizer/get-work-cache-stats.js +7 -0
- package/dist/optimizer/work-task-cache-description.js +5 -3
- package/dist/planner/image-build.js +5 -0
- package/dist/planner/service-definition.js +2 -1
- package/dist/planner/utils/append-work-service.js +12 -4
- package/dist/planner/utils/dependency-outputs.js +7 -6
- package/dist/planner/validate.js +41 -0
- package/dist/planner/work-healthcheck.js +23 -2
- 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 +33 -6
- package/dist/planner/work-runtime-kubernetes.js +313 -70
- package/dist/planner/work-runtime-local.js +8 -4
- package/dist/planner/work-secret.js +33 -11
- package/dist/planner/work-service-id.js +30 -6
- package/dist/planner/work-service.js +2 -2
- package/dist/program.js +19 -1
- package/dist/remote/annotations.js +8 -2
- package/dist/remote/bundle.js +6 -8
- package/dist/remote/device-login.js +4 -1
- package/dist/remote/remote-commands.js +16 -7
- package/dist/remote/remote-status.js +1 -1
- package/dist/remote/remote-work-commands.js +220 -68
- package/dist/remote/server-client.js +38 -40
- package/dist/schema/build-file-base-task-schema.js +16 -1
- package/dist/schema/build-file-image-build-schema.js +5 -8
- package/dist/schema/build-file-service-container-healthcheck.js +25 -7
- package/dist/schema/reference-parser.js +108 -43
- package/dist/schema/work-scope-parser.js +8 -0
- package/dist/secrets/prefetch-secrets.js +20 -1
- package/dist/server/artifacts-api.js +56 -0
- package/dist/server/borrowed-quota.js +216 -0
- package/dist/server/cache-push.js +50 -0
- package/dist/server/capacity.js +18 -6
- package/dist/server/definitions-api.js +62 -8
- package/dist/server/executor.js +131 -31
- package/dist/server/http.js +4 -1
- package/dist/server/keep-artifacts.js +230 -0
- package/dist/server/kubernetes-backend.js +292 -79
- package/dist/server/kubernetes-sandbox-storage.js +86 -24
- package/dist/server/overview.js +73 -9
- package/dist/server/paging.js +167 -0
- package/dist/server/plan.js +54 -8
- 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 +11 -0
- package/dist/server/run-source-environment.js +1 -1
- package/dist/server/run-worker.js +305 -40
- package/dist/server/runs.js +531 -105
- package/dist/server/sandbox-files-api.js +27 -12
- package/dist/server/sandbox-files.js +12 -10
- package/dist/server/sandbox-follow.js +54 -0
- package/dist/server/sandbox-pod.js +1 -1
- package/dist/server/sandbox-storage.js +38 -1
- package/dist/server/sandbox-sync.js +392 -0
- package/dist/server/sandboxes-api.js +116 -19
- package/dist/server/sandboxes.js +38 -3
- package/dist/server/server-config.js +133 -2
- package/dist/server/server.js +189 -39
- 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/graph-canvas-DtJSpova.js +0 -8
- package/dist/dashboard/assets/index-BndChMep.css +0 -2
- package/dist/dashboard/assets/index-DRSwIRXd.js +0 -17
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getServiceContainerName = exports.MIN_READY_SECONDS = exports.getPodTemplateHash = exports.POD_ANNOTATION = exports.ROLLOUT_DEADLINE_SECONDS = exports.ensureKubernetesDeploymentExists = exports.DEBUG_CONTAINER_RESOURCES = exports.DEFINITION_LABEL = void 0;
|
|
3
|
+
exports.getHealthcheckProbe = exports.getServiceContainerName = exports.MIN_READY_SECONDS = exports.getPodTemplateHash = exports.POD_ANNOTATION = exports.ROLLOUT_DEADLINE_SECONDS = exports.ensureKubernetesDeploymentExists = exports.DEBUG_CONTAINER_RESOURCES = exports.DEFINITION_LABEL = void 0;
|
|
4
4
|
const service_definition_1 = require("../planner/service-definition");
|
|
5
5
|
const work_service_1 = require("../planner/work-service");
|
|
6
6
|
const volumes_1 = require("./volumes");
|
|
@@ -18,6 +18,8 @@ const network_policy_1 = require("./network-policy");
|
|
|
18
18
|
const egress_proxy_1 = require("../network/egress-proxy");
|
|
19
19
|
const service_rollouts_1 = require("./service-rollouts");
|
|
20
20
|
const quota_wait_1 = require("./quota-wait");
|
|
21
|
+
const transfer_tools_1 = require("./transfer-tools");
|
|
22
|
+
const healthcheck_request_1 = require("../network/healthcheck-request");
|
|
21
23
|
// what the service was created from, to tell a changed one
|
|
22
24
|
exports.DEFINITION_LABEL = 'hammerkit.dev/definition';
|
|
23
25
|
// how often a starting container is checked: as the liveness probe
|
|
@@ -34,18 +36,15 @@ network,
|
|
|
34
36
|
rollout = {}) {
|
|
35
37
|
const envs = (0, replace_env_variables_1.getEnvironmentVariables)(service.data.envs);
|
|
36
38
|
const name = (0, resources_1.getResourceName)(service, env);
|
|
37
|
-
const healthcheckCommand = (0, work_service_1.getHealthcheckCommand)(service.data);
|
|
38
39
|
const serviceCommand = (0, work_service_1.getServiceCommand)(service.data, { kubernetes: true });
|
|
39
|
-
const probe =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
periodSeconds: 5,
|
|
46
|
-
failureThreshold: 3,
|
|
40
|
+
const probe = getHealthcheckProbe(service.data, network.env);
|
|
41
|
+
const probeTools = needsProbeTools(service.data);
|
|
42
|
+
if (probeTools) {
|
|
43
|
+
const over = [...persistence.mounts.map((m) => m.mount), ...secrets.mounts].find((mount) => (0, transfer_tools_1.isTransferToolsPath)(mount.mountPath));
|
|
44
|
+
if (over) {
|
|
45
|
+
throw new Error(`service ${service.name} mounts ${over.mountPath}, over ${transfer_tools_1.TRANSFER_TOOLS_PATH} where its healthcheck's tools are`);
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
}
|
|
49
48
|
// the healthcheck's `timeout` for each start: until it passed once, the liveness probe
|
|
50
49
|
// doesn't kill a container that starts slowly, and the wait fails it with the timeout
|
|
51
50
|
const startupProbe = probe && service.data.healthcheck
|
|
@@ -96,7 +95,7 @@ rollout = {}) {
|
|
|
96
95
|
// the pod resolves its own service name, as with Docker's Hostname
|
|
97
96
|
hostname: (0, service_hostname_1.getServiceHostname)(service.name),
|
|
98
97
|
hostAliases: network.hostAliases,
|
|
99
|
-
initContainers: network.initContainers,
|
|
98
|
+
initContainers: [...network.initContainers, ...(probeTools ? [(0, transfer_tools_1.getTransferToolsInitContainer)()] : [])],
|
|
100
99
|
// on a server the pod is the build's: no token of the namespace, and the
|
|
101
100
|
// nodes of the first pool
|
|
102
101
|
...(placement
|
|
@@ -127,7 +126,11 @@ rollout = {}) {
|
|
|
127
126
|
livenessProbe: probe,
|
|
128
127
|
startupProbe,
|
|
129
128
|
...(0, container_resources_1.getKubernetesResources)(service.data.resources),
|
|
130
|
-
volumeMounts: [
|
|
129
|
+
volumeMounts: [
|
|
130
|
+
...persistence.mounts.map((m) => m.mount),
|
|
131
|
+
...secrets.mounts,
|
|
132
|
+
...(probeTools ? [transfer_tools_1.TRANSFER_TOOLS_MOUNT] : []),
|
|
133
|
+
],
|
|
131
134
|
...(0, job_placement_1.getContainerSecurity)(env),
|
|
132
135
|
},
|
|
133
136
|
{
|
|
@@ -142,7 +145,12 @@ rollout = {}) {
|
|
|
142
145
|
...(0, job_placement_1.getContainerSecurity)(env),
|
|
143
146
|
},
|
|
144
147
|
],
|
|
145
|
-
volumes: [
|
|
148
|
+
volumes: [
|
|
149
|
+
...persistence.volumes,
|
|
150
|
+
...persistence.workspace,
|
|
151
|
+
...secrets.volumes,
|
|
152
|
+
...(probeTools ? transfer_tools_1.TRANSFER_TOOLS_VOLUMES : []),
|
|
153
|
+
],
|
|
146
154
|
},
|
|
147
155
|
},
|
|
148
156
|
},
|
|
@@ -276,6 +284,46 @@ function getKubernetesCommand(command) {
|
|
|
276
284
|
}
|
|
277
285
|
return {};
|
|
278
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* The healthcheck as the probe of the service's container: a `cmd` as an exec probe, `tcp`
|
|
289
|
+
* and `http` as the kubelet's own tcpSocket and httpGet, which no NetworkPolicy of a limited
|
|
290
|
+
* service keeps out. httpGet counts 200 to 399 as healthy, so an `http` check with status
|
|
291
|
+
* codes of its own is an exec probe of the busybox an init container copies into the pod
|
|
292
|
+
* (needsProbeTools), the check a service on Docker runs (getHealthcheckRequestCommand).
|
|
293
|
+
*/
|
|
294
|
+
function getHealthcheckProbe(service, env) {
|
|
295
|
+
const healthcheck = service.healthcheck;
|
|
296
|
+
if (!healthcheck) {
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
const timing = { periodSeconds: STARTUP_PERIOD_SECONDS, failureThreshold: 3 };
|
|
300
|
+
if ('cmd' in healthcheck) {
|
|
301
|
+
// the service itself, not through the proxy (see getProxylessEnvironment)
|
|
302
|
+
return { exec: { command: withoutProxy((0, work_service_1.getHealthcheckCommand)(service) ?? [], env) }, ...timing };
|
|
303
|
+
}
|
|
304
|
+
if ('tcp' in healthcheck) {
|
|
305
|
+
return { tcpSocket: { port: healthcheck.tcp.port }, timeoutSeconds: healthcheck_request_1.HEALTHCHECK_REQUEST_SECONDS, ...timing };
|
|
306
|
+
}
|
|
307
|
+
if (needsProbeTools(service)) {
|
|
308
|
+
return {
|
|
309
|
+
exec: { command: (0, healthcheck_request_1.getHealthcheckRequestCommand)(transfer_tools_1.TRANSFER_BUSYBOX, healthcheck) },
|
|
310
|
+
// its request's bound, and the start of the busybox
|
|
311
|
+
timeoutSeconds: healthcheck_request_1.HEALTHCHECK_REQUEST_SECONDS + 1,
|
|
312
|
+
...timing,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
const { port, path, scheme } = healthcheck.http;
|
|
316
|
+
return {
|
|
317
|
+
httpGet: { port, path, scheme: scheme === 'https' ? 'HTTPS' : 'HTTP' },
|
|
318
|
+
timeoutSeconds: healthcheck_request_1.HEALTHCHECK_REQUEST_SECONDS,
|
|
319
|
+
...timing,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
exports.getHealthcheckProbe = getHealthcheckProbe;
|
|
323
|
+
// an `http` healthcheck with status codes of its own, which the kubelet's httpGet can't check
|
|
324
|
+
function needsProbeTools(service) {
|
|
325
|
+
return !!service.healthcheck && 'http' in service.healthcheck && service.healthcheck.http.status !== null;
|
|
326
|
+
}
|
|
279
327
|
// A probe runs with the container's variables, so it empties the proxy ones
|
|
280
328
|
// through `env`, as a Docker healthcheck does with the exec's own variables.
|
|
281
329
|
function withoutProxy(command, env) {
|
|
@@ -102,7 +102,7 @@ signal, fn) {
|
|
|
102
102
|
// outputs of its deps are not mounted, so an output inside a folder of its src
|
|
103
103
|
// (pkg/coverage/lcov.info) has a place in the pod even when the claim holds no src,
|
|
104
104
|
// after a restore into a new claim
|
|
105
|
-
own.filter((m) => service.data.type !== 'container-task' || !m.mount.readOnly).map((m) => m.mount)
|
|
105
|
+
own.filter((m) => !m.sync && (service.data.type !== 'container-task' || !m.mount.readOnly)).map((m) => m.mount)
|
|
106
106
|
: own.reduce((array, v) => {
|
|
107
107
|
if (!array.some((i) => i.name === v.mount.name)) {
|
|
108
108
|
array.push({
|
|
@@ -49,14 +49,17 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
|
|
|
49
49
|
const positionOf = (id) => {
|
|
50
50
|
let position = positions.get(id);
|
|
51
51
|
if (!position) {
|
|
52
|
-
|
|
52
|
+
const from = Array.isArray(options.from) ? options.from.find((cursor) => cursor?.container === id) : undefined;
|
|
53
|
+
position = from
|
|
54
|
+
? { at: from.at, since: `${from.at.slice(0, 19)}Z`, count: from.count, reads: 0 }
|
|
55
|
+
: { at: null, since: null, count: 0, reads: 0 };
|
|
53
56
|
positions.set(id, position);
|
|
54
57
|
}
|
|
55
58
|
return position;
|
|
56
59
|
};
|
|
57
60
|
// a reader of the log of one instance from where it got to: the lines read before, again
|
|
58
61
|
// at the start of a log read since their second, are passed over
|
|
59
|
-
const reader = (position) => {
|
|
62
|
+
const reader = (id, position) => {
|
|
60
63
|
const from = position.at;
|
|
61
64
|
const skip = position.count;
|
|
62
65
|
let atFrom = 0;
|
|
@@ -80,7 +83,7 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
|
|
|
80
83
|
position.since = `${match[1]}Z`;
|
|
81
84
|
position.count = 1;
|
|
82
85
|
}
|
|
83
|
-
onLine(match[3] ?? '');
|
|
86
|
+
onLine(match[3] ?? '', { container: id, at, count: position.count });
|
|
84
87
|
};
|
|
85
88
|
};
|
|
86
89
|
const readEnded = async (pod, id, previous) => {
|
|
@@ -98,7 +101,7 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
|
|
|
98
101
|
? { sinceSeconds: Math.max(1, Math.ceil((Date.now() - Date.parse(position.since)) / 1000) + 60) }
|
|
99
102
|
: {}),
|
|
100
103
|
});
|
|
101
|
-
const read = reader(position);
|
|
104
|
+
const read = reader(id, position);
|
|
102
105
|
for (const line of String(log ?? '').split(/\r?\n/)) {
|
|
103
106
|
if (line.length > 0) {
|
|
104
107
|
read(line);
|
|
@@ -139,7 +142,7 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
|
|
|
139
142
|
end();
|
|
140
143
|
}));
|
|
141
144
|
output.on('end', end);
|
|
142
|
-
(0, read_lines_1.readLines)(output, exports.MAX_LOG_LINE_CHARS, reader(position));
|
|
145
|
+
(0, read_lines_1.readLines)(output, exports.MAX_LOG_LINE_CHARS, reader(id, position));
|
|
143
146
|
streaming++;
|
|
144
147
|
let controller;
|
|
145
148
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evictKeptClaims = exports.sweepKeptClaims = exports.expireKeptClaims = exports.recordClaimState = exports.forgetClaimState = exports.rememberedClaimState = exports.useClaimState = exports.isKeptClaim = exports.getClaimName = exports.EXPIRES_ANNOTATION = exports.STATE_ANNOTATION = exports.KEPT_BY_LABEL = exports.VOLUME_SCOPE_LABEL = void 0;
|
|
3
|
+
exports.evictKeptClaims = exports.sweepKeptClaims = exports.expireKeptClaims = exports.isClaimWrittenBy = exports.recordClaimState = exports.markClaimWriter = exports.forgetClaimState = exports.rememberedClaimState = exports.useClaimState = exports.isKeptClaim = exports.getClaimName = exports.WRITER_ANNOTATION = exports.EXPIRES_ANNOTATION = exports.STATE_ANNOTATION = exports.KEPT_BY_LABEL = exports.VOLUME_SCOPE_LABEL = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const apply_1 = require("./apply");
|
|
6
6
|
const sleep_1 = require("../utils/sleep");
|
|
@@ -18,14 +18,21 @@ exports.KEPT_BY_LABEL = 'hammerkit.dev/kept-by';
|
|
|
18
18
|
exports.STATE_ANNOTATION = 'hammerkit.dev/state';
|
|
19
19
|
// when it goes, set by the end of the run that mounted it last
|
|
20
20
|
exports.EXPIRES_ANNOTATION = 'hammerkit.dev/expires';
|
|
21
|
+
// while a Job writes to it and it names no state: which run and state the Job is of, so a
|
|
22
|
+
// run that resumes after a restart of the server takes the Job over only when no other run
|
|
23
|
+
// wrote to the claim since
|
|
24
|
+
exports.WRITER_ANNOTATION = 'hammerkit.dev/writer';
|
|
21
25
|
// The claim of a work item: a task's on a server that keeps them carries the scope, so a
|
|
22
|
-
// run of another source never mounts it, and the
|
|
23
|
-
//
|
|
24
|
-
//
|
|
26
|
+
// run of another source never mounts it, and the name of the task, so that only runs with
|
|
27
|
+
// that task in their plan mount it: two runs of one scope go one at a time when they have a
|
|
28
|
+
// task in common (KubernetesExecutor.excludes), and two tasks of one definition under two
|
|
29
|
+
// names have a claim each. Any other claim on a server is the run's own, as the runs of a
|
|
30
|
+
// caller share their namespace. 63 characters at most, a pod's volume name.
|
|
25
31
|
function getClaimName(work, kubernetes) {
|
|
26
32
|
const scope = kubernetes.server?.volumeScope;
|
|
27
33
|
if (scope && isTask(work)) {
|
|
28
|
-
|
|
34
|
+
const owner = (0, crypto_1.createHash)('sha256').update(`${scope}\0${work.name}`).digest('hex').slice(0, 12);
|
|
35
|
+
return `hammerkit-${work.id()}-${owner}`;
|
|
29
36
|
}
|
|
30
37
|
return 'hammerkit-' + (0, resources_1.getItemKey)(work, kubernetes);
|
|
31
38
|
}
|
|
@@ -113,17 +120,34 @@ async function rememberedClaimState(instance, kubernetes, name) {
|
|
|
113
120
|
return claim.metadata?.annotations?.[exports.STATE_ANNOTATION] ?? null;
|
|
114
121
|
}
|
|
115
122
|
exports.rememberedClaimState = rememberedClaimState;
|
|
116
|
-
// Before a task writes to its kept claim: the outputs in it stop being those of a state
|
|
117
|
-
//
|
|
123
|
+
// Before a task writes to its kept claim: the outputs in it stop being those of a state, and
|
|
124
|
+
// the Job that wrote to it last is not the one that writes to it now. Whether the claim was
|
|
125
|
+
// there, with what an earlier run left in it.
|
|
118
126
|
function forgetClaimState(instance, kubernetes, name) {
|
|
119
|
-
return annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: null });
|
|
127
|
+
return annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: null, [exports.WRITER_ANNOTATION]: null });
|
|
120
128
|
}
|
|
121
129
|
exports.forgetClaimState = forgetClaimState;
|
|
130
|
+
// Once the files of a Job are in the claim, before the Job starts: which run and state it is
|
|
131
|
+
// of (WRITER_ANNOTATION)
|
|
132
|
+
async function markClaimWriter(instance, kubernetes, name, writer) {
|
|
133
|
+
await annotate(instance, kubernetes.namespace, name, { [exports.WRITER_ANNOTATION]: writer });
|
|
134
|
+
}
|
|
135
|
+
exports.markClaimWriter = markClaimWriter;
|
|
122
136
|
// Once the outputs of `stateKey` are whole in the kept claim
|
|
123
137
|
async function recordClaimState(instance, kubernetes, name, stateKey) {
|
|
124
|
-
await annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: stateKey });
|
|
138
|
+
await annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: stateKey, [exports.WRITER_ANNOTATION]: null });
|
|
125
139
|
}
|
|
126
140
|
exports.recordClaimState = recordClaimState;
|
|
141
|
+
// Whether the Job of `writer` was the last to write to the claim, and it names no state since
|
|
142
|
+
async function isClaimWrittenBy(instance, kubernetes, name, writer) {
|
|
143
|
+
const claim = await readClaim(instance, kubernetes.namespace, name);
|
|
144
|
+
const annotations = claim?.metadata?.annotations ?? {};
|
|
145
|
+
return (!!claim &&
|
|
146
|
+
!claim.metadata?.deletionTimestamp &&
|
|
147
|
+
!annotations[exports.STATE_ANNOTATION] &&
|
|
148
|
+
annotations[exports.WRITER_ANNOTATION] === writer);
|
|
149
|
+
}
|
|
150
|
+
exports.isClaimWrittenBy = isClaimWrittenBy;
|
|
127
151
|
// The kept claims in a namespace
|
|
128
152
|
async function listKeptClaims(instance, namespace, labelSelector = exports.VOLUME_SCOPE_LABEL) {
|
|
129
153
|
const claims = await instance.coreApi.listNamespacedPersistentVolumeClaim({ namespace, labelSelector });
|
|
@@ -201,17 +225,17 @@ async function sweepKeptClaims(instance, namespace, options) {
|
|
|
201
225
|
exports.sweepKeptClaims = sweepKeptClaims;
|
|
202
226
|
// When a run needs room under the quota of its namespace: the kept claims it does not use
|
|
203
227
|
// go, those of the other sources and those of its own a task of this run did not take (one
|
|
204
|
-
// renamed or changed since
|
|
205
|
-
// expiry: one without is mounted by a run of the caller that executes now
|
|
206
|
-
//
|
|
228
|
+
// renamed or changed since, or of a task of another run). Only one its last run released,
|
|
229
|
+
// which has an expiry: one without is mounted by a run of the caller that executes now, of
|
|
230
|
+
// this scope too when it has no task in common with this run (or was left by a server that
|
|
231
|
+
// stopped, which the next sweep removes). The names of those removed.
|
|
207
232
|
async function evictKeptClaims(instance, kubernetes, timeout) {
|
|
208
233
|
const server = kubernetes.server;
|
|
209
234
|
if (!server?.volumeScope) {
|
|
210
235
|
return [];
|
|
211
236
|
}
|
|
212
237
|
const unused = await listKeptClaims(instance, kubernetes.namespace, `${exports.VOLUME_SCOPE_LABEL},${exports.KEPT_BY_LABEL}!=${(0, job_placement_1.getRunLabelValue)(server.run)}`);
|
|
213
|
-
const released = unused.filter((claim) => claim.metadata?.
|
|
214
|
-
!!claim.metadata?.annotations?.[exports.EXPIRES_ANNOTATION]);
|
|
238
|
+
const released = unused.filter((claim) => !!claim.metadata?.annotations?.[exports.EXPIRES_ANNOTATION]);
|
|
215
239
|
return removeClaims(instance, kubernetes.namespace, released, timeout);
|
|
216
240
|
}
|
|
217
241
|
exports.evictKeptClaims = evictKeptClaims;
|