hammerkit 2.1.0-next.9 → 2.2.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/dashboard/assets/{graph-canvas-BFnEN5i0.js → graph-canvas-D6GMgkoe.js} +1 -1
  2. package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
  3. package/dist/dashboard/assets/{index-Dt3ITvRO.css → index-DP3_hKOe.css} +1 -1
  4. package/dist/dashboard/index.html +2 -2
  5. package/dist/executer/archive-task-entry.js +1 -1
  6. package/dist/executer/deadline.js +63 -10
  7. package/dist/executer/event-cache.js +5 -1
  8. package/dist/executer/execute-work-task.js +15 -3
  9. package/dist/executer/runner-commands.js +36 -0
  10. package/dist/file/get-file-context.js +4 -7
  11. package/dist/harness/connect.js +12 -8
  12. package/dist/harness/reconnect.js +141 -0
  13. package/dist/harness/sandbox-client.js +242 -33
  14. package/dist/harness/service-tools.js +36 -3
  15. package/dist/kubernetes/cluster-state.js +48 -14
  16. package/dist/kubernetes/ensure-persistent-data.js +15 -4
  17. package/dist/kubernetes/follow-pod-logs.js +8 -5
  18. package/dist/kubernetes/kept-claims.js +26 -5
  19. package/dist/kubernetes/resources.js +5 -1
  20. package/dist/kubernetes/sandbox-runner.js +526 -156
  21. package/dist/kubernetes/store-kubernetes-data.js +18 -3
  22. package/dist/kubernetes/sync-changes.js +463 -0
  23. package/dist/kubernetes/volumes.js +23 -1
  24. package/dist/optimizer/get-work-cache-stats.js +7 -0
  25. package/dist/planner/work-item-status.js +12 -2
  26. package/dist/planner/work-runtime-aggregate.js +1 -0
  27. package/dist/planner/work-runtime-docker.js +9 -5
  28. package/dist/planner/work-runtime-kubernetes.js +277 -55
  29. package/dist/planner/work-runtime-local.js +8 -4
  30. package/dist/remote/annotations.js +29 -3
  31. package/dist/remote/bundle.js +6 -8
  32. package/dist/remote/collect-bundle.js +3 -2
  33. package/dist/remote/device-login.js +4 -1
  34. package/dist/remote/remote-commands.js +16 -7
  35. package/dist/remote/remote-work-commands.js +265 -72
  36. package/dist/remote/server-client.js +38 -40
  37. package/dist/server/artifacts-api.js +56 -0
  38. package/dist/server/definitions-api.js +62 -8
  39. package/dist/server/endpoints.js +52 -32
  40. package/dist/server/executor.js +117 -30
  41. package/dist/server/http.js +4 -1
  42. package/dist/server/keep-artifacts.js +230 -0
  43. package/dist/server/kubernetes-backend.js +186 -59
  44. package/dist/server/kubernetes-sandbox-storage.js +83 -22
  45. package/dist/server/overview.js +67 -9
  46. package/dist/server/paging.js +167 -0
  47. package/dist/server/plan.js +8 -1
  48. package/dist/server/public-paths.js +52 -0
  49. package/dist/server/run-access.js +24 -0
  50. package/dist/server/run-artifacts.js +171 -0
  51. package/dist/server/run-logs.js +25 -1
  52. package/dist/server/run-request.js +63 -1
  53. package/dist/server/run-retry.js +6 -0
  54. package/dist/server/run-worker.js +267 -33
  55. package/dist/server/runs.js +527 -99
  56. package/dist/server/sandbox-files.js +9 -8
  57. package/dist/server/sandbox-follow.js +54 -0
  58. package/dist/server/sandbox-storage.js +38 -1
  59. package/dist/server/sandbox-sync.js +392 -0
  60. package/dist/server/sandboxes-api.js +54 -8
  61. package/dist/server/sandboxes.js +19 -0
  62. package/dist/server/server-config.js +14 -0
  63. package/dist/server/server.js +189 -46
  64. package/dist/server/service-runs.js +41 -8
  65. package/dist/server/task-order.js +56 -0
  66. package/dist/utils/project-path.js +20 -0
  67. package/dist/utils/tar-files.js +52 -0
  68. package/dist/utils/tar.js +37 -1
  69. package/package.json +1 -1
  70. package/dist/dashboard/assets/index-CE5PSB3y.js +0 -23
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensurePersistentData = exports.packSource = exports.clearStateFiles = exports.ENSURE_OUTPUT_FILES = exports.restoreLiveFiles = exports.syncLiveFiles = exports.SYNC_FILES = exports.getStateDirsInUse = exports.REMOVE_OTHER_STATES = exports.execInPod = exports.clearClaim = exports.getPodForPersistence = exports.applyWithinQuota = exports.QUOTA_TIMEOUT = exports.TRANSFER_POD_RESOURCES = void 0;
3
+ exports.ensurePersistentData = exports.packSource = exports.clearStateFiles = exports.ENSURE_OUTPUT_FILES = exports.restoreLiveFiles = exports.syncLiveFiles = exports.SYNC_FILES = exports.getStateDirsInUse = exports.REMOVE_OTHER_STATES = exports.execInPod = exports.clearClaim = exports.getPodForPersistence = exports.applyWithinQuota = exports.QUOTA_TIMEOUT = exports.getTransferPodScript = exports.TRANSFER_POD_RESOURCES = void 0;
4
4
  const quota_wait_1 = require("./quota-wait");
