hammerkit 2.0.0-next.1 → 2.0.0-next.10
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/cache/explain.js +7 -5
- package/dist/dashboard/assets/graph-canvas-DLioOiRN.css +1 -0
- package/dist/dashboard/assets/graph-canvas-HmkW_-XJ.js +8 -0
- package/dist/dashboard/assets/index-gIBDC_m8.css +2 -0
- package/dist/dashboard/assets/index-vE22S5E_.js +17 -0
- package/dist/dashboard/index.html +3 -3
- package/dist/dashboard/logo.png +0 -0
- package/dist/executer/docker-task.js +3 -0
- package/dist/executer/execute-work-task.js +3 -1
- package/dist/executer/local-task.js +3 -0
- package/dist/executer/scheduler/enqueue-next.js +6 -1
- package/dist/executer/scheduler/state-key.js +71 -34
- package/dist/executer/watch-loop.js +18 -5
- package/dist/file/get-file-context.js +5 -1
- package/dist/kubernetes/await-running-state.js +69 -5
- package/dist/kubernetes/claim-layout.js +10 -1
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +10 -1
- package/dist/kubernetes/ensure-persistent-data.js +108 -20
- package/dist/kubernetes/follow-pod-logs.js +128 -29
- package/dist/kubernetes/kept-claims.js +16 -1
- package/dist/kubernetes/network-policy.js +4 -4
- package/dist/kubernetes/quota-wait.js +97 -0
- package/dist/kubernetes/restore-kubernetes-data.js +27 -4
- package/dist/kubernetes/store-kubernetes-data.js +13 -2
- package/dist/kubernetes/volumes.js +34 -7
- package/dist/optimizer/calculate-checksum.js +46 -3
- package/dist/optimizer/check-keys.js +4 -2
- package/dist/optimizer/get-work-cache-stats.js +36 -24
- package/dist/parser/read-build-file.js +8 -3
- package/dist/planner/utils/template-value.js +20 -4
- package/dist/planner/work-item-executions.js +27 -0
- package/dist/planner/work-runtime-kubernetes.js +69 -41
- package/dist/remote/host-config.js +1 -1
- package/dist/remote/remote-work-commands.js +14 -5
- package/dist/schema/schema-parser.js +46 -2
- package/dist/server/capacity.js +71 -41
- package/dist/server/dashboard.js +27 -9
- package/dist/server/endpoints.js +10 -1
- package/dist/server/executor.js +65 -34
- package/dist/server/kubernetes-sandbox-storage.js +14 -4
- package/dist/server/oauth.js +16 -1
- package/dist/server/overview.js +80 -11
- package/dist/server/plan.js +16 -3
- package/dist/server/policy.js +9 -3
- package/dist/server/run-worker.js +47 -6
- package/dist/server/runs.js +74 -6
- package/dist/server/sandbox-files.js +107 -16
- package/dist/server/sandbox-patch.js +43 -17
- package/dist/server/sandboxes.js +57 -23
- package/dist/server/server-config.js +4 -1
- package/dist/server/server.js +45 -10
- package/dist/server/service-runs.js +8 -1
- package/dist/server/sources.js +68 -11
- package/dist/server/timings.js +23 -3
- package/dist/utils/buffer-context.js +30 -20
- package/dist/utils/limit.js +30 -0
- package/dist/utils/read-lines.js +65 -0
- package/dist/utils/units.js +36 -1
- package/dist/utils/web-links.js +34 -0
- package/package.json +1 -1
- package/dist/dashboard/assets/index-CjnKm5-3.css +0 -2
- package/dist/dashboard/assets/index-zPXa4klZ.js +0 -13
- package/dist/dashboard/favicon.svg +0 -1
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<meta name="robots" content="noindex" />
|
|
7
|
-
<link rel="icon" href="/
|
|
7
|
+
<link rel="icon" href="/logo.png" type="image/png" />
|
|
8
8
|
<title>hammerkit</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-vE22S5E_.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/index-gIBDC_m8.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
|
Binary file
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dockerTask = exports.getCapabilityHostConfig = exports.buildCreateOptions = void 0;
|
|
4
|
+
const work_item_executions_1 = require("../planner/work-item-executions");
|
|
4
5
|
const run_labels_1 = require("../docker/run-labels");
|
|
5
6
|
const execute_docker_1 = require("./execute-docker");
|
|
6
7
|
const abort_1 = require("./abort");
|
|
@@ -106,7 +107,9 @@ async function dockerTask(docker, item, environment, options) {
|
|
|
106
107
|
for (const cmd of item.data.cmds) {
|
|
107
108
|
(0, abort_1.checkForAbort)(options.abort);
|
|
108
109
|
item.status.write('info', `execute cmd "${cmd.cmd}" in container`);
|
|
110
|
+
const commandStarted = new Date();
|
|
109
111
|
const result = await (0, execute_docker_1.execCommand)(item.status, environment, container, (0, execute_docker_1.convertToPosixPath)(cmd.cwd), [item.data.shell, '-c', cmd.cmd], item.data.user, undefined, options.abort);
|
|
112
|
+
(0, work_item_executions_1.recordExecution)(item.data, commandStarted, new Date());
|
|
110
113
|
if (result.type === 'timeout') {
|
|
111
114
|
throw new Error(`command ${cmd.cmd} timed out`);
|
|
112
115
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeWorkTask = void 0;
|
|
4
|
+
const work_item_executions_1 = require("../planner/work-item-executions");
|
|
4
5
|
const work_task_1 = require("../planner/work-task");
|
|
5
6
|
const states_1 = require("./states");
|
|
6
7
|
const abort_1 = require("./abort");
|
|
@@ -83,7 +84,7 @@ dependents = null) {
|
|
|
83
84
|
// build summary can show the cause column. Reporting only.
|
|
84
85
|
let missCauses;
|
|
85
86
|
if (options.explain) {
|
|
86
|
-
const explanation = await (0, explain_1.explainTask)(work, options.cacheDefault, environment);
|
|
87
|
+
const explanation = await (0, explain_1.explainTask)(work, options.cacheDefault, environment, undefined, undefined, (0, watch_loop_1.getSharedStateKeys)(work, options));
|
|
87
88
|
missCauses = explanation.causes.map(explain_1.describeCause);
|
|
88
89
|
for (const cause of missCauses) {
|
|
89
90
|
work.status.write('info', `cache miss: ${cause}`);
|
|
@@ -103,6 +104,7 @@ dependents = null) {
|
|
|
103
104
|
});
|
|
104
105
|
const timeout = (0, deadline_1.getTaskTimeout)(work.data.timeout, options);
|
|
105
106
|
const deadline = (0, deadline_1.withDeadline)(abort, timeout);
|
|
107
|
+
(0, work_item_executions_1.clearExecutions)(work.data);
|
|
106
108
|
try {
|
|
107
109
|
await work.runtime.execute(environment, {
|
|
108
110
|
cache: cacheState,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.localTask = void 0;
|
|
4
|
+
const work_item_executions_1 = require("../planner/work-item-executions");
|
|
4
5
|
const abort_1 = require("./abort");
|
|
5
6
|
const execute_command_1 = require("./execute-command");
|
|
6
7
|
const log_1 = require("../log");
|
|
@@ -18,7 +19,9 @@ async function localTask(item, environment, options) {
|
|
|
18
19
|
for (const cmd of item.data.cmds) {
|
|
19
20
|
(0, abort_1.checkForAbort)(options.abort);
|
|
20
21
|
item.status.write('info', `execute cmd "${cmd.cmd}" locally`);
|
|
22
|
+
const commandStarted = new Date();
|
|
21
23
|
const exitCode = await (0, execute_command_1.executeCommand)(item.status, options.abort, cmd.cwd, cmd.cmd, envs, environment);
|
|
24
|
+
(0, work_item_executions_1.recordExecution)(item.data, commandStarted, new Date());
|
|
22
25
|
if (exitCode !== 0) {
|
|
23
26
|
options.state.set({
|
|
24
27
|
type: 'crash',
|
|
@@ -18,6 +18,7 @@ async function checkCacheState(item, defaultCacheMethod, environment,
|
|
|
18
18
|
// the cache is off
|
|
19
19
|
// restore: false only looks a backend hit up, its outputs are downloaded once
|
|
20
20
|
// something that runs depends on them (`run --no-restore`, see deferred-restore)
|
|
21
|
+
// memo: the keys of the execution so far, see getExecutionStateKeys
|
|
21
22
|
options = {}) {
|
|
22
23
|
(0, deferred_restore_1.clearDeferredRestore)(item);
|
|
23
24
|
// A task whose cache is off is never looked up, so hashing its sources buys
|
|
@@ -28,7 +29,11 @@ options = {}) {
|
|
|
28
29
|
item.status.write('debug', `${item.name} is skipping cache check, because caching is disabled`);
|
|
29
30
|
return { cached: false, stateKey: exports.UNCACHED_STATE_KEY, resolved: declared, provable: false };
|
|
30
31
|
}
|
|
31
|
-
const { stateKey, stats: currentStats, resolved, provable, unmatched, } = await (0, state_key_1.computeStateKey)(item, defaultCacheMethod, environment);
|
|
32
|
+
const { stateKey, stats: currentStats, resolved, provable, unmatched, } = await (0, state_key_1.computeStateKey)(item, defaultCacheMethod, environment, options.memo);
|
|
33
|
+
// what depends on it takes its key from here
|
|
34
|
+
if (options.memo && !options.memo.has(item.id())) {
|
|
35
|
+
options.memo.set(item.id(), Promise.resolve({ stateKey, provable }));
|
|
36
|
+
}
|
|
32
37
|
for (const src of unmatched) {
|
|
33
38
|
item.status.write('warn', `src "${src.source}" matches no files`);
|
|
34
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computeStateKey = exports.combineStateKeys = exports.isOwnProvable = exports.resolveEffective = void 0;
|
|
3
|
+
exports.computeStateKey = exports.combineStateKeys = exports.getExecutionStateKeys = exports.isOwnProvable = exports.resolveEffective = void 0;
|
|
4
4
|
const get_work_cache_stats_1 = require("../../optimizer/get-work-cache-stats");
|
|
5
5
|
const work_task_1 = require("../../planner/work-task");
|
|
6
6
|
// The state-key engine is shared by the scheduler's hit/miss decision
|
|
@@ -29,6 +29,43 @@ function isOwnProvable(item, unmatched) {
|
|
|
29
29
|
return unmatched.length < item.data.src.filter((src) => !src.inherited).length;
|
|
30
30
|
}
|
|
31
31
|
exports.isOwnProvable = isOwnProvable;
|
|
32
|
+
// What an item on its own way down stands for. Items that depend on or need each other in a
|
|
33
|
+
// loop fail to plan (checkForLoop) and never run: this only has to end. The loop is told by
|
|
34
|
+
// the path of one computation, never by the shared memo, which tasks checked at the same time
|
|
35
|
+
// read, so a placeholder can never end up in another task's key.
|
|
36
|
+
const LOOP = { stateKey: 'loop', provable: true };
|
|
37
|
+
// Keep a computation in the memo, and take it out again if it fails, so a later check
|
|
38
|
+
// computes it anew instead of failing the same way.
|
|
39
|
+
function memoized(memo, key, compute) {
|
|
40
|
+
const existing = memo.get(key);
|
|
41
|
+
if (existing) {
|
|
42
|
+
return existing;
|
|
43
|
+
}
|
|
44
|
+
const promise = compute();
|
|
45
|
+
memo.set(key, promise);
|
|
46
|
+
promise.catch(() => {
|
|
47
|
+
if (memo.get(key) === promise) {
|
|
48
|
+
memo.delete(key);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return promise;
|
|
52
|
+
}
|
|
53
|
+
const executionKeys = new WeakMap();
|
|
54
|
+
// The keys of one execution (the options of `exec`, which all its items share): its items
|
|
55
|
+
// are checked once, before they run, from the files as they are then. Not for watch mode,
|
|
56
|
+
// where a key is computed again because files changed.
|
|
57
|
+
// The items it holds keys of must have no loop: checkForLoop fails the tree before it runs.
|
|
58
|
+
// Two tasks checked at once that enter a loop of needs from opposite ends would each wait for
|
|
59
|
+
// the other's computation.
|
|
60
|
+
function getExecutionStateKeys(options) {
|
|
61
|
+
let memo = executionKeys.get(options);
|
|
62
|
+
if (!memo) {
|
|
63
|
+
memo = new Map();
|
|
64
|
+
executionKeys.set(options, memo);
|
|
65
|
+
}
|
|
66
|
+
return memo;
|
|
67
|
+
}
|
|
68
|
+
exports.getExecutionStateKeys = getExecutionStateKeys;
|
|
32
69
|
// Fold a task's own state key together with the state keys of its dependencies.
|
|
33
70
|
// A change anywhere in the dependency subtree must change the resulting key, so
|
|
34
71
|
// that a downstream task is invalidated when an upstream source changes — even
|
|
@@ -51,34 +88,36 @@ function concreteMethod(resolved, defaultCacheMethod) {
|
|
|
51
88
|
// state keys of its dependencies, recursively. This is derived purely from the
|
|
52
89
|
// work tree and the filesystem, so it does not depend on scheduler/run state —
|
|
53
90
|
// important because it runs before dependencies are awaited.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return existing;
|
|
91
|
+
function resolveEffectiveStateKey(item, defaultCacheMethod, environment, memo, path) {
|
|
92
|
+
if (path.has(item.id())) {
|
|
93
|
+
return Promise.resolve(LOOP);
|
|
58
94
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
95
|
+
return memoized(memo, item.id(), async () => {
|
|
96
|
+
const { stateKey, provable } = await computeStateKey(item, defaultCacheMethod, environment, memo, path);
|
|
97
|
+
return { stateKey, provable };
|
|
98
|
+
});
|
|
63
99
|
}
|
|
64
100
|
// Compute the combined state key for a single item together with the source
|
|
65
101
|
// stats it was derived from, sharing one filesystem walk with callers that also
|
|
66
102
|
// need the stats (the scheduler, the explain engine).
|
|
67
|
-
async function computeStateKey(item, defaultCacheMethod, environment, memo = new Map()
|
|
103
|
+
async function computeStateKey(item, defaultCacheMethod, environment, memo = new Map(),
|
|
104
|
+
// the items being computed on the way here, see LOOP
|
|
105
|
+
parentPath = new Set()) {
|
|
106
|
+
const path = new Set(parentPath).add(item.id());
|
|
68
107
|
const resolved = resolveEffective(item, defaultCacheMethod);
|
|
69
108
|
const { stats, unmatched } = await (0, get_work_cache_stats_1.getWorkItemCacheStats)(item, environment);
|
|
70
109
|
const ownKey = (0, get_work_cache_stats_1.getStateKey)(stats, concreteMethod(resolved, defaultCacheMethod));
|
|
71
110
|
const depKeys = [];
|
|
72
111
|
let provable = isOwnProvable(item, unmatched);
|
|
73
112
|
for (const dep of item.deps) {
|
|
74
|
-
const effective = await resolveEffectiveStateKey(dep, defaultCacheMethod, environment, memo);
|
|
113
|
+
const effective = await resolveEffectiveStateKey(dep, defaultCacheMethod, environment, memo, path);
|
|
75
114
|
depKeys.push(effective.stateKey);
|
|
76
115
|
provable = provable && effective.provable;
|
|
77
116
|
}
|
|
78
117
|
// what a task that needs a service passed against: the sources of the service and of the
|
|
79
118
|
// tasks it depends on (its definition is in the task id, getWorkServiceCacheIdentity)
|
|
80
119
|
for (const need of item.needs) {
|
|
81
|
-
const effective = await resolveNeedStateKey(need.service, defaultCacheMethod, environment, memo);
|
|
120
|
+
const effective = await resolveNeedStateKey(need.service, defaultCacheMethod, environment, memo, path);
|
|
82
121
|
depKeys.push(`${need.name}=${effective.stateKey}`);
|
|
83
122
|
}
|
|
84
123
|
return { stateKey: combineStateKeys(ownKey, depKeys), stats, resolved, provable, unmatched };
|
|
@@ -87,29 +126,27 @@ exports.computeStateKey = computeStateKey;
|
|
|
87
126
|
// A needed service's sources folded with the state keys of its dependencies and needs. It
|
|
88
127
|
// does not make the task that needs it unprovable: a dependency without `src` (resetting the
|
|
89
128
|
// service's data, say) is skipped with the service when the task is a cache hit.
|
|
90
|
-
|
|
129
|
+
function resolveNeedStateKey(service, defaultCacheMethod, environment, memo, parentPath) {
|
|
91
130
|
const memoKey = `need\0${service.name}`;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return existing;
|
|
95
|
-
}
|
|
96
|
-
// services that need each other in a loop fail to plan (checkForLoop): this only has to end
|
|
97
|
-
memo.set(memoKey, { stateKey: 'loop', provable: true });
|
|
98
|
-
const resolved = resolveEffective(service, defaultCacheMethod);
|
|
99
|
-
const { stats } = await (0, get_work_cache_stats_1.getWorkItemCacheStats)(service, environment);
|
|
100
|
-
const keys = [];
|
|
101
|
-
for (const dep of service.deps) {
|
|
102
|
-
keys.push((await resolveEffectiveStateKey(dep, defaultCacheMethod, environment, memo)).stateKey);
|
|
103
|
-
}
|
|
104
|
-
for (const need of service.needs) {
|
|
105
|
-
const effective = await resolveNeedStateKey(need.service, defaultCacheMethod, environment, memo);
|
|
106
|
-
keys.push(`${need.name}=${effective.stateKey}`);
|
|
131
|
+
if (parentPath.has(memoKey)) {
|
|
132
|
+
return Promise.resolve(LOOP);
|
|
107
133
|
}
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
const path = new Set(parentPath).add(memoKey);
|
|
135
|
+
return memoized(memo, memoKey, async () => {
|
|
136
|
+
const resolved = resolveEffective(service, defaultCacheMethod);
|
|
137
|
+
const { stats } = await (0, get_work_cache_stats_1.getWorkItemCacheStats)(service, environment);
|
|
138
|
+
const keys = [];
|
|
139
|
+
for (const dep of service.deps) {
|
|
140
|
+
keys.push((await resolveEffectiveStateKey(dep, defaultCacheMethod, environment, memo, path)).stateKey);
|
|
141
|
+
}
|
|
142
|
+
for (const need of service.needs) {
|
|
143
|
+
const effective = await resolveNeedStateKey(need.service, defaultCacheMethod, environment, memo, path);
|
|
144
|
+
keys.push(`${need.name}=${effective.stateKey}`);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
stateKey: combineStateKeys((0, get_work_cache_stats_1.getStateKey)(stats, concreteMethod(resolved, defaultCacheMethod)), keys),
|
|
148
|
+
provable: true,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
114
151
|
}
|
|
115
152
|
//# sourceMappingURL=state-key.js.map
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.watchLoop = void 0;
|
|
3
|
+
exports.watchLoop = exports.getSharedStateKeys = exports.isWatchMode = void 0;
|
|
4
4
|
const watch_state_key_1 = require("./watch-state-key");
|
|
5
5
|
const state_1 = require("./state");
|
|
6
6
|
const abort_event_1 = require("../utils/abort-event");
|
|
7
7
|
const state_resolver_1 = require("./state-resolver");
|
|
8
8
|
const abort_1 = require("./abort");
|
|
9
9
|
const enqueue_next_1 = require("./scheduler/enqueue-next");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const state_key_1 = require("./scheduler/state-key");
|
|
11
|
+
// Whether an item is rechecked when its files change: not in daemon mode, and not for a
|
|
12
|
+
// container service that watches its own files (`continuous`); a kubernetes-service and a
|
|
13
|
+
// task have no such field
|
|
14
|
+
function isWatchMode(work, options) {
|
|
13
15
|
const continuous = 'continuous' in work.data ? work.data.continuous : false;
|
|
14
|
-
|
|
16
|
+
return !!options.watch && !options.daemon && !continuous;
|
|
17
|
+
}
|
|
18
|
+
exports.isWatchMode = isWatchMode;
|
|
19
|
+
// The keys of the execution to share, see getExecutionStateKeys: none in watch mode, where a
|
|
20
|
+
// key is computed again because files changed
|
|
21
|
+
function getSharedStateKeys(work, options) {
|
|
22
|
+
return isWatchMode(work, options) ? undefined : (0, state_key_1.getExecutionStateKeys)(options);
|
|
23
|
+
}
|
|
24
|
+
exports.getSharedStateKeys = getSharedStateKeys;
|
|
25
|
+
async function watchLoop(work, environment, options, factory) {
|
|
26
|
+
const watchMode = isWatchMode(work, options);
|
|
15
27
|
const currentStats = await (0, enqueue_next_1.checkCacheState)(work, options.cacheDefault, environment, {
|
|
16
28
|
watch: watchMode,
|
|
17
29
|
restore: options.restore,
|
|
30
|
+
memo: getSharedStateKeys(work, options),
|
|
18
31
|
});
|
|
19
32
|
(0, abort_1.checkForAbort)(environment.abortCtrl.signal);
|
|
20
33
|
const watchState = watchMode
|
|
@@ -39,7 +39,11 @@ function getFileContext(cwd) {
|
|
|
39
39
|
resolve({ type: 'directory' });
|
|
40
40
|
}
|
|
41
41
|
else if (stats.isFile()) {
|
|
42
|
-
resolve({
|
|
42
|
+
resolve({
|
|
43
|
+
type: 'file',
|
|
44
|
+
lastModified: stats.mtimeMs,
|
|
45
|
+
identity: { size: stats.size, changed: stats.ctimeMs, inode: stats.ino },
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
else {
|
|
45
49
|
resolve({ type: 'other' });
|
|
@@ -6,6 +6,7 @@ const abort_event_1 = require("../utils/abort-event");
|
|
|
6
6
|
const apply_1 = require("./apply");
|
|
7
7
|
const sleep_1 = require("../utils/sleep");
|
|
8
8
|
const cluster_state_1 = require("./cluster-state");
|
|
9
|
+
const quota_wait_1 = require("./quota-wait");
|
|
9
10
|
// The waits below poll instead of using the client's Watch: Watch aborts every
|
|
10
11
|
// request after 30s, which a pod or deployment still pulling its image outlasts.
|
|
11
12
|
async function awaitRunningState(instance, env, name, phase, pollInterval = 1000) {
|
|
@@ -22,11 +23,16 @@ async function awaitRunningState(instance, env, name, phase, pollInterval = 1000
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
exports.awaitRunningState = awaitRunningState;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
async function awaitJobCompletion(instance, env, name, abort, pollInterval = 1000, quota) {
|
|
27
|
+
const wait = quota
|
|
28
|
+
? new quota_wait_1.QuotaWait(instance, env, {
|
|
29
|
+
subject: `the pod of job ${name}`,
|
|
30
|
+
timeout: quota.timeout,
|
|
31
|
+
onWaiting: quota.onWaiting,
|
|
32
|
+
})
|
|
33
|
+
: null;
|
|
34
|
+
// when the job last had a pod: a refusal before it is not one of the pod it waits for now
|
|
35
|
+
let hadPod = 0;
|
|
30
36
|
for (;;) {
|
|
31
37
|
if (abort.aborted) {
|
|
32
38
|
await deleteJob(instance, env, name);
|
|
@@ -41,10 +47,50 @@ async function awaitJobCompletion(instance, env, name, abort, pollInterval = 100
|
|
|
41
47
|
if (failed) {
|
|
42
48
|
throw new Error(`job ${name} failed: ${failed.message ?? failed.reason ?? 'unknown reason'}`);
|
|
43
49
|
}
|
|
50
|
+
if (wait) {
|
|
51
|
+
let refusal = null;
|
|
52
|
+
if (status?.active || status?.ready) {
|
|
53
|
+
hadPod = Date.now();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// the job controller can't make the pod: no pod to wait on, only its events say why
|
|
57
|
+
refusal = await readJobRefusal(instance, env, name, job, hadPod);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
await wait.check(refusal);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
await deleteJob(instance, env, name);
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
44
67
|
await sleep(pollInterval, abort);
|
|
45
68
|
}
|
|
46
69
|
}
|
|
47
70
|
exports.awaitJobCompletion = awaitJobCompletion;
|
|
71
|
+
// The last `FailedCreate` of the job for its quota after `after`. Events the server may not list
|
|
72
|
+
// leave the wait as it was.
|
|
73
|
+
async function readJobRefusal(instance, env, name, job, after) {
|
|
74
|
+
try {
|
|
75
|
+
const events = await instance.coreApi.listNamespacedEvent({
|
|
76
|
+
namespace: env.namespace,
|
|
77
|
+
fieldSelector: `involvedObject.kind=Job,involvedObject.name=${name},reason=FailedCreate`,
|
|
78
|
+
});
|
|
79
|
+
const uid = job.metadata?.uid;
|
|
80
|
+
const latest = events.items
|
|
81
|
+
.filter((event) => !uid || !event.involvedObject?.uid || event.involvedObject.uid === uid)
|
|
82
|
+
.filter((event) => eventTime(event) > after && (0, quota_wait_1.getQuotaRefusal)(event.message))
|
|
83
|
+
.sort((a, b) => eventTime(b) - eventTime(a))[0];
|
|
84
|
+
return (0, quota_wait_1.getQuotaRefusal)(latest?.message);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function eventTime(event) {
|
|
91
|
+
const at = event.lastTimestamp ?? event.eventTime ?? event.firstTimestamp ?? event.metadata?.creationTimestamp;
|
|
92
|
+
return at ? new Date(at).getTime() : 0;
|
|
93
|
+
}
|
|
48
94
|
function sleep(ms, abort) {
|
|
49
95
|
if (abort.aborted) {
|
|
50
96
|
return Promise.resolve();
|
|
@@ -77,6 +123,20 @@ async function deleteJob(instance, env, name) {
|
|
|
77
123
|
}
|
|
78
124
|
}
|
|
79
125
|
exports.deleteJob = deleteJob;
|
|
126
|
+
// The Deployment says when its ReplicaSet can't make a pod: `ReplicaFailure`, `FailedCreate`.
|
|
127
|
+
function getDeploymentRefusal(deployment) {
|
|
128
|
+
const failure = deployment.status?.conditions?.find((condition) => condition.type === 'ReplicaFailure' && condition.status === 'True');
|
|
129
|
+
return (0, quota_wait_1.getQuotaRefusal)(failure?.message);
|
|
130
|
+
}
|
|
131
|
+
function getDeployQuotaWait(instance, env, name, readiness, now) {
|
|
132
|
+
return new quota_wait_1.QuotaWait(instance, env, {
|
|
133
|
+
subject: readiness.subject ?? name,
|
|
134
|
+
// without a limit of its own it waits as long as the run does
|
|
135
|
+
timeout: readiness.quotaTimeout ?? Number.POSITIVE_INFINITY,
|
|
136
|
+
onWaiting: (text) => readiness.onWaiting?.(text),
|
|
137
|
+
now,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
80
140
|
// how long a reason that may still pass (an image pull a registry refused for now, a
|
|
81
141
|
// container the runtime could not create) may last before it fails the service
|
|
82
142
|
exports.PASSING_FAILURE_MS = 60000;
|
|
@@ -96,12 +156,14 @@ async function awaitDeployRunningState(instance, env, name, readiness, pollInter
|
|
|
96
156
|
let said;
|
|
97
157
|
// since when a pod has had a failure that may still pass, by pod
|
|
98
158
|
const failingSince = new Map();
|
|
159
|
+
const quota = getDeployQuotaWait(instance, env, name, readiness, now);
|
|
99
160
|
for (;;) {
|
|
100
161
|
const deployment = await instance.appsApi.readNamespacedDeployment({ name, namespace: env.namespace });
|
|
101
162
|
// available: ready for the Deployment's minReadySeconds
|
|
102
163
|
if ((deployment.status?.availableReplicas ?? 0) > 0) {
|
|
103
164
|
return;
|
|
104
165
|
}
|
|
166
|
+
await quota.check(getDeploymentRefusal(deployment));
|
|
105
167
|
const created = deployment.metadata?.creationTimestamp;
|
|
106
168
|
const listed = await instance.coreApi.listNamespacedPod({
|
|
107
169
|
namespace: env.namespace,
|
|
@@ -163,6 +225,7 @@ async function awaitDeployRollout(instance, env, name, readiness, pollInterval =
|
|
|
163
225
|
let runningSince = null;
|
|
164
226
|
let said;
|
|
165
227
|
const failingSince = new Map();
|
|
228
|
+
const quota = getDeployQuotaWait(instance, env, name, readiness, now);
|
|
166
229
|
for (;;) {
|
|
167
230
|
if (readiness.signal?.aborted) {
|
|
168
231
|
throw new abort_1.AbortError();
|
|
@@ -179,6 +242,7 @@ async function awaitDeployRollout(instance, env, name, readiness, pollInterval =
|
|
|
179
242
|
if (stalled && (status?.observedGeneration ?? 0) >= readiness.generation) {
|
|
180
243
|
throw new Error(`${timeoutMessage}: ${stalled.message ?? 'its rollout made no progress'}`);
|
|
181
244
|
}
|
|
245
|
+
await quota.check(getDeploymentRefusal(deployment));
|
|
182
246
|
const listed = await instance.coreApi.listNamespacedPod({
|
|
183
247
|
namespace: env.namespace,
|
|
184
248
|
labelSelector: readiness.podSelector,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasOutputsFlatteningAlike = exports.hasPathsEndingAlike = exports.byDepth = exports.getClaimSubPath = void 0;
|
|
3
|
+
exports.hasOutputsFlatteningAlike = exports.hasPathsEndingAlike = exports.byDepth = exports.getInheritedSourceSubPath = exports.getClaimSubPath = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const portable_path_1 = require("../planner/utils/portable-path");
|
|
@@ -45,6 +45,15 @@ function getClaimSubPath(work, path) {
|
|
|
45
45
|
return `${name}-${(0, crypto_1.createHash)('sha256').update(own).digest('hex').slice(0, 12)}`;
|
|
46
46
|
}
|
|
47
47
|
exports.getClaimSubPath = getClaimSubPath;
|
|
48
|
+
// Where a src of one of its deps is in the claim of `work`: always with the hash of its
|
|
49
|
+
// path, so it is apart from the paths of the task itself, which getClaimSubPath names
|
|
50
|
+
// without looking at them (they are not part of the task's id, see claimLayout), and from
|
|
51
|
+
// the other srcs of its deps (`package.json` and `core/package.json` of an `npm ci`)
|
|
52
|
+
function getInheritedSourceSubPath(work, path) {
|
|
53
|
+
const name = (0, path_1.basename)(path) || 'root';
|
|
54
|
+
return `${name}-${(0, crypto_1.createHash)('sha256').update((0, portable_path_1.portablePath)(work.data.projectRoot, path)).digest('hex').slice(0, 12)}`;
|
|
55
|
+
}
|
|
56
|
+
exports.getInheritedSourceSubPath = getInheritedSourceSubPath;
|
|
48
57
|
function byDepth(a, b) {
|
|
49
58
|
return a.split('/').length - b.split('/').length || (a < b ? -1 : a > b ? 1 : 0);
|
|
50
59
|
}
|
|
@@ -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.DEFINITION_LABEL = void 0;
|
|
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;
|
|
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");
|
|
@@ -17,10 +17,15 @@ const job_placement_1 = require("./job-placement");
|
|
|
17
17
|
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
|
+
const quota_wait_1 = require("./quota-wait");
|
|
20
21
|
// what the service was created from, to tell a changed one
|
|
21
22
|
exports.DEFINITION_LABEL = 'hammerkit.dev/definition';
|
|
22
23
|
// how often a starting container is checked: as the liveness probe
|
|
23
24
|
const STARTUP_PERIOD_SECONDS = 5;
|
|
25
|
+
exports.DEBUG_CONTAINER_RESOURCES = {
|
|
26
|
+
requests: { cpu: '10m', memory: '16Mi' },
|
|
27
|
+
limits: { cpu: '100m', memory: '256Mi' },
|
|
28
|
+
};
|
|
24
29
|
async function ensureKubernetesDeploymentExists(instance, env, service, persistence, secrets, stateKey,
|
|
25
30
|
// the needed services by name, and the proxy of a limited network
|
|
26
31
|
network,
|
|
@@ -131,6 +136,9 @@ rollout = {}) {
|
|
|
131
136
|
command: ['sleep'],
|
|
132
137
|
args: ['3600'],
|
|
133
138
|
volumeMounts: persistence.mounts.map((m) => m.mount),
|
|
139
|
+
// a shell to look at the service's files: without a size of its own it would get
|
|
140
|
+
// the namespace's default, and count as much against its quota as the service
|
|
141
|
+
resources: exports.DEBUG_CONTAINER_RESOURCES,
|
|
134
142
|
...(0, job_placement_1.getContainerSecurity)(env),
|
|
135
143
|
},
|
|
136
144
|
],
|
|
@@ -149,6 +157,7 @@ rollout = {}) {
|
|
|
149
157
|
subject: `service ${service.name}`,
|
|
150
158
|
onWaiting: (text) => service.status.write('warn', `${service.name} ${text}`),
|
|
151
159
|
...(service.data.restarts !== null ? { restarts: service.data.restarts } : {}),
|
|
160
|
+
quotaTimeout: quota_wait_1.QUOTA_TIMEOUT,
|
|
152
161
|
};
|
|
153
162
|
if (env.server?.serviceRun) {
|
|
154
163
|
await rollOut(instance, env, service, deployment, readiness, rollout);
|