@leitwerk-dev/worker-runners 0.1.8 → 0.2.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.
- package/dist/chunk-4F7EMXMU.js +119 -0
- package/dist/chunk-4F7EMXMU.js.map +1 -0
- package/dist/{chunk-HLTGLGUS.js → chunk-63BBCX7B.js} +69 -93
- package/dist/chunk-63BBCX7B.js.map +1 -0
- package/dist/{chunk-6WACBFXN.js → chunk-6BSZBMHH.js} +18 -1
- package/dist/chunk-6BSZBMHH.js.map +1 -0
- package/dist/{chunk-DL3Y3R6E.js → chunk-7NF2P2VP.js} +74 -8
- package/dist/chunk-7NF2P2VP.js.map +1 -0
- package/dist/chunk-7X5FBNT7.js +14 -0
- package/dist/chunk-7X5FBNT7.js.map +1 -0
- package/dist/chunk-D56NJQ5X.js +90 -0
- package/dist/chunk-D56NJQ5X.js.map +1 -0
- package/dist/chunk-ISEDLYKQ.js +881 -0
- package/dist/chunk-ISEDLYKQ.js.map +1 -0
- package/dist/{chunk-IRFVGUXJ.js → chunk-OSS62AOL.js} +7 -3
- package/dist/{chunk-IRFVGUXJ.js.map → chunk-OSS62AOL.js.map} +1 -1
- package/dist/chunk-UGKQOL5E.js +39 -0
- package/dist/chunk-UGKQOL5E.js.map +1 -0
- package/dist/{chunk-2TSWMVLZ.js → chunk-YBSX4N2K.js} +156 -37
- package/dist/chunk-YBSX4N2K.js.map +1 -0
- package/dist/chunk-YJMHXKNO.js +308 -0
- package/dist/chunk-YJMHXKNO.js.map +1 -0
- package/dist/{docker-engine-client-Cpmy2yma.d.ts → docker-engine-client-CnXspTGq.d.ts} +8 -21
- package/dist/docker-engine-client.d.ts +7 -20
- package/dist/docker-engine-client.d.ts.map +1 -1
- package/dist/docker-engine-http-client.d.ts +0 -8
- package/dist/docker-engine-http-client.d.ts.map +1 -1
- package/dist/docker-engine-http-client.js +12 -201
- package/dist/docker-engine-http-client.js.map +1 -1
- package/dist/docker-worker-runner.d.ts +11 -4
- package/dist/docker-worker-runner.d.ts.map +1 -1
- package/dist/docker-worker-runner.js +12 -235
- package/dist/docker-worker-runner.js.map +1 -1
- package/dist/fake-docker-engine-client.d.ts.map +1 -1
- package/dist/filesystem-process-state-exporter.d.ts +10 -0
- package/dist/filesystem-process-state-exporter.d.ts.map +1 -0
- package/dist/helper-process-state-exporter.d.ts +28 -0
- package/dist/helper-process-state-exporter.d.ts.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +305 -9
- package/dist/index.js.map +1 -1
- package/dist/{kubernetes-api-client-BcwF2uon.d.ts → kubernetes-api-client-DD2YevYP.d.ts} +128 -85
- package/dist/kubernetes-api-client.d.ts +33 -6
- package/dist/kubernetes-api-client.d.ts.map +1 -1
- package/dist/kubernetes-http-client.d.ts.map +1 -1
- package/dist/kubernetes-http-client.js +496 -286
- package/dist/kubernetes-http-client.js.map +1 -1
- package/dist/kubernetes-manifests.d.ts +40 -77
- package/dist/kubernetes-manifests.d.ts.map +1 -1
- package/dist/kubernetes-startup-sampler.d.ts +14 -0
- package/dist/kubernetes-startup-sampler.d.ts.map +1 -0
- package/dist/kubernetes-volume-pool-api.d.ts +69 -0
- package/dist/kubernetes-volume-pool-api.d.ts.map +1 -0
- package/dist/kubernetes-volume-pool.d.ts +24 -0
- package/dist/kubernetes-volume-pool.d.ts.map +1 -0
- package/dist/kubernetes-worker-runner.d.ts +26 -2
- package/dist/kubernetes-worker-runner.d.ts.map +1 -1
- package/dist/kubernetes-worker-runner.js +12 -161
- package/dist/kubernetes-worker-runner.js.map +1 -1
- package/dist/local-worker-runner.d.ts +11 -1
- package/dist/local-worker-runner.d.ts.map +1 -1
- package/dist/local-worker-runner.js +14 -108
- package/dist/local-worker-runner.js.map +1 -1
- package/dist/runner-utils.d.ts +3 -1
- package/dist/runner-utils.d.ts.map +1 -1
- package/dist/session-transfer-helper-cli.d.ts +2 -0
- package/dist/session-transfer-helper-cli.d.ts.map +1 -0
- package/dist/session-transfer-helper-cli.js +9 -0
- package/dist/session-transfer-helper-cli.js.map +1 -0
- package/dist/session-transfer-helper.d.ts +4 -0
- package/dist/session-transfer-helper.d.ts.map +1 -0
- package/dist/session-transfer-helper.js +11 -0
- package/dist/session-transfer-helper.js.map +1 -0
- package/dist/types.d.ts +60 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -11
- package/dist/types.js.map +1 -1
- package/dist/worker-labels.d.ts +7 -0
- package/dist/worker-labels.d.ts.map +1 -1
- package/package.json +13 -5
- package/src/docker-engine-client.ts +7 -20
- package/src/docker-engine-http-client.ts +77 -96
- package/src/docker-worker-runner.ts +180 -54
- package/src/fake-docker-engine-client.ts +13 -41
- package/src/filesystem-process-state-exporter.ts +42 -0
- package/src/helper-process-state-exporter.ts +149 -0
- package/src/index.ts +14 -5
- package/src/kubernetes-api-client.ts +70 -10
- package/src/kubernetes-http-client.ts +228 -92
- package/src/kubernetes-manifests.ts +265 -336
- package/src/kubernetes-startup-sampler.ts +191 -0
- package/src/kubernetes-volume-pool-api.ts +187 -0
- package/src/kubernetes-volume-pool.ts +357 -0
- package/src/kubernetes-worker-runner.ts +316 -39
- package/src/local-worker-runner.ts +82 -6
- package/src/runner-utils.ts +10 -2
- package/src/session-transfer-helper-cli.ts +5 -0
- package/src/session-transfer-helper.ts +105 -0
- package/src/types.ts +87 -14
- package/src/worker-labels.ts +18 -0
- package/dist/chunk-2TSWMVLZ.js.map +0 -1
- package/dist/chunk-6WACBFXN.js.map +0 -1
- package/dist/chunk-DL3Y3R6E.js.map +0 -1
- package/dist/chunk-DUFA24LP.js +0 -401
- package/dist/chunk-DUFA24LP.js.map +0 -1
- package/dist/chunk-HLTGLGUS.js.map +0 -1
- package/dist/chunk-P4DIFRBH.js +0 -187
- package/dist/chunk-P4DIFRBH.js.map +0 -1
- package/dist/docker-engine-client.js +0 -10
- package/dist/docker-engine-client.js.map +0 -1
- package/dist/fake-docker-engine-client.js +0 -131
- package/dist/fake-docker-engine-client.js.map +0 -1
- package/dist/kubernetes-api-client.js +0 -142
- package/dist/kubernetes-api-client.js.map +0 -1
- package/dist/kubernetes-manifests.js +0 -379
- package/dist/kubernetes-manifests.js.map +0 -1
- package/dist/process-volume-retention.js +0 -46
- package/dist/process-volume-retention.js.map +0 -1
- package/dist/runner-utils.js +0 -36
- package/dist/runner-utils.js.map +0 -1
- package/dist/worker-labels.js +0 -83
- package/dist/worker-labels.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/kubernetes-worker-runner.ts","../src/kubernetes-startup-sampler.ts","../src/kubernetes-volume-pool.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport {\n\tcreateHelperProcessStateExporter,\n\texportHelperEnvironment,\n} from \"./helper-process-state-exporter.js\";\nimport type { KubernetesApiClient } from \"./kubernetes-api-client.js\";\nimport {\n\tbuildKubernetesDockerConfigJsonSecretManifest,\n\tbuildKubernetesExportHelperPodManifest,\n\tbuildKubernetesProcessNamespaceManifest,\n\tbuildKubernetesProcessPvcManifest,\n\tbuildKubernetesServerCaConfigMapManifest,\n\tbuildKubernetesWorkerPodManifest,\n\tKUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_KEY,\n\tKUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_NAME,\n\tKUBERNETES_WORKER_SERVER_CA_MOUNT_PATH,\n\ttype KubernetesDockerPodSpecOptions,\n\ttype KubernetesPodSpecOptions,\n\ttype KubernetesProcessVolumeSpec,\n\tkubernetesExportHelperPodName,\n\tkubernetesProcessNamespaceName,\n\tkubernetesProcessPvcName,\n\tredactKubernetesDiagnostic,\n\tvolumeRefFromPvc,\n} from \"./kubernetes-manifests.js\";\nimport { sampleKubernetesStartup, startupReceipt } from \"./kubernetes-startup-sampler.js\";\nimport { createKubernetesVolumePool } from \"./kubernetes-volume-pool.js\";\nimport { UnitExitNotifier } from \"./runner-utils.js\";\nimport {\n\tSESSION_TRANSFER_HELPER_ENTRY_PATH,\n\tSESSION_TRANSFER_HELPER_MOUNT_PATH,\n} from \"./session-transfer-helper.js\";\nimport type {\n\tIsolatedStartWorkerInput,\n\tProcessStateExporter,\n\tProcessStateExportHelperRelayProvider,\n\tProcessVolume,\n\tStopWorkerOptions,\n\tWorkerRunner,\n\tWorkerUnit,\n\tWorkerUnitDescriptor,\n\tWorkerUnitRef,\n} from \"./types.js\";\nimport { WorkerStartDiagnosticError } from \"./types.js\";\nimport {\n\tmanagedExportHelperLabelSelector,\n\tmanagedProcessNamespaceLabelSelector,\n\tmanagedWorkerLabelSelector,\n\tparseWorkerUnitIdentity,\n\tWORKER_LABEL_COMPONENT,\n\tWORKER_LABEL_INSTANCE_ID,\n\tWORKER_LABEL_MANAGED_BY,\n\tWORKER_LABEL_MANAGED_BY_VALUE,\n} from \"./worker-labels.js\";\n\nconst KUBERNETES_START_DIAGNOSTIC_MAX_LENGTH = 2_048;\n\nfunction boundedKubernetesStartDiagnostic(\n\terror: unknown,\n\tsensitiveValues: readonly string[],\n): string {\n\tconst detail = error instanceof Error ? error.message : \"Kubernetes Pod admission failed\";\n\treturn redactKubernetesDiagnostic(detail, sensitiveValues).slice(\n\t\t0,\n\t\tKUBERNETES_START_DIAGNOSTIC_MAX_LENGTH,\n\t);\n}\n\nexport interface KubernetesWorkerRunnerOptions {\n\tpreProvision?: { count: number; onError?: () => void };\n\tclient: KubernetesApiClient;\n\t/** Prefix used to derive one Kubernetes namespace per process instance. */\n\tprocessNamespacePrefix: string;\n\tvolume: KubernetesProcessVolumeSpec;\n\t/** Storage and Pod wiring for process definitions that require private Docker. */\n\tdocker?: KubernetesDockerPodSpecOptions & { processStorageClassName: string };\n\t/** Maximum wait after deletion before replacement is rejected. */\n\tpodDisappearanceTimeoutMs?: number;\n\tpodDisappearancePollIntervalMs?: number;\n\t/** Test seam for bounded disappearance polling. */\n\tdelay?: (ms: number) => Promise<void>;\n\t/** Server-local CA bundle copied into each process namespace for worker TLS trust. */\n\tserverCaFile?: string;\n\t/** Namespace containing operator-managed source image-pull Secrets. */\n\tserverNamespace?: string;\n\t/** Docker registry Secrets copied into every process namespace. */\n\timagePullSecretCopies?: Array<{ sourceName: string; targetName: string }>;\n\tpod?: Omit<KubernetesPodSpecOptions, \"namespace\">;\n\t/** Stable internal URL used by PVC export helpers. */\n\tserverUrl?: string;\n\t/** Trusted image containing the bundled session-transfer helper entrypoint. */\n\texporterImage?: string;\n\t/** Pull policy for the trusted helper image. */\n\texporterImagePullPolicy?: string;\n\t/** Server-owned relay registry used by PVC export helpers. */\n\thelperRelays?: ProcessStateExportHelperRelayProvider;\n}\n\nexport function createKubernetesWorkerRunner(options: KubernetesWorkerRunnerOptions): {\n\trunner: WorkerRunner<IsolatedStartWorkerInput>;\n\tvolume: ProcessVolume;\n\texporter: ProcessStateExporter;\n\tvolumePool?: ReturnType<typeof createKubernetesVolumePool>;\n} {\n\tif (!options.serverUrl || !options.exporterImage || !options.helperRelays) {\n\t\tthrow new Error(\"Kubernetes transfer exporter is not configured\");\n\t}\n\tconst { client } = options;\n\tconst exporterServerUrl = options.serverUrl;\n\tconst exporterImage = options.exporterImage;\n\tconst helperRelays = options.helperRelays;\n\tconst serverCaFile = options.serverCaFile?.trim();\n\tconst namespaceForProcess = (instanceId: string) =>\n\t\tkubernetesProcessNamespaceName(instanceId, options.processNamespacePrefix);\n\tconst delay =\n\t\toptions.delay ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)));\n\tconst podDisappearanceTimeoutMs = options.podDisappearanceTimeoutMs ?? 30_000;\n\tconst podDisappearancePollIntervalMs = options.podDisappearancePollIntervalMs ?? 250;\n\n\tconst samplers = new Map<string, ReturnType<typeof sampleKubernetesStartup>>();\n\tconst volume: ProcessVolume = {\n\t\tasync ensure(instanceId, requirements, observer) {\n\t\t\tconst namespaceManifest = buildKubernetesProcessNamespaceManifest({\n\t\t\t\tinstanceId,\n\t\t\t\tprocessNamespacePrefix: options.processNamespacePrefix,\n\t\t\t});\n\t\t\tawait client.ensureNamespace(namespaceManifest);\n\t\t\tconst copySecrets = (options.imagePullSecretCopies ?? []).map(async (copy) => {\n\t\t\t\tconst dockerConfigJson = await client.getDockerConfigJsonSecret(\n\t\t\t\t\tcopy.sourceName,\n\t\t\t\t\toptions.serverNamespace ?? \"leitwerk-system\",\n\t\t\t\t);\n\t\t\t\tawait client.ensureDockerConfigJsonSecret(\n\t\t\t\t\tbuildKubernetesDockerConfigJsonSecretManifest({\n\t\t\t\t\t\tinstanceId,\n\t\t\t\t\t\tnamespace: namespaceManifest.metadata.name,\n\t\t\t\t\t\tname: copy.targetName,\n\t\t\t\t\t\tdockerConfigJson,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst workerServiceAccount = options.pod?.workerServiceAccount?.trim();\n\t\t\tconst manifest = buildKubernetesProcessPvcManifest({\n\t\t\t\tinstanceId,\n\t\t\t\tnamespace: namespaceManifest.metadata.name,\n\t\t\t\tvolume: {\n\t\t\t\t\t...options.volume,\n\t\t\t\t\tsize: requirements?.size ?? options.volume.size,\n\t\t\t\t\t...(requirements?.docker && options.docker\n\t\t\t\t\t\t? { storageClassName: options.docker.processStorageClassName }\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait Promise.all([\n\t\t\t\t...copySecrets,\n\t\t\t\t...(serverCaFile\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tclient.ensureConfigMap(\n\t\t\t\t\t\t\t\tbuildKubernetesServerCaConfigMapManifest({\n\t\t\t\t\t\t\t\t\tinstanceId,\n\t\t\t\t\t\t\t\t\tnamespace: namespaceManifest.metadata.name,\n\t\t\t\t\t\t\t\t\tcaPem: readFileSync(serverCaFile, \"utf8\"),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t: []),\n\t\t\t\t...(workerServiceAccount && workerServiceAccount !== \"default\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tclient.ensureServiceAccount(workerServiceAccount, namespaceManifest.metadata.name, {\n\t\t\t\t\t\t\t\t[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,\n\t\t\t\t\t\t\t\t[WORKER_LABEL_COMPONENT]: \"worker-service-account\",\n\t\t\t\t\t\t\t\t[WORKER_LABEL_INSTANCE_ID]: instanceId,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]\n\t\t\t\t\t: []),\n\t\t\t\t(async () => {\n\t\t\t\t\tstartupReceipt(observer, \"pvc_requested\", {\n\t\t\t\t\t\tstorageClass: manifest.spec.storageClassName,\n\t\t\t\t\t});\n\t\t\t\t\tawait client.ensurePersistentVolumeClaim(manifest);\n\t\t\t\t\tstartupReceipt(observer, \"pvc_acknowledged\", {\n\t\t\t\t\t\tstorageClass: manifest.spec.storageClassName,\n\t\t\t\t\t});\n\t\t\t\t\tif (observer?.observe) {\n\t\t\t\t\t\tsamplers.get(instanceId)?.stop();\n\t\t\t\t\t\tsamplers.set(\n\t\t\t\t\t\t\tinstanceId,\n\t\t\t\t\t\t\tsampleKubernetesStartup(\n\t\t\t\t\t\t\t\tclient,\n\t\t\t\t\t\t\t\tobserver,\n\t\t\t\t\t\t\t\tmanifest.metadata.namespace,\n\t\t\t\t\t\t\t\tmanifest.metadata.name,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t})(),\n\t\t\t]);\n\t\t\treturn volumeRefFromPvc({\n\t\t\t\tinstanceId,\n\t\t\t\tpvcName: manifest.metadata.name,\n\t\t\t\tmountPath: options.volume.mountPath,\n\t\t\t\tnamespace: manifest.metadata.namespace,\n\t\t\t});\n\t\t},\n\t\tasync release(instanceId) {\n\t\t\tawait client.deletePersistentVolumeClaim(\n\t\t\t\tkubernetesProcessPvcName(instanceId, options.volume.namePrefix),\n\t\t\t\tnamespaceForProcess(instanceId),\n\t\t\t);\n\t\t},\n\t\tasync deleteProcessResources(instanceId) {\n\t\t\tsamplers.get(instanceId)?.stop();\n\t\t\tsamplers.delete(instanceId);\n\t\t\tawait client.deleteNamespace(namespaceForProcess(instanceId));\n\t\t},\n\t};\n\n\tconst exitNotifier = new UnitExitNotifier();\n\tconst unsubscribers = new Map<string, () => void>();\n\tconst disappearancePromises = new Map<string, Promise<void>>();\n\n\tfunction unitKey(namespace: string, unitId: string): string {\n\t\treturn `${namespace}/${unitId}`;\n\t}\n\n\tfunction deletePodAndWait(\n\t\tname: string,\n\t\tnamespace: string,\n\t\tgracePeriodSeconds: number,\n\t): Promise<void> {\n\t\tconst key = unitKey(namespace, name);\n\t\tconst existing = disappearancePromises.get(key);\n\t\tif (existing) return existing;\n\t\tconst operation = Promise.resolve()\n\t\t\t.then(async () => {\n\t\t\t\tconst deadline = Date.now() + podDisappearanceTimeoutMs;\n\t\t\t\tconst timeoutError = new Error(\n\t\t\t\t\t`Kubernetes worker Pod ${namespace}/${name} did not disappear within ${podDisappearanceTimeoutMs}ms; replacement was not started`,\n\t\t\t\t);\n\t\t\t\tconst controller = new AbortController();\n\t\t\t\tconst { signal } = controller;\n\t\t\t\tlet rejectTimeout!: (error: Error) => void;\n\t\t\t\tconst timedOut = new Promise<never>((_resolve, reject) => {\n\t\t\t\t\trejectTimeout = reject;\n\t\t\t\t});\n\t\t\t\tconst timer = setTimeout(() => {\n\t\t\t\t\tcontroller.abort(timeoutError);\n\t\t\t\t\trejectTimeout(timeoutError);\n\t\t\t\t}, podDisappearanceTimeoutMs);\n\t\t\t\tconst waitForDisappearance = async () => {\n\t\t\t\t\tawait client.deletePod(name, namespace, { gracePeriodSeconds, signal });\n\t\t\t\t\twhile (true) {\n\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\tif (Date.now() >= deadline) throw timeoutError;\n\t\t\t\t\t\tconst pod = await client.getPod(name, namespace, { signal });\n\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\tif (Date.now() >= deadline) throw timeoutError;\n\t\t\t\t\t\tif (!pod) return;\n\t\t\t\t\t\tawait delay(\n\t\t\t\t\t\t\tMath.min(podDisappearancePollIntervalMs, Math.max(0, deadline - Date.now())),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\ttry {\n\t\t\t\t\tawait Promise.race([waitForDisappearance(), timedOut]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (signal.aborted) throw timeoutError;\n\t\t\t\t\tthrow error;\n\t\t\t\t} finally {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => disappearancePromises.delete(key));\n\t\tdisappearancePromises.set(key, operation);\n\t\treturn operation;\n\t}\n\n\tfunction watchPod(\n\t\tunitId: string,\n\t\tnamespace: string,\n\t\tsensitiveValues: readonly string[] = [],\n\t): void {\n\t\tconst key = unitKey(namespace, unitId);\n\t\tif (unsubscribers.has(key)) return;\n\t\tconst unsubscribe = client.onPodExit(\n\t\t\tunitId,\n\t\t\tnamespace,\n\t\t\t(info) => {\n\t\t\t\texitNotifier.fireExit(key, info);\n\t\t\t\tunsubscribers.get(key)?.();\n\t\t\t\tunsubscribers.delete(key);\n\t\t\t},\n\t\t\t{ sensitiveValues },\n\t\t);\n\t\tunsubscribers.set(key, unsubscribe);\n\t}\n\n\tconst runner: WorkerRunner<IsolatedStartWorkerInput> = {\n\t\tasync start(input: IsolatedStartWorkerInput, observer): Promise<WorkerUnit> {\n\t\t\tobserver?.report(\"preparing_runtime\");\n\t\t\tif (input.docker && !options.docker) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Kubernetes Docker runtime is unavailable; configure kubernetes.docker completely\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst processNamespace = input.volume.namespace ?? namespaceForProcess(input.instanceId);\n\t\t\tconst manifest = buildKubernetesWorkerPodManifest(input, {\n\t\t\t\tnamespace: processNamespace,\n\t\t\t\t...(options.pod ?? {}),\n\t\t\t\t...(input.docker && options.docker ? { docker: options.docker } : {}),\n\t\t\t\t...(serverCaFile\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tserverCaConfigMap: {\n\t\t\t\t\t\t\t\tname: KUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_NAME,\n\t\t\t\t\t\t\t\tkey: KUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_KEY,\n\t\t\t\t\t\t\t\tmountPath: KUBERNETES_WORKER_SERVER_CA_MOUNT_PATH,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t\tobserver?.report(\"allocating_runtime\");\n\t\t\ttry {\n\t\t\t\tstartupReceipt(observer, \"pod_requested\", {\n\t\t\t\t\timage: input.image.reference,\n\t\t\t\t\t...input.resources,\n\t\t\t\t});\n\t\t\t\tawait client.createPod(manifest);\n\t\t\t\tstartupReceipt(observer, \"pod_acknowledged\");\n\t\t\t\tsamplers.get(input.instanceId)?.attachPod({\n\t\t\t\t\tname: manifest.metadata.name,\n\t\t\t\t\tworkerId: input.workerId,\n\t\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tsamplers.get(input.instanceId)?.stop();\n\t\t\t\tsamplers.delete(input.instanceId);\n\t\t\t\tthrow new WorkerStartDiagnosticError(\n\t\t\t\t\tboundedKubernetesStartDiagnostic(error, Object.values(input.env)),\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t\tobserver?.report(\"starting_runtime\");\n\t\t\tconst ref: WorkerUnitRef = {\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: input.workerId,\n\t\t\t\tunitId: manifest.metadata.name,\n\t\t\t\tnamespace: manifest.metadata.namespace,\n\t\t\t};\n\t\t\twatchPod(ref.unitId, ref.namespace ?? processNamespace, Object.values(input.env));\n\t\t\treturn exitNotifier.wrapUnit(ref, unitKey(ref.namespace ?? processNamespace, ref.unitId), {\n\t\t\t\treplacementHandoff: \"stop-before-replacement\",\n\t\t\t});\n\t\t},\n\t\tasync stop(ref: WorkerUnitRef, opts: StopWorkerOptions): Promise<void> {\n\t\t\tsamplers.get(ref.instanceId)?.stop();\n\t\t\tsamplers.delete(ref.instanceId);\n\t\t\tawait deletePodAndWait(\n\t\t\t\tref.unitId,\n\t\t\t\tref.namespace ?? namespaceForProcess(ref.instanceId),\n\t\t\t\tMath.max(0, Math.ceil(opts.graceMs / 1000)),\n\t\t\t);\n\t\t},\n\t\tasync list(): Promise<WorkerUnitDescriptor[]> {\n\t\t\tconst namespaces = await client.listNamespaces(managedProcessNamespaceLabelSelector());\n\t\t\tconst descriptors: WorkerUnitDescriptor[] = [];\n\t\t\tfor (const namespace of namespaces) {\n\t\t\t\tif (!namespace.name.startsWith(options.processNamespacePrefix)) continue;\n\t\t\t\tconst pods = await client.listPods(namespace.name, managedWorkerLabelSelector());\n\t\t\t\tfor (const pod of pods) {\n\t\t\t\t\tconst identity = parseWorkerUnitIdentity(pod.labels);\n\t\t\t\t\tif (!identity) continue;\n\t\t\t\t\tdescriptors.push({\n\t\t\t\t\t\tinstanceId: identity.instanceId,\n\t\t\t\t\t\tworkerId: identity.workerId,\n\t\t\t\t\t\tunitId: pod.name,\n\t\t\t\t\t\tnamespace: pod.namespace,\n\t\t\t\t\t\tobservedState:\n\t\t\t\t\t\t\tpod.phase === \"Failed\" || pod.phase === \"Succeeded\"\n\t\t\t\t\t\t\t\t? \"terminal\"\n\t\t\t\t\t\t\t\t: pod.phase === \"Pending\"\n\t\t\t\t\t\t\t\t\t? \"pending\"\n\t\t\t\t\t\t\t\t\t: pod.phase === \"Running\"\n\t\t\t\t\t\t\t\t\t\t? \"running\"\n\t\t\t\t\t\t\t\t\t\t: \"unknown\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn descriptors;\n\t\t},\n\t\tasync adopt(descriptor: WorkerUnitDescriptor, observer): Promise<WorkerUnit> {\n\t\t\tconst podNamespace = descriptor.namespace ?? namespaceForProcess(descriptor.instanceId);\n\t\t\tconst pod = await client.getPod(descriptor.unitId, podNamespace);\n\t\t\tconst identity = pod ? parseWorkerUnitIdentity(pod.labels) : null;\n\t\t\tif (\n\t\t\t\t!identity ||\n\t\t\t\tidentity.instanceId !== descriptor.instanceId ||\n\t\t\t\tidentity.workerId !== descriptor.workerId\n\t\t\t) {\n\t\t\t\tthrow new Error(`Cannot adopt worker pod ${descriptor.unitId}: labels changed`);\n\t\t\t}\n\t\t\tif (!pod || pod.phase === \"Failed\" || pod.phase === \"Succeeded\") {\n\t\t\t\tthrow new Error(`Cannot adopt worker pod ${descriptor.unitId}: not running`);\n\t\t\t}\n\t\t\tconst ref: WorkerUnitRef = {\n\t\t\t\tinstanceId: descriptor.instanceId,\n\t\t\t\tworkerId: descriptor.workerId,\n\t\t\t\tunitId: descriptor.unitId,\n\t\t\t\tnamespace: podNamespace,\n\t\t\t};\n\t\t\tif (observer?.observe && pod.pvcName) {\n\t\t\t\tsamplers.get(descriptor.instanceId)?.stop();\n\t\t\t\tconst sampler = sampleKubernetesStartup(client, observer, podNamespace, pod.pvcName);\n\t\t\t\tsampler.attachPod({ name: ref.unitId, workerId: ref.workerId, instanceId: ref.instanceId });\n\t\t\t\tsamplers.set(descriptor.instanceId, sampler);\n\t\t\t}\n\t\t\twatchPod(ref.unitId, podNamespace);\n\t\t\treturn exitNotifier.wrapUnit(ref, unitKey(podNamespace, ref.unitId), {\n\t\t\t\treplacementHandoff: \"stop-before-replacement\",\n\t\t\t});\n\t\t},\n\t};\n\n\tconst exporter = createHelperProcessStateExporter({\n\t\tvolume,\n\t\thelperRelays,\n\t\tasync launch(input) {\n\t\t\tconst namespace = input.volume.namespace ?? namespaceForProcess(input.instanceId);\n\t\t\tconst podName = kubernetesExportHelperPodName(input.instanceId, input.exportId);\n\t\t\tconst manifest = buildKubernetesExportHelperPodManifest(\n\t\t\t\t{\n\t\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\t\texportId: input.exportId,\n\t\t\t\t\timage: exporterImage,\n\t\t\t\t\tcommand: [\"node\", SESSION_TRANSFER_HELPER_ENTRY_PATH],\n\t\t\t\t\tenv: exportHelperEnvironment({\n\t\t\t\t\t\tserverUrl: exporterServerUrl,\n\t\t\t\t\t\texportId: input.exportId,\n\t\t\t\t\t\tcredential: input.credential,\n\t\t\t\t\t}),\n\t\t\t\t\tvolume: { ...input.volume, mountPath: SESSION_TRANSFER_HELPER_MOUNT_PATH },\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tnamespace,\n\t\t\t\t\t...(options.pod ?? {}),\n\t\t\t\t\timagePullPolicy: options.exporterImagePullPolicy,\n\t\t\t\t\t...(serverCaFile\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tserverCaConfigMap: {\n\t\t\t\t\t\t\t\t\tname: KUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_NAME,\n\t\t\t\t\t\t\t\t\tkey: KUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_KEY,\n\t\t\t\t\t\t\t\t\tmountPath: KUBERNETES_WORKER_SERVER_CA_MOUNT_PATH,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t);\n\t\t\tawait client.createPod(manifest);\n\t\t\tconst exit = new Promise<{ exitCode: number | null; reason?: string }>((resolve) => {\n\t\t\t\tclient.onPodExit(podName, namespace, (info) =>\n\t\t\t\t\tresolve({ exitCode: info.exitCode, reason: info.reason }),\n\t\t\t\t);\n\t\t\t});\n\t\t\treturn {\n\t\t\t\twait: () => exit,\n\t\t\t\tremove: () => client.deletePod(podName, namespace, { gracePeriodSeconds: 0 }),\n\t\t\t};\n\t\t},\n\t\tasync reconcileHelpers() {\n\t\t\tconst namespaces = await client.listNamespaces(managedProcessNamespaceLabelSelector());\n\t\t\tfor (const namespace of namespaces) {\n\t\t\t\tconst helpers = await client.listPods(namespace.name, managedExportHelperLabelSelector());\n\t\t\t\tawait Promise.all(\n\t\t\t\t\thelpers.map((helper) =>\n\t\t\t\t\t\tclient.deletePod(helper.name, helper.namespace, { gracePeriodSeconds: 0 }),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t});\n\n\tlet volumePool: ReturnType<typeof createKubernetesVolumePool> | undefined;\n\tif (options.preProvision) {\n\t\tif (!client.volumePool || !options.volume.storageClassName || !options.serverNamespace) {\n\t\t\tthrow new Error(\"Volume pre-provisioning requires an API, namespace and StorageClass\");\n\t\t}\n\t\tvolumePool = createKubernetesVolumePool({\n\t\t\tapi: client.volumePool,\n\t\t\tnamespace: options.serverNamespace,\n\t\t\tstorageClassName: options.volume.storageClassName,\n\t\t\tsize: options.volume.size,\n\t\t\taccessModes: options.volume.accessModes,\n\t\t\t...options.preProvision,\n\t\t\timage: exporterImage,\n\t\t\timagePullPolicy: options.exporterImagePullPolicy,\n\t\t\timagePullSecrets: (options.pod?.imagePullSecrets ?? []).map(\n\t\t\t\t(name) =>\n\t\t\t\t\toptions.imagePullSecretCopies?.find((copy) => copy.targetName === name)?.sourceName ??\n\t\t\t\t\tname,\n\t\t\t),\n\t\t\tnodeSelector: options.pod?.nodeSelector,\n\t\t\ttolerations: options.pod?.tolerations,\n\t\t});\n\t}\n\treturn { runner, volume, exporter, volumePool };\n}\n","import type { StartupMilestone, StartupObservation } from \"@leitwerk-dev/domain\";\nimport type { KubernetesApiClient } from \"./kubernetes-api-client.js\";\nimport type { WorkerStartObserver } from \"./types.js\";\nimport { parseWorkerUnitIdentity } from \"./worker-labels.js\";\nexport function startupReceipt(\n\tobserver: WorkerStartObserver | undefined,\n\tmilestone: StartupMilestone,\n\tmetadata: StartupObservation[\"metadata\"] = {},\n): void {\n\ttry {\n\t\tobserver?.observe?.({\n\t\t\tmilestone,\n\t\t\tobservedAt: new Date().toISOString(),\n\t\t\tsourceAt: null,\n\t\t\tsourceKind: \"server\",\n\t\t\tobjectUid: null,\n\t\t\tnotBefore: null,\n\t\t\tmetadata,\n\t\t});\n\t} catch {\n\t\t/* Observation cannot fail startup. */\n\t}\n}\n/** One asynchronous collection cycle per physical worker. Never awaited by lifecycle work. */\nexport function sampleKubernetesStartup(\n\tclient: KubernetesApiClient,\n\tobserver: WorkerStartObserver,\n\tnamespace: string,\n\tpvcName: string,\n) {\n\tlet pod: { name: string; workerId: string; instanceId: string } | undefined;\n\tlet podUid: string | undefined;\n\tlet pvcUid: string | undefined;\n\tlet lastUnbound: string | null = null;\n\tlet stopped = false;\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tlet active: AbortController | undefined;\n\tlet failures = 0;\n\tconst seen = new Set<StartupMilestone>();\n\tconst deadline = Date.now() + 120_000;\n\tconst emit = (\n\t\tmilestone: StartupMilestone,\n\t\tobjectUid: string,\n\t\tsourceAt: string | null,\n\t\tmetadata: StartupObservation[\"metadata\"],\n\t\tsourceKind: StartupObservation[\"sourceKind\"] = \"kubernetes_status\",\n\t\tnotBefore: string | null = null,\n\t) => {\n\t\tif (\n\t\t\tstopped ||\n\t\t\tseen.has(milestone) ||\n\t\t\t(sourceAt !== null && !Number.isFinite(Date.parse(sourceAt)))\n\t\t)\n\t\t\treturn;\n\t\tobserver.observe?.({\n\t\t\tmilestone,\n\t\t\tobservedAt: new Date().toISOString(),\n\t\t\tsourceAt,\n\t\t\tobjectUid,\n\t\t\tsourceKind,\n\t\t\tnotBefore,\n\t\t\tmetadata: {\n\t\t\t\t...metadata,\n\t\t\t\t...(sourceAt !== null ? { precision: sourcePrecision(sourceAt) } : {}),\n\t\t\t},\n\t\t});\n\t\tseen.add(milestone);\n\t};\n\tconst stop = () => {\n\t\tstopped = true;\n\t\tif (timer) clearTimeout(timer);\n\t\tactive?.abort();\n\t};\n\tconst reportFailure = () => {\n\t\tif (!stopped && failures++ < 3)\n\t\t\tconsole.warn(\"Worker startup observation unavailable: Kubernetes collection failed\");\n\t};\n\tconst cycle = async () => {\n\t\tif (stopped || observer.shouldStop?.() || Date.now() >= deadline) {\n\t\t\tstop();\n\t\t\treturn;\n\t\t}\n\t\tactive = new AbortController();\n\t\tconst timeout = setTimeout(() => active?.abort(), 1500);\n\t\tconst signal = active.signal;\n\t\tconst collectPvc = async () => {\n\t\t\tif (!seen.has(\"pvc_bound\") && client.getPersistentVolumeClaim) {\n\t\t\t\tconst pvc = await client.getPersistentVolumeClaim(pvcName, namespace, { signal });\n\t\t\t\tif (pvc?.uid) {\n\t\t\t\t\tif (pvcUid && pvcUid !== pvc.uid) {\n\t\t\t\t\t\tstop();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tpvcUid = pvc.uid;\n\t\t\t\t\tif (pvc.phase === \"Bound\")\n\t\t\t\t\t\temit(\n\t\t\t\t\t\t\t\"pvc_bound\",\n\t\t\t\t\t\t\tpvc.uid,\n\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t{ storageClass: pvc.storageClass, precision: \"sampling_interval\" },\n\t\t\t\t\t\t\t\"kubernetes_status\",\n\t\t\t\t\t\t\tlastUnbound,\n\t\t\t\t\t\t);\n\t\t\t\t\telse lastUnbound = new Date().toISOString();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tconst collectPod = async () => {\n\t\t\tif (pod) {\n\t\t\t\tconst summary = await client.getPod(pod.name, namespace, { signal });\n\t\t\t\tif (!summary) {\n\t\t\t\t\tstop();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst identity = parseWorkerUnitIdentity(summary.labels);\n\t\t\t\tif (\n\t\t\t\t\t!identity ||\n\t\t\t\t\tidentity.workerId !== pod.workerId ||\n\t\t\t\t\tidentity.instanceId !== pod.instanceId ||\n\t\t\t\t\t(podUid && podUid !== summary.uid)\n\t\t\t\t) {\n\t\t\t\t\tstop();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (summary.uid) {\n\t\t\t\t\tpodUid = summary.uid;\n\t\t\t\t\tconst metadata = {\n\t\t\t\t\t\tnode: summary.node,\n\t\t\t\t\t\timageId: summary.imageId,\n\t\t\t\t\t\tnamespace,\n\t\t\t\t\t\tpodName: pod.name,\n\t\t\t\t\t\t...summary.resources,\n\t\t\t\t\t};\n\t\t\t\t\tif (summary.createdAt) emit(\"pod_created\", podUid, summary.createdAt, metadata);\n\t\t\t\t\tif (summary.scheduledAt) emit(\"pod_scheduled\", podUid, summary.scheduledAt, metadata);\n\t\t\t\t\tif (summary.containerStartedAt)\n\t\t\t\t\t\temit(\"container_started\", podUid, summary.containerStartedAt, metadata);\n\t\t\t\t\tconst events = await client.listPodEvents(pod.name, namespace, { signal });\n\t\t\t\t\tfor (const event of events) {\n\t\t\t\t\t\tif (event.objectUid !== podUid || event.fieldPath !== \"spec.containers{worker}\")\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tconst at = event.eventTime || event.firstTimestamp;\n\t\t\t\t\t\tif (!at) continue;\n\t\t\t\t\t\tif (event.reason === \"Pulling\")\n\t\t\t\t\t\t\temit(\"image_pull_started\", podUid, at, metadata, \"kubernetes_event\");\n\t\t\t\t\t\tif (event.reason === \"Pulled\")\n\t\t\t\t\t\t\temit(\n\t\t\t\t\t\t\t\tevent.message?.includes(\"already present\") ? \"image_cached\" : \"image_pull_finished\",\n\t\t\t\t\t\t\t\tpodUid,\n\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t\t\t\"kubernetes_event\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (summary.phase === \"Failed\" || summary.phase === \"Succeeded\") stop();\n\t\t\t}\n\t\t};\n\t\ttry {\n\t\t\tawait Promise.all([collectPvc().catch(reportFailure), collectPod().catch(reportFailure)]);\n\t\t\tif (\n\t\t\t\tseen.has(\"container_started\") &&\n\t\t\t\tseen.has(\"pod_scheduled\") &&\n\t\t\t\tseen.has(\"pvc_bound\") &&\n\t\t\t\t(seen.has(\"image_cached\") ||\n\t\t\t\t\t(seen.has(\"image_pull_started\") && seen.has(\"image_pull_finished\")))\n\t\t\t)\n\t\t\t\tstop();\n\t\t} finally {\n\t\t\tclearTimeout(timeout);\n\t\t\tactive = undefined;\n\t\t\tif (!stopped) {\n\t\t\t\ttimer = setTimeout(() => void cycle(), 250);\n\t\t\t\ttimer.unref?.();\n\t\t\t}\n\t\t}\n\t};\n\ttimer = setTimeout(() => void cycle(), 0);\n\ttimer.unref?.();\n\treturn {\n\t\tstop,\n\t\tattachPod(input: NonNullable<typeof pod>) {\n\t\t\tpod = input;\n\t\t},\n\t};\n}\n\nfunction sourcePrecision(timestamp: string): \"seconds\" | \"milliseconds\" | \"microseconds\" {\n\tconst digits = /\\.(\\d+)/.exec(timestamp)?.[1].length ?? 0;\n\treturn digits === 0 ? \"seconds\" : digits <= 3 ? \"milliseconds\" : \"microseconds\";\n}\n","import { createHash, randomUUID } from \"node:crypto\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport type { PoolObject, VolumePoolApi } from \"./kubernetes-volume-pool-api.js\";\n\nexport const POOL_LABEL = \"leitwerk.dev/volume-pool\";\nconst CLAIM_UID = \"leitwerk.dev/preparation-claim-uid\";\nconst CLAIM_NAME = \"leitwerk.dev/preparation-claim-name\";\nconst POLICY = \"leitwerk.dev/original-reclaim-policy\";\nconst TARGET_CLASS = \"leitwerk.dev/target-storage-class\";\nconst STATE = \"leitwerk.dev/volume-pool-state\";\nconst SIZE = \"leitwerk.dev/preparation-size\";\nconst MODES = \"leitwerk.dev/preparation-access-modes\";\n\nexport interface VolumePoolOptions {\n\tapi: VolumePoolApi;\n\tnamespace: string;\n\tcount: number;\n\tstorageClassName: string;\n\tsize: string;\n\taccessModes: string[];\n\timage: string;\n\timagePullPolicy?: string;\n\timagePullSecrets?: string[];\n\tnodeSelector?: Record<string, string>;\n\ttolerations?: unknown[];\n\tonError?: () => void;\n}\n\n/** Only the staging claim's UID authorizes rebinding; process claims are never recycled. */\nexport function createKubernetesVolumePool(options: VolumePoolOptions) {\n\tconst { api, namespace } = options;\n\tif (!Number.isSafeInteger(options.count) || options.count < 0)\n\t\tthrow new Error(\"Invalid volume pool count\");\n\tconst poolId = createHash(\"sha256\")\n\t\t.update(`${namespace}/${options.storageClassName}`)\n\t\t.digest(\"hex\")\n\t\t.slice(0, 16);\n\tconst selector = `${POOL_LABEL}=${poolId}`;\n\tconst labels = {\n\t\t\"leitwerk.dev/managed-by\": \"leitwerk\",\n\t\t[POOL_LABEL]: poolId,\n\t\t\"leitwerk.dev/component\": \"volume-preparation\",\n\t};\n\tlet controller: AbortController | undefined;\n\tlet running: Promise<void> | undefined;\n\n\tfunction preparationPod(claim: PoolObject): PoolObject {\n\t\treturn {\n\t\t\tapiVersion: \"v1\",\n\t\t\tkind: \"Pod\",\n\t\t\tmetadata: {\n\t\t\t\tname: claim.metadata.name,\n\t\t\t\tnamespace,\n\t\t\t\tlabels,\n\t\t\t\townerReferences: [\n\t\t\t\t\t{\n\t\t\t\t\t\tapiVersion: \"v1\",\n\t\t\t\t\t\tkind: \"PersistentVolumeClaim\",\n\t\t\t\t\t\tname: claim.metadata.name,\n\t\t\t\t\t\tuid: claim.metadata.uid ?? \"\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\tspec: {\n\t\t\t\trestartPolicy: \"Never\",\n\t\t\t\tserviceAccountName: \"default\",\n\t\t\t\tautomountServiceAccountToken: false,\n\t\t\t\tnodeSelector: options.nodeSelector ?? {},\n\t\t\t\ttolerations: options.tolerations ?? [],\n\t\t\t\timagePullSecrets: (options.imagePullSecrets ?? []).map((name) => ({ name })),\n\t\t\t\tcontainers: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"prepare\",\n\t\t\t\t\t\timage: options.image,\n\t\t\t\t\t\timagePullPolicy: options.imagePullPolicy ?? \"IfNotPresent\",\n\t\t\t\t\t\tcommand: [\"node\", \"-e\", \"process.exit(0)\"],\n\t\t\t\t\t\tresources: {\n\t\t\t\t\t\t\trequests: { cpu: \"1m\", memory: \"32Mi\" },\n\t\t\t\t\t\t\tlimits: { cpu: \"100m\", memory: \"64Mi\" },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsecurityContext: {\n\t\t\t\t\t\t\tallowPrivilegeEscalation: false,\n\t\t\t\t\t\t\treadOnlyRootFilesystem: true,\n\t\t\t\t\t\t\tcapabilities: { drop: [\"ALL\"] },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvolumeMounts: [{ name: \"volume\", mountPath: \"/volume\" }],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tvolumes: [{ name: \"volume\", persistentVolumeClaim: { claimName: claim.metadata.name } }],\n\t\t\t},\n\t\t};\n\t}\n\n\tasync function advanceVolume(pv: PoolObject, signal: AbortSignal): Promise<boolean> {\n\t\tconst annotations = pv.metadata.annotations ?? {};\n\t\tconst uid = annotations[CLAIM_UID];\n\t\tconst name = annotations[CLAIM_NAME];\n\t\tconst policy = annotations[POLICY];\n\t\tif (!uid || !name || ![\"Delete\", \"Retain\"].includes(policy))\n\t\t\tthrow new Error(\"Invalid prepared-volume ownership\");\n\t\tif (pv.metadata.deletionTimestamp) return false;\n\t\tconst claim = pv.spec.claimRef;\n\t\tif (claim && claim.uid !== uid) {\n\t\t\t// A process has consumed this PV, including if it was already released again.\n\t\t\tconst remainingLabels = { ...pv.metadata.labels };\n\t\t\tdelete remainingLabels[POOL_LABEL];\n\t\t\tawait api.patchVolume(\n\t\t\t\tpv,\n\t\t\t\t[\n\t\t\t\t\t{ op: \"add\", path: \"/spec/persistentVolumeReclaimPolicy\", value: policy },\n\t\t\t\t\t{ op: \"add\", path: \"/metadata/labels\", value: remainingLabels },\n\t\t\t\t],\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\treturn false;\n\t\t}\n\t\tif (claim) {\n\t\t\tif (pv.spec.persistentVolumeReclaimPolicy !== \"Retain\")\n\t\t\t\tthrow new Error(\"Staging PV must be retained before release\");\n\t\t\tconst pod = await api.get(\"pods\", namespace, name, signal);\n\t\t\tif (pod) {\n\t\t\t\tif (\n\t\t\t\t\tpod.metadata.labels?.[POOL_LABEL] !== poolId ||\n\t\t\t\t\t!pod.metadata.ownerReferences?.some((owner) => owner.uid === uid)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Preparation Pod ownership mismatch\");\n\t\t\t\tawait api.delete(\"pods\", namespace, pod, signal);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst pvc = await api.get(\"persistentvolumeclaims\", namespace, name, signal);\n\t\t\tif (pvc) {\n\t\t\t\tif (pvc.metadata.uid !== uid) throw new Error(\"Preparation PVC ownership mismatch\");\n\t\t\t\tawait api.delete(\"persistentvolumeclaims\", namespace, pvc, signal);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (pv.status?.phase === \"Released\") {\n\t\t\t\tawait api.patchVolume(\n\t\t\t\t\tpv,\n\t\t\t\t\t[\n\t\t\t\t\t\t{ op: \"test\", path: \"/spec/claimRef/uid\", value: uid },\n\t\t\t\t\t\t{ op: \"remove\", path: \"/spec/claimRef\" },\n\t\t\t\t\t],\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\t// Never restore Delete while the old Released status remains: a provisioner could reclaim it.\n\t\tif (pv.status?.phase === \"Available\" && annotations[STATE] !== \"ready\") {\n\t\t\tconst stagingClass = await api.getStorageClass(name, signal);\n\t\t\tif (stagingClass) {\n\t\t\t\tif (stagingClass.metadata.labels?.[POOL_LABEL] !== poolId)\n\t\t\t\t\tthrow new Error(\"Staging StorageClass ownership mismatch\");\n\t\t\t\tawait api.deleteStorageClass(stagingClass, signal);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst targetClass = annotations[TARGET_CLASS];\n\t\t\tif (!targetClass) throw new Error(\"Target StorageClass is missing\");\n\t\t\tawait api.patchVolume(\n\t\t\t\tpv,\n\t\t\t\t[\n\t\t\t\t\t{ op: \"add\", path: \"/spec/persistentVolumeReclaimPolicy\", value: policy },\n\t\t\t\t\t{ op: \"add\", path: \"/spec/storageClassName\", value: targetClass },\n\t\t\t\t\t{ op: \"add\", path: \"/metadata/annotations\", value: { ...annotations, [STATE]: \"ready\" } },\n\t\t\t\t],\n\t\t\t\tsignal,\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\tannotations[STATE] !== \"ready\" ||\n\t\t\t(annotations[SIZE] === options.size &&\n\t\t\t\tannotations[MODES] === JSON.stringify(options.accessModes))\n\t\t);\n\t}\n\n\tasync function reconcile(signal: AbortSignal) {\n\t\tconst volumes = await api.list(\"persistentvolumes\", \"\", selector, signal);\n\t\tconst classes = await api.listStorageClasses(selector, signal);\n\t\tconst active = new Set<string>(classes.map((value) => value.metadata.name));\n\t\tfor (const pv of volumes) {\n\t\t\tif (await advanceVolume(pv, signal)) active.add(pv.metadata.annotations?.[CLAIM_NAME] ?? \"\");\n\t\t}\n\t\tconst claims = await api.list(\"persistentvolumeclaims\", namespace, selector, signal);\n\t\tfor (const claim of claims) {\n\t\t\tactive.add(claim.metadata.name);\n\t\t\tif (!claim.metadata.uid || claim.spec.storageClassName !== claim.metadata.name)\n\t\t\t\tthrow new Error(\"Invalid staging PVC identity\");\n\t\t\tif (\n\t\t\t\tclaim.metadata.deletionTimestamp ||\n\t\t\t\tvolumes.some((pv) => pv.metadata.annotations?.[CLAIM_UID] === claim.metadata.uid)\n\t\t\t)\n\t\t\t\tcontinue;\n\t\t\tconst pod = await api.get(\"pods\", namespace, claim.metadata.name, signal);\n\t\t\tif (!pod) {\n\t\t\t\tawait api.create(\"pods\", namespace, preparationPod(claim), signal);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tpod.metadata.labels?.[POOL_LABEL] !== poolId ||\n\t\t\t\t!pod.metadata.ownerReferences?.some((owner) => owner.uid === claim.metadata.uid)\n\t\t\t)\n\t\t\t\tthrow new Error(\"Preparation Pod ownership mismatch\");\n\t\t\tif (pod.status?.phase === \"Failed\") {\n\t\t\t\tawait api.delete(\"pods\", namespace, pod, signal);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (pod.status?.phase !== \"Succeeded\" || !claim.spec.volumeName) continue;\n\t\t\tconst pv = await api.get(\"persistentvolumes\", \"\", claim.spec.volumeName, signal);\n\t\t\tif (\n\t\t\t\t!pv ||\n\t\t\t\tpv.spec.claimRef?.uid !== claim.metadata.uid ||\n\t\t\t\tpv.metadata.ownerReferences?.length ||\n\t\t\t\tpv.metadata.deletionTimestamp\n\t\t\t)\n\t\t\t\tthrow new Error(\"Cannot safely retain staging volume\");\n\t\t\tif (pv.metadata.labels?.[POOL_LABEL]) throw new Error(\"PV already belongs to a pool\");\n\t\t\tconst policy = pv.spec.persistentVolumeReclaimPolicy;\n\t\t\tif (!policy || ![\"Delete\", \"Retain\"].includes(policy))\n\t\t\t\tthrow new Error(\"Unsupported reclaim policy\");\n\t\t\tawait api.patchVolume(\n\t\t\t\tpv,\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\top: \"add\",\n\t\t\t\t\t\tpath: \"/metadata/labels\",\n\t\t\t\t\t\tvalue: { ...pv.metadata.labels, [POOL_LABEL]: poolId },\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\top: \"add\",\n\t\t\t\t\t\tpath: \"/metadata/annotations\",\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t...pv.metadata.annotations,\n\t\t\t\t\t\t\t[CLAIM_UID]: claim.metadata.uid,\n\t\t\t\t\t\t\t[CLAIM_NAME]: claim.metadata.name,\n\t\t\t\t\t\t\t[POLICY]: policy,\n\t\t\t\t\t\t\t[STATE]: \"preparing\",\n\t\t\t\t\t\t\t[TARGET_CLASS]: options.storageClassName,\n\t\t\t\t\t\t\t[SIZE]: claim.metadata.annotations?.[SIZE],\n\t\t\t\t\t\t\t[MODES]: claim.metadata.annotations?.[MODES],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{ op: \"add\", path: \"/spec/persistentVolumeReclaimPolicy\", value: \"Retain\" },\n\t\t\t\t],\n\t\t\t\tsignal,\n\t\t\t);\n\t\t}\n\t\tfor (const stagingClass of classes) {\n\t\t\tconst name = stagingClass.metadata.name;\n\t\t\tif (\n\t\t\t\tstagingClass.metadata.deletionTimestamp ||\n\t\t\t\tclaims.some((claim) => claim.metadata.name === name) ||\n\t\t\t\tvolumes.some((pv) => pv.metadata.annotations?.[CLAIM_NAME] === name)\n\t\t\t)\n\t\t\t\tcontinue;\n\t\t\tawait api.create(\n\t\t\t\t\"persistentvolumeclaims\",\n\t\t\t\tnamespace,\n\t\t\t\t{\n\t\t\t\t\tapiVersion: \"v1\",\n\t\t\t\t\tkind: \"PersistentVolumeClaim\",\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tnamespace,\n\t\t\t\t\t\tlabels,\n\t\t\t\t\t\tannotations: {\n\t\t\t\t\t\t\t[SIZE]: stagingClass.metadata.annotations?.[SIZE] ?? \"\",\n\t\t\t\t\t\t\t[MODES]: stagingClass.metadata.annotations?.[MODES] ?? \"\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tspec: {\n\t\t\t\t\t\tstorageClassName: name,\n\t\t\t\t\t\taccessModes: JSON.parse(stagingClass.metadata.annotations?.[MODES] ?? \"null\"),\n\t\t\t\t\t\tvolumeMode: \"Filesystem\",\n\t\t\t\t\t\tresources: {\n\t\t\t\t\t\t\trequests: {\n\t\t\t\t\t\t\t\tstorage: stagingClass.metadata.annotations?.[SIZE],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsignal,\n\t\t\t);\n\t\t}\n\t\tif (active.size < options.count) {\n\t\t\tconst source = await api.getStorageClass(options.storageClassName, signal);\n\t\t\tif (!source || [\"kubernetes.io/no-provisioner\", \"manual\"].includes(source.provisioner))\n\t\t\t\tthrow new Error(\"Volume pre-provisioning requires a dynamic StorageClass\");\n\t\t\tfor (let i = active.size; i < options.count; i++) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t// A unique staging class prevents preparation PVCs from consuming the ready pool.\n\t\t\t\tawait api.createStorageClass(\n\t\t\t\t\t{\n\t\t\t\t\t\tapiVersion: \"storage.k8s.io/v1\",\n\t\t\t\t\t\tkind: \"StorageClass\",\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tname: `lw-volume-${randomUUID()}`,\n\t\t\t\t\t\t\tlabels,\n\t\t\t\t\t\t\tannotations: {\n\t\t\t\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\t\t\t\tObject.entries(source.metadata.annotations ?? {}).filter(\n\t\t\t\t\t\t\t\t\t\t([key]) =>\n\t\t\t\t\t\t\t\t\t\t\t![\n\t\t\t\t\t\t\t\t\t\t\t\t\"storageclass.kubernetes.io/is-default-class\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"storageclass.beta.kubernetes.io/is-default-class\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"kubectl.kubernetes.io/last-applied-configuration\",\n\t\t\t\t\t\t\t\t\t\t\t].includes(key),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t[SIZE]: options.size,\n\t\t\t\t\t\t\t\t[MODES]: JSON.stringify(options.accessModes),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tprovisioner: source.provisioner,\n\t\t\t\t\t\tparameters: source.parameters,\n\t\t\t\t\t\treclaimPolicy: source.reclaimPolicy,\n\t\t\t\t\t\tmountOptions: source.mountOptions,\n\t\t\t\t\t\tallowVolumeExpansion: source.allowVolumeExpansion,\n\t\t\t\t\t\tvolumeBindingMode: source.volumeBindingMode,\n\t\t\t\t\t\tallowedTopologies: source.allowedTopologies,\n\t\t\t\t\t},\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tpoolId,\n\t\treconcile,\n\t\tstart() {\n\t\t\tif (controller) return;\n\t\t\tcontroller = new AbortController();\n\t\t\tconst { signal } = controller;\n\t\t\trunning = (async () => {\n\t\t\t\twhile (!signal.aborted) {\n\t\t\t\t\tlet interval = 2_000;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait reconcile(signal);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tinterval = 30_000;\n\t\t\t\t\t\tif (!signal.aborted) options.onError?.();\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait delay(interval, undefined, { signal });\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})();\n\t\t},\n\t\tasync stop() {\n\t\t\tcontroller?.abort();\n\t\t\tawait running;\n\t\t\tcontroller = undefined;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,oBAAoB;;;ACItB,SAAS,eACf,UACA,WACA,WAA2C,CAAC,GACrC;AACP,MAAI;AACH,cAAU,UAAU;AAAA,MACnB;AAAA,MACA,aAAY,oBAAI,KAAK,GAAE,YAAY;AAAA,MACnC,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,WAAW;AAAA,MACX;AAAA,IACD,CAAC;AAAA,EACF,QAAQ;AAAA,EAER;AACD;AAEO,SAAS,wBACf,QACA,UACA,WACA,SACC;AACD,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI,cAA6B;AACjC,MAAI,UAAU;AACd,MAAI;AACJ,MAAI;AACJ,MAAI,WAAW;AACf,QAAM,OAAO,oBAAI,IAAsB;AACvC,QAAM,WAAW,KAAK,IAAI,IAAI;AAC9B,QAAM,OAAO,CACZ,WACA,WACA,UACA,UACA,aAA+C,qBAC/C,YAA2B,SACvB;AACJ,QACC,WACA,KAAK,IAAI,SAAS,KACjB,aAAa,QAAQ,CAAC,OAAO,SAAS,KAAK,MAAM,QAAQ,CAAC;AAE3D;AACD,aAAS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|
|
@@ -20,12 +20,16 @@ var UnitExitNotifier = class {
|
|
|
20
20
|
this.listeners.delete(key);
|
|
21
21
|
for (const listener of list.splice(0)) listener(info);
|
|
22
22
|
}
|
|
23
|
-
wrapUnit(ref, key) {
|
|
24
|
-
return {
|
|
23
|
+
wrapUnit(ref, key, options) {
|
|
24
|
+
return {
|
|
25
|
+
...ref,
|
|
26
|
+
...options?.replacementHandoff ? { replacementHandoff: options.replacementHandoff } : {},
|
|
27
|
+
onExit: (listener) => this.onExit(key, listener)
|
|
28
|
+
};
|
|
25
29
|
}
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
export {
|
|
29
33
|
UnitExitNotifier
|
|
30
34
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
35
|
+
//# sourceMappingURL=chunk-OSS62AOL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runner-utils.ts"],"sourcesContent":["import type { WorkerExitInfo, WorkerUnit, WorkerUnitRef } from \"./types.js\";\n\n/**\n * Shared exit-notification machinery used by every {@link WorkerRunner}.\n *\n * Each runner implementation tracks physical unit exits and maps them to\n * `WorkerUnit.onExit` callbacks. This utility captures the identical map +\n * fire/wrap logic and leaves only the unit-keying to each runner.\n */\nexport class UnitExitNotifier {\n\tprivate readonly listeners = new Map<string, Array<(info: WorkerExitInfo) => void>>();\n\tprivate readonly exited = new Map<string, WorkerExitInfo>();\n\n\tonExit(key: string, listener: (info: WorkerExitInfo) => void): void {\n\t\tconst exit = this.exited.get(key);\n\t\tif (exit) {\n\t\t\tqueueMicrotask(() => listener(exit));\n\t\t\treturn;\n\t\t}\n\t\tconst list = this.listeners.get(key) ?? [];\n\t\tlist.push(listener);\n\t\tthis.listeners.set(key, list);\n\t}\n\n\tfireExit(key: string, info: WorkerExitInfo): void {\n\t\tif (this.exited.has(key)) return;\n\t\tthis.exited.set(key, info);\n\t\tconst list = this.listeners.get(key);\n\t\tif (!list) return;\n\t\tthis.listeners.delete(key);\n\t\tfor (const listener of list.splice(0)) listener(info);\n\t}\n\n\twrapUnit<T extends WorkerUnitRef>(
|
|
1
|
+
{"version":3,"sources":["../src/runner-utils.ts"],"sourcesContent":["import type { WorkerExitInfo, WorkerUnit, WorkerUnitRef } from \"./types.js\";\n\n/**\n * Shared exit-notification machinery used by every {@link WorkerRunner}.\n *\n * Each runner implementation tracks physical unit exits and maps them to\n * `WorkerUnit.onExit` callbacks. This utility captures the identical map +\n * fire/wrap logic and leaves only the unit-keying to each runner.\n */\nexport class UnitExitNotifier {\n\tprivate readonly listeners = new Map<string, Array<(info: WorkerExitInfo) => void>>();\n\tprivate readonly exited = new Map<string, WorkerExitInfo>();\n\n\tonExit(key: string, listener: (info: WorkerExitInfo) => void): void {\n\t\tconst exit = this.exited.get(key);\n\t\tif (exit) {\n\t\t\tqueueMicrotask(() => listener(exit));\n\t\t\treturn;\n\t\t}\n\t\tconst list = this.listeners.get(key) ?? [];\n\t\tlist.push(listener);\n\t\tthis.listeners.set(key, list);\n\t}\n\n\tfireExit(key: string, info: WorkerExitInfo): void {\n\t\tif (this.exited.has(key)) return;\n\t\tthis.exited.set(key, info);\n\t\tconst list = this.listeners.get(key);\n\t\tif (!list) return;\n\t\tthis.listeners.delete(key);\n\t\tfor (const listener of list.splice(0)) listener(info);\n\t}\n\n\twrapUnit<T extends WorkerUnitRef>(\n\t\tref: T,\n\t\tkey: string,\n\t\toptions?: { replacementHandoff?: WorkerUnit[\"replacementHandoff\"] },\n\t): WorkerUnit {\n\t\treturn {\n\t\t\t...ref,\n\t\t\t...(options?.replacementHandoff ? { replacementHandoff: options.replacementHandoff } : {}),\n\t\t\tonExit: (listener) => this.onExit(key, listener),\n\t\t};\n\t}\n}\n"],"mappings":";AASO,IAAM,mBAAN,MAAuB;AAAA,EACZ,YAAY,oBAAI,IAAmD;AAAA,EACnE,SAAS,oBAAI,IAA4B;AAAA,EAE1D,OAAO,KAAa,UAAgD;AACnE,UAAM,OAAO,KAAK,OAAO,IAAI,GAAG;AAChC,QAAI,MAAM;AACT,qBAAe,MAAM,SAAS,IAAI,CAAC;AACnC;AAAA,IACD;AACA,UAAM,OAAO,KAAK,UAAU,IAAI,GAAG,KAAK,CAAC;AACzC,SAAK,KAAK,QAAQ;AAClB,SAAK,UAAU,IAAI,KAAK,IAAI;AAAA,EAC7B;AAAA,EAEA,SAAS,KAAa,MAA4B;AACjD,QAAI,KAAK,OAAO,IAAI,GAAG,EAAG;AAC1B,SAAK,OAAO,IAAI,KAAK,IAAI;AACzB,UAAM,OAAO,KAAK,UAAU,IAAI,GAAG;AACnC,QAAI,CAAC,KAAM;AACX,SAAK,UAAU,OAAO,GAAG;AACzB,eAAW,YAAY,KAAK,OAAO,CAAC,EAAG,UAAS,IAAI;AAAA,EACrD;AAAA,EAEA,SACC,KACA,KACA,SACa;AACb,WAAO;AAAA,MACN,GAAG;AAAA,MACH,GAAI,SAAS,qBAAqB,EAAE,oBAAoB,QAAQ,mBAAmB,IAAI,CAAC;AAAA,MACxF,QAAQ,CAAC,aAAa,KAAK,OAAO,KAAK,QAAQ;AAAA,IAChD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/filesystem-process-state-exporter.ts
|
|
2
|
+
import { lstat, realpath } from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { isPathInside, prepareTransferArchive } from "@leitwerk-dev/session-transfer";
|
|
5
|
+
function createFilesystemProcessStateExporter(input) {
|
|
6
|
+
return {
|
|
7
|
+
async prepare(request) {
|
|
8
|
+
const source = await input.resolveSource(request.instanceId);
|
|
9
|
+
const allowedRoots = await Promise.all(
|
|
10
|
+
input.allowedRoots.map((root) => realpath(path.resolve(root)))
|
|
11
|
+
);
|
|
12
|
+
const workspaceRoot = await realpath(path.resolve(source.workspaceRoot));
|
|
13
|
+
const sessionFile = await realpath(path.resolve(source.sessionFile));
|
|
14
|
+
for (const candidate of [workspaceRoot, sessionFile]) {
|
|
15
|
+
if (!allowedRoots.some((root) => isPathInside(root, candidate))) {
|
|
16
|
+
throw new Error("Transfer source escapes configured process storage roots");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!(await lstat(workspaceRoot)).isDirectory())
|
|
20
|
+
throw new Error("Process workspace is unavailable");
|
|
21
|
+
if (!(await lstat(sessionFile)).isFile())
|
|
22
|
+
throw new Error("Primary Pi session is unavailable");
|
|
23
|
+
return prepareTransferArchive({
|
|
24
|
+
workspaceRoot,
|
|
25
|
+
sessionFile,
|
|
26
|
+
manifest: request.manifest,
|
|
27
|
+
limits: request.limits,
|
|
28
|
+
signal: request.signal
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
async reconcile() {
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
createFilesystemProcessStateExporter
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-UGKQOL5E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/filesystem-process-state-exporter.ts"],"sourcesContent":["import { lstat, realpath } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { isPathInside, prepareTransferArchive } from \"@leitwerk-dev/session-transfer\";\nimport type { ProcessStateExporter } from \"./types.js\";\n\nexport interface FilesystemExportSource {\n\tworkspaceRoot: string;\n\tsessionFile: string;\n}\n\nexport function createFilesystemProcessStateExporter(input: {\n\tresolveSource(instanceId: string): FilesystemExportSource | Promise<FilesystemExportSource>;\n\tallowedRoots: readonly string[];\n}): ProcessStateExporter {\n\treturn {\n\t\tasync prepare(request) {\n\t\t\tconst source = await input.resolveSource(request.instanceId);\n\t\t\tconst allowedRoots = await Promise.all(\n\t\t\t\tinput.allowedRoots.map((root) => realpath(path.resolve(root))),\n\t\t\t);\n\t\t\tconst workspaceRoot = await realpath(path.resolve(source.workspaceRoot));\n\t\t\tconst sessionFile = await realpath(path.resolve(source.sessionFile));\n\t\t\tfor (const candidate of [workspaceRoot, sessionFile]) {\n\t\t\t\tif (!allowedRoots.some((root) => isPathInside(root, candidate))) {\n\t\t\t\t\tthrow new Error(\"Transfer source escapes configured process storage roots\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!(await lstat(workspaceRoot)).isDirectory())\n\t\t\t\tthrow new Error(\"Process workspace is unavailable\");\n\t\t\tif (!(await lstat(sessionFile)).isFile())\n\t\t\t\tthrow new Error(\"Primary Pi session is unavailable\");\n\t\t\treturn prepareTransferArchive({\n\t\t\t\tworkspaceRoot,\n\t\t\t\tsessionFile,\n\t\t\t\tmanifest: request.manifest,\n\t\t\t\tlimits: request.limits,\n\t\t\t\tsignal: request.signal,\n\t\t\t});\n\t\t},\n\t\tasync reconcile() {},\n\t};\n}\n"],"mappings":";AAAA,SAAS,OAAO,gBAAgB;AAChC,OAAO,UAAU;AACjB,SAAS,cAAc,8BAA8B;AAQ9C,SAAS,qCAAqC,OAG5B;AACxB,SAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AACtB,YAAM,SAAS,MAAM,MAAM,cAAc,QAAQ,UAAU;AAC3D,YAAM,eAAe,MAAM,QAAQ;AAAA,QAClC,MAAM,aAAa,IAAI,CAAC,SAAS,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC;AAAA,MAC9D;AACA,YAAM,gBAAgB,MAAM,SAAS,KAAK,QAAQ,OAAO,aAAa,CAAC;AACvE,YAAM,cAAc,MAAM,SAAS,KAAK,QAAQ,OAAO,WAAW,CAAC;AACnE,iBAAW,aAAa,CAAC,eAAe,WAAW,GAAG;AACrD,YAAI,CAAC,aAAa,KAAK,CAAC,SAAS,aAAa,MAAM,SAAS,CAAC,GAAG;AAChE,gBAAM,IAAI,MAAM,0DAA0D;AAAA,QAC3E;AAAA,MACD;AACA,UAAI,EAAE,MAAM,MAAM,aAAa,GAAG,YAAY;AAC7C,cAAM,IAAI,MAAM,kCAAkC;AACnD,UAAI,EAAE,MAAM,MAAM,WAAW,GAAG,OAAO;AACtC,cAAM,IAAI,MAAM,mCAAmC;AACpD,aAAO,uBAAuB;AAAA,QAC7B;AAAA,QACA;AAAA,QACA,UAAU,QAAQ;AAAA,QAClB,QAAQ,QAAQ;AAAA,QAChB,QAAQ,QAAQ;AAAA,MACjB,CAAC;AAAA,IACF;AAAA,IACA,MAAM,YAAY;AAAA,IAAC;AAAA,EACpB;AACD;","names":[]}
|
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isDockerEngineNotFoundError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-63BBCX7B.js";
|
|
4
4
|
import {
|
|
5
|
+
createHelperProcessStateExporter,
|
|
6
|
+
exportHelperEnvironment
|
|
7
|
+
} from "./chunk-4F7EMXMU.js";
|
|
8
|
+
import {
|
|
9
|
+
buildExportHelperLabels,
|
|
5
10
|
buildWorkerUnitLabels,
|
|
11
|
+
managedExportHelperLabelSelector,
|
|
6
12
|
managedWorkerLabelSelector,
|
|
7
13
|
parseWorkerUnitIdentity
|
|
8
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-6BSZBMHH.js";
|
|
15
|
+
import {
|
|
16
|
+
createFilesystemProcessStateExporter
|
|
17
|
+
} from "./chunk-UGKQOL5E.js";
|
|
9
18
|
import {
|
|
10
19
|
UnitExitNotifier
|
|
11
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-OSS62AOL.js";
|
|
21
|
+
import {
|
|
22
|
+
SESSION_TRANSFER_HELPER_ENTRY_PATH,
|
|
23
|
+
SESSION_TRANSFER_HELPER_MOUNT_PATH
|
|
24
|
+
} from "./chunk-D56NJQ5X.js";
|
|
12
25
|
|
|
13
26
|
// src/docker-worker-runner.ts
|
|
14
27
|
import { mkdirSync } from "fs";
|
|
15
28
|
import path from "path";
|
|
16
29
|
var DEFAULT_NAMED_VOLUME_PREFIX = "leitwerk-process-";
|
|
17
30
|
var NANO_CPUS_PER_CPU = 1e9;
|
|
18
|
-
var
|
|
31
|
+
var PRIVATE_DOCKER_ENV = "LEITWERK_PRIVATE_DOCKER";
|
|
32
|
+
var PROCESS_VOLUME_MOUNT_PATH_ENV = "LEITWERK_PROCESS_VOLUME_MOUNT_PATH";
|
|
19
33
|
var WORKER_SERVER_CA_MOUNT_PATH = "/leitwerk/server-ca.pem";
|
|
20
34
|
function sanitizeNameSegment(value) {
|
|
21
35
|
const cleaned = value.replace(/[^a-zA-Z0-9_.-]/g, "-");
|
|
@@ -76,6 +90,9 @@ function mapExit(info) {
|
|
|
76
90
|
};
|
|
77
91
|
}
|
|
78
92
|
function createDockerWorkerRunner(options) {
|
|
93
|
+
if (options.volume.mode === "named_volume" && (!options.serverUrl || !options.exporterImage || !options.helperRelays)) {
|
|
94
|
+
throw new Error("Docker named-volume transfer exporter is not configured");
|
|
95
|
+
}
|
|
79
96
|
const { engine } = options;
|
|
80
97
|
const mountPath = options.volume.mountPath;
|
|
81
98
|
const namedVolumePrefix = options.volume.namedVolumePrefix ?? DEFAULT_NAMED_VOLUME_PREFIX;
|
|
@@ -105,6 +122,36 @@ function createDockerWorkerRunner(options) {
|
|
|
105
122
|
};
|
|
106
123
|
const exitNotifier = new UnitExitNotifier();
|
|
107
124
|
const watched = /* @__PURE__ */ new Set();
|
|
125
|
+
const stopPromises = /* @__PURE__ */ new Map();
|
|
126
|
+
function stopAndRemove(ref, opts) {
|
|
127
|
+
const existing = stopPromises.get(ref.unitId);
|
|
128
|
+
if (existing) return existing;
|
|
129
|
+
const operation = Promise.resolve().then(async () => {
|
|
130
|
+
const timeoutSeconds = Math.max(0, Math.ceil(opts.graceMs / 1e3));
|
|
131
|
+
try {
|
|
132
|
+
await engine.stopContainer(ref.unitId, { timeoutSeconds });
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (!isDockerEngineNotFoundError(error)) throw error;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
await engine.removeContainer(ref.unitId, { force: true });
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (!isDockerEngineNotFoundError(error)) throw error;
|
|
140
|
+
}
|
|
141
|
+
}).finally(() => stopPromises.delete(ref.unitId));
|
|
142
|
+
stopPromises.set(ref.unitId, operation);
|
|
143
|
+
return operation;
|
|
144
|
+
}
|
|
145
|
+
function applyServerCa(mounts, env) {
|
|
146
|
+
if (options.serverCaFile) {
|
|
147
|
+
mounts.push({
|
|
148
|
+
source: options.serverCaFile,
|
|
149
|
+
target: WORKER_SERVER_CA_MOUNT_PATH,
|
|
150
|
+
readOnly: true
|
|
151
|
+
});
|
|
152
|
+
env.NODE_EXTRA_CA_CERTS = WORKER_SERVER_CA_MOUNT_PATH;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
108
155
|
function watchForExit(unitId) {
|
|
109
156
|
if (watched.has(unitId)) return;
|
|
110
157
|
watched.add(unitId);
|
|
@@ -113,7 +160,8 @@ function createDockerWorkerRunner(options) {
|
|
|
113
160
|
).finally(() => watched.delete(unitId));
|
|
114
161
|
}
|
|
115
162
|
const runner = {
|
|
116
|
-
async start(input) {
|
|
163
|
+
async start(input, observer) {
|
|
164
|
+
observer?.report("preparing_runtime");
|
|
117
165
|
const volume2 = input.volume;
|
|
118
166
|
const labels = buildWorkerUnitLabels({
|
|
119
167
|
instanceId: input.instanceId,
|
|
@@ -121,24 +169,21 @@ function createDockerWorkerRunner(options) {
|
|
|
121
169
|
serverEpoch: input.serverEpoch
|
|
122
170
|
});
|
|
123
171
|
const mounts = [{ source: volume2.id, target: volume2.mountPath }];
|
|
124
|
-
const env = {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
env.NODE_EXTRA_CA_CERTS = WORKER_SERVER_CA_MOUNT_PATH;
|
|
132
|
-
}
|
|
133
|
-
const privileged = input.isolation.dind === "privileged";
|
|
134
|
-
const dindMode = input.isolation.dind;
|
|
135
|
-
const sysbox = dindMode === "sysbox";
|
|
136
|
-
if (sysbox && !options.sysboxRuntime) {
|
|
172
|
+
const env = {
|
|
173
|
+
...input.env,
|
|
174
|
+
[PROCESS_VOLUME_MOUNT_PATH_ENV]: volume2.mountPath
|
|
175
|
+
};
|
|
176
|
+
applyServerCa(mounts, env);
|
|
177
|
+
const isolation = input.docker ? options.privateDaemonIsolation : void 0;
|
|
178
|
+
if (input.docker && !isolation) {
|
|
137
179
|
throw new Error(
|
|
138
|
-
`Cannot start
|
|
180
|
+
`Cannot start Docker-requiring process ${input.instanceId}: docker.private_daemon is not configured`
|
|
139
181
|
);
|
|
140
182
|
}
|
|
141
|
-
|
|
183
|
+
if (input.docker) env[PRIVATE_DOCKER_ENV] = "1";
|
|
184
|
+
const privileged = isolation === "privileged";
|
|
185
|
+
const sysbox = isolation === "sysbox-runc";
|
|
186
|
+
observer?.report("allocating_runtime");
|
|
142
187
|
const { id } = await engine.createContainer({
|
|
143
188
|
name: containerName(input.instanceId, input.workerId),
|
|
144
189
|
image: input.image.reference,
|
|
@@ -147,11 +192,11 @@ function createDockerWorkerRunner(options) {
|
|
|
147
192
|
mounts,
|
|
148
193
|
networkMode: options.defaultNetwork,
|
|
149
194
|
privileged,
|
|
150
|
-
...sysbox ? { runtime:
|
|
151
|
-
...anonymousVolumes ? { anonymousVolumes } : {},
|
|
195
|
+
...sysbox ? { runtime: "sysbox-runc" } : {},
|
|
152
196
|
nanoCpus: parseCpuToNanoCpus(input.resources?.cpu),
|
|
153
197
|
memoryBytes: parseMemoryToBytes(input.resources?.memory)
|
|
154
198
|
});
|
|
199
|
+
observer?.report("starting_runtime");
|
|
155
200
|
await engine.startContainer(id);
|
|
156
201
|
const ref = {
|
|
157
202
|
instanceId: input.instanceId,
|
|
@@ -159,20 +204,12 @@ function createDockerWorkerRunner(options) {
|
|
|
159
204
|
unitId: id
|
|
160
205
|
};
|
|
161
206
|
watchForExit(id);
|
|
162
|
-
return exitNotifier.wrapUnit(ref, ref.unitId
|
|
207
|
+
return exitNotifier.wrapUnit(ref, ref.unitId, {
|
|
208
|
+
replacementHandoff: "stop-before-replacement"
|
|
209
|
+
});
|
|
163
210
|
},
|
|
164
211
|
async stop(ref, opts) {
|
|
165
|
-
|
|
166
|
-
try {
|
|
167
|
-
await engine.stopContainer(ref.unitId, { timeoutSeconds });
|
|
168
|
-
} catch (error) {
|
|
169
|
-
if (!isDockerEngineNotFoundError(error)) throw error;
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
await engine.removeContainer(ref.unitId, { force: true });
|
|
173
|
-
} catch (error) {
|
|
174
|
-
if (!isDockerEngineNotFoundError(error)) throw error;
|
|
175
|
-
}
|
|
212
|
+
await stopAndRemove(ref, opts);
|
|
176
213
|
},
|
|
177
214
|
async list() {
|
|
178
215
|
const summaries = await engine.listContainers({
|
|
@@ -208,13 +245,95 @@ function createDockerWorkerRunner(options) {
|
|
|
208
245
|
unitId: descriptor.unitId
|
|
209
246
|
};
|
|
210
247
|
watchForExit(descriptor.unitId);
|
|
211
|
-
return exitNotifier.wrapUnit(ref, ref.unitId
|
|
248
|
+
return exitNotifier.wrapUnit(ref, ref.unitId, {
|
|
249
|
+
replacementHandoff: "stop-before-replacement"
|
|
250
|
+
});
|
|
212
251
|
}
|
|
213
252
|
};
|
|
214
|
-
|
|
253
|
+
const exporterServerUrl = options.serverUrl ?? "";
|
|
254
|
+
const exporterImage = options.exporterImage ?? "";
|
|
255
|
+
const helperRelays = options.helperRelays;
|
|
256
|
+
const exporter = options.volume.mode === "bind" ? createFilesystemProcessStateExporter({
|
|
257
|
+
allowedRoots: [options.volume.hostRoot],
|
|
258
|
+
resolveSource: async (instanceId) => {
|
|
259
|
+
const { id } = await volume.ensure(instanceId);
|
|
260
|
+
return {
|
|
261
|
+
workspaceRoot: path.join(id, "workspace"),
|
|
262
|
+
sessionFile: path.join(id, "tree", "primary.jsonl")
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}) : createHelperProcessStateExporter({
|
|
266
|
+
volume,
|
|
267
|
+
helperRelays,
|
|
268
|
+
async launch(input) {
|
|
269
|
+
const mounts = ["workspace", "tree"].map((volumeSubpath) => ({
|
|
270
|
+
source: input.volume.id,
|
|
271
|
+
target: path.posix.join(SESSION_TRANSFER_HELPER_MOUNT_PATH, volumeSubpath),
|
|
272
|
+
readOnly: true,
|
|
273
|
+
volumeSubpath
|
|
274
|
+
}));
|
|
275
|
+
const env = exportHelperEnvironment({
|
|
276
|
+
serverUrl: exporterServerUrl,
|
|
277
|
+
exportId: input.exportId,
|
|
278
|
+
credential: input.credential
|
|
279
|
+
});
|
|
280
|
+
applyServerCa(mounts, env);
|
|
281
|
+
const created = await engine.createContainer({
|
|
282
|
+
name: sanitizeNameSegment(input.name),
|
|
283
|
+
image: exporterImage,
|
|
284
|
+
command: ["node", SESSION_TRANSFER_HELPER_ENTRY_PATH],
|
|
285
|
+
env: toEnvList(env),
|
|
286
|
+
labels: buildExportHelperLabels({
|
|
287
|
+
instanceId: input.instanceId,
|
|
288
|
+
exportId: input.exportId
|
|
289
|
+
}),
|
|
290
|
+
mounts,
|
|
291
|
+
networkMode: options.defaultNetwork,
|
|
292
|
+
privileged: false
|
|
293
|
+
});
|
|
294
|
+
try {
|
|
295
|
+
await engine.startContainer(created.id);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
try {
|
|
298
|
+
await engine.removeContainer(created.id, { force: true });
|
|
299
|
+
} catch (cleanupError) {
|
|
300
|
+
if (!isDockerEngineNotFoundError(cleanupError)) throw cleanupError;
|
|
301
|
+
}
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
wait: async () => {
|
|
306
|
+
const exit = await engine.waitContainer(created.id);
|
|
307
|
+
return { exitCode: exit.statusCode, reason: exit.error };
|
|
308
|
+
},
|
|
309
|
+
remove: async () => {
|
|
310
|
+
try {
|
|
311
|
+
await engine.removeContainer(created.id, { force: true });
|
|
312
|
+
} catch (error) {
|
|
313
|
+
if (!isDockerEngineNotFoundError(error)) throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
},
|
|
318
|
+
async reconcileHelpers() {
|
|
319
|
+
const helpers = await engine.listContainers({
|
|
320
|
+
labels: managedExportHelperLabelSelector()
|
|
321
|
+
});
|
|
322
|
+
await Promise.all(
|
|
323
|
+
helpers.map(async (helper) => {
|
|
324
|
+
try {
|
|
325
|
+
await engine.removeContainer(helper.id, { force: true });
|
|
326
|
+
} catch (error) {
|
|
327
|
+
if (!isDockerEngineNotFoundError(error)) throw error;
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
return { runner, volume, exporter };
|
|
215
334
|
}
|
|
216
335
|
|
|
217
336
|
export {
|
|
218
337
|
createDockerWorkerRunner
|
|
219
338
|
};
|
|
220
|
-
//# sourceMappingURL=chunk-
|
|
339
|
+
//# sourceMappingURL=chunk-YBSX4N2K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/docker-worker-runner.ts"],"sourcesContent":["import { mkdirSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n\tDockerContainerExit,\n\tDockerEngineClient,\n\tDockerMountSpec,\n} from \"./docker-engine-client.js\";\nimport { isDockerEngineNotFoundError } from \"./docker-engine-http-client.js\";\nimport { createFilesystemProcessStateExporter } from \"./filesystem-process-state-exporter.js\";\nimport {\n\tcreateHelperProcessStateExporter,\n\texportHelperEnvironment,\n} from \"./helper-process-state-exporter.js\";\nimport { UnitExitNotifier } from \"./runner-utils.js\";\nimport {\n\tSESSION_TRANSFER_HELPER_ENTRY_PATH,\n\tSESSION_TRANSFER_HELPER_MOUNT_PATH,\n} from \"./session-transfer-helper.js\";\nimport type {\n\tIsolatedStartWorkerInput,\n\tProcessStateExporter,\n\tProcessStateExportHelperRelayProvider,\n\tProcessVolume,\n\tStopWorkerOptions,\n\tWorkerExitInfo,\n\tWorkerRunner,\n\tWorkerUnit,\n\tWorkerUnitDescriptor,\n\tWorkerUnitRef,\n} from \"./types.js\";\nimport {\n\tbuildExportHelperLabels,\n\tbuildWorkerUnitLabels,\n\tmanagedExportHelperLabelSelector,\n\tmanagedWorkerLabelSelector,\n\tparseWorkerUnitIdentity,\n} from \"./worker-labels.js\";\n\nexport type DockerProcessVolumeMode = \"bind\" | \"named_volume\";\n\nexport interface DockerProcessVolumeOptions {\n\tmode: DockerProcessVolumeMode;\n\t/** Host root for per-process bind mounts (bind mode). */\n\thostRoot: string;\n\t/** Mount path injected into worker containers. */\n\tmountPath: string;\n\t/** Prefix for named volumes (named_volume mode). */\n\tnamedVolumePrefix?: string;\n}\n\nexport interface DockerWorkerRunnerOptions {\n\tengine: DockerEngineClient;\n\tvolume: DockerProcessVolumeOptions;\n\t/** Shared private network attached to every worker container. */\n\tdefaultNetwork: string;\n\t/** Exact isolation used for Docker-requiring processes. Omit to make them unavailable. */\n\tprivateDaemonIsolation?: \"privileged\" | \"sysbox-runc\";\n\t/** Host CA bundle mounted read-only into workers and export helpers. */\n\tserverCaFile?: string;\n\t/** Stable internal URL used by named-volume export helpers. */\n\tserverUrl?: string;\n\t/** Trusted image containing the bundled session-transfer helper entrypoint. */\n\texporterImage?: string;\n\t/** Server-owned relay registry used by named-volume export helpers. */\n\thelperRelays?: ProcessStateExportHelperRelayProvider;\n}\n\nconst DEFAULT_NAMED_VOLUME_PREFIX = \"leitwerk-process-\";\nconst NANO_CPUS_PER_CPU = 1_000_000_000;\nconst PRIVATE_DOCKER_ENV = \"LEITWERK_PRIVATE_DOCKER\";\nconst PROCESS_VOLUME_MOUNT_PATH_ENV = \"LEITWERK_PROCESS_VOLUME_MOUNT_PATH\";\nconst WORKER_SERVER_CA_MOUNT_PATH = \"/leitwerk/server-ca.pem\";\n\n/** Replaces characters Docker rejects in container names. */\nfunction sanitizeNameSegment(value: string): string {\n\tconst cleaned = value.replace(/[^a-zA-Z0-9_.-]/g, \"-\");\n\treturn cleaned.length > 0 ? cleaned : \"x\";\n}\n\nfunction containerName(instanceId: string, workerId: string): string {\n\treturn `leitwerk-worker-${sanitizeNameSegment(instanceId)}-${sanitizeNameSegment(workerId)}`;\n}\n\nfunction toEnvList(env: Record<string, string>): string[] {\n\treturn Object.entries(env).map(([key, value]) => `${key}=${value}`);\n}\n\nfunction parseCpuToNanoCpus(cpu: string | undefined): number | undefined {\n\tif (cpu === undefined) {\n\t\treturn undefined;\n\t}\n\tconst parsed = Number.parseFloat(cpu);\n\tif (!Number.isFinite(parsed) || parsed <= 0) {\n\t\treturn undefined;\n\t}\n\treturn Math.round(parsed * NANO_CPUS_PER_CPU);\n}\n\nconst MEMORY_SUFFIX_MULTIPLIERS: ReadonlyArray<[string, number]> = [\n\t[\"Gi\", 1024 ** 3],\n\t[\"Mi\", 1024 ** 2],\n\t[\"Ki\", 1024],\n\t[\"G\", 1000 ** 3],\n\t[\"M\", 1000 ** 2],\n\t[\"K\", 1000],\n\t[\"g\", 1024 ** 3],\n\t[\"m\", 1024 ** 2],\n\t[\"k\", 1024],\n\t[\"b\", 1],\n\t[\"B\", 1],\n];\n\nfunction parseMemoryToBytes(memory: string | undefined): number | undefined {\n\tif (memory === undefined) {\n\t\treturn undefined;\n\t}\n\tconst trimmed = memory.trim();\n\tfor (const [suffix, multiplier] of MEMORY_SUFFIX_MULTIPLIERS) {\n\t\tif (trimmed.endsWith(suffix)) {\n\t\t\tconst value = Number.parseFloat(trimmed.slice(0, -suffix.length));\n\t\t\tif (!Number.isFinite(value) || value <= 0) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn Math.round(value * multiplier);\n\t\t}\n\t}\n\tconst bytes = Number.parseInt(trimmed, 10);\n\treturn Number.isFinite(bytes) && bytes > 0 ? bytes : undefined;\n}\n\nfunction mapExit(info: DockerContainerExit): WorkerExitInfo {\n\treturn {\n\t\texitCode: Number.isFinite(info.statusCode) ? info.statusCode : null,\n\t\tsignal: info.signal ?? null,\n\t\t...(info.oomKilled !== undefined ? { oomKilled: info.oomKilled } : {}),\n\t\t...(info.error !== undefined ? { reason: info.error } : {}),\n\t};\n}\n\n/**\n * Docker Engine API {@link ProcessVolume} / {@link WorkerRunner}.\n *\n * Container-per-process, labelled for adoption, bind- or named-volume backed.\n * The server never reads the volume; it only injects the mount. Physical\n * container exits are observed via the engine's wait call and mapped into the\n * supervisor's existing failure paths through `onExit`.\n */\nexport function createDockerWorkerRunner(options: DockerWorkerRunnerOptions): {\n\trunner: WorkerRunner<IsolatedStartWorkerInput>;\n\tvolume: ProcessVolume;\n\texporter: ProcessStateExporter;\n} {\n\tif (\n\t\toptions.volume.mode === \"named_volume\" &&\n\t\t(!options.serverUrl || !options.exporterImage || !options.helperRelays)\n\t) {\n\t\tthrow new Error(\"Docker named-volume transfer exporter is not configured\");\n\t}\n\tconst { engine } = options;\n\tconst mountPath = options.volume.mountPath;\n\tconst namedVolumePrefix = options.volume.namedVolumePrefix ?? DEFAULT_NAMED_VOLUME_PREFIX;\n\tfunction volumeId(instanceId: string): string {\n\t\tif (options.volume.mode === \"named_volume\") {\n\t\t\treturn `${namedVolumePrefix}${instanceId}`;\n\t\t}\n\t\treturn path.join(options.volume.hostRoot, instanceId);\n\t}\n\n\tasync function releaseManagedStorage(instanceId: string): Promise<void> {\n\t\tif (options.volume.mode === \"named_volume\") {\n\t\t\tawait engine.removeVolume(volumeId(instanceId));\n\t\t}\n\t\t// Bind mounts are retained on the host filesystem; retention/GC of the\n\t\t// host directory is an operator concern, not a runner action.\n\t}\n\n\tconst volume: ProcessVolume = {\n\t\tasync ensure(instanceId) {\n\t\t\tconst id = volumeId(instanceId);\n\t\t\tif (options.volume.mode === \"named_volume\") {\n\t\t\t\tawait engine.ensureVolume(id);\n\t\t\t} else {\n\t\t\t\tmkdirSync(id, { recursive: true });\n\t\t\t}\n\t\t\treturn { instanceId, id, mountPath };\n\t\t},\n\t\trelease: releaseManagedStorage,\n\t\tdeleteProcessResources: releaseManagedStorage,\n\t};\n\n\tconst exitNotifier = new UnitExitNotifier();\n\tconst watched = new Set<string>();\n\tconst stopPromises = new Map<string, Promise<void>>();\n\n\tfunction stopAndRemove(ref: WorkerUnitRef, opts: StopWorkerOptions): Promise<void> {\n\t\tconst existing = stopPromises.get(ref.unitId);\n\t\tif (existing) return existing;\n\t\tconst operation = Promise.resolve()\n\t\t\t.then(async () => {\n\t\t\t\tconst timeoutSeconds = Math.max(0, Math.ceil(opts.graceMs / 1000));\n\t\t\t\ttry {\n\t\t\t\t\tawait engine.stopContainer(ref.unitId, { timeoutSeconds });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait engine.removeContainer(ref.unitId, { force: true });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => stopPromises.delete(ref.unitId));\n\t\tstopPromises.set(ref.unitId, operation);\n\t\treturn operation;\n\t}\n\n\tfunction applyServerCa(mounts: DockerMountSpec[], env: Record<string, string>): void {\n\t\tif (options.serverCaFile) {\n\t\t\tmounts.push({\n\t\t\t\tsource: options.serverCaFile,\n\t\t\t\ttarget: WORKER_SERVER_CA_MOUNT_PATH,\n\t\t\t\treadOnly: true,\n\t\t\t});\n\t\t\tenv.NODE_EXTRA_CA_CERTS = WORKER_SERVER_CA_MOUNT_PATH;\n\t\t}\n\t}\n\n\tfunction watchForExit(unitId: string): void {\n\t\tif (watched.has(unitId)) return;\n\t\twatched.add(unitId);\n\t\tengine\n\t\t\t.waitContainer(unitId)\n\t\t\t.then((exit) => exitNotifier.fireExit(unitId, mapExit(exit)))\n\t\t\t.catch(() =>\n\t\t\t\texitNotifier.fireExit(unitId, { exitCode: null, signal: null, reason: \"wait_failed\" }),\n\t\t\t)\n\t\t\t.finally(() => watched.delete(unitId));\n\t}\n\n\tconst runner: WorkerRunner<IsolatedStartWorkerInput> = {\n\t\tasync start(input: IsolatedStartWorkerInput, observer) {\n\t\t\tobserver?.report(\"preparing_runtime\");\n\t\t\tconst volume = input.volume;\n\t\t\tconst labels = buildWorkerUnitLabels({\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: input.workerId,\n\t\t\t\tserverEpoch: input.serverEpoch,\n\t\t\t});\n\t\t\tconst mounts: DockerMountSpec[] = [{ source: volume.id, target: volume.mountPath }];\n\t\t\tconst env: Record<string, string> = {\n\t\t\t\t...input.env,\n\t\t\t\t[PROCESS_VOLUME_MOUNT_PATH_ENV]: volume.mountPath,\n\t\t\t};\n\t\t\tapplyServerCa(mounts, env);\n\t\t\tconst isolation = input.docker ? options.privateDaemonIsolation : undefined;\n\t\t\tif (input.docker && !isolation) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot start Docker-requiring process ${input.instanceId}: docker.private_daemon is not configured`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (input.docker) env[PRIVATE_DOCKER_ENV] = \"1\";\n\t\t\tconst privileged = isolation === \"privileged\";\n\t\t\tconst sysbox = isolation === \"sysbox-runc\";\n\t\t\tobserver?.report(\"allocating_runtime\");\n\t\t\tconst { id } = await engine.createContainer({\n\t\t\t\tname: containerName(input.instanceId, input.workerId),\n\t\t\t\timage: input.image.reference,\n\t\t\t\tenv: toEnvList(env),\n\t\t\t\tlabels,\n\t\t\t\tmounts,\n\t\t\t\tnetworkMode: options.defaultNetwork,\n\t\t\t\tprivileged,\n\t\t\t\t...(sysbox ? { runtime: \"sysbox-runc\" } : {}),\n\t\t\t\tnanoCpus: parseCpuToNanoCpus(input.resources?.cpu),\n\t\t\t\tmemoryBytes: parseMemoryToBytes(input.resources?.memory),\n\t\t\t});\n\t\t\tobserver?.report(\"starting_runtime\");\n\t\t\tawait engine.startContainer(id);\n\t\t\tconst ref: WorkerUnitRef = {\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: input.workerId,\n\t\t\t\tunitId: id,\n\t\t\t};\n\t\t\twatchForExit(id);\n\t\t\treturn exitNotifier.wrapUnit(ref, ref.unitId, {\n\t\t\t\treplacementHandoff: \"stop-before-replacement\",\n\t\t\t});\n\t\t},\n\t\tasync stop(ref: WorkerUnitRef, opts: StopWorkerOptions) {\n\t\t\tawait stopAndRemove(ref, opts);\n\t\t\t// Container removal is the replacement handoff boundary. The process volume,\n\t\t\t// including private daemon state, remains available to the replacement.\n\t\t},\n\t\tasync list(): Promise<WorkerUnitDescriptor[]> {\n\t\t\tconst summaries = await engine.listContainers({\n\t\t\t\tlabels: managedWorkerLabelSelector(),\n\t\t\t});\n\t\t\tconst descriptors: WorkerUnitDescriptor[] = [];\n\t\t\tfor (const summary of summaries) {\n\t\t\t\tconst identity = parseWorkerUnitIdentity(summary.labels);\n\t\t\t\tif (!identity) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdescriptors.push({\n\t\t\t\t\tinstanceId: identity.instanceId,\n\t\t\t\t\tworkerId: identity.workerId,\n\t\t\t\t\tunitId: summary.id,\n\t\t\t\t\tobservedState: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn descriptors;\n\t\t},\n\t\tasync adopt(descriptor: WorkerUnitDescriptor): Promise<WorkerUnit> {\n\t\t\tconst inspect = await engine.inspectContainer(descriptor.unitId);\n\t\t\tconst identity = parseWorkerUnitIdentity(inspect.labels);\n\t\t\tif (\n\t\t\t\t!identity ||\n\t\t\t\tidentity.instanceId !== descriptor.instanceId ||\n\t\t\t\tidentity.workerId !== descriptor.workerId\n\t\t\t) {\n\t\t\t\tthrow new Error(`Cannot adopt worker unit ${descriptor.unitId}: labels changed`);\n\t\t\t}\n\t\t\tif (!inspect.running) {\n\t\t\t\tthrow new Error(`Cannot adopt worker unit ${descriptor.unitId}: not running`);\n\t\t\t}\n\t\t\tconst ref: WorkerUnitRef = {\n\t\t\t\tinstanceId: descriptor.instanceId,\n\t\t\t\tworkerId: descriptor.workerId,\n\t\t\t\tunitId: descriptor.unitId,\n\t\t\t};\n\t\t\twatchForExit(descriptor.unitId);\n\t\t\treturn exitNotifier.wrapUnit(ref, ref.unitId, {\n\t\t\t\treplacementHandoff: \"stop-before-replacement\",\n\t\t\t});\n\t\t},\n\t};\n\n\tconst exporterServerUrl = options.serverUrl ?? \"\";\n\tconst exporterImage = options.exporterImage ?? \"\";\n\tconst helperRelays = options.helperRelays as ProcessStateExportHelperRelayProvider;\n\tconst exporter =\n\t\toptions.volume.mode === \"bind\"\n\t\t\t? createFilesystemProcessStateExporter({\n\t\t\t\t\tallowedRoots: [options.volume.hostRoot],\n\t\t\t\t\tresolveSource: async (instanceId) => {\n\t\t\t\t\t\tconst { id } = await volume.ensure(instanceId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tworkspaceRoot: path.join(id, \"workspace\"),\n\t\t\t\t\t\t\tsessionFile: path.join(id, \"tree\", \"primary.jsonl\"),\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: createHelperProcessStateExporter({\n\t\t\t\t\tvolume,\n\t\t\t\t\thelperRelays,\n\t\t\t\t\tasync launch(input) {\n\t\t\t\t\t\tconst mounts: DockerMountSpec[] = [\"workspace\", \"tree\"].map((volumeSubpath) => ({\n\t\t\t\t\t\t\tsource: input.volume.id,\n\t\t\t\t\t\t\ttarget: path.posix.join(SESSION_TRANSFER_HELPER_MOUNT_PATH, volumeSubpath),\n\t\t\t\t\t\t\treadOnly: true,\n\t\t\t\t\t\t\tvolumeSubpath,\n\t\t\t\t\t\t}));\n\t\t\t\t\t\tconst env = exportHelperEnvironment({\n\t\t\t\t\t\t\tserverUrl: exporterServerUrl,\n\t\t\t\t\t\t\texportId: input.exportId,\n\t\t\t\t\t\t\tcredential: input.credential,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tapplyServerCa(mounts, env);\n\t\t\t\t\t\tconst created = await engine.createContainer({\n\t\t\t\t\t\t\tname: sanitizeNameSegment(input.name),\n\t\t\t\t\t\t\timage: exporterImage,\n\t\t\t\t\t\t\tcommand: [\"node\", SESSION_TRANSFER_HELPER_ENTRY_PATH],\n\t\t\t\t\t\t\tenv: toEnvList(env),\n\t\t\t\t\t\t\tlabels: buildExportHelperLabels({\n\t\t\t\t\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\t\t\t\t\texportId: input.exportId,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tmounts,\n\t\t\t\t\t\t\tnetworkMode: options.defaultNetwork,\n\t\t\t\t\t\t\tprivileged: false,\n\t\t\t\t\t\t});\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait engine.startContainer(created.id);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait engine.removeContainer(created.id, { force: true });\n\t\t\t\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\t\t\t\tif (!isDockerEngineNotFoundError(cleanupError)) throw cleanupError;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\twait: async () => {\n\t\t\t\t\t\t\t\tconst exit = await engine.waitContainer(created.id);\n\t\t\t\t\t\t\t\treturn { exitCode: exit.statusCode, reason: exit.error };\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tremove: async () => {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait engine.removeContainer(created.id, { force: true });\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tasync reconcileHelpers() {\n\t\t\t\t\t\tconst helpers = await engine.listContainers({\n\t\t\t\t\t\t\tlabels: managedExportHelperLabelSelector(),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\thelpers.map(async (helper) => {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait engine.removeContainer(helper.id, { force: true });\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t});\n\treturn { runner, volume, exporter };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,OAAO,UAAU;AAkEjB,IAAM,8BAA8B;AACpC,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAC3B,IAAM,gCAAgC;AACtC,IAAM,8BAA8B;AAGpC,SAAS,oBAAoB,OAAuB;AACnD,QAAM,UAAU,MAAM,QAAQ,oBAAoB,GAAG;AACrD,SAAO,QAAQ,SAAS,IAAI,UAAU;AACvC;AAEA,SAAS,cAAc,YAAoB,UAA0B;AACpE,SAAO,mBAAmB,oBAAoB,UAAU,CAAC,IAAI,oBAAoB,QAAQ,CAAC;AAC3F;AAEA,SAAS,UAAU,KAAuC;AACzD,SAAO,OAAO,QAAQ,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE;AACnE;AAEA,SAAS,mBAAmB,KAA6C;AACxE,MAAI,QAAQ,QAAW;AACtB,WAAO;AAAA,EACR;AACA,QAAM,SAAS,OAAO,WAAW,GAAG;AACpC,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG;AAC5C,WAAO;AAAA,EACR;AACA,SAAO,KAAK,MAAM,SAAS,iBAAiB;AAC7C;AAEA,IAAM,4BAA6D;AAAA,EAClE,CAAC,MAAM,QAAQ,CAAC;AAAA,EAChB,CAAC,MAAM,QAAQ,CAAC;AAAA,EAChB,CAAC,MAAM,IAAI;AAAA,EACX,CAAC,KAAK,OAAQ,CAAC;AAAA,EACf,CAAC,KAAK,OAAQ,CAAC;AAAA,EACf,CA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