5
5
  Object.defineProperty(exports, "QUOTA_TIMEOUT", { enumerable: true, get: function () { return quota_wait_1.QUOTA_TIMEOUT; } });
6
6
  const volumes_1 = require("./volumes");
@@ -54,6 +54,15 @@ exports.TRANSFER_POD_RESOURCES = {
54
54
  requests: { cpu: '50m', memory: '64Mi' },
55
55
  limits: { memory: '512Mi' },
56
56
  };
57
+ // What the transfer pod runs while files are copied through exec: it waits, and ends at once
58
+ // and with 0 when the pod is deleted. A shell as process 1 ignores SIGTERM unless it traps it,
59
+ // and was killed at the end of the grace period of its deletion, 30 seconds later and with
60
+ // 137, which the log of a run that failed meanwhile showed as a failed pod.
61
+ // `busybox` is the one of the pod.
62
+ function getTransferPodScript(busybox) {
63
+ return `trap 'kill $! 2>/dev/null; exit 0' TERM; ${busybox} sleep 2147483647 & wait`;
64
+ }
65
+ exports.getTransferPodScript = getTransferPodScript;
57
66
  // A Job waits for room under a full quota, a pod is refused: so a transfer pod is
58
67
  // created again until the pods of the tasks it runs beside are done and make room
