@leitwerk-dev/worker-runners 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/{chunk-ZGFD76I6.js → chunk-GF3H4C3J.js} +1 -1
  2. package/dist/chunk-GF3H4C3J.js.map +1 -0
  3. package/dist/{chunk-SFI5TMFN.js → chunk-GMZOYHQD.js} +121 -8
  4. package/dist/chunk-GMZOYHQD.js.map +1 -0
  5. package/dist/{chunk-DSSMRFB4.js → chunk-LZOVBKHR.js} +1 -1
  6. package/dist/{chunk-DSSMRFB4.js.map → chunk-LZOVBKHR.js.map} +1 -1
  7. package/dist/index.js +15 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/{kubernetes-api-client-BeZPZqmj.d.ts → kubernetes-api-client-BMWAgyfW.d.ts} +14 -1
  10. package/dist/kubernetes-client-public.js +1 -1
  11. package/dist/kubernetes-http-client.js +1 -1
  12. package/dist/kubernetes-preparation.d.ts +1 -1
  13. package/dist/kubernetes-preparation.d.ts.map +1 -1
  14. package/dist/kubernetes-public.js +2 -2
  15. package/dist/kubernetes-volume-pool-api.d.ts +14 -1
  16. package/dist/kubernetes-volume-pool-api.d.ts.map +1 -1
  17. package/dist/kubernetes-volume-pool.d.ts +3 -1
  18. package/dist/kubernetes-volume-pool.d.ts.map +1 -1
  19. package/dist/kubernetes-volume-retirement.d.ts +20 -0
  20. package/dist/kubernetes-volume-retirement.d.ts.map +1 -0
  21. package/dist/kubernetes-worker-runner.d.ts +3 -1
  22. package/dist/kubernetes-worker-runner.d.ts.map +1 -1
  23. package/dist/kubernetes-worker-runner.js +2 -2
  24. package/dist/process-volume-retention.d.ts +4 -0
  25. package/dist/process-volume-retention.d.ts.map +1 -1
  26. package/dist/types-public.js +1 -1
  27. package/dist/types.d.ts +11 -1
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/types.js +1 -1
  30. package/package.json +5 -5
  31. package/src/kubernetes-preparation.ts +3 -3
  32. package/src/kubernetes-volume-pool-api.ts +14 -1
  33. package/src/kubernetes-volume-pool.ts +26 -4
  34. package/src/kubernetes-volume-retirement.ts +139 -0
  35. package/src/kubernetes-worker-runner.ts +29 -2
  36. package/src/process-volume-retention.ts +27 -4
  37. package/src/types.ts +15 -1
  38. package/dist/chunk-SFI5TMFN.js.map +0 -1
  39. package/dist/chunk-ZGFD76I6.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/kubernetes-worker-runner.ts","../src/kubernetes-image-preload.ts","../src/kubernetes-preparation.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\tcreateKubernetesImagePreload,\n\ttype ImagePreparationEvent,\n} from \"./kubernetes-image-preload.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 { createKubernetesPreparation } from \"./kubernetes-preparation.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\n/** @internal */\nexport interface KubernetesWorkerRunnerOptions {\n\t/** @internal */\n\timagePreload?: {\n\t\t/** @internal */\n\t\timages: string[];\n\t\t/** @internal */\n\t\tonEvent?: (event: ImagePreparationEvent) => void;\n\t};\n\t/** @internal */\n\tpreProvision?: {\n\t\t/** @internal */\n\t\tcount: number;\n\t\t/** @internal */\n\t\tonError?: () => void;\n\t};\n\t/** @internal */\n\tclient: KubernetesApiClient;\n\t/** Prefix used to derive one Kubernetes namespace per process instance. @internal */\n\tprocessNamespacePrefix: string;\n\t/** @internal */\n\tvolume: KubernetesProcessVolumeSpec;\n\t/** Storage and Pod wiring for process definitions that require private Docker. @internal */\n\tdocker?: KubernetesDockerPodSpecOptions & {\n\t\t/** @internal */\n\t\tprocessStorageClassName: string;\n\t};\n\t/** Maximum wait after deletion before replacement is rejected. @internal */\n\tpodDisappearanceTimeoutMs?: number;\n\t/** @internal */\n\tpodDisappearancePollIntervalMs?: number;\n\t/** Test seam for bounded disappearance polling. @internal */\n\tdelay?: (ms: number) => Promise<void>;\n\t/** Server-local CA bundle copied into each process namespace for worker TLS trust. @internal */\n\tserverCaFile?: string;\n\t/** Namespace containing operator-managed source image-pull Secrets. @internal */\n\tserverNamespace?: string;\n\t/** Docker registry Secrets copied into every process namespace. @internal */\n\timagePullSecretCopies?: Array<{\n\t\t/** @internal */\n\t\tsourceName: string;\n\t\t/** @internal */\n\t\ttargetName: string;\n\t}>;\n\t/** @internal */\n\tpod?: Omit<KubernetesPodSpecOptions, \"namespace\">;\n\t/** Stable internal URL used by PVC export helpers. @internal */\n\tserverUrl?: string;\n\t/** Trusted image containing the bundled session-transfer helper entrypoint. @internal */\n\texporterImage?: string;\n\t/** Pull policy for the trusted helper image. @internal */\n\texporterImagePullPolicy?: string;\n\t/** Server-owned relay registry used by PVC export helpers. @internal */\n\thelperRelays?: ProcessStateExportHelperRelayProvider;\n}\n\n/** @internal */\nexport function createKubernetesWorkerRunner(options: KubernetesWorkerRunnerOptions): {\n\t/** @internal */\n\trunner: WorkerRunner<IsolatedStartWorkerInput>;\n\t/** @internal */\n\tvolume: ProcessVolume;\n\t/** @internal */\n\texporter: ProcessStateExporter;\n\t/** @internal */\n\tpreparation?: ReturnType<typeof createKubernetesPreparation>;\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 serverCaConfig = serverCaFile\n\t\t? {\n\t\t\t\tserverCaConfigMap: {\n\t\t\t\t\tname: KUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_NAME,\n\t\t\t\t\tkey: KUBERNETES_WORKER_SERVER_CA_CONFIG_MAP_KEY,\n\t\t\t\t\tmountPath: KUBERNETES_WORKER_SERVER_CA_MOUNT_PATH,\n\t\t\t\t},\n\t\t\t}\n\t\t: {};\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\t...(requirements?.docker && options.docker?.isolation\n\t\t\t\t\t? { extraLabels: { \"pod-security.kubernetes.io/enforce\": \"privileged\" } }\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t\tif (requirements?.docker && options.docker) {\n\t\t\t\tif (!client.getPersistentVolumeClaim)\n\t\t\t\t\tthrow new Error(\"Docker requires process storage inspection\");\n\t\t\t\tconst existing = await client.getPersistentVolumeClaim(\n\t\t\t\t\tkubernetesProcessPvcName(instanceId, options.volume.namePrefix),\n\t\t\t\t\tnamespaceManifest.metadata.name,\n\t\t\t\t);\n\t\t\t\tif (existing && existing.storageClass !== options.docker.processStorageClassName) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"Docker requires the configured block StorageClass; preserve and migrate the existing process volume before resuming\",\n\t\t\t\t\t);\n\t\t\t\t}\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...serverCaConfig,\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...serverCaConfig,\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\tconst preparationPullSecrets = (options.pod?.imagePullSecrets ?? []).map(\n\t\t(name) =>\n\t\t\toptions.imagePullSecretCopies?.find((copy) => copy.targetName === name)?.sourceName ?? name,\n\t);\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: preparationPullSecrets,\n\t\t\tnodeSelector: options.pod?.nodeSelector,\n\t\t\ttolerations: options.pod?.tolerations,\n\t\t});\n\t}\n\tlet imagePreload: ReturnType<typeof createKubernetesImagePreload> | undefined;\n\tif (options.imagePreload) {\n\t\tif (!client.imagePreload || !options.serverNamespace)\n\t\t\tthrow new Error(\"Image preloading requires an API and server namespace\");\n\t\timagePreload = createKubernetesImagePreload({\n\t\t\tapi: client.imagePreload,\n\t\t\tnamespace: options.serverNamespace,\n\t\t\t...options.imagePreload,\n\t\t\timagePullSecrets: preparationPullSecrets,\n\t\t\tnodeSelector: options.pod?.nodeSelector,\n\t\t\tadditionalNodeSelectors: options.docker\n\t\t\t\t? [{ ...options.pod?.nodeSelector, ...options.docker.nodeSelector }]\n\t\t\t\t: undefined,\n\t\t\ttolerations: options.pod?.tolerations,\n\t\t});\n\t}\n\tconst controllers = [volumePool, imagePreload].filter((value) => value !== undefined);\n\tconst preparation = controllers.length ? createKubernetesPreparation(controllers) : undefined;\n\treturn { runner, volume, exporter, preparation };\n}\n","import { createHash } from \"node:crypto\";\nimport type {\n\tImagePreloadApi,\n\tImagePreparationPod,\n\tPreparationNode,\n} from \"./kubernetes-image-preload-api.js\";\nimport { buildPreparationPodSpec, createPreparationController } from \"./kubernetes-preparation.js\";\n\nexport const IMAGE_PRELOAD_LABEL = \"leitwerk.dev/image-preload\";\nconst NODE_UID = \"leitwerk.dev/preparation-node-uid\";\nconst NODE_NAME = \"leitwerk.dev/preparation-node-name\";\nconst IMAGE = \"leitwerk.dev/preparation-image\";\nconst INTERVAL = 30_000;\nconst hash = (value: string) => createHash(\"sha256\").update(value).digest(\"hex\");\n\n/** @internal */\nexport interface ImagePreparationEvent {\n\t/** @internal */\n\tcomponent: \"image-preparation\";\n\t/** @internal */\n\toutcome: \"succeeded\" | \"failed\";\n\t/** @internal */\n\tnode?: string;\n\t/** @internal */\n\tnodeUid?: string;\n\t/** @internal */\n\timage?: string;\n\t/** @internal */\n\tpod?: string;\n\t/** @internal */\n\treason?: string;\n}\n\n/** @internal */\nexport function immutableWorkerImage(image: string): string {\n\tconst match = /^([a-zA-Z0-9][a-zA-Z0-9._:/-]*)@(sha256:[0-9a-f]{64})$/.exec(image);\n\tif (!match) throw new Error(\"Image preloading requires digest-qualified worker images\");\n\treturn `${match[1].replace(/:[^/:]+$/, \"\")}@${match[2]}`;\n}\n\n/** @internal */\nexport function eligiblePreparationNode(\n\tnode: PreparationNode,\n\tselector: Record<string, string>,\n\ttolerations: unknown[],\n): boolean {\n\tif (!node.metadata.uid || node.metadata.deletionTimestamp || node.spec?.unschedulable)\n\t\treturn false;\n\tif (\n\t\t!node.status?.conditions?.some(\n\t\t\t(condition) => condition.type === \"Ready\" && condition.status === \"True\",\n\t\t)\n\t)\n\t\treturn false;\n\tif (!Object.entries(selector).every(([key, value]) => node.metadata.labels?.[key] === value))\n\t\treturn false;\n\treturn (node.spec?.taints ?? []).every((taint) => {\n\t\tif (![\"NoSchedule\", \"NoExecute\"].includes(taint.effect)) return true;\n\t\treturn tolerations.some((value) => {\n\t\t\tif (!value || typeof value !== \"object\") return false;\n\t\t\tconst tolerance = value as Record<string, unknown>;\n\t\t\tif (tolerance.effect && tolerance.effect !== taint.effect) return false;\n\t\t\tif (tolerance.operator === \"Exists\") return !tolerance.key || tolerance.key === taint.key;\n\t\t\treturn (\n\t\t\t\t(!tolerance.operator || tolerance.operator === \"Equal\") &&\n\t\t\t\ttolerance.key === taint.key &&\n\t\t\t\t(tolerance.value ?? \"\") === (taint.value ?? \"\")\n\t\t\t);\n\t\t});\n\t});\n}\n\n/** @internal */\nexport function createKubernetesImagePreload(options: {\n\t/** @internal */\n\tapi: ImagePreloadApi;\n\t/** @internal */\n\tnamespace: string;\n\t/** @internal */\n\timages: string[];\n\t/** @internal */\n\timagePullSecrets?: string[];\n\t/** @internal */\n\tnodeSelector?: Record<string, string>;\n\t/** Other worker placements to prepare, deduplicated by node and image. @internal */\n\tadditionalNodeSelectors?: Record<string, string>[];\n\t/** @internal */\n\ttolerations?: unknown[];\n\t/** @internal */\n\tonEvent?: (event: ImagePreparationEvent) => void;\n}) {\n\tconst { api, namespace } = options;\n\tconst nodeSelectors = [options.nodeSelector ?? {}, ...(options.additionalNodeSelectors ?? [])];\n\tconst selectorForNode = (node: PreparationNode) =>\n\t\tnodeSelectors.find((selector) =>\n\t\t\teligiblePreparationNode(node, selector, options.tolerations ?? []),\n\t\t);\n\tconst images = [...new Set(options.images.map(immutableWorkerImage))];\n\tconst preloadId = hash(namespace).slice(0, 16);\n\tconst selector = `${IMAGE_PRELOAD_LABEL}=${preloadId}`;\n\tconst labels = {\n\t\t\"leitwerk.dev/managed-by\": \"leitwerk\",\n\t\t\"leitwerk.dev/component\": \"image-preparation\",\n\t\t[IMAGE_PRELOAD_LABEL]: preloadId,\n\t};\n\tconst podName = (uid: string, image: string) =>\n\t\t`lw-image-${hash(`${uid}/${image}`).slice(0, 40)}`;\n\tconst reported = new Map<string, string>();\n\tconst failedSince = new Map<string, number>();\n\n\tfunction owned(pod: ImagePreparationPod) {\n\t\tconst annotations = pod.metadata.annotations ?? {};\n\t\tconst uid = annotations[NODE_UID];\n\t\tconst name = annotations[NODE_NAME];\n\t\tconst image = annotations[IMAGE];\n\t\tconst containers = pod.spec.containers as\n\t\t\t| Array<{\n\t\t\t\t\t/** @internal */ image?: string /** @internal */;\n\t\t\t\t\tcommand?: string[];\n\t\t\t }>\n\t\t\t| undefined;\n\t\treturn (\n\t\t\tpod.metadata.namespace === namespace &&\n\t\t\t!!pod.metadata.uid &&\n\t\t\t!!uid &&\n\t\t\t!!name &&\n\t\t\t!!image &&\n\t\t\tObject.entries(labels).every(([key, value]) => pod.metadata.labels?.[key] === value) &&\n\t\t\tpod.metadata.name === podName(uid, image) &&\n\t\t\tpod.metadata.ownerReferences?.some(\n\t\t\t\t(owner) =>\n\t\t\t\t\towner.apiVersion === \"v1\" &&\n\t\t\t\t\towner.kind === \"Node\" &&\n\t\t\t\t\towner.name === name &&\n\t\t\t\t\towner.uid === uid,\n\t\t\t) &&\n\t\t\tpod.spec.nodeName === name &&\n\t\t\tpod.spec.automountServiceAccountToken === false &&\n\t\t\tcontainers?.length === 1 &&\n\t\t\tcontainers[0].image === image &&\n\t\t\tJSON.stringify(containers[0].command) === JSON.stringify([\"node\", \"-e\", \"process.exit(0)\"])\n\t\t);\n\t}\n\tfunction report(\n\t\tpod: ImagePreparationPod,\n\t\toutcome: ImagePreparationEvent[\"outcome\"],\n\t\treason?: string,\n\t) {\n\t\tconst uid = pod.metadata.uid ?? pod.metadata.name;\n\t\tconst state = `${outcome}/${reason ?? \"\"}`;\n\t\tif (reported.get(uid) === state) return;\n\t\treported.set(uid, state);\n\t\toptions.onEvent?.({\n\t\t\tcomponent: \"image-preparation\",\n\t\t\toutcome,\n\t\t\treason,\n\t\t\tpod: pod.metadata.name,\n\t\t\tnode: pod.metadata.annotations?.[NODE_NAME],\n\t\t\tnodeUid: pod.metadata.annotations?.[NODE_UID],\n\t\t\timage: pod.metadata.annotations?.[IMAGE],\n\t\t});\n\t}\n\tfunction manifest(\n\t\tnode: PreparationNode,\n\t\timage: string,\n\t\tnodeSelector: Record<string, string>,\n\t): ImagePreparationPod {\n\t\tconst uid = node.metadata.uid ?? \"\";\n\t\treturn {\n\t\t\tapiVersion: \"v1\",\n\t\t\tkind: \"Pod\",\n\t\t\tmetadata: {\n\t\t\t\tname: podName(uid, image),\n\t\t\t\tnamespace,\n\t\t\t\tlabels,\n\t\t\t\tannotations: { [NODE_UID]: uid, [NODE_NAME]: node.metadata.name, [IMAGE]: image },\n\t\t\t\townerReferences: [{ apiVersion: \"v1\", kind: \"Node\", name: node.metadata.name, uid }],\n\t\t\t},\n\t\t\tspec: {\n\t\t\t\t...buildPreparationPodSpec({\n\t\t\t\t\t...options,\n\t\t\t\t\timage,\n\t\t\t\t\timagePullPolicy: \"IfNotPresent\",\n\t\t\t\t\tnodeSelector: { ...nodeSelector },\n\t\t\t\t}),\n\t\t\t\tnodeName: node.metadata.name,\n\t\t\t\tsecurityContext: {\n\t\t\t\t\trunAsNonRoot: true,\n\t\t\t\t\trunAsUser: 1000,\n\t\t\t\t\trunAsGroup: 1000,\n\t\t\t\t\tseccompProfile: { type: \"RuntimeDefault\" },\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\t/** @internal */\n\tasync function reconcile(signal: AbortSignal) {\n\t\tconst nodes = await api.listNodes(signal);\n\t\tconst desired = new Map<string, ImagePreparationPod>();\n\t\tfor (const node of nodes) {\n\t\t\tconst nodeSelector = selectorForNode(node);\n\t\t\tif (!nodeSelector) continue;\n\t\t\tfor (const image of images) {\n\t\t\t\tconst pod = manifest(node, image, nodeSelector);\n\t\t\t\tdesired.set(pod.metadata.name, pod);\n\t\t\t}\n\t\t}\n\t\tconst pods = await api.listPods(namespace, selector, signal);\n\t\tfor (const pod of pods) {\n\t\t\tif (desired.has(pod.metadata.name) || !owned(pod) || pod.metadata.deletionTimestamp) continue;\n\t\t\ttry {\n\t\t\t\tawait api.deletePod(namespace, pod, signal);\n\t\t\t} catch {\n\t\t\t\tif (!signal.aborted) report(pod, \"failed\", \"cleanup_failed\");\n\t\t\t}\n\t\t}\n\t\tconst liveUids = new Set(pods.map((pod) => pod.metadata.uid ?? \"\"));\n\t\tfor (const uid of reported.keys())\n\t\t\tif (!liveUids.has(uid)) {\n\t\t\t\treported.delete(uid);\n\t\t\t\tfailedSince.delete(uid);\n\t\t\t}\n\t\tfor (const expected of desired.values()) {\n\t\t\ttry {\n\t\t\t\tconst pod =\n\t\t\t\t\tpods.find((value) => value.metadata.name === expected.metadata.name) ??\n\t\t\t\t\t(await api.getPod(namespace, expected.metadata.name, signal));\n\t\t\t\tif (!pod) {\n\t\t\t\t\tawait api.createPod(namespace, expected, signal);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!owned(pod)) {\n\t\t\t\t\treport(expected, \"failed\", \"ownership_mismatch\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (pod.metadata.deletionTimestamp) continue;\n\t\t\t\tif (pod.status?.phase === \"Succeeded\") {\n\t\t\t\t\treport(pod, \"succeeded\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (pod.status?.phase === \"Failed\") {\n\t\t\t\t\treport(pod, \"failed\", \"pod_failed\");\n\t\t\t\t\tconst uid = pod.metadata.uid ?? \"\";\n\t\t\t\t\tconst finished = Date.parse(\n\t\t\t\t\t\tpod.status.containerStatuses?.[0]?.state?.terminated?.finishedAt ?? \"\",\n\t\t\t\t\t);\n\t\t\t\t\tconst since = failedSince.get(uid) ?? (Number.isFinite(finished) ? finished : Date.now());\n\t\t\t\t\tfailedSince.set(uid, since);\n\t\t\t\t\tif (Date.now() - since >= INTERVAL) {\n\t\t\t\t\t\tawait api.deletePod(namespace, pod, signal);\n\t\t\t\t\t\tawait api.createPod(namespace, expected, signal);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst reason = pod.status?.containerStatuses?.[0]?.state?.waiting?.reason;\n\t\t\t\tif (\n\t\t\t\t\treason === \"ErrImagePull\" ||\n\t\t\t\t\treason === \"ImagePullBackOff\" ||\n\t\t\t\t\treason === \"InvalidImageName\"\n\t\t\t\t)\n\t\t\t\t\treport(pod, \"failed\", reason);\n\t\t\t} catch {\n\t\t\t\tif (!signal.aborted) report(expected, \"failed\", \"api_error\");\n\t\t\t}\n\t\t}\n\t}\n\treturn {\n\t\t/** @internal */\n\t\treconcile,\n\t\t...createPreparationController(reconcile, INTERVAL, () =>\n\t\t\toptions.onEvent?.({\n\t\t\t\tcomponent: \"image-preparation\",\n\t\t\t\toutcome: \"failed\",\n\t\t\t\treason: \"discovery_failed\",\n\t\t\t}),\n\t\t),\n\t};\n}\n","import { setTimeout as delay } from \"node:timers/promises\";\nimport type { VolumePoolOptions } from \"./kubernetes-volume-pool.js\";\nimport type { PoolObject } from \"./kubernetes-volume-pool-api.js\";\n\n/** Shared inert preparation workload; callers supply ownership and placement constraints. @internal */\nexport function buildPreparationPodSpec(\n\toptions: Pick<\n\t\tVolumePoolOptions,\n\t\t\"image\" | \"imagePullPolicy\" | \"imagePullSecrets\" | \"nodeSelector\" | \"tolerations\"\n\t>,\n\tvolumeMounts?: unknown[],\n): PoolObject[\"spec\"] {\n\treturn {\n\t\trestartPolicy: \"Never\",\n\t\tserviceAccountName: \"default\",\n\t\tautomountServiceAccountToken: false,\n\t\tnodeSelector: options.nodeSelector ?? {},\n\t\ttolerations: options.tolerations ?? [],\n\t\timagePullSecrets: (options.imagePullSecrets ?? []).map((name) => ({ name })),\n\t\tcontainers: [\n\t\t\t{\n\t\t\t\tname: \"prepare\",\n\t\t\t\timage: options.image,\n\t\t\t\timagePullPolicy: options.imagePullPolicy ?? \"IfNotPresent\",\n\t\t\t\tcommand: [\"node\", \"-e\", \"process.exit(0)\"],\n\t\t\t\tresources: {\n\t\t\t\t\trequests: { cpu: \"1m\", memory: \"32Mi\" },\n\t\t\t\t\tlimits: { cpu: \"100m\", memory: \"64Mi\" },\n\t\t\t\t},\n\t\t\t\tsecurityContext: {\n\t\t\t\t\tallowPrivilegeEscalation: false,\n\t\t\t\t\treadOnlyRootFilesystem: true,\n\t\t\t\t\tcapabilities: { drop: [\"ALL\"] },\n\t\t\t\t},\n\t\t\t\t...(volumeMounts ? { volumeMounts } : {}),\n\t\t\t},\n\t\t],\n\t};\n}\n\n/** @internal */\nexport interface PreparationController {\n\t/** @internal */\n\tstart(): void;\n\t/** @internal */\n\tstop(): Promise<void>;\n}\n\n/** One non-overlapping loop; stopping cancels and joins its current work. @internal */\nexport function createPreparationController(\n\treconcile: (signal: AbortSignal) => Promise<void>,\n\tintervalMs: number,\n\tonError?: () => void,\n\terrorIntervalMs = intervalMs,\n): PreparationController {\n\tlet controller: AbortController | undefined;\n\tlet running: Promise<void> | undefined;\n\treturn {\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 = intervalMs;\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 = errorIntervalMs;\n\t\t\t\t\t\tif (!signal.aborted) 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\n/** Controllers own separate asynchronous reconciliation loops. @internal */\nexport function createKubernetesPreparation(controllers: PreparationController[]) {\n\treturn {\n\t\t/** @internal */\n\t\tstart() {\n\t\t\tfor (const controller of controllers) controller.start();\n\t\t},\n\t\t/** @internal */\n\t\tasync stop() {\n\t\t\tawait Promise.allSettled(controllers.map((controller) => controller.stop()));\n\t\t},\n\t};\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 { buildPreparationPodSpec, createPreparationController } from \"./kubernetes-preparation.js\";\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\n/** @internal */\nexport interface VolumePoolOptions {\n\t/** @internal */\n\tapi: VolumePoolApi;\n\t/** @internal */\n\tnamespace: string;\n\t/** @internal */\n\tcount: number;\n\t/** @internal */\n\tstorageClassName: string;\n\t/** @internal */\n\tsize: string;\n\t/** @internal */\n\taccessModes: string[];\n\t/** @internal */\n\timage: string;\n\t/** @internal */\n\timagePullPolicy?: string;\n\t/** @internal */\n\timagePullSecrets?: string[];\n\t/** @internal */\n\tnodeSelector?: Record<string, string>;\n\t/** @internal */\n\ttolerations?: unknown[];\n\t/** @internal */\n\tonError?: () => void;\n}\n\n/** Only the staging claim's UID authorizes rebinding; process claims are never recycled. @internal */\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\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\t...buildPreparationPodSpec(options, [{ name: \"volume\", mountPath: \"/volume\" }]),\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\t/** @internal */\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\t/** @internal */\n\t\tpoolId,\n\t\t/** @internal */\n\t\treconcile,\n\t\t...createPreparationController(reconcile, 2_000, () => options.onError?.(), 30_000),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,kBAAkB;;;ACA3B,SAAS,cAAc,aAAa;AAK7B,SAAS,wBACf,SAIA,cACqB;AACrB,SAAO;AAAA,IACN,eAAe;AAAA,IACf,oBAAoB;AAAA,IACpB,8BAA8B;AAAA,IAC9B,cAAc,QAAQ,gBAAgB,CAAC;AAAA,IACvC,aAAa,QAAQ,eAAe,CAAC;AAAA,IACrC,mBAAmB,QAAQ,oBAAoB,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAAA,IAC3E,YAAY;AAAA,MACX;AAAA,QACC,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,iBAAiB,QAAQ,mBAAmB;AAAA,QAC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M,IAAI,MAAM,uDAAuD;AACxE,mBAAe,6BAA6B;AAAA,MAC3C,KAAK,OAAO;AAAA,MACZ,WAAW,QAAQ;AAAA,MACnB,GAAG,QAAQ;AAAA,MACX,kBAAkB;AAAA,MAClB,cAAc,QAAQ,KAAK;AAAA,MAC3B,yBAAyB,QAAQ,SAC9B,CAAC,EAAE,GAAG,QAAQ,KAAK,cAAc,GAAG,QAAQ,OAAO,aAAa,CAAC,IACjE;AAAA,MACH,aAAa,QAAQ,KAAK;AAAA,IAC3B,CAAC;AAAA,EACF;AACA,QAAM,cAAc,CAAC,YAAY,YAAY,EAAE,OAAO,CAAC,UAAU,UAAU,MAAS;AACpF,QAAM,cAAc,YAAY,SAAS,4BAA4B,WAAW,IAAI;AACpF,SAAO,EAAE,QAAQ,QAAQ,UAAU,YAAY;AAChD;","names":["selector","createHash","createHash","pv","delay"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Readable } from \"node:stream\";\nimport type {\n\tLeitwerkTransferManifestV1,\n\tSessionTransferLimits,\n\tSessionTransferPreflight,\n\tSessionTransferPreflightReport,\n} from \"@leitwerk-dev/session-transfer\";\n\n/**\n * Runner API seams shared by worker run modes (Docker, Kubernetes, best-effort local).\n *\n * The seam is cut so the runtimes share everything except the runtime-specific\n * bodies of two interfaces. The IPC transport is deliberately *not* a runner\n * axis: the runner only injects connect env, the worker dials back over\n * WebSocket, and the existing `WorkerWebSocketIpcManager` binds the socket to\n * the lease. The supervisor stays the lease/lifecycle coordinator; the runner\n * only does runtime-specific work.\n */\n\n/**\n * Durable per-process storage handle.\n *\n * The server NEVER mounts or reads the volume contents. It learns tree and leaf\n * state over the protocol (the session-snapshot exchange), never by reading the\n * volume, which keeps every run mode symmetric.\n */\n/** @internal */\nexport interface VolumeRef {\n\t/** @internal */\n\tinstanceId: string;\n\t/** Runtime-specific identifier (host path, named volume, PVC name). @internal */\n\tid: string;\n\t/** Path inside the worker container where the volume is mounted. @internal */\n\tmountPath: string;\n\t/** Runtime-specific namespace/project for the volume (Kubernetes process namespace). @internal */\n\tnamespace?: string;\n}\n\n/** @internal */\nexport interface ProcessVolumeRequirements {\n\t/** New Kubernetes PVC capacity. Existing volumes are unchanged; other runners ignore it. @internal */\n\tsize?: string;\n\t/** Select storage compatible with a private Docker daemon. @internal */\n\tdocker?: boolean;\n}\n\n/** @internal */\nexport type ProcessStateExportPreflight = SessionTransferPreflight;\n/** @internal */\nexport type ProcessStateExportHelperReport = SessionTransferPreflightReport;\n\n/** Server-owned, credential-scoped relay used by isolated export helpers. @internal */\nexport interface ProcessStateExportHelperRelay {\n\t/** @internal */\n\treadonly exportId: string;\n\t/** @internal */\n\treadonly credential: string;\n\t/** @internal */\n\twaitForPreflight(signal?: AbortSignal): Promise<ProcessStateExportHelperReport>;\n\t/** @internal */\n\tactivateStream(): Readable;\n\t/** @internal */\n\tfail(error: Error): void;\n}\n\n/** @internal */\nexport interface PreparedProcessStateExport {\n\t/** @internal */\n\tmanifest: LeitwerkTransferManifestV1;\n\t/** @internal */\n\tpreflight: ProcessStateExportPreflight;\n\t/** @internal */\n\tstream(input: {\n\t\t/** @internal */\n\t\tsignal?: AbortSignal;\n\t}): Readable;\n}\n\n/** Purpose-specific read-only export seam. It never creates a worker lease. @internal */\nexport interface ProcessStateExporter {\n\t/** @internal */\n\tprepare(input: {\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\tmanifest: LeitwerkTransferManifestV1;\n\t\t/** @internal */\n\t\tlimits: SessionTransferLimits;\n\t\t/** @internal */\n\t\tsignal?: AbortSignal;\n\t}): Promise<PreparedProcessStateExport>;\n\t/** Removes stale runner-specific export helpers after restart. @internal */\n\treconcile(): Promise<void>;\n}\n\n/** @internal */\nexport interface ProcessStateExportHelperRelayProvider {\n\t/** @internal */\n\tcreate(input: {\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\tmanifest: LeitwerkTransferManifestV1;\n\t}): ProcessStateExportHelperRelay;\n}\n\n/** @internal */\nexport interface ProcessVolume {\n\t/** Idempotently provisions durable storage for a process instance. @internal */\n\tensure(\n\t\tinstanceId: string,\n\t\trequirements?: ProcessVolumeRequirements,\n\t\tobserver?: WorkerStartObserver,\n\t): Promise<VolumeRef>;\n\t/** Retention cleanup only. Stopping a worker never calls this. @internal */\n\trelease(instanceId: string): Promise<void>;\n\t/** Permanently deletes every runner-managed resource owned by a deleted process. @internal */\n\tdeleteProcessResources(instanceId: string): Promise<void>;\n}\n\n/**\n * Output of runtime-profile selection. MVP resolves to a single configured\n * worker image; repository branch content must never select an image.\n */\n/** @internal */\nexport interface ResolvedWorkerImage {\n\t/** Fully qualified image reference, ideally digest-pinned. @internal */\n\treference: string;\n}\n\n/** @internal */\nexport interface WorkerResourceLimits {\n\t/** @internal */\n\tcpu?: string;\n\t/** @internal */\n\tmemory?: string;\n}\n\n/** @internal */\nexport interface WorkerUnitRef {\n\t/** @internal */\n\tinstanceId: string;\n\t/** @internal */\n\tworkerId: string;\n\t/** Runtime-specific handle id (container id, pod name). @internal */\n\tunitId: string;\n\t/** Runtime-specific namespace/project for the unit (Kubernetes process namespace). @internal */\n\tnamespace?: string;\n}\n\n/** @internal */\nexport class WorkerStartDiagnosticError extends Error {\n\t/** @internal */\n\treadonly publicDiagnostic: string;\n\n\t/** @internal */\n\tconstructor(publicDiagnostic: string, cause?: unknown) {\n\t\tsuper(\"Worker runtime start failed\", { cause });\n\t\tthis.name = \"WorkerStartDiagnosticError\";\n\t\tthis.publicDiagnostic = publicDiagnostic;\n\t}\n}\n\n/** @internal */\nexport interface WorkerExitInfo {\n\t/** Process exit code when the runtime reports one. @internal */\n\texitCode: number | null;\n\t/** Termination signal when the runtime reports one. @internal */\n\tsignal: string | null;\n\t/** True when the runtime killed the unit for exceeding memory limits. @internal */\n\toomKilled?: boolean;\n\t/** Human-readable reason surfaced by the runtime, if any. @internal */\n\treason?: string;\n}\n\n/** @internal */\nexport interface WorkerUnit extends WorkerUnitRef {\n\t/** Require successful runtime removal before the supervisor permits replacement. @internal */\n\treplacementHandoff?: \"stop-before-replacement\";\n\t/** Maps physical worker exit into the supervisor's existing failure paths. @internal */\n\tonExit(listener: (info: WorkerExitInfo) => void): void;\n}\n\n/** @internal */\nexport interface WorkerUnitDescriptor extends WorkerUnitRef {\n\t/** @internal */\n\tobservedState?: \"running\" | \"pending\" | \"terminal\" | \"unknown\";\n}\n\n/** @internal */\ninterface StartWorkerInputBase {\n\t/** @internal */\n\tinstanceId: string;\n\t/** @internal */\n\tworkerId: string;\n\t/** @internal */\n\tserverEpoch: string;\n\t/** Runtime-profile selection output; MVP = single image. @internal */\n\timage: ResolvedWorkerImage;\n\t/** Server URL, ids, connect token, `PI_CODING_AGENT_DIR`, etc. @internal */\n\tenv: Record<string, string>;\n\t/** Start the image's private Docker daemon before the worker. @internal */\n\tdocker: boolean;\n\t/** @internal */\n\tresources?: WorkerResourceLimits;\n\t/** @internal */\n\tresourceRequests?: WorkerResourceLimits;\n}\n\n/** Start input for the best-effort local runner, which uses configured host storage. @internal */\nexport interface LocalStartWorkerInput extends StartWorkerInputBase {\n\t/** @internal */\n\trunnerKind: \"local\";\n\t/** @internal */\n\tvolume?: never;\n}\n\n/** Start input for isolated runners, whose durable process volume is mandatory. @internal */\nexport interface IsolatedStartWorkerInput extends StartWorkerInputBase {\n\t/** @internal */\n\trunnerKind: \"isolated\";\n\t/** @internal */\n\tvolume: VolumeRef;\n}\n\n/** @internal */\nexport type StartWorkerInput = LocalStartWorkerInput | IsolatedStartWorkerInput;\n\n/** @internal */\nexport interface StopWorkerOptions {\n\t/** Grace period before forceful termination. The volume is always kept. @internal */\n\tgraceMs: number;\n}\n\n/** @internal */\nexport type WorkerStartPhase = \"preparing_runtime\" | \"allocating_runtime\" | \"starting_runtime\";\n\n/** @internal */\nexport interface WorkerStartObserver {\n\t/** @internal */\n\tobserve?(\n\t\tobservation: Omit<\n\t\t\timport(\"@leitwerk-dev/domain\").StartupObservation,\n\t\t\t\"workerLeaseId\" | \"turnRecordId\"\n\t\t>,\n\t): void;\n\t/** @internal */\n\tshouldStop?(): boolean;\n\t/** @internal */\n\treport(phase: WorkerStartPhase): void;\n}\n\n/** @internal */\nexport interface WorkerRunner<TStartInput extends StartWorkerInput = StartWorkerInput> {\n\t/** @internal */\n\tstart(input: TStartInput, observer?: WorkerStartObserver): Promise<WorkerUnit>;\n\t/** Stops the unit but keeps the process volume for resume. @internal */\n\tstop(ref: WorkerUnitRef, opts: StopWorkerOptions): Promise<void>;\n\t/** Adoption scan: lists labelled worker units. @internal */\n\tlist(): Promise<WorkerUnitDescriptor[]>;\n\t/** Reconnects to a live unit discovered by {@link WorkerRunner.list}. @internal */\n\tadopt(descriptor: WorkerUnitDescriptor, observer?: WorkerStartObserver): Promise<WorkerUnit>;\n}\n"],"mappings":";AAuJO,IAAM,6BAAN,cAAyC,MAAM;AAAA;AAAA,EAE5C;AAAA;AAAA,EAGT,YAAY,kBAA0B,OAAiB;AACtD,UAAM,+BAA+B,EAAE,MAAM,CAAC;AAC9C,SAAK,OAAO;AACZ,SAAK,mBAAmB;AAAA,EACzB;AACD;","names":[]}