@leitwerk-dev/worker-runners 0.3.1 → 0.4.0

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 (44) hide show
  1. package/dist/{chunk-ISH4647R.js → chunk-DSSMRFB4.js} +89 -89
  2. package/dist/chunk-DSSMRFB4.js.map +1 -0
  3. package/dist/{chunk-YDYI3BD2.js → chunk-FEIZN5GL.js} +53 -9
  4. package/dist/chunk-FEIZN5GL.js.map +1 -0
  5. package/dist/{chunk-V7TTFLGE.js → chunk-SFI5TMFN.js} +297 -78
  6. package/dist/chunk-SFI5TMFN.js.map +1 -0
  7. package/dist/{kubernetes-api-client-CEe7pHC4.d.ts → kubernetes-api-client-BeZPZqmj.d.ts} +179 -103
  8. package/dist/kubernetes-api-client.d.ts +3 -0
  9. package/dist/kubernetes-api-client.d.ts.map +1 -1
  10. package/dist/kubernetes-client-public.js +2 -2
  11. package/dist/kubernetes-http-client.d.ts.map +1 -1
  12. package/dist/kubernetes-http-client.js +2 -2
  13. package/dist/kubernetes-image-preload-api.d.ts +69 -0
  14. package/dist/kubernetes-image-preload-api.d.ts.map +1 -0
  15. package/dist/kubernetes-image-preload.d.ts +48 -0
  16. package/dist/kubernetes-image-preload.d.ts.map +1 -0
  17. package/dist/kubernetes-manifests.d.ts +10 -1
  18. package/dist/kubernetes-manifests.d.ts.map +1 -1
  19. package/dist/kubernetes-preparation-api.d.ts +26 -0
  20. package/dist/kubernetes-preparation-api.d.ts.map +1 -0
  21. package/dist/kubernetes-preparation.d.ts +21 -0
  22. package/dist/kubernetes-preparation.d.ts.map +1 -0
  23. package/dist/kubernetes-public.js +2 -2
  24. package/dist/kubernetes-volume-pool-api.d.ts +3 -13
  25. package/dist/kubernetes-volume-pool-api.d.ts.map +1 -1
  26. package/dist/kubernetes-volume-pool.d.ts +2 -4
  27. package/dist/kubernetes-volume-pool.d.ts.map +1 -1
  28. package/dist/kubernetes-worker-runner.d.ts +10 -2
  29. package/dist/kubernetes-worker-runner.d.ts.map +1 -1
  30. package/dist/kubernetes-worker-runner.js +2 -2
  31. package/package.json +5 -5
  32. package/src/kubernetes-api-client.ts +3 -0
  33. package/src/kubernetes-http-client.ts +4 -0
  34. package/src/kubernetes-image-preload-api.ts +96 -0
  35. package/src/kubernetes-image-preload.ts +278 -0
  36. package/src/kubernetes-manifests.ts +75 -11
  37. package/src/kubernetes-preparation-api.ts +77 -0
  38. package/src/kubernetes-preparation.ts +100 -0
  39. package/src/kubernetes-volume-pool-api.ts +31 -104
  40. package/src/kubernetes-volume-pool.ts +3 -55
  41. package/src/kubernetes-worker-runner.ts +49 -26
  42. package/dist/chunk-ISH4647R.js.map +0 -1
  43. package/dist/chunk-V7TTFLGE.js.map +0 -1
  44. package/dist/chunk-YDYI3BD2.js.map +0 -1