59
68
  async function applyWithinQuota(instance, podSpec, service, timeout = quota_wait_1.QUOTA_TIMEOUT, pollInterval = 2000,
@@ -93,7 +102,7 @@ signal, fn) {
93
102
  // outputs of its deps are not mounted, so an output inside a folder of its src
94
103
  // (pkg/coverage/lcov.info) has a place in the pod even when the claim holds no src,
95
104
  // after a restore into a new claim
96
- own.filter((m) => service.data.type !== 'container-task' || !m.mount.readOnly).map((m) => m.mount)
105
+ own.filter((m) => !m.sync && (service.data.type !== 'container-task' || !m.mount.readOnly)).map((m) => m.mount)
97
106
  : own.reduce((array, v) => {
98
107
  if (!array.some((i) => i.name === v.mount.name)) {
99
108
  array.push({
@@ -139,6 +148,8 @@ signal, fn) {
139
148
  },
140
149
  annotations: {
141
150
  'hammerkit.dev/version': (0, version_1.getVersion)(),
151
+ [resources_1.HELPER_ANNOTATION]: type === 'write' ? 'upload' : 'download',
152
+ [resources_1.ITEM_ANNOTATION]: service.name,
142
153
  },
143
154
  },
144
155
  spec: {
@@ -156,8 +167,8 @@ signal, fn) {
156
167
  {
157
168
  name: 'volume',
158
169
  image: transfer_tools_1.HELPER_TOOLS_IMAGE,
159
- command: (0, transfer_tools_1.inTransferPod)(['sh']),
160
- tty: true,
170
+ // no tty: it kept an interactive shell waiting, which ignores SIGTERM
171
+ command: (0, transfer_tools_1.inTransferPod)(['sh', '-c', getTransferPodScript(transfer_tools_1.TRANSFER_BUSYBOX)]),
161
172
  env: transfer_tools_1.TRANSFER_TOOLS_ENV,
162
173
  volumeMounts: [...mounts, transfer_tools_1.TRANSFER_TOOLS_MOUNT],
163
174
  resources: exports.TRANSFER_POD_RESOURCES,
@@ -49,14 +49,17 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
49
49
  const positionOf = (id) => {
50
50
  let position = positions.get(id);
51
51
  if (!position) {
52
- position = { at: null, since: null, count: 0, reads: 0 };
52
+ const from = Array.isArray(options.from) ? options.from.find((cursor) => cursor?.container === id) : undefined;
53
+ position = from
54
+ ? { at: from.at, since: `${from.at.slice(0, 19)}Z`, count: from.count, reads: 0 }
55
+ : { at: null, since: null, count: 0, reads: 0 };
53
56
  positions.set(id, position);
54
57
  }
55
58
  return position;
56
59
  };
57
60
  // a reader of the log of one instance from where it got to: the lines read before, again
58
61
  // at the start of a log read since their second, are passed over
59
- const reader = (position) => {
62
+ const reader = (id, position) => {
60
63
  const from = position.at;
61
64
  const skip = position.count;
62
65
  let atFrom = 0;
@@ -80,7 +83,7 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
80
83
  position.since = `${match[1]}Z`;
81
84
  position.count = 1;
82
85
  }
83
- onLine(match[3] ?? '');
86
+ onLine(match[3] ?? '', { container: id, at, count: position.count });
84
87
  };
85
88
  };
86
89
  const readEnded = async (pod, id, previous) => {
@@ -98,7 +101,7 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
98
101
  ? { sinceSeconds: Math.max(1, Math.ceil((Date.now() - Date.parse(position.since)) / 1000) + 60) }
99
102
  : {}),
100
103
  });
101
- const read = reader(position);
104
+ const read = reader(id, position);
102
105
  for (const line of String(log ?? '').split(/\r?\n/)) {
103
106
  if (line.length > 0) {
104
107
  read(line);
@@ -139,7 +142,7 @@ function followPodLogs(instance, namespace, labelSelector, container, onLine, op
139
142
  end();
140
143
  }));
141
144
  output.on('end', end);
142
- (0, read_lines_1.readLines)(output, exports.MAX_LOG_LINE_CHARS, reader(position));
145
+ (0, read_lines_1.readLines)(output, exports.MAX_LOG_LINE_CHARS, reader(id, position));
143
146
  streaming++;
144
147
  let controller;
145
148
  try {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.evictKeptClaims = exports.sweepKeptClaims = exports.expireKeptClaims = exports.recordClaimState = exports.forgetClaimState = exports.rememberedClaimState = exports.useClaimState = exports.isKeptClaim = exports.getClaimName = exports.EXPIRES_ANNOTATION = exports.STATE_ANNOTATION = exports.KEPT_BY_LABEL = exports.VOLUME_SCOPE_LABEL = void 0;
3
+ exports.evictKeptClaims = exports.sweepKeptClaims = exports.expireKeptClaims = exports.isClaimWrittenBy = exports.recordClaimState = exports.markClaimWriter = exports.forgetClaimState = exports.rememberedClaimState = exports.useClaimState = exports.isKeptClaim = exports.getClaimName = exports.WRITER_ANNOTATION = exports.EXPIRES_ANNOTATION = exports.STATE_ANNOTATION = exports.KEPT_BY_LABEL = exports.VOLUME_SCOPE_LABEL = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  const apply_1 = require("./apply");
6
6
  const sleep_1 = require("../utils/sleep");
@@ -18,6 +18,10 @@ exports.KEPT_BY_LABEL = 'hammerkit.dev/kept-by';
18
18
  exports.STATE_ANNOTATION = 'hammerkit.dev/state';
19
19
  // when it goes, set by the end of the run that mounted it last
20
20
  exports.EXPIRES_ANNOTATION = 'hammerkit.dev/expires';
21
+ // while a Job writes to it and it names no state: which run and state the Job is of, so a
22
+ // run that resumes after a restart of the server takes the Job over only when no other run
23
+ // wrote to the claim since
24
+ exports.WRITER_ANNOTATION = 'hammerkit.dev/writer';
21
25
  // The claim of a work item: a task's on a server that keeps them carries the scope, so a
22
26
  // run of another source never mounts it, and the name of the task, so that only runs with
23
27
  // that task in their plan mount it: two runs of one scope go one at a time when they have a
@@ -116,17 +120,34 @@ async function rememberedClaimState(instance, kubernetes, name) {
116
120
  return claim.metadata?.annotations?.[exports.STATE_ANNOTATION] ?? null;
117
121
  }
118
122
  exports.rememberedClaimState = rememberedClaimState;
119
- // Before a task writes to its kept claim: the outputs in it stop being those of a state.
120
- // Whether the claim was there, with what an earlier run left in it.
123
+ // Before a task writes to its kept claim: the outputs in it stop being those of a state, and
124
+ // the Job that wrote to it last is not the one that writes to it now. Whether the claim was
125
+ // there, with what an earlier run left in it.
121
126
  function forgetClaimState(instance, kubernetes, name) {
122
- return annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: null });
127
+ return annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: null, [exports.WRITER_ANNOTATION]: null });
123
128
  }
