hammerkit 1.27.0-next.9 → 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/build.schema.json +176 -6
- package/dist/cache/backends/local-cache-backend.js +6 -0
- package/dist/cache/backends/registry/registry-client.js +1 -0
- package/dist/cache/cache-sync.js +1 -1
- package/dist/cache/explain.js +23 -4
- package/dist/cli.js +2 -0
- 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 +15 -0
- package/dist/dashboard/logo.png +0 -0
- package/dist/docker/item-network.js +13 -5
- package/dist/executer/archive-task-entry.js +4 -2
- package/dist/executer/deadline.js +17 -3
- package/dist/executer/deferred-restore.js +36 -0
- package/dist/executer/docker-service.js +30 -8
- package/dist/executer/docker-task.js +24 -1
- package/dist/executer/execute-work-service.js +2 -0
- package/dist/executer/execute-work-task.js +14 -5
- package/dist/executer/execution-steps.js +25 -4
- package/dist/executer/local-task.js +3 -0
- package/dist/executer/reset-work-tree.js +4 -0
- package/dist/executer/scheduler/enqueue-next.js +63 -7
- package/dist/executer/scheduler/state-key.js +89 -15
- package/dist/executer/watch-loop.js +22 -6
- package/dist/file/get-file-context.js +5 -1
- package/dist/harness/connect.js +20 -6
- package/dist/harness/mcp-command.js +22 -6
- package/dist/harness/mcp.js +63 -114
- package/dist/harness/opencode.js +158 -50
- package/dist/harness/pi.js +29 -0
- package/dist/harness/sandbox-client.js +194 -23
- package/dist/harness/service-tools.js +141 -0
- package/dist/harness/task-tools.js +221 -0
- package/dist/kubernetes/apply.js +49 -1
- package/dist/kubernetes/await-running-state.js +241 -18
- package/dist/kubernetes/claim-layout.js +10 -1
- package/dist/kubernetes/cluster-state.js +245 -0
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +142 -9
- package/dist/kubernetes/ensure-kubernetes-service-exists.js +2 -0
- package/dist/kubernetes/ensure-persistent-data.js +305 -12
- package/dist/kubernetes/follow-pod-logs.js +281 -0
- package/dist/kubernetes/job-placement.js +36 -12
- package/dist/kubernetes/kept-claims.js +16 -1
- package/dist/kubernetes/kubernetes-instance.js +1 -0
- package/dist/kubernetes/network-policy.js +6 -5
- package/dist/kubernetes/quota-wait.js +97 -0
- package/dist/kubernetes/remove-stale-items.js +46 -0
- package/dist/kubernetes/restore-kubernetes-data.js +35 -8
- package/dist/kubernetes/sandbox-runner.js +628 -0
- package/dist/kubernetes/service-rollouts.js +74 -0
- package/dist/kubernetes/store-kubernetes-data.js +18 -4
- package/dist/kubernetes/volumes.js +124 -12
- package/dist/main.js +2 -0
- package/dist/optimizer/calculate-checksum.js +49 -5
- package/dist/optimizer/check-key.js +94 -0
- package/dist/optimizer/check-keys.js +66 -0
- package/dist/optimizer/get-work-cache-stats.js +53 -27
- package/dist/optimizer/work-task-cache-description.js +49 -1
- package/dist/parser/read-build-file.js +8 -3
- package/dist/planner/service-definition.js +9 -4
- package/dist/planner/utils/append-work-dependencies.js +5 -3
- package/dist/planner/utils/append-work-service.js +18 -1
- package/dist/planner/utils/append-work-task.js +13 -3
- package/dist/planner/utils/get-work-runtime.js +6 -1
- package/dist/planner/utils/normalize-path.js +19 -1
- package/dist/planner/utils/parse-work-mount.js +7 -1
- package/dist/planner/utils/parse-work-port.js +4 -1
- package/dist/planner/utils/template-value.js +20 -4
- package/dist/planner/validate.js +22 -0
- package/dist/planner/work-item-executions.js +27 -0
- package/dist/planner/work-network.js +3 -1
- package/dist/planner/work-runtime-aggregate.js +32 -0
- package/dist/planner/work-runtime-kubernetes.js +204 -53
- package/dist/planner/work-task.js +6 -1
- package/dist/program.js +27 -9
- package/dist/remote/device-login.js +7 -2
- package/dist/remote/host-config.js +69 -3
- package/dist/remote/remote-commands.js +33 -7
- package/dist/remote/remote-status.js +112 -0
- package/dist/remote/remote-work-commands.js +571 -45
- package/dist/remote/server-client.js +15 -2
- package/dist/remote/token-source.js +64 -26
- package/dist/run-program.js +9 -0
- package/dist/schema/build-file-base-task-schema.js +3 -3
- package/dist/schema/build-file-container-service-schema.js +10 -0
- package/dist/schema/build-file-container-task-schema.js +16 -1
- package/dist/schema/build-file-include-schema.js +18 -4
- package/dist/schema/build-file-kubernetes-service-schema.js +2 -0
- package/dist/schema/build-file-task-schema.js +5 -1
- package/dist/schema/capabilities-schema.js +56 -0
- package/dist/schema/reference-parser.js +119 -11
- package/dist/schema/removed-properties.js +20 -0
- package/dist/schema/schema-parser.js +140 -43
- package/dist/schema/work-scope-parser.js +33 -10
- package/dist/secrets/command-secret-provider.js +3 -1
- package/dist/secrets/github-app-token-command.js +3 -1
- package/dist/secrets/secret-catalog.js +43 -19
- package/dist/server/accounts-api.js +4 -1
- package/dist/server/approvals-api.js +1 -1
- package/dist/server/capacity-format.js +36 -0
- package/dist/server/capacity.js +330 -0
- package/dist/server/checks-api.js +83 -0
- package/dist/server/checks.js +116 -0
- package/dist/server/dashboard.js +214 -0
- package/dist/server/definitions-api.js +66 -3
- package/dist/server/endpoints.js +803 -0
- package/dist/server/executor.js +216 -30
- package/dist/server/kubernetes-backend.js +415 -48
- package/dist/server/kubernetes-sandbox-storage.js +60 -6
- package/dist/server/oauth.js +16 -1
- package/dist/server/overview.js +340 -0
- package/dist/server/plan.js +186 -124
- package/dist/server/policy.js +42 -4
- package/dist/server/proposals-api.js +17 -8
- package/dist/server/repo-access.js +5 -0
- package/dist/server/run-logs.js +4 -0
- package/dist/server/run-plan.js +38 -4
- package/dist/server/run-request.js +58 -3
- package/dist/server/run-worker.js +307 -17
- package/dist/server/runs.js +1036 -42
- package/dist/server/sandbox-files.js +107 -16
- package/dist/server/sandbox-patch.js +43 -17
- package/dist/server/sandbox-pod.js +28 -0
- package/dist/server/sandbox-storage.js +23 -0
- package/dist/server/sandboxes.js +65 -23
- package/dist/server/server-config.js +250 -11
- package/dist/server/server.js +465 -33
- package/dist/server/service-runs.js +89 -0
- package/dist/server/sources.js +68 -11
- package/dist/server/timings.js +152 -0
- package/dist/server/wait-reason.js +21 -0
- 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/tar.js +28 -1
- package/dist/utils/terminal-prompt.js +53 -0
- package/dist/utils/units.js +36 -1
- package/dist/utils/web-links.js +34 -0
- package/package.json +8 -2
package/dist/kubernetes/apply.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replace = exports.apply = exports.statusCodeOf = void 0;
|
|
3
|
+
exports.replaceDeployment = exports.replace = exports.apply = exports.statusCodeOf = void 0;
|
|
4
4
|
// The client throws an ApiException carrying the HTTP status as `code`; watch
|
|
5
5
|
// errors carry it as `statusCode`.
|
|
6
6
|
function statusCodeOf(e) {
|
|
@@ -71,4 +71,52 @@ async function replace(instance, spec) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
exports.replace = replace;
|
|
74
|
+
/**
|
|
75
|
+
* Makes a Deployment exactly as given, as `replace` does, with a JSON patch of all of it:
|
|
76
|
+
* the runRole of a server has `patch` on Deployments, not `update` (see the backend docs).
|
|
77
|
+
* The patch applies only to the version it read, another change in between reads it again.
|
|
78
|
+
*/
|
|
79
|
+
async function replaceDeployment(instance, spec) {
|
|
80
|
+
const { name, namespace } = spec.metadata;
|
|
81
|
+
for (let attempt = 1;; attempt++) {
|
|
82
|
+
let current;
|
|
83
|
+
try {
|
|
84
|
+
current = await instance.appsApi.readNamespacedDeployment({ name, namespace });
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
if (statusCodeOf(e) !== 404) {
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
return await instance.appsApi.createNamespacedDeployment({ namespace, body: spec });
|
|
92
|
+
}
|
|
93
|
+
catch (createError) {
|
|
94
|
+
if (statusCodeOf(createError) !== 409 || attempt >= 3) {
|
|
95
|
+
throw createError;
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
return await instance.appsApi.patchNamespacedDeployment({
|
|
102
|
+
name,
|
|
103
|
+
namespace,
|
|
104
|
+
body: [
|
|
105
|
+
{ op: 'test', path: '/metadata/resourceVersion', value: current.metadata?.resourceVersion },
|
|
106
|
+
{ op: 'add', path: '/metadata/labels', value: spec.metadata.labels ?? {} },
|
|
107
|
+
{ op: 'add', path: '/metadata/annotations', value: spec.metadata.annotations ?? {} },
|
|
108
|
+
{ op: 'add', path: '/spec', value: spec.spec },
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
// changed since it was read: its test fails (422), or a conflict (409)
|
|
114
|
+
const code = statusCodeOf(e);
|
|
115
|
+
if ((code !== 409 && code !== 422) || attempt >= 3) {
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.replaceDeployment = replaceDeployment;
|
|
74
122
|
//# sourceMappingURL=apply.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stopJob = exports.deleteJobAndWait = exports.awaitDeployRunningState = exports.deleteJob = exports.awaitJobCompletion = exports.awaitRunningState = void 0;
|
|
3
|
+
exports.stopJob = exports.deleteJobAndWait = exports.watchKeptPods = exports.KEPT_POD_MS = exports.awaitDeployRollout = exports.awaitDeployRunningState = exports.PASSING_FAILURE_MS = exports.deleteJob = exports.awaitJobCompletion = exports.awaitRunningState = void 0;
|
|
4
4
|
const abort_1 = require("../executer/abort");
|
|
5
5
|
const abort_event_1 = require("../utils/abort-event");
|
|
6
6
|
const apply_1 = require("./apply");
|
|
7
7
|
const sleep_1 = require("../utils/sleep");
|
|
8
|
+
const cluster_state_1 = require("./cluster-state");
|
|
9
|
+
const quota_wait_1 = require("./quota-wait");
|
|
8
10
|
// The waits below poll instead of using the client's Watch: Watch aborts every
|
|
9
11
|
// request after 30s, which a pod or deployment still pulling its image outlasts.
|
|
10
12
|
async function awaitRunningState(instance, env, name, phase, pollInterval = 1000) {
|
|
@@ -21,11 +23,16 @@ async function awaitRunningState(instance, env, name, phase, pollInterval = 1000
|
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
exports.awaitRunningState = awaitRunningState;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
|
29
36
|
for (;;) {
|
|
30
37
|
if (abort.aborted) {
|
|
31
38
|
await deleteJob(instance, env, name);
|
|
@@ -40,10 +47,50 @@ async function awaitJobCompletion(instance, env, name, abort, pollInterval = 100
|
|
|
40
47
|
if (failed) {
|
|
41
48
|
throw new Error(`job ${name} failed: ${failed.message ?? failed.reason ?? 'unknown reason'}`);
|
|
42
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
|
+
}
|
|
43
67
|
await sleep(pollInterval, abort);
|
|
44
68
|
}
|
|
45
69
|
}
|
|
46
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
|
+
}
|
|
47
94
|
function sleep(ms, abort) {
|
|
48
95
|
if (abort.aborted) {
|
|
49
96
|
return Promise.resolve();
|
|
@@ -76,34 +123,210 @@ async function deleteJob(instance, env, name) {
|
|
|
76
123
|
}
|
|
77
124
|
}
|
|
78
125
|
exports.deleteJob = deleteJob;
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
}
|
|
140
|
+
// how long a reason that may still pass (an image pull a registry refused for now, a
|
|
141
|
+
// container the runtime could not create) may last before it fails the service
|
|
142
|
+
exports.PASSING_FAILURE_MS = 60000;
|
|
143
|
+
// Waits for an available replica: a ready one, for a service without a healthcheck one that
|
|
144
|
+
// stayed ready for a while. The deadline only starts once the container runs, and again
|
|
145
|
+
// at each start of it, so an image pull or a back-off doesn't count against it (as on
|
|
146
|
+
// docker, where it starts after the container started). A pod that won't get there without a change (an image
|
|
147
|
+
// that isn't there, a container that crashed once more than its
|
|
148
|
+
// service's `restarts`, 2 by default) fails it at once, with
|
|
149
|
+
// the reason the cluster gives; one that may still pass fails once it lasted a minute.
|
|
150
|
+
// Only the pods of this Deployment count: not the ones of one deleted before it was
|
|
151
|
+
// created again, which may still be there, terminating or not yet.
|
|
82
152
|
async function awaitDeployRunningState(instance, env, name, readiness, pollInterval = 1000, now = Date.now) {
|
|
83
153
|
let runningSince = null;
|
|
154
|
+
// how often the container was restarted when last looked at
|
|
155
|
+
let restarts = 0;
|
|
156
|
+
let said;
|
|
157
|
+
// since when a pod has had a failure that may still pass, by pod
|
|
158
|
+
const failingSince = new Map();
|
|
159
|
+
const quota = getDeployQuotaWait(instance, env, name, readiness, now);
|
|
84
160
|
for (;;) {
|
|
85
161
|
const deployment = await instance.appsApi.readNamespacedDeployment({ name, namespace: env.namespace });
|
|
86
|
-
|
|
162
|
+
// available: ready for the Deployment's minReadySeconds
|
|
163
|
+
if ((deployment.status?.availableReplicas ?? 0) > 0) {
|
|
87
164
|
return;
|
|
88
165
|
}
|
|
166
|
+
await quota.check(getDeploymentRefusal(deployment));
|
|
167
|
+
const created = deployment.metadata?.creationTimestamp;
|
|
168
|
+
const listed = await instance.coreApi.listNamespacedPod({
|
|
169
|
+
namespace: env.namespace,
|
|
170
|
+
labelSelector: readiness.podSelector,
|
|
171
|
+
});
|
|
172
|
+
const pods = listed.items.filter((pod) => !pod.metadata?.deletionTimestamp &&
|
|
173
|
+
!(created && pod.metadata?.creationTimestamp && pod.metadata.creationTimestamp < created));
|
|
174
|
+
for (const [index, pod] of pods.entries()) {
|
|
175
|
+
const key = pod.metadata?.name ?? `${index}`;
|
|
176
|
+
const failure = (0, cluster_state_1.getPodFailure)(pod, readiness.container, readiness.restarts);
|
|
177
|
+
if (!failure) {
|
|
178
|
+
failingSince.delete(key);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const since = failingSince.get(key) ?? now();
|
|
182
|
+
failingSince.set(key, since);
|
|
183
|
+
if (failure.final || now() - since >= exports.PASSING_FAILURE_MS) {
|
|
184
|
+
throw new Error(`${readiness.subject ?? name} can not become ready, ${failure.text}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const waiting = pods.map((pod) => (0, cluster_state_1.getPodWaiting)(pod, readiness.container)).find((text) => !!text);
|
|
188
|
+
if (waiting && waiting !== said) {
|
|
189
|
+
readiness.onWaiting?.(waiting);
|
|
190
|
+
}
|
|
191
|
+
said = waiting;
|
|
89
192
|
if (readiness.timeout !== null) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
193
|
+
// the deadline bounds each start of the container, as on Docker: a crash is counted by
|
|
194
|
+
// `restarts`, and the back-off before the next start doesn't count against it
|
|
195
|
+
const statuses = pods.flatMap((pod) => (pod.status?.containerStatuses ?? []).filter((status) => !readiness.container || status.name === readiness.container));
|
|
196
|
+
const running = statuses.length > 0
|
|
197
|
+
? statuses.some((status) => status.state?.running)
|
|
198
|
+
: pods.some((pod) => pod.status?.phase === 'Running');
|
|
199
|
+
const restarted = Math.max(0, ...statuses.map((status) => status.restartCount ?? 0));
|
|
200
|
+
if (!running) {
|
|
201
|
+
runningSince = null;
|
|
202
|
+
}
|
|
203
|
+
else if (runningSince === null || restarted !== restarts) {
|
|
204
|
+
runningSince = now();
|
|
98
205
|
}
|
|
99
206
|
else if (now() - runningSince >= readiness.timeout) {
|
|
100
207
|
throw new Error(readiness.timeoutMessage);
|
|
101
208
|
}
|
|
209
|
+
restarts = restarted;
|
|
102
210
|
}
|
|
103
211
|
await (0, sleep_1.sleep)(pollInterval);
|
|
104
212
|
}
|
|
105
213
|
}
|
|
106
214
|
exports.awaitDeployRunningState = awaitDeployRunningState;
|
|
215
|
+
/**
|
|
216
|
+
* Waits until every pod of a Deployment is of its spec `generation` and available, as a
|
|
217
|
+
* rollout of a changed service does. Fails when Kubernetes gave up on it (its progress
|
|
218
|
+
* deadline), when a new pod (`podSelector`) won't get there without a change (as
|
|
219
|
+
* awaitDeployRunningState tells), or once one ran for the readiness timeout without getting
|
|
220
|
+
* ready.
|
|
221
|
+
*/
|
|
222
|
+
async function awaitDeployRollout(instance, env, name, readiness, pollInterval = 1000, now = Date.now) {
|
|
223
|
+
const subject = readiness.subject ?? name;
|
|
224
|
+
const timeoutMessage = readiness.timeoutMessage || `${subject} did not get ready`;
|
|
225
|
+
let runningSince = null;
|
|
226
|
+
let said;
|
|
227
|
+
const failingSince = new Map();
|
|
228
|
+
const quota = getDeployQuotaWait(instance, env, name, readiness, now);
|
|
229
|
+
for (;;) {
|
|
230
|
+
if (readiness.signal?.aborted) {
|
|
231
|
+
throw new abort_1.AbortError();
|
|
232
|
+
}
|
|
233
|
+
const deployment = await instance.appsApi.readNamespacedDeployment({ name, namespace: env.namespace });
|
|
234
|
+
const status = deployment.status;
|
|
235
|
+
if ((status?.observedGeneration ?? 0) >= readiness.generation &&
|
|
236
|
+
(status?.updatedReplicas ?? 0) >= 1 &&
|
|
237
|
+
(status?.availableReplicas ?? 0) >= 1 &&
|
|
238
|
+
(status?.replicas ?? 0) === (status?.updatedReplicas ?? 0)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const stalled = status?.conditions?.find((condition) => condition.type === 'Progressing' && condition.reason === 'ProgressDeadlineExceeded');
|
|
242
|
+
if (stalled && (status?.observedGeneration ?? 0) >= readiness.generation) {
|
|
243
|
+
throw new Error(`${timeoutMessage}: ${stalled.message ?? 'its rollout made no progress'}`);
|
|
244
|
+
}
|
|
245
|
+
await quota.check(getDeploymentRefusal(deployment));
|
|
246
|
+
const listed = await instance.coreApi.listNamespacedPod({
|
|
247
|
+
namespace: env.namespace,
|
|
248
|
+
labelSelector: readiness.podSelector,
|
|
249
|
+
});
|
|
250
|
+
const pods = listed.items.filter((pod) => !pod.metadata?.deletionTimestamp);
|
|
251
|
+
for (const [index, pod] of pods.entries()) {
|
|
252
|
+
const key = pod.metadata?.name ?? `${index}`;
|
|
253
|
+
const failure = (0, cluster_state_1.getPodFailure)(pod, readiness.container);
|
|
254
|
+
if (!failure) {
|
|
255
|
+
failingSince.delete(key);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const since = failingSince.get(key) ?? now();
|
|
259
|
+
failingSince.set(key, since);
|
|
260
|
+
if (failure.final || now() - since >= exports.PASSING_FAILURE_MS) {
|
|
261
|
+
throw new Error(`${subject} can not become ready, ${failure.text}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const waiting = pods.map((pod) => (0, cluster_state_1.getPodWaiting)(pod, readiness.container)).find((text) => !!text);
|
|
265
|
+
if (waiting && waiting !== said) {
|
|
266
|
+
readiness.onWaiting?.(waiting);
|
|
267
|
+
}
|
|
268
|
+
said = waiting;
|
|
269
|
+
if (readiness.timeout !== null) {
|
|
270
|
+
if (runningSince === null) {
|
|
271
|
+
if (pods.some((pod) => pod.status?.phase === 'Running')) {
|
|
272
|
+
runningSince = now();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else if (now() - runningSince >= readiness.timeout) {
|
|
276
|
+
throw new Error(timeoutMessage);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
await sleep(pollInterval, readiness.signal ?? new AbortController().signal);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.awaitDeployRollout = awaitDeployRollout;
|
|
283
|
+
// how long the pod a service that watches its files keeps has to go on running once it got
|
|
284
|
+
// the changed files
|
|
285
|
+
exports.KEPT_POD_MS = 15000;
|
|
286
|
+
/**
|
|
287
|
+
* Watches the pods of a Deployment that stays (a service that watches its files got the
|
|
288
|
+
* changed ones, see syncLiveFiles) for `windowMs`: fails when one of them restarts, fails as
|
|
289
|
+
* awaitDeployRunningState tells, or the Deployment has no available pod any more, so a move
|
|
290
|
+
* whose files break the service does not count as up.
|
|
291
|
+
*/
|
|
292
|
+
async function watchKeptPods(instance, env, name, readiness, windowMs = exports.KEPT_POD_MS, pollInterval = 1000, now = Date.now) {
|
|
293
|
+
const subject = readiness.subject ?? name;
|
|
294
|
+
const restarts = new Map();
|
|
295
|
+
const started = now();
|
|
296
|
+
for (;;) {
|
|
297
|
+
if (readiness.signal?.aborted) {
|
|
298
|
+
throw new abort_1.AbortError();
|
|
299
|
+
}
|
|
300
|
+
const listed = await instance.coreApi.listNamespacedPod({
|
|
301
|
+
namespace: env.namespace,
|
|
302
|
+
labelSelector: readiness.podSelector,
|
|
303
|
+
});
|
|
304
|
+
for (const pod of listed.items.filter((pod) => !pod.metadata?.deletionTimestamp)) {
|
|
305
|
+
const key = pod.metadata?.name ?? '';
|
|
306
|
+
const failure = (0, cluster_state_1.getPodFailure)(pod, readiness.container, readiness.restarts);
|
|
307
|
+
if (failure) {
|
|
308
|
+
throw new Error(`${subject} stopped working with the changed files, ${failure.text}`);
|
|
309
|
+
}
|
|
310
|
+
const count = (pod.status?.containerStatuses ?? [])
|
|
311
|
+
.filter((status) => !readiness.container || status.name === readiness.container)
|
|
312
|
+
.reduce((sum, status) => sum + (status.restartCount ?? 0), 0);
|
|
313
|
+
const before = restarts.get(key);
|
|
314
|
+
if (before !== undefined && count > before) {
|
|
315
|
+
throw new Error(`${subject} stopped working with the changed files, its container restarted`);
|
|
316
|
+
}
|
|
317
|
+
restarts.set(key, count);
|
|
318
|
+
}
|
|
319
|
+
const deployment = await instance.appsApi.readNamespacedDeployment({ name, namespace: env.namespace });
|
|
320
|
+
if ((deployment.status?.availableReplicas ?? 0) < 1) {
|
|
321
|
+
throw new Error(`${subject} stopped working with the changed files, it has no ready pod`);
|
|
322
|
+
}
|
|
323
|
+
if (now() - started >= windowMs) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
await sleep(pollInterval, readiness.signal ?? new AbortController().signal);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
exports.watchKeptPods = watchKeptPods;
|
|
107
330
|
// Delete a job and wait until it is gone: its name is reused for the task's next
|
|
108
331
|
// command (and the next run with the same state), and creating it while the old
|
|
109
332
|
// one is still being deleted would pick up the old job.
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readClusterState = exports.describeEvent = exports.describePod = exports.getPodWaiting = exports.describeLastExit = exports.getPodFailure = exports.CRASHES_TO_FAIL = void 0;
|
|
4
|
+
const log_1 = require("../log");
|
|
5
|
+
const apply_1 = require("./apply");
|
|
6
|
+
const job_placement_1 = require("./job-placement");
|
|
7
|
+
const network_gate_1 = require("./network-gate");
|
|
8
|
+
const resources_1 = require("./resources");
|
|
9
|
+
// what a pod's or event's message is cut to
|
|
10
|
+
const MAX_MESSAGE = 500;
|
|
11
|
+
// how many events of a run are said, the newest
|
|
12
|
+
const MAX_EVENTS = 20;
|
|
13
|
+
// events the result of a task says better: a Job of a failed command
|
|
14
|
+
const SAID_ELSEWHERE = ['BackoffLimitExceeded'];
|
|
15
|
+
// A container restarted this often (ended three times) is taken as one that keeps crashing,
|
|
16
|
+
// unless its service sets `restarts`: once may be a race with a dependency or a slow first start
|
|
17
|
+
exports.CRASHES_TO_FAIL = 2;
|
|
18
|
+
// what a pull error says when the image is not there to pull, or not for this cluster:
|
|
19
|
+
// waiting does not change it. Others (a registry that limits, a token not there yet) may pass.
|
|
20
|
+
const IMAGE_GONE = /not found|manifest unknown|unauthorized|denied|forbidden|invalid reference|no such host/i;
|
|
21
|
+
/**
|
|
22
|
+
* Why a pod of a service will not become ready without a change, as the cluster says it:
|
|
23
|
+
* an image that can not be pulled, a container that keeps crashing or can not be created,
|
|
24
|
+
* an init container that failed. Null while it may still get there. A container fails once
|
|
25
|
+
* it was restarted `restarts` times and crashed again.
|
|
26
|
+
*
|
|
27
|
+
* Only what the cluster wrote is quoted: the termination message of a container is its
|
|
28
|
+
* own output (and may hold a value it read), except for the network gate's, which says why
|
|
29
|
+
* the policy did not take hold.
|
|
30
|
+
*/
|
|
31
|
+
function getPodFailure(pod, container, restarts = exports.CRASHES_TO_FAIL) {
|
|
32
|
+
for (const status of pod.status?.initContainerStatuses ?? []) {
|
|
33
|
+
const terminated = status.state?.terminated ?? status.lastState?.terminated;
|
|
34
|
+
if (!terminated || terminated.exitCode === 0) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (status.name === network_gate_1.NETWORK_GATE_CONTAINER) {
|
|
38
|
+
return {
|
|
39
|
+
text: `the network policy did not take hold: ${cut(terminated.message?.trim() || 'the gate failed')}`,
|
|
40
|
+
final: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (status.restartCount >= exports.CRASHES_TO_FAIL) {
|
|
44
|
+
return { text: `its init container ${status.name} failed with exit code ${terminated.exitCode}`, final: true };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const status of mainStatuses(pod, container)) {
|
|
48
|
+
const failure = getContainerFailure(status, restartsEnded(pod, status), restarts);
|
|
49
|
+
if (failure) {
|
|
50
|
+
return failure;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
exports.getPodFailure = getPodFailure;
|
|
56
|
+
function getContainerFailure(status, restartsEnded, restarts) {
|
|
57
|
+
const waiting = status.state?.waiting;
|
|
58
|
+
const reason = waiting?.reason;
|
|
59
|
+
const said = waiting?.message ? `: ${cut(waiting.message)}` : '';
|
|
60
|
+
switch (reason) {
|
|
61
|
+
// the first pull: final only when the registry said the image is not there, as older
|
|
62
|
+
// kubelets leave that out of the ImagePullBackOff that follows
|
|
63
|
+
case 'ErrImagePull':
|
|
64
|
+
return IMAGE_GONE.test(waiting?.message ?? '')
|
|
65
|
+
? { text: `its image ${status.image} could not be pulled (${reason})${said}`, final: true }
|
|
66
|
+
: null;
|
|
67
|
+
case 'ImagePullBackOff':
|
|
68
|
+
return {
|
|
69
|
+
text: `its image ${status.image} could not be pulled (${reason})${said}`,
|
|
70
|
+
final: IMAGE_GONE.test(waiting?.message ?? ''),
|
|
71
|
+
};
|
|
72
|
+
case 'ErrImageNeverPull':
|
|
73
|
+
case 'InvalidImageName':
|
|
74
|
+
return { text: `its image ${status.image} could not be pulled (${reason})${said}`, final: true };
|
|
75
|
+
case 'CreateContainerConfigError':
|
|
76
|
+
case 'CreateContainerError':
|
|
77
|
+
case 'RunContainerError':
|
|
78
|
+
return { text: `its container could not be started (${reason})${said}`, final: false };
|
|
79
|
+
case 'CrashLoopBackOff':
|
|
80
|
+
return status.restartCount >= restarts
|
|
81
|
+
? { text: `it keeps crashing: ${describeLastExit(status)}`, final: true }
|
|
82
|
+
: null;
|
|
83
|
+
}
|
|
84
|
+
// a kubelet may leave an instance that ended as it is until its back-off is over, and say
|
|
85
|
+
// CrashLoopBackOff only when it looks at the pod again, a minute later: the same crash
|
|
86
|
+
if (restartsEnded && status.state?.terminated && status.restartCount >= restarts) {
|
|
87
|
+
return { text: `it keeps crashing: ${describeLastExit(status)}`, final: true };
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
// How the last instance of a container ended, as the cluster says it.
|
|
92
|
+
function describeLastExit(status) {
|
|
93
|
+
// the instance that ended now, else the one before the one that waits or runs
|
|
94
|
+
const last = status.state?.terminated ?? status.lastState?.terminated;
|
|
95
|
+
const restarts = `, restarted ${status.restartCount} time${status.restartCount === 1 ? '' : 's'}`;
|
|
96
|
+
if (!last) {
|
|
97
|
+
return `it ended${restarts}`;
|
|
98
|
+
}
|
|
99
|
+
if (last.reason === 'OOMKilled') {
|
|
100
|
+
return `it was killed for using more memory than its limit (OOMKilled)${restarts}`;
|
|
101
|
+
}
|
|
102
|
+
// the kubelet kills a container whose liveness probe (its healthcheck) keeps failing
|
|
103
|
+
const killed = last.exitCode === 137 || last.exitCode === 143 ? ', killed as when its healthcheck kept failing' : '';
|
|
104
|
+
return `it exited with code ${last.exitCode}${last.reason ? ` (${last.reason})` : ''}${killed}${restarts}`;
|
|
105
|
+
}
|
|
106
|
+
exports.describeLastExit = describeLastExit;
|
|
107
|
+
/**
|
|
108
|
+
* What a pod of a service waits for, in a few words, while it is not ready: a node, its
|
|
109
|
+
* image, its container. Undefined when it waits for nothing the cluster names.
|
|
110
|
+
*/
|
|
111
|
+
function getPodWaiting(pod, container) {
|
|
112
|
+
const scheduled = pod.status?.conditions?.find((condition) => condition.type === 'PodScheduled');
|
|
113
|
+
if (scheduled?.status === 'False') {
|
|
114
|
+
return `waits for a node: ${cut(scheduled.message ?? scheduled.reason ?? 'not scheduled yet')}`;
|
|
115
|
+
}
|
|
116
|
+
for (const status of mainStatuses(pod, container)) {
|
|
117
|
+
const waiting = status.state?.waiting;
|
|
118
|
+
const said = waiting?.message ? `: ${cut(waiting.message)}` : '';
|
|
119
|
+
switch (waiting?.reason) {
|
|
120
|
+
case 'ErrImagePull':
|
|
121
|
+
case 'ImagePullBackOff':
|
|
122
|
+
return `can not pull its image ${status.image} yet${said}`;
|
|
123
|
+
case 'CreateContainerConfigError':
|
|
124
|
+
case 'CreateContainerError':
|
|
125
|
+
case 'RunContainerError':
|
|
126
|
+
return `can not start its container yet (${waiting.reason})${said}`;
|
|
127
|
+
case 'CrashLoopBackOff':
|
|
128
|
+
return `crashed and starts again: ${describeLastExit(status)}`;
|
|
129
|
+
}
|
|
130
|
+
const ended = status.state?.terminated;
|
|
131
|
+
if (ended && restartsEnded(pod, status)) {
|
|
132
|
+
return `${ended.exitCode === 0 ? 'ended' : 'crashed'} and starts again: ${describeLastExit(status)}`;
|
|
133
|
+
}
|
|
134
|
+
if (status.restartCount > 0 && status.state?.running && !status.ready) {
|
|
135
|
+
return `restarted: ${describeLastExit(status)}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
exports.getPodWaiting = getPodWaiting;
|
|
141
|
+
// Whether the kubelet starts a container that ended again: not one of a pod that finished (a
|
|
142
|
+
// task's Job, an evicted pod, which its ReplicaSet replaces) or that never restarts.
|
|
143
|
+
function restartsEnded(pod, status) {
|
|
144
|
+
const phase = pod.status?.phase;
|
|
145
|
+
if (phase === 'Succeeded' || phase === 'Failed') {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
const policy = pod.spec?.restartPolicy ?? 'Always';
|
|
149
|
+
return policy === 'Always' || (policy === 'OnFailure' && status.state?.terminated?.exitCode !== 0);
|
|
150
|
+
}
|
|
151
|
+
function mainStatuses(pod, container) {
|
|
152
|
+
return (pod.status?.containerStatuses ?? []).filter((status) => !container || status.name === container);
|
|
153
|
+
}
|
|
154
|
+
// One line of a pod that is not as it should be, or null for one that runs, ready, or ended well.
|
|
155
|
+
function describePod(pod) {
|
|
156
|
+
const name = pod.metadata?.name ?? '?';
|
|
157
|
+
const phase = pod.status?.phase ?? 'Unknown';
|
|
158
|
+
const failure = getPodFailure(pod)?.text;
|
|
159
|
+
const waiting = getPodWaiting(pod);
|
|
160
|
+
const unready = (pod.status?.containerStatuses ?? [])
|
|
161
|
+
.filter((status) => !status.ready && !status.state?.terminated)
|
|
162
|
+
.map((status) => status.name);
|
|
163
|
+
const crashed = (pod.status?.containerStatuses ?? []).filter((status) => (status.state?.terminated && status.state.terminated.exitCode !== 0) || status.restartCount > 0);
|
|
164
|
+
if (!failure && !waiting && crashed.length === 0 && (phase === 'Succeeded' || unready.length === 0)) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const said = failure ?? waiting;
|
|
168
|
+
const parts = [phase, ...(said ? [said] : [])];
|
|
169
|
+
for (const status of crashed) {
|
|
170
|
+
if (!said?.includes(describeLastExit(status))) {
|
|
171
|
+
parts.push(`${status.name}: ${describeLastExit(status)}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (!said && unready.length > 0) {
|
|
175
|
+
parts.push(`not ready: ${unready.join(', ')}`);
|
|
176
|
+
}
|
|
177
|
+
return `pod ${name}: ${parts.join(', ')}`;
|
|
178
|
+
}
|
|
179
|
+
exports.describePod = describePod;
|
|
180
|
+
/**
|
|
181
|
+
* The message of a warning event, as far as it is the cluster's: a failed probe says the
|
|
182
|
+
* output of the command, which is the service's, and is left out.
|
|
183
|
+
*/
|
|
184
|
+
function describeEvent(event) {
|
|
185
|
+
const object = event.involvedObject;
|
|
186
|
+
const message = (event.message ?? '').replace(/^((Readiness|Liveness|Startup) probe (failed|errored)).*$/s, '$1');
|
|
187
|
+
const count = (event.count ?? 1) > 1 ? ` (${event.count} times)` : '';
|
|
188
|
+
return `${event.reason ?? 'Warning'} ${object.kind?.toLowerCase() ?? 'object'}/${object.name ?? '?'}: ${cut(message.trim())}${count}`;
|
|
189
|
+
}
|
|
190
|
+
exports.describeEvent = describeEvent;
|
|
191
|
+
/**
|
|
192
|
+
* What the cluster said of a run that failed, into its log before the server removes its
|
|
193
|
+
* objects: its pods that are not as they should be, and the warning events of its objects.
|
|
194
|
+
* In the namespace of a service run everything is the run's; in a caller's namespace, which
|
|
195
|
+
* runs share, only the objects of the run's items (named by their key) are.
|
|
196
|
+
*/
|
|
197
|
+
async function readClusterState(instance, kubernetes, workTree, ownNamespace) {
|
|
198
|
+
const namespace = kubernetes.namespace;
|
|
199
|
+
const keys = [...Object.values(workTree.tasks), ...Object.values(workTree.services)].map((item) => (0, resources_1.getItemKey)(item, kubernetes));
|
|
200
|
+
const ours = (name) => ownNamespace || keys.some((key) => name?.includes(key));
|
|
201
|
+
const lines = [];
|
|
202
|
+
try {
|
|
203
|
+
const labels = (0, job_placement_1.getRunLabels)(kubernetes);
|
|
204
|
+
const labelSelector = Object.entries(labels)
|
|
205
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
206
|
+
.join(',');
|
|
207
|
+
const pods = await instance.coreApi.listNamespacedPod({
|
|
208
|
+
namespace,
|
|
209
|
+
...(labelSelector && !ownNamespace ? { labelSelector } : {}),
|
|
210
|
+
});
|
|
211
|
+
for (const pod of pods.items) {
|
|
212
|
+
const line = ours(pod.metadata?.name) ? describePod(pod) : null;
|
|
213
|
+
if (line) {
|
|
214
|
+
lines.push(line);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
lines.push(`its pods could not be read: ${(0, log_1.getErrorMessage)(e)}`);
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const events = await instance.coreApi.listNamespacedEvent({ namespace, fieldSelector: 'type=Warning' });
|
|
223
|
+
const warnings = events.items
|
|
224
|
+
.filter((event) => ours(event.involvedObject.name) && !SAID_ELSEWHERE.includes(event.reason ?? ''))
|
|
225
|
+
.sort((a, b) => eventTime(a) - eventTime(b))
|
|
226
|
+
.slice(-MAX_EVENTS);
|
|
227
|
+
lines.push(...warnings.map((event) => `event ${describeEvent(event)}`));
|
|
228
|
+
}
|
|
229
|
+
catch (e) {
|
|
230
|
+
lines.push((0, apply_1.statusCodeOf)(e) === 403
|
|
231
|
+
? `its events could not be read: the runRole of the server needs list on events (see the backend docs)`
|
|
232
|
+
: `its events could not be read: ${(0, log_1.getErrorMessage)(e)}`);
|
|
233
|
+
}
|
|
234
|
+
return lines;
|
|
235
|
+
}
|
|
236
|
+
exports.readClusterState = readClusterState;
|
|
237
|
+
function eventTime(event) {
|
|
238
|
+
const time = event.lastTimestamp ?? event.eventTime ?? event.firstTimestamp ?? event.metadata?.creationTimestamp;
|
|
239
|
+
return time ? new Date(time).getTime() : 0;
|
|
240
|
+
}
|
|
241
|
+
function cut(text) {
|
|
242
|
+
const line = text.replace(/\s+/g, ' ');
|
|
243
|
+
return line.length > MAX_MESSAGE ? `${line.slice(0, MAX_MESSAGE)}…` : line;
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=cluster-state.js.map
|