@@ -52,12 +52,14 @@ export interface KubernetesWorkerServerCaConfigMapSpec {
52
52
 
53
53
  /** @internal */
54
54
  export interface KubernetesDockerPodSpecOptions {
55
+ /** Docker-only keys override the global Pod selector. @internal */
56
+ nodeSelector?: Record<string, string>;
55
57
  /** @internal */
56
58
  runtimeClassName: string;
57
59
  /** @internal */
58
60
  hostUsers?: boolean;
59
61
  /** @internal */
60
- gvisor?: boolean;
62
+ isolation?: "gvisor" | "virtual-machine";
61
63
  /** @internal */
62
64
  network?: DockerNetworkConfig;
63
65
  }
@@ -147,6 +149,13 @@ export interface KubernetesDockerConfigJsonSecretManifest extends NamespacedMani
147
149
 
148
150
  /** @internal */
149
151
  export interface KubernetesPodEventSummary {
152
+ /** @internal */
153
+ series?: {
154
+ /** @internal */
155
+ count?: number;
156
+ /** @internal */
157
+ lastObservedTime?: string;
158
+ };
150
159
  /** @internal */
151
160
  objectUid?: string;
152
161
  /** @internal */
@@ -598,25 +607,37 @@ export function buildKubernetesWorkerPodManifest(
598
607
  });
599
608
  const containerResources = resources(input);
600
609
  const ca = options.serverCaConfigMap;
610
+ const dockerEnv = { ...input.env };
611
+ delete dockerEnv.LEITWERK_DOCKER_GVISOR;
612
+ delete dockerEnv.LEITWERK_DOCKER_ISOLATION;
601
613
  const trustedDockerEnv = input.docker
602
614
  ? {
603
- ...input.env,
615
+ ...dockerEnv,
604
616
  DOCKER_HOST: "unix:///var/run/docker.sock",
605
617
  LEITWERK_PRIVATE_DOCKER: "1",
606
- ...(options.docker?.gvisor ? { LEITWERK_DOCKER_GVISOR: "1" } : {}),
618
+ ...(options.docker?.isolation === "gvisor" ? { LEITWERK_DOCKER_GVISOR: "1" } : {}),
619
+ ...(options.docker?.isolation === "virtual-machine"
620
+ ? { LEITWERK_DOCKER_ISOLATION: "virtual-machine" }
621
+ : {}),
607
622
  LEITWERK_PROCESS_VOLUME_MOUNT_PATH: volume.mountPath,
608
623
  ...(options.docker?.network
609
624
  ? { LEITWERK_DOCKER_NETWORK: JSON.stringify(options.docker.network) }
610
625
  : {}),
611
626
  }
612
- : input.env;
627
+ : dockerEnv;
613
628
  const container: KubernetesPodManifest["spec"]["containers"][number] = {
614
629
  name: "worker",
615
- ...(input.docker && options.docker?.gvisor
630
+ ...(input.docker && options.docker?.isolation
616
631
  ? {
617
632
  securityContext: {
618
633
  privileged: false as const,
619
- capabilities: { add: ["SYS_ADMIN", "NET_ADMIN"] },
634
+ // Docker opens nonroot child namespace handles within the VM guest.
635
+ capabilities: {
636
+ add:
637
+ options.docker?.isolation === "virtual-machine"
638
+ ? ["SYS_ADMIN", "NET_ADMIN", "SYS_PTRACE"]
639
+ : ["SYS_ADMIN", "NET_ADMIN"],
640
+ },
620
641
  },
621
642
  }
622
643
  : {}),
@@ -634,7 +655,13 @@ export function buildKubernetesWorkerPodManifest(
634
655
  input.docker && options.docker
635
656
  ? {
636
657
  runtimeClassName: options.docker.runtimeClassName,
637
- ...(options.docker.gvisor ? {} : { hostUsers: options.docker.hostUsers }),
658
+ ...(options.docker.nodeSelector
659
+ ? { nodeSelector: { ...options.nodeSelector, ...options.docker.nodeSelector } }
660
+ : {}),
661
+ ...(options.docker.isolation ? {} : { hostUsers: options.docker.hostUsers }),
662
+ ...(options.docker.isolation === "virtual-machine"
663
+ ? { automountServiceAccountToken: false }
664
+ : {}),
638
665
  }
639
666
  : {},
640
667
  );
@@ -667,7 +694,8 @@ function formatPodEvent(
667
694
  const pieces: string[] = [];
668
695
  if (event.type?.trim()) pieces.push(event.type.trim());
669
696
  if (event.reason?.trim()) pieces.push(event.reason.trim());
670
- if (event.count !== undefined && event.count > 1) pieces.push(`x${event.count}`);
697
+ const count = event.series?.count ?? event.count;
698
+ if (count !== undefined && count > 1) pieces.push(`x${count}`);
671
699
  const prefix = pieces.join(" ");
672
700
  const message = event.message?.trim();
673
701
  if (!prefix && !message) return null;
@@ -677,15 +705,51 @@ function formatPodEvent(
677
705
  );
678
706
  }
679
707
 
708
+ function podEventTimestamp(event: KubernetesPodEventSummary): number {
709
+ for (const value of [
710
+ event.series?.lastObservedTime,
711
+ event.lastTimestamp,
712
+ event.eventTime,
713
+ event.firstTimestamp,
714
+ ]) {
715
+ if (!value) continue;
716
+ const timestamp = Date.parse(value);
717
+ if (Number.isFinite(timestamp)) return timestamp;
718
+ }
719
+ return Number.NEGATIVE_INFINITY;
720
+ }
721
+
680
722
  /** @internal */
681
723
  export function formatKubernetesPodDiagnostics(
682
724
  events: readonly KubernetesPodEventSummary[] | undefined,
683
725
  limit = 3,
684
726
  sensitiveValues: readonly string[] = [],
685
727
  ): string | undefined {
686
- const formatted = (events ?? [])
687
- .map((event) => formatPodEvent(event, sensitiveValues))
688
- .filter((entry): entry is string => entry !== null)
728
+ const candidates = (events ?? []).map((event) => ({
729
+ formatted: formatPodEvent(event, sensitiveValues),
730
+ timestamp: podEventTimestamp(event),
731
+ warning: event.type?.trim() === "Warning",
732
+ identity: redactKubernetesDiagnostic(
733
+ JSON.stringify([event.type?.trim(), event.reason?.trim(), event.message?.trim()]),
734
+ sensitiveValues,
735
+ ),
736
+ }));
737
+ // API list order is not chronological. Keep recent phase context, using warnings only for ties.
738
+ candidates.sort((left, right) => {
739
+ if (left.timestamp !== right.timestamp) return left.timestamp > right.timestamp ? -1 : 1;
740
+ if (left.warning !== right.warning) return left.warning ? -1 : 1;
741
+ const leftText = left.formatted ?? "";
742
+ const rightText = right.formatted ?? "";
743
+ return leftText < rightText ? -1 : leftText > rightText ? 1 : 0;
744
+ });
745
+ const seen = new Set<string>();
746
+ const formatted = candidates
747
+ .filter((candidate) => {
748
+ if (candidate.formatted === null || seen.has(candidate.identity)) return false;
749
+ seen.add(candidate.identity);
750
+ return true;
751
+ })
752
+ .map((candidate) => candidate.formatted)
689
753
  .slice(0, limit);
690
754
  return formatted.length > 0
691
755
  ? boundedDiagnostic(`Kubernetes events: ${formatted.join(" | ")}`, sensitiveValues)
@@ -0,0 +1,77 @@
1
+ /** @internal */
2
+ export type PreparationRequest = <T>(input: {
3
+ /** @internal */ method: string;
4
+ /** @internal */ path: string;
5
+ /** @internal */ body?: unknown;
6
+ /** @internal */ contentType?: string;
7
+ /** @internal */ ok?: readonly number[];
8
+ /** @internal */ signal?: AbortSignal;
9
+ }) => Promise<{
10
+ /** @internal */ status: number;
11
+ /** @internal */ body: T | null;
12
+ }>;
13
+
14
+ /** Bounded transport for the server-owned preparation resources. @internal */
15
+ export function createPreparationApi(transport: PreparationRequest, component: string) {
16
+ const request: PreparationRequest = <T>(input: Parameters<PreparationRequest>[0]) =>
17
+ transport<T>({
18
+ ...input,
19
+ signal: input.signal
20
+ ? AbortSignal.any([input.signal, AbortSignal.timeout(10_000)])
21
+ : undefined,
22
+ });
23
+ return {
24
+ /** @internal */
25
+ request,
26
+ /** @internal */
27
+ async list<T>(path: string, selector: string, signal: AbortSignal): Promise<T[]> {
28
+ const items: T[] = [];
29
+ let cursor = "";
30
+ do {
31
+ const query = new URLSearchParams({ labelSelector: selector, limit: "100" });
32
+ if (cursor) query.set("continue", cursor);
33
+ const response = await request<{
34
+ /** @internal */ items: T[];
35
+ /** @internal */ metadata?: {
36
+ /** @internal */ continue?: string;
37
+ };
38
+ }>({ method: "GET", path: `${path}?${query}`, signal });
39
+ if (!response.body) throw new Error(`Missing ${component} list response`);
40
+ items.push(...response.body.items);
41
+ cursor = response.body.metadata?.continue ?? "";
42
+ } while (cursor);
43
+ return items;
44
+ },
45
+ /** @internal */
46
+ async get<T>(path: string, signal: AbortSignal): Promise<T | null> {
47
+ const response = await request<T>({ method: "GET", path, ok: [200, 404], signal });
48
+ return response.status === 404 ? null : response.body;
49
+ },
50
+ /** @internal */
51
+ async create(path: string, body: unknown, signal: AbortSignal): Promise<void> {
52
+ await request({ method: "POST", path, body, ok: [201, 409], signal });
53
+ },
54
+ /** @internal */
55
+ async delete(
56
+ path: string,
57
+ uid: string | undefined,
58
+ signal: AbortSignal,
59
+ identity: string,
60
+ gracePeriodSeconds?: number,
61
+ ): Promise<void> {
62
+ if (!uid) throw new Error(`${identity} identity is missing`);
63
+ await request({
64
+ method: "DELETE",
65
+ path,
66
+ body: {
67
+ apiVersion: "v1",
68
+ kind: "DeleteOptions",
69
+ preconditions: { uid },
70
+ ...(gracePeriodSeconds === undefined ? {} : { gracePeriodSeconds }),
71
+ },
72
+ ok: [200, 202, 404],
73
+ signal,
74
+ });
75
+ },
76
+ };
77
+ }
@@ -0,0 +1,100 @@
1
+ import { setTimeout as delay } from "node:timers/promises";
2
+ import type { VolumePoolOptions } from "./kubernetes-volume-pool.js";
3
+ import type { PoolObject } from "./kubernetes-volume-pool-api.js";
4
+
5
+ /** Shared inert preparation workload; callers supply ownership and placement constraints. @internal */
6
+ export function buildPreparationPodSpec(
7
+ options: Pick<
8
+ VolumePoolOptions,
9
+ "image" | "imagePullPolicy" | "imagePullSecrets" | "nodeSelector" | "tolerations"
10
+ >,
11
+ volumeMounts?: unknown[],
12
+ ): PoolObject["spec"] {
13
+ return {
14
+ restartPolicy: "Never",
15
+ serviceAccountName: "default",
16
+ automountServiceAccountToken: false,
17
+ nodeSelector: options.nodeSelector ?? {},
18
+ tolerations: options.tolerations ?? [],
19
+ imagePullSecrets: (options.imagePullSecrets ?? []).map((name) => ({ name })),
20
+ containers: [
21
+ {
22
+ name: "prepare",
23
+ image: options.image,
24
+ imagePullPolicy: options.imagePullPolicy ?? "IfNotPresent",
25
+ command: ["node", "-e", "process.exit(0)"],
26
+ resources: {
27
+ requests: { cpu: "1m", memory: "32Mi" },
28
+ limits: { cpu: "100m", memory: "64Mi" },
29
+ },
30
+ securityContext: {
31
+ allowPrivilegeEscalation: false,
32
+ readOnlyRootFilesystem: true,
33
+ capabilities: { drop: ["ALL"] },
34
+ },
35
+ ...(volumeMounts ? { volumeMounts } : {}),
36
+ },
37
+ ],
38
+ };
39
+ }
40
+
41
+ /** @internal */
42
+ export interface PreparationController {
43
+ /** @internal */
44
+ start(): void;
45
+ /** @internal */
46
+ stop(): Promise<void>;
47
+ }
48
+
49
+ /** One non-overlapping loop; stopping cancels and joins its current work. @internal */
50
+ export function createPreparationController(
51
+ reconcile: (signal: AbortSignal) => Promise<void>,
52
+ intervalMs: number,
53
+ onError?: () => void,
54
+ errorIntervalMs = intervalMs,
55
+ ): PreparationController {
56
+ let controller: AbortController | undefined;
57
+ let running: Promise<void> | undefined;
58
+ return {
59
+ start() {
60
+ if (controller) return;
61
+ controller = new AbortController();
62
+ const { signal } = controller;
63
+ running = (async () => {
64
+ while (!signal.aborted) {
65
+ let interval = intervalMs;
66
+ try {
67
+ await reconcile(signal);
68
+ } catch {
69
+ interval = errorIntervalMs;
70
+ if (!signal.aborted) onError?.();
71
+ }
72
+ try {
73
+ await delay(interval, undefined, { signal });
74
+ } catch {
75
+ break;
76
+ }
77
+ }
78
+ })();
79
+ },
80
+ async stop() {
81
+ controller?.abort();
82
+ await running;
83
+ controller = undefined;
84
+ },
85
+ };
86
+ }
87
+
88
+ /** Controllers own separate asynchronous reconciliation loops. @internal */
89
+ export function createKubernetesPreparation(controllers: PreparationController[]) {
90
+ return {
91
+ /** @internal */
92
+ start() {
93
+ for (const controller of controllers) controller.start();
94
+ },
95
+ /** @internal */
96
+ async stop() {
97
+ await Promise.allSettled(controllers.map((controller) => controller.stop()));
98
+ },
99
+ };
100
+ }
@@ -1,3 +1,5 @@
1
+ import { createPreparationApi, type PreparationRequest } from "./kubernetes-preparation-api.js";
2
+
1
3
  /** Kubernetes objects used for native PVC provisioning and safe PV rebinding. @internal */
2
4
  export interface PoolObject {
3
5
  /** @internal */
@@ -115,102 +117,34 @@ export interface VolumePoolApi {
115
117
  delete(kind: string, namespace: string, object: PoolObject, signal: AbortSignal): Promise<void>;
116
118
  }
117
119
 
118
- type Request = <T>(input: {
119
- method: string;
120
- path: string;
121
- body?: unknown;
122
- contentType?: string;
123
- ok?: readonly number[];
124
- signal?: AbortSignal;
125
- }) => Promise<{ status: number; body: T | null }>;
126
-
127
- export function createVolumePoolApi(request: Request): VolumePoolApi {
120
+ /** @internal */
121
+ export function createVolumePoolApi(request: PreparationRequest): VolumePoolApi {
122
+ const api = createPreparationApi(request, "volume-pool");
128
123
  const path = (kind: string, namespace: string, name?: string) =>
129
124
  `/api/v1/${namespace ? `namespaces/${encodeURIComponent(namespace)}/` : ""}${kind}${name ? `/${encodeURIComponent(name)}` : ""}`;
130
- const bounded = (signal: AbortSignal) => AbortSignal.any([signal, AbortSignal.timeout(10_000)]);
131
125
  const classes = "/apis/storage.k8s.io/v1/storageclasses";
132
- async function list<T>(collection: string, selector: string, signal: AbortSignal): Promise<T[]> {
133
- const items: T[] = [];
134
- let cursor = "";
135
- do {
136
- const query = new URLSearchParams({
137
- labelSelector: selector,
138
- limit: "100",
139
- ...(cursor ? { continue: cursor } : {}),
140
- });
141
- const response = await request<{ items: T[]; metadata?: { continue?: string } }>({
142
- method: "GET",
143
- path: `${collection}?${query}`,
144
- signal: bounded(signal),
145
- });
146
- if (!response.body) throw new Error("Missing volume-pool list response");
147
- items.push(...response.body.items);
148
- cursor = response.body.metadata?.continue ?? "";
149
- } while (cursor);
150
- return items;
151
- }
152
126
 
153
127
  return {
154
- async getStorageClass(name, signal) {
155
- const response = await request<PoolStorageClass>({
156
- method: "GET",
157
- path: `${classes}/${encodeURIComponent(name)}`,
158
- ok: [200, 404],
159
- signal: bounded(signal),
160
- });
161
- return response.status === 404 ? null : response.body;
162
- },
163
- listStorageClasses(selector, signal) {
164
- return list<PoolStorageClass>(classes, selector, signal);
165
- },
166
- async createStorageClass(value, signal) {
167
- await request({
168
- method: "POST",
169
- path: classes,
170
- body: value,
171
- ok: [201, 409],
172
- signal: bounded(signal),
173
- });
174
- },
175
- async deleteStorageClass(value, signal) {
176
- if (!value.metadata.uid) throw new Error("Staging StorageClass identity is missing");
177
- await request({
178
- method: "DELETE",
179
- path: `${classes}/${encodeURIComponent(value.metadata.name)}`,
180
- body: {
181
- apiVersion: "v1",
182
- kind: "DeleteOptions",
183
- preconditions: { uid: value.metadata.uid },
184
- },
185
- ok: [200, 202, 404],
186
- signal: bounded(signal),
187
- });
188
- },
189
- list(kind, namespace, selector, signal) {
190
- return list<PoolObject>(path(kind, namespace), selector, signal);
191
- },
192
- async get(kind, namespace, name, signal) {
193
- const result = await request<PoolObject>({
194
- method: "GET",
195
- path: path(kind, namespace, name),
196
- ok: [200, 404],
197
- signal: bounded(signal),
198
- });
199
- return result.status === 404 ? null : result.body;
200
- },
201
- async create(kind, namespace, object, signal) {
202
- await request({
203
- method: "POST",
204
- path: path(kind, namespace),
205
- body: object,
206
- ok: [201, 409],
207
- signal: bounded(signal),
208
- });
209
- },
128
+ getStorageClass: (name, signal) =>
129
+ api.get<PoolStorageClass>(`${classes}/${encodeURIComponent(name)}`, signal),
130
+ listStorageClasses: (selector, signal) => api.list<PoolStorageClass>(classes, selector, signal),
131
+ createStorageClass: (value, signal) => api.create(classes, value, signal),
132
+ deleteStorageClass: (value, signal) =>
133
+ api.delete(
134
+ `${classes}/${encodeURIComponent(value.metadata.name)}`,
135
+ value.metadata.uid,
136
+ signal,
137
+ "Staging StorageClass",
138
+ ),
139
+ list: (kind, namespace, selector, signal) =>
140
+ api.list<PoolObject>(path(kind, namespace), selector, signal),
141
+ get: (kind, namespace, name, signal) =>
142
+ api.get<PoolObject>(path(kind, namespace, name), signal),
143
+ create: (kind, namespace, object, signal) => api.create(path(kind, namespace), object, signal),
210
144
  async patchVolume(volume, operations, signal) {
211
145
  if (!volume.metadata.uid || !volume.metadata.resourceVersion)
212
146
  throw new Error("PV identity is missing");
213
- await request({
147
+ await api.request({
214
148
  method: "PATCH",
215
149
  path: path("persistentvolumes", "", volume.metadata.name),
216
150
  contentType: "application/json-patch+json",
@@ -219,23 +153,16 @@ export function createVolumePoolApi(request: Request): VolumePoolApi {
219
153
  { op: "test", path: "/metadata/resourceVersion", value: volume.metadata.resourceVersion },
220
154
  ...operations,
221
155
  ],
222
- signal: bounded(signal),
223
- });
224
- },
225
- async delete(kind, namespace, object, signal) {
226
- if (!object.metadata.uid) throw new Error("Preparation resource identity is missing");
227
- await request({
228
- method: "DELETE",
229
- path: path(kind, namespace, object.metadata.name),
230
- body: {
231
- apiVersion: "v1",
232
- kind: "DeleteOptions",
233
- preconditions: { uid: object.metadata.uid },
234
- gracePeriodSeconds: 1,
235
- },
236
- ok: [200, 202, 404],
237
- signal: bounded(signal),
156
+ signal,
238
157
  });
239
158
  },
159
+ delete: (kind, namespace, object, signal) =>
160
+ api.delete(
161
+ path(kind, namespace, object.metadata.name),
162
+ object.metadata.uid,
163
+ signal,
164
+ "Preparation resource",
165
+ 1,
166
+ ),
240
167
  };
241
168
  }
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import { setTimeout as delay } from "node:timers/promises";
2
+ import { buildPreparationPodSpec, createPreparationController } from "./kubernetes-preparation.js";
3
3
  import type { PoolObject, VolumePoolApi } from "./kubernetes-volume-pool-api.js";
4
4
 
5
5
  export const POOL_LABEL = "leitwerk.dev/volume-pool";
@@ -54,8 +54,6 @@ export function createKubernetesVolumePool(options: VolumePoolOptions) {
54
54
  [POOL_LABEL]: poolId,
55
55
  "leitwerk.dev/component": "volume-preparation",
56
56
  };
57
- let controller: AbortController | undefined;
58
- let running: Promise<void> | undefined;
59
57
 
60
58
  function preparationPod(claim: PoolObject): PoolObject {
61
59
  return {
@@ -75,30 +73,7 @@ export function createKubernetesVolumePool(options: VolumePoolOptions) {
75
73
  ],
76
74
  },
77
75
  spec: {
78
- restartPolicy: "Never",
79
- serviceAccountName: "default",
80
- automountServiceAccountToken: false,
81
- nodeSelector: options.nodeSelector ?? {},
82
- tolerations: options.tolerations ?? [],
83
- imagePullSecrets: (options.imagePullSecrets ?? []).map((name) => ({ name })),
84
- containers: [
85
- {
86
- name: "prepare",
87
- image: options.image,
88
- imagePullPolicy: options.imagePullPolicy ?? "IfNotPresent",
89
- command: ["node", "-e", "process.exit(0)"],
90
- resources: {
91
- requests: { cpu: "1m", memory: "32Mi" },
92
- limits: { cpu: "100m", memory: "64Mi" },
93
- },
94
- securityContext: {
95
- allowPrivilegeEscalation: false,
96
- readOnlyRootFilesystem: true,
97
- capabilities: { drop: ["ALL"] },
98
- },
99
- volumeMounts: [{ name: "volume", mountPath: "/volume" }],
100
- },
101
- ],
76
+ ...buildPreparationPodSpec(options, [{ name: "volume", mountPath: "/volume" }]),
102
77
  volumes: [{ name: "volume", persistentVolumeClaim: { claimName: claim.metadata.name } }],
103
78
  },
104
79
  };
@@ -343,33 +318,6 @@ export function createKubernetesVolumePool(options: VolumePoolOptions) {
343
318
  poolId,
344
319
  /** @internal */
345
320
  reconcile,
346
- /** @internal */
347
- start() {
348
- if (controller) return;
349
- controller = new AbortController();
350
- const { signal } = controller;
351
- running = (async () => {
352
- while (!signal.aborted) {
353
- let interval = 2_000;
354
- try {
355
- await reconcile(signal);
356
- } catch {
357
- interval = 30_000;
358
- if (!signal.aborted) options.onError?.();
359
- }
360
- try {
361
- await delay(interval, undefined, { signal });
362
- } catch {
363
- break;
364
- }
365
- }
366
- })();
367
- },
368
- /** @internal */
369
- async stop() {
370
- controller?.abort();
371
- await running;
372
- controller = undefined;
373
- },
321
+ ...createPreparationController(reconcile, 2_000, () => options.onError?.(), 30_000),
374
322
  };
375
323
  }