124
129
  exports.forgetClaimState = forgetClaimState;
130
+ // Once the files of a Job are in the claim, before the Job starts: which run and state it is
131
+ // of (WRITER_ANNOTATION)
132
+ async function markClaimWriter(instance, kubernetes, name, writer) {
133
+ await annotate(instance, kubernetes.namespace, name, { [exports.WRITER_ANNOTATION]: writer });
134
+ }
135
+ exports.markClaimWriter = markClaimWriter;
125
136
  // Once the outputs of `stateKey` are whole in the kept claim
126
137
  async function recordClaimState(instance, kubernetes, name, stateKey) {
127
- await annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: stateKey });
138
+ await annotate(instance, kubernetes.namespace, name, { [exports.STATE_ANNOTATION]: stateKey, [exports.WRITER_ANNOTATION]: null });
128
139
  }
129
140
  exports.recordClaimState = recordClaimState;
141
+ // Whether the Job of `writer` was the last to write to the claim, and it names no state since
142
+ async function isClaimWrittenBy(instance, kubernetes, name, writer) {
143
+ const claim = await readClaim(instance, kubernetes.namespace, name);
144
+ const annotations = claim?.metadata?.annotations ?? {};
145
+ return (!!claim &&
146
+ !claim.metadata?.deletionTimestamp &&
147
+ !annotations[exports.STATE_ANNOTATION] &&
148
+ annotations[exports.WRITER_ANNOTATION] === writer);
149
+ }
150
+ exports.isClaimWrittenBy = isClaimWrittenBy;
130
151
  // The kept claims in a namespace
131
152
  async function listKeptClaims(instance, namespace, labelSelector = exports.VOLUME_SCOPE_LABEL) {
132
153
  const claims = await instance.coreApi.listNamespacedPersistentVolumeClaim({ namespace, labelSelector });
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeInvalidCharacters = exports.getResourceName = exports.getItemSelector = exports.getItemLabels = exports.getItemKey = exports.ID_LABEL = void 0;
3
+ exports.removeInvalidCharacters = exports.getResourceName = exports.getItemSelector = exports.getItemLabels = exports.getItemKey = exports.ITEM_ANNOTATION = exports.HELPER_ANNOTATION = exports.ID_LABEL = void 0;
4
4
  const job_placement_1 = require("./job-placement");
5
5
  // An object name is a DNS label: lowercase letters, digits and `-`, at most 63
6
6
  // characters, starting and ending with a letter or digit. The id makes a name
7
7
  // unique; the item's name is there for people and is cut to fit.
8
8
  const MAX_NAME = 63;
9
9
  exports.ID_LABEL = 'hammerkit.dev/id';
10
+ // On a pod that copies files of an item into or out of its claim: `upload` or `download`, and
11
+ // the item's name, so what the cluster says of the pod is not taken for the item
12
+ exports.HELPER_ANNOTATION = 'hammerkit.dev/helper';
13
+ exports.ITEM_ANNOTATION = 'hammerkit.dev/item';
10
14
  // What tells the objects of an item apart in its namespace: its id, and on a server the
11
15
  // run's label too. The runs of a caller execute side by side in their namespace, and two
12
16
  // of them often run the same task (the same command on two sandboxes of a repository),