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
|
@@ -31,7 +31,7 @@ exports.hostServerSchema = zod_1.z
|
|
|
31
31
|
.strict();
|
|
32
32
|
// A command that prints the token for a server instead of a login, see token-source.ts.
|
|
33
33
|
// It is bound to the url and issuer it was registered for, like a sign-in, and lives
|
|
34
|
-
// beside `servers` rather than in it: hammerkit before
|
|
34
|
+
// beside `servers` rather than in it: hammerkit before 2.0 refuses unknown keys of a
|
|
35
35
|
// server, but keeps unknown top-level keys. It is only ever read from the host config,
|
|
36
36
|
// a build file can't name one.
|
|
37
37
|
const tokenCommandSchema = zod_1.z
|
|
@@ -221,7 +221,7 @@ function registerWorkCommands(remote, context) {
|
|
|
221
221
|
}
|
|
222
222
|
return { version, proposed };
|
|
223
223
|
};
|
|
224
|
-
// what publishing the bundle would do, undefined from a server that can't say (before
|
|
224
|
+
// what publishing the bundle would do, undefined from a server that can't say (before 2.0)
|
|
225
225
|
const planBundle = async (server, token, bundle) => {
|
|
226
226
|
try {
|
|
227
227
|
return (await (0, server_client_1.callServer)(server, token, 'POST', '/v1/definitions/plan', bundle)).body;
|
|
@@ -271,7 +271,7 @@ function registerWorkCommands(remote, context) {
|
|
|
271
271
|
if (!environment.prompt) {
|
|
272
272
|
throw new Error(`${notPublished}, publish it first with: hammerkit remote publish ${serverName}, or pass --publish`);
|
|
273
273
|
}
|
|
274
|
-
// a server before
|
|
274
|
+
// a server before 2.0 can't say what publishing would do: it is asked all the same,
|
|
275
275
|
// and refuses then what the caller may not do
|
|
276
276
|
const planned = await planBundle(server, token, local);
|
|
277
277
|
if (planned && planned.outcome === null) {
|
|
@@ -322,7 +322,7 @@ function registerWorkCommands(remote, context) {
|
|
|
322
322
|
const { name: serverName, server, token } = await connect(name);
|
|
323
323
|
const answer = await (0, server_client_1.callServer)(server, token, 'POST', '/v1/definitions/plan', bundle).catch((e) => {
|
|
324
324
|
throw e instanceof server_client_1.ServerError && e.status === 404
|
|
325
|
-
? new Error(`${serverName} can't check a build file without publishing it, it needs hammerkit
|
|
325
|
+
? new Error(`${serverName} can't check a build file without publishing it, it needs hammerkit 2.0`)
|
|
326
326
|
: e;
|
|
327
327
|
});
|
|
328
328
|
const planned = answer.body;
|
|
@@ -519,16 +519,25 @@ function registerWorkCommands(remote, context) {
|
|
|
519
519
|
.command('tasks [server]')
|
|
520
520
|
.description('show what the past runs of each task took, over the runs the server keeps: how often it ran, failed and came from the cache, the median and 90th percentile of its time, and how long its runs waited for a place')
|
|
521
521
|
.addOption(new commander_1.Option('--mine', 'only your runs'))
|
|
522
|
+
.addOption(new commander_1.Option('--since <when>', 'only the runs created since then: back from now, such as 24h or 7d, or a time'))
|
|
523
|
+
.addOption(new commander_1.Option('--until <when>', 'only the runs created until then: back from now, or a time'))
|
|
522
524
|
.addOption(new commander_1.Option('--json', 'print it as the server answers it'))
|
|
523
525
|
.action(guarded('Remote tasks was not successful', async (name, options) => {
|
|
524
526
|
const { name: serverName, server, token } = await connect(name);
|
|
525
|
-
const
|
|
527
|
+
const query = new URLSearchParams({ scope: options.mine ? 'mine' : 'visible' });
|
|
528
|
+
if (options.since) {
|
|
529
|
+
query.set('since', options.since);
|
|
530
|
+
}
|
|
531
|
+
if (options.until) {
|
|
532
|
+
query.set('until', options.until);
|
|
533
|
+
}
|
|
534
|
+
const { tasks } = (await (0, server_client_1.callServer)(server, token, 'GET', `/v1/tasks?${query}`)).body;
|
|
526
535
|
if (options.json) {
|
|
527
536
|
environment.stdout.write(`${JSON.stringify(tasks, null, 2)}\n`);
|
|
528
537
|
return;
|
|
529
538
|
}
|
|
530
539
|
if (tasks.length === 0) {
|
|
531
|
-
environment.stdout.write(`${serverName}: no task ran in the runs it keeps\n`);
|
|
540
|
+
environment.stdout.write(`${serverName}: no task ran in the runs it keeps${options.since || options.until ? ' of that period' : ''}\n`);
|
|
532
541
|
return;
|
|
533
542
|
}
|
|
534
543
|
for (const line of (0, remote_status_1.describeTaskStats)(tasks)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appendBuildFile = exports.createParseContext = void 0;
|
|
3
|
+
exports.appendBuildFile = exports.MAX_BUILD_FILE_ITEMS = exports.MAX_BUILD_FILE_BYTES = exports.MAX_INCLUDE_INPUT_BYTES = exports.MAX_BUILD_FILES = exports.MAX_INCLUDE_DEPTH = exports.createParseContext = void 0;
|
|
4
4
|
const build_file_schema_1 = require("./build-file-schema");
|
|
5
5
|
const read_build_file_1 = require("../parser/read-build-file");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -20,6 +20,17 @@ async function createParseContext(fileName, environment, options) {
|
|
|
20
20
|
return { ctx, scope };
|
|
21
21
|
}
|
|
22
22
|
exports.createParseContext = createParseContext;
|
|
23
|
+
// How deep includes and references may nest, how many build files one parse may read (a
|
|
24
|
+
// file included with other inputs counts again), and how large the inputs one include
|
|
25
|
+
// passes on may be. A file that includes itself with inputs that change each time ends at
|
|
26
|
+
// these instead of reading on without end.
|
|
27
|
+
exports.MAX_INCLUDE_DEPTH = 32;
|
|
28
|
+
exports.MAX_BUILD_FILES = 1000;
|
|
29
|
+
exports.MAX_INCLUDE_INPUT_BYTES = 64 * 1024;
|
|
30
|
+
// What the build files of one parse may take together, and how many tasks and services they
|
|
31
|
+
// may declare, a file included again counted again.
|
|
32
|
+
exports.MAX_BUILD_FILE_BYTES = 16 * 1024 * 1024;
|
|
33
|
+
exports.MAX_BUILD_FILE_ITEMS = 10000;
|
|
23
34
|
async function appendBuildFile(cwd, ctx, environment, fileName, namePrefix, remote, inputs,
|
|
24
35
|
// on a server: the file is included with `publish: false`, or below such an include
|
|
25
36
|
leftOut = false) {
|
|
@@ -30,12 +41,26 @@ leftOut = false) {
|
|
|
30
41
|
if (ctx.files[key]) {
|
|
31
42
|
return ctx.files[key];
|
|
32
43
|
}
|
|
33
|
-
|
|
44
|
+
if (namePrefix.length > exports.MAX_INCLUDE_DEPTH) {
|
|
45
|
+
throw new Error(`${relativeName} (${fileName}) is included ${namePrefix.length} levels deep, at most ${exports.MAX_INCLUDE_DEPTH} are read`);
|
|
46
|
+
}
|
|
47
|
+
if (Object.keys(ctx.files).length >= exports.MAX_BUILD_FILES) {
|
|
48
|
+
throw new Error(`${relativeName} (${fileName}): the build file includes more than ${exports.MAX_BUILD_FILES} files, counting a file included with other inputs again`);
|
|
49
|
+
}
|
|
50
|
+
if (inputs && Buffer.byteLength(JSON.stringify(inputs), 'utf8') > exports.MAX_INCLUDE_INPUT_BYTES) {
|
|
51
|
+
throw new Error(`${relativeName} (${fileName}): the inputs passed to it take more than ${exports.MAX_INCLUDE_INPUT_BYTES} bytes`);
|
|
52
|
+
}
|
|
53
|
+
const input = await readCounted(ctx, fileName, environment, relativeName);
|
|
34
54
|
(0, removed_properties_1.assertNoRemovedProperties)(input, fileName);
|
|
35
55
|
const result = await build_file_schema_1.buildFileSchema.safeParseAsync(input);
|
|
36
56
|
if (!result.success) {
|
|
37
57
|
throw new parse_error_1.ParseError(result.error, fileName);
|
|
38
58
|
}
|
|
59
|
+
const read = readOf(ctx);
|
|
60
|
+
read.items += Object.keys(result.data.tasks ?? {}).length + Object.keys(result.data.services ?? {}).length;
|
|
61
|
+
if (read.items > exports.MAX_BUILD_FILE_ITEMS) {
|
|
62
|
+
throw new Error(`${relativeName} (${fileName}): the build file declares more than ${exports.MAX_BUILD_FILE_ITEMS} tasks and services, counting a file included with other inputs again`);
|
|
63
|
+
}
|
|
39
64
|
const scope = {
|
|
40
65
|
fileName,
|
|
41
66
|
cwd,
|
|
@@ -77,6 +102,25 @@ leftOut = false) {
|
|
|
77
102
|
return scope;
|
|
78
103
|
}
|
|
79
104
|
exports.appendBuildFile = appendBuildFile;
|
|
105
|
+
// A build file, parsed once per parse and counted each time it is read.
|
|
106
|
+
async function readCounted(ctx, fileName, environment, relativeName) {
|
|
107
|
+
const read = readOf(ctx);
|
|
108
|
+
let parsed = read.parsed.get(fileName);
|
|
109
|
+
if (!parsed) {
|
|
110
|
+
parsed = await (0, read_build_file_1.readSized)(fileName, environment);
|
|
111
|
+
read.parsed.set(fileName, parsed);
|
|
112
|
+
}
|
|
113
|
+
read.bytes += parsed.bytes;
|
|
114
|
+
if (read.bytes > exports.MAX_BUILD_FILE_BYTES) {
|
|
115
|
+
throw new Error(`${relativeName} (${fileName}): the build file includes more than ${exports.MAX_BUILD_FILE_BYTES} bytes of build files, counting a file included with other inputs again`);
|
|
116
|
+
}
|
|
117
|
+
// every scope gets a value of its own
|
|
118
|
+
return structuredClone(parsed.value);
|
|
119
|
+
}
|
|
120
|
+
function readOf(ctx) {
|
|
121
|
+
ctx.read ?? (ctx.read = { bytes: 0, items: 0, parsed: new Map() });
|
|
122
|
+
return ctx.read;
|
|
123
|
+
}
|
|
80
124
|
// The scope of a git source a server does not fetch, see ParseScope.notFetched
|
|
81
125
|
function notFetched(cwd, namePrefix, include) {
|
|
82
126
|
return {
|
package/dist/server/capacity.js
CHANGED
|
@@ -4,41 +4,11 @@ exports.formatMemory = exports.formatCpu = exports.HostCapacity = exports.Kubern
|
|
|
4
4
|
const os_1 = require("os");
|
|
5
5
|
const log_1 = require("../log");
|
|
6
6
|
const apply_1 = require("../kubernetes/apply");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
k: 1e3,
|
|
13
|
-
K: 1e3,
|
|
14
|
-
M: 1e6,
|
|
15
|
-
G: 1e9,
|
|
16
|
-
T: 1e12,
|
|
17
|
-
P: 1e15,
|
|
18
|
-
E: 1e18,
|
|
19
|
-
Ki: 1024,
|
|
20
|
-
Mi: 1024 ** 2,
|
|
21
|
-
Gi: 1024 ** 3,
|
|
22
|
-
Ti: 1024 ** 4,
|
|
23
|
-
Pi: 1024 ** 5,
|
|
24
|
-
Ei: 1024 ** 6,
|
|
25
|
-
};
|
|
26
|
-
// A quantity of Kubernetes (`250m`, `1.5`, `512Mi`, `12345678n`, `1e3`), as a number.
|
|
27
|
-
function parseQuantity(value) {
|
|
28
|
-
if (value === undefined) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === 'number') {
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
const match = /^([+-]?[0-9.]+(?:[eE][+-]?\d+)?)([a-zA-Z]*)$/.exec(value.trim());
|
|
35
|
-
if (!match || !(match[2] in UNITS)) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
const number = Number(match[1]);
|
|
39
|
-
return Number.isFinite(number) ? number * UNITS[match[2]] : undefined;
|
|
40
|
-
}
|
|
41
|
-
exports.parseQuantity = parseQuantity;
|
|
7
|
+
const job_placement_1 = require("../kubernetes/job-placement");
|
|
8
|
+
const volumes_1 = require("../kubernetes/volumes");
|
|
9
|
+
const network_policy_1 = require("../kubernetes/network-policy");
|
|
10
|
+
const units_1 = require("../utils/units");
|
|
11
|
+
Object.defineProperty(exports, "parseQuantity", { enumerable: true, get: function () { return units_1.parseQuantity; } });
|
|
42
12
|
function add(into, cpu, memory) {
|
|
43
13
|
if (cpu !== undefined) {
|
|
44
14
|
into.cpu = (into.cpu ?? 0) + cpu;
|
|
@@ -90,6 +60,17 @@ function why(what, e, rule) {
|
|
|
90
60
|
}
|
|
91
61
|
return `${what}: ${(0, log_1.getErrorMessage)(e)}`;
|
|
92
62
|
}
|
|
63
|
+
// `why`, in a few words
|
|
64
|
+
function briefly(e, what) {
|
|
65
|
+
const code = (0, apply_1.statusCodeOf)(e);
|
|
66
|
+
if (code === 403) {
|
|
67
|
+
return what === 'nodes' ? 'may not list nodes' : 'may not read metrics';
|
|
68
|
+
}
|
|
69
|
+
if (code === 404 && what === 'metrics') {
|
|
70
|
+
return 'no metrics API';
|
|
71
|
+
}
|
|
72
|
+
return what === 'nodes' ? 'nodes not readable' : 'metrics not readable';
|
|
73
|
+
}
|
|
93
74
|
const ENDED = ['Succeeded', 'Failed'];
|
|
94
75
|
// On Kubernetes: per namespace of the server, its pods' requests, its quota and its usage.
|
|
95
76
|
class KubernetesCapacity {
|
|
@@ -107,6 +88,37 @@ class KubernetesCapacity {
|
|
|
107
88
|
catch (e) {
|
|
108
89
|
problems.push(why('the namespaces of the server', e));
|
|
109
90
|
}
|
|
91
|
+
const unknown = {};
|
|
92
|
+
// the runs by the value of their label, and what the pods of each run or sandbox take
|
|
93
|
+
const byLabel = new Map(runs.map((run) => [(0, job_placement_1.getRunLabelValue)(run.id), run]));
|
|
94
|
+
const uses = new Map();
|
|
95
|
+
const useOf = (namespace, labels, owner) => {
|
|
96
|
+
const run = byLabel.get(labels?.[job_placement_1.RUN_LABEL] ?? '');
|
|
97
|
+
const sandbox = labels?.[volumes_1.SANDBOX_LABEL] ?? labels?.[network_policy_1.PROXY_OF_SANDBOX_LABEL];
|
|
98
|
+
const key = run ? `run ${run.id}` : sandbox ? `sandbox ${sandbox}` : `other ${namespace}`;
|
|
99
|
+
let use = uses.get(key);
|
|
100
|
+
if (!use) {
|
|
101
|
+
use = run
|
|
102
|
+
? {
|
|
103
|
+
kind: 'run',
|
|
104
|
+
run: run.id,
|
|
105
|
+
tasks: run.tasks,
|
|
106
|
+
...(run.up ? { up: { name: run.up.name, services: run.up.services } } : {}),
|
|
107
|
+
repo: run.source.type === 'upload' ? 'an upload' : run.source.repo,
|
|
108
|
+
owner: { iss: run.owner.iss, sub: run.owner.sub, ...(run.owner.name ? { name: run.owner.name } : {}) },
|
|
109
|
+
pods: 0,
|
|
110
|
+
requested: { cpu: 0, memory: 0 },
|
|
111
|
+
}
|
|
112
|
+
: {
|
|
113
|
+
kind: sandbox ? 'sandbox' : 'other',
|
|
114
|
+
...(owner ? { owner } : {}),
|
|
115
|
+
pods: 0,
|
|
116
|
+
requested: { cpu: 0, memory: 0 },
|
|
117
|
+
};
|
|
118
|
+
uses.set(key, use);
|
|
119
|
+
}
|
|
120
|
+
return use;
|
|
121
|
+
};
|
|
110
122
|
const said = new Set();
|
|
111
123
|
const once = (text) => {
|
|
112
124
|
if (!said.has(text)) {
|
|
@@ -123,6 +135,8 @@ class KubernetesCapacity {
|
|
|
123
135
|
// a namespace whose pods could be listed and that has none asks for nothing
|
|
124
136
|
requested: { cpu: 0, memory: 0 },
|
|
125
137
|
};
|
|
138
|
+
// the use of each pod that runs, by its name
|
|
139
|
+
const usesOfPods = new Map();
|
|
126
140
|
try {
|
|
127
141
|
const pods = await this.instance.coreApi.listNamespacedPod({ namespace });
|
|
128
142
|
for (const pod of pods.items) {
|
|
@@ -130,9 +144,13 @@ class KubernetesCapacity {
|
|
|
130
144
|
continue;
|
|
131
145
|
}
|
|
132
146
|
group.pods++;
|
|
147
|
+
const use = useOf(namespace, pod.metadata?.labels, group.owner);
|
|
148
|
+
usesOfPods.set(pod.metadata?.name ?? '', use);
|
|
149
|
+
use.pods++;
|
|
133
150
|
for (const container of pod.spec?.containers ?? []) {
|
|
134
151
|
const requests = container.resources?.requests ?? {};
|
|
135
|
-
add(group.requested, parseQuantity(requests.cpu) ?? 0, parseQuantity(requests.memory) ?? 0);
|
|
152
|
+
add(group.requested, (0, units_1.parseQuantity)(requests.cpu) ?? 0, (0, units_1.parseQuantity)(requests.memory) ?? 0);
|
|
153
|
+
add(use.requested, (0, units_1.parseQuantity)(requests.cpu) ?? 0, (0, units_1.parseQuantity)(requests.memory) ?? 0);
|
|
136
154
|
}
|
|
137
155
|
}
|
|
138
156
|
}
|
|
@@ -145,8 +163,8 @@ class KubernetesCapacity {
|
|
|
145
163
|
namespace,
|
|
146
164
|
});
|
|
147
165
|
const hard = quota.spec?.hard ?? {};
|
|
148
|
-
const cpu = parseQuantity(hard['requests.cpu'] ?? hard.cpu);
|
|
149
|
-
const memory = parseQuantity(hard['requests.memory'] ?? hard.memory);
|
|
166
|
+
const cpu = (0, units_1.parseQuantity)(hard['requests.cpu'] ?? hard.cpu);
|
|
167
|
+
const memory = (0, units_1.parseQuantity)(hard['requests.memory'] ?? hard.memory);
|
|
150
168
|
if (cpu !== undefined || memory !== undefined) {
|
|
151
169
|
group.quota = { ...(cpu !== undefined ? { cpu } : {}), ...(memory !== undefined ? { memory } : {}) };
|
|
152
170
|
}
|
|
@@ -162,13 +180,19 @@ class KubernetesCapacity {
|
|
|
162
180
|
const metrics = await this.instance.metrics.getPodMetrics(namespace);
|
|
163
181
|
const used = { cpu: 0, memory: 0 };
|
|
164
182
|
for (const pod of metrics.items) {
|
|
183
|
+
const use = usesOfPods.get(pod.metadata?.name ?? '');
|
|
165
184
|
for (const container of pod.containers) {
|
|
166
|
-
add(used, parseQuantity(container.usage.cpu), parseQuantity(container.usage.memory));
|
|
185
|
+
add(used, (0, units_1.parseQuantity)(container.usage.cpu), (0, units_1.parseQuantity)(container.usage.memory));
|
|
186
|
+
if (use) {
|
|
187
|
+
use.used ?? (use.used = { cpu: 0, memory: 0 });
|
|
188
|
+
add(use.used, (0, units_1.parseQuantity)(container.usage.cpu), (0, units_1.parseQuantity)(container.usage.memory));
|
|
189
|
+
}
|
|
167
190
|
}
|
|
168
191
|
}
|
|
169
192
|
group.used = used;
|
|
170
193
|
}
|
|
171
194
|
catch (e) {
|
|
195
|
+
unknown.used ?? (unknown.used = briefly(e, 'metrics'));
|
|
172
196
|
once(why('what the pods use (metrics)', e, 'list on pods.metrics.k8s.io in them (runRole, see the backend docs)'));
|
|
173
197
|
}
|
|
174
198
|
}
|
|
@@ -191,7 +215,7 @@ class KubernetesCapacity {
|
|
|
191
215
|
const allocatable = {};
|
|
192
216
|
for (const node of nodes.items) {
|
|
193
217
|
const of = node.status?.allocatable ?? {};
|
|
194
|
-
add(allocatable, parseQuantity(of.cpu), parseQuantity(of.memory));
|
|
218
|
+
add(allocatable, (0, units_1.parseQuantity)(of.cpu), (0, units_1.parseQuantity)(of.memory));
|
|
195
219
|
}
|
|
196
220
|
machines = { count: nodes.items.length, allocatable };
|
|
197
221
|
if (this.instance.metrics) {
|
|
@@ -199,16 +223,18 @@ class KubernetesCapacity {
|
|
|
199
223
|
const metrics = await this.instance.metrics.getNodeMetrics();
|
|
200
224
|
const nodesUsed = {};
|
|
201
225
|
for (const node of metrics.items) {
|
|
202
|
-
add(nodesUsed, parseQuantity(node.usage.cpu), parseQuantity(node.usage.memory));
|
|
226
|
+
add(nodesUsed, (0, units_1.parseQuantity)(node.usage.cpu), (0, units_1.parseQuantity)(node.usage.memory));
|
|
203
227
|
}
|
|
204
228
|
machines.used = nodesUsed;
|
|
205
229
|
}
|
|
206
230
|
catch (e) {
|
|
231
|
+
unknown.used ?? (unknown.used = briefly(e, 'metrics'));
|
|
207
232
|
once(why('what the nodes use (metrics)', e, 'list on nodes.metrics.k8s.io (see the backend docs)'));
|
|
208
233
|
}
|
|
209
234
|
}
|
|
210
235
|
}
|
|
211
236
|
catch (e) {
|
|
237
|
+
unknown.total = briefly(e, 'nodes');
|
|
212
238
|
// listing nodes is optional, and many clusters do not let a workload do it
|
|
213
239
|
if ((0, apply_1.statusCodeOf)(e) === 403) {
|
|
214
240
|
once('the nodes: not shown, the server may not list nodes (optional, see the backend docs)');
|
|
@@ -223,7 +249,11 @@ class KubernetesCapacity {
|
|
|
223
249
|
...(machines ? { machines } : {}),
|
|
224
250
|
runs: total,
|
|
225
251
|
groups,
|
|
252
|
+
uses: [...uses.values()].sort((a, b) => (b.used?.cpu ?? 0) - (a.used?.cpu ?? 0) ||
|
|
253
|
+
(b.requested.cpu ?? 0) - (a.requested.cpu ?? 0) ||
|
|
254
|
+
(b.requested.memory ?? 0) - (a.requested.memory ?? 0)),
|
|
226
255
|
problems,
|
|
256
|
+
...(Object.keys(unknown).length > 0 ? { unknown } : {}),
|
|
227
257
|
};
|
|
228
258
|
}
|
|
229
259
|
}
|
package/dist/server/dashboard.js
CHANGED
|
@@ -5,12 +5,14 @@ const crypto_1 = require("crypto");
|
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const http_1 = require("./http");
|
|
8
|
+
const oauth_1 = require("./oauth");
|
|
8
9
|
const policy_1 = require("./policy");
|
|
9
10
|
const overview_1 = require("./overview");
|
|
10
11
|
// Approving and publishing take a sign-in of the last minutes: the groups of a session are
|
|
11
12
|
// those of its sign-in, and somebody taken out of a group must not decide for hours.
|
|
12
13
|
exports.DECIDE_WITHIN_MS = 15 * 60000;
|
|
13
14
|
const RUN = 'run_[A-Za-z0-9_-]{16}';
|
|
15
|
+
const SANDBOX = 'sbx_[A-Za-z0-9_-]{16}';
|
|
14
16
|
// a hash of a build file version, checked by the API
|
|
15
17
|
const HASH = '[A-Za-z0-9:_-]{1,200}';
|
|
16
18
|
const path = (pattern) => new RegExp(`^/v1/${pattern}$`);
|
|
@@ -28,9 +30,19 @@ const READS = [
|
|
|
28
30
|
'proposals',
|
|
29
31
|
`proposals/${HASH}`,
|
|
30
32
|
`proposals/${HASH}/files`,
|
|
33
|
+
// the build files, and the page of the version a task or run ran
|
|
34
|
+
'definitions',
|
|
35
|
+
`definitions/${HASH}`,
|
|
36
|
+
`definitions/${HASH}/files`,
|
|
37
|
+
// the person's sandboxes and what changed in them; not their files, nothing that writes
|
|
38
|
+
'sandboxes',
|
|
39
|
+
`sandboxes/${SANDBOX}`,
|
|
40
|
+
`sandboxes/${SANDBOX}/changes`,
|
|
31
41
|
].map(path);
|
|
32
42
|
// what the buttons do
|
|
33
|
-
const ACTIONS = [`runs/${RUN}/(cancel|extend)`].map(path);
|
|
43
|
+
const ACTIONS = [`runs/${RUN}/(cancel|extend|wake)`].map(path);
|
|
44
|
+
// what the delete buttons remove: a sandbox of the person's
|
|
45
|
+
const REMOVALS = [`sandboxes/${SANDBOX}`].map(path);
|
|
34
46
|
// what needs a recent sign-in
|
|
35
47
|
const DECISIONS = [`approvals/${RUN}/(approve|reject)`, `proposals/${HASH}/(approve|reject)`].map(path);
|
|
36
48
|
exports.HEADERS = {
|
|
@@ -52,8 +64,8 @@ const TYPES = {
|
|
|
52
64
|
};
|
|
53
65
|
async function handleDashboard(context, principal, req, res, url) {
|
|
54
66
|
const now = context.now ?? Date.now;
|
|
55
|
-
const
|
|
56
|
-
const
|
|
67
|
+
const viewer = (0, overview_1.getViewer)(context.config, principal);
|
|
68
|
+
const { grant } = viewer;
|
|
57
69
|
const pathname = url.pathname;
|
|
58
70
|
for (const [name, value] of Object.entries(exports.HEADERS)) {
|
|
59
71
|
res.setHeader(name, value);
|
|
@@ -78,9 +90,11 @@ async function api(context, principal, viewer, now, req, res, url) {
|
|
|
78
90
|
if (method !== 'GET') {
|
|
79
91
|
return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow: 'GET' });
|
|
80
92
|
}
|
|
93
|
+
const name = (0, oauth_1.displayName)(principal);
|
|
81
94
|
const session = {
|
|
82
95
|
iss: principal.iss,
|
|
83
96
|
sub: principal.sub,
|
|
97
|
+
...(name ? { name } : {}),
|
|
84
98
|
observe: grant.observe,
|
|
85
99
|
seesOthers: grant.observe || (0, overview_1.seesActivity)(viewer),
|
|
86
100
|
publishes: (0, policy_1.mayPublish)(grant),
|
|
@@ -103,15 +117,19 @@ async function api(context, principal, viewer, now, req, res, url) {
|
|
|
103
117
|
const read = READS.some((pattern) => pattern.test(target));
|
|
104
118
|
const action = ACTIONS.some((pattern) => pattern.test(target));
|
|
105
119
|
const decision = DECISIONS.some((pattern) => pattern.test(target));
|
|
106
|
-
|
|
120
|
+
const removal = REMOVALS.some((pattern) => pattern.test(target));
|
|
121
|
+
if (!read && !action && !decision && !removal) {
|
|
107
122
|
return (0, http_1.send)(res, 404, { error: 'not found' });
|
|
108
123
|
}
|
|
124
|
+
const allow = [read ? 'GET' : '', action || decision ? 'POST' : '', removal ? 'DELETE' : '']
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.join(', ');
|
|
109
127
|
if (method === 'GET' || method === 'HEAD') {
|
|
110
128
|
if (!read) {
|
|
111
|
-
return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow
|
|
129
|
+
return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow });
|
|
112
130
|
}
|
|
113
131
|
}
|
|
114
|
-
else if (method === 'POST' && (action || decision)) {
|
|
132
|
+
else if ((method === 'POST' && (action || decision)) || (method === 'DELETE' && removal)) {
|
|
115
133
|
// a page of another site can not set the header, nor read the token
|
|
116
134
|
const given = Buffer.from(String(req.headers['x-hammerkit-csrf'] ?? ''));
|
|
117
135
|
const expected = Buffer.from(csrf);
|
|
@@ -128,7 +146,7 @@ async function api(context, principal, viewer, now, req, res, url) {
|
|
|
128
146
|
context.log(`dashboard ${method} ${target} iss=${principal.iss} sub=${principal.sub}`);
|
|
129
147
|
}
|
|
130
148
|
else {
|
|
131
|
-
return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow
|
|
149
|
+
return (0, http_1.send)(res, 405, { error: 'method not allowed' }, { allow });
|
|
132
150
|
}
|
|
133
151
|
const forwarded = new URL(`${target}${url.search}`, 'http://localhost');
|
|
134
152
|
return context.api(principal, req, res, forwarded);
|
|
@@ -165,8 +183,8 @@ async function asset(context, req, res, pathname) {
|
|
|
165
183
|
const root = context.assets ?? (0, path_1.join)(__dirname, '..', 'dashboard');
|
|
166
184
|
const file = /^\/assets\/[A-Za-z0-9_-][A-Za-z0-9._-]{0,200}$/.test(pathname)
|
|
167
185
|
? pathname.slice(1)
|
|
168
|
-
: pathname === '/
|
|
169
|
-
? '
|
|
186
|
+
: pathname === '/logo.png'
|
|
187
|
+
? 'logo.png'
|
|
170
188
|
: pathname.startsWith('/assets/') || pathname.startsWith('/.')
|
|
171
189
|
? undefined
|
|
172
190
|
: 'index.html';
|
package/dist/server/endpoints.js
CHANGED
|
@@ -285,7 +285,15 @@ class EndpointGateway {
|
|
|
285
285
|
return null;
|
|
286
286
|
}
|
|
287
287
|
const session = this.readSession(label, req.headers.cookie);
|
|
288
|
-
return session
|
|
288
|
+
return session
|
|
289
|
+
? {
|
|
290
|
+
iss: session.iss,
|
|
291
|
+
sub: session.sub,
|
|
292
|
+
groups: session.groups,
|
|
293
|
+
claims: session.claims,
|
|
294
|
+
...(session.name ? { name: session.name } : {}),
|
|
295
|
+
}
|
|
296
|
+
: null;
|
|
289
297
|
}
|
|
290
298
|
// Whether the browser sends the request for another page than the endpoint's own: an
|
|
291
299
|
// upgrade from another origin, or a request a page of another site makes (a frame too),
|
|
@@ -652,6 +660,7 @@ ${run.state === 'up'
|
|
|
652
660
|
host: label,
|
|
653
661
|
iss: issued.principal.iss,
|
|
654
662
|
sub: issued.principal.sub,
|
|
663
|
+
...((0, oauth_1.displayName)(issued.principal) ? { name: (0, oauth_1.displayName)(issued.principal) } : {}),
|
|
655
664
|
groups: issued.principal.groups,
|
|
656
665
|
claims: this.matchedClaims(issued.principal),
|
|
657
666
|
exp,
|