@leitwerk-dev/worker-runners 0.1.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/LICENSE +13 -0
- package/dist/chunk-2TSWMVLZ.js +220 -0
- package/dist/chunk-2TSWMVLZ.js.map +1 -0
- package/dist/chunk-6WACBFXN.js +78 -0
- package/dist/chunk-6WACBFXN.js.map +1 -0
- package/dist/chunk-CCV2UXAM.js +187 -0
- package/dist/chunk-CCV2UXAM.js.map +1 -0
- package/dist/chunk-DL3Y3R6E.js +107 -0
- package/dist/chunk-DL3Y3R6E.js.map +1 -0
- package/dist/chunk-HLTGLGUS.js +223 -0
- package/dist/chunk-HLTGLGUS.js.map +1 -0
- package/dist/chunk-IRFVGUXJ.js +31 -0
- package/dist/chunk-IRFVGUXJ.js.map +1 -0
- package/dist/chunk-PM7IYWFL.js +394 -0
- package/dist/chunk-PM7IYWFL.js.map +1 -0
- package/dist/docker-engine-client-Cpmy2yma.d.ts +87 -0
- package/dist/docker-engine-client.d.ts +86 -0
- package/dist/docker-engine-client.d.ts.map +1 -0
- package/dist/docker-engine-client.js +10 -0
- package/dist/docker-engine-client.js.map +1 -0
- package/dist/docker-engine-http-client.d.ts +26 -0
- package/dist/docker-engine-http-client.d.ts.map +1 -0
- package/dist/docker-engine-http-client.js +202 -0
- package/dist/docker-engine-http-client.js.map +1 -0
- package/dist/docker-worker-runner.d.ts +35 -0
- package/dist/docker-worker-runner.d.ts.map +1 -0
- package/dist/docker-worker-runner.js +236 -0
- package/dist/docker-worker-runner.js.map +1 -0
- package/dist/fake-docker-engine-client.d.ts +40 -0
- package/dist/fake-docker-engine-client.d.ts.map +1 -0
- package/dist/fake-docker-engine-client.js +131 -0
- package/dist/fake-docker-engine-client.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/kubernetes-api-client-DF77hbtl.d.ts +278 -0
- package/dist/kubernetes-api-client.d.ts +71 -0
- package/dist/kubernetes-api-client.d.ts.map +1 -0
- package/dist/kubernetes-api-client.js +142 -0
- package/dist/kubernetes-api-client.js.map +1 -0
- package/dist/kubernetes-http-client.d.ts +15 -0
- package/dist/kubernetes-http-client.d.ts.map +1 -0
- package/dist/kubernetes-http-client.js +296 -0
- package/dist/kubernetes-http-client.js.map +1 -0
- package/dist/kubernetes-manifests.d.ts +232 -0
- package/dist/kubernetes-manifests.d.ts.map +1 -0
- package/dist/kubernetes-manifests.js +370 -0
- package/dist/kubernetes-manifests.js.map +1 -0
- package/dist/kubernetes-worker-runner.d.ts +24 -0
- package/dist/kubernetes-worker-runner.d.ts.map +1 -0
- package/dist/kubernetes-worker-runner.js +162 -0
- package/dist/kubernetes-worker-runner.js.map +1 -0
- package/dist/local-worker-runner.d.ts +26 -0
- package/dist/local-worker-runner.d.ts.map +1 -0
- package/dist/local-worker-runner.js +109 -0
- package/dist/local-worker-runner.js.map +1 -0
- package/dist/process-volume-retention.d.ts +21 -0
- package/dist/process-volume-retention.d.ts.map +1 -0
- package/dist/process-volume-retention.js +46 -0
- package/dist/process-volume-retention.js.map +1 -0
- package/dist/runner-utils.d.ts +16 -0
- package/dist/runner-utils.d.ts.map +1 -0
- package/dist/runner-utils.js +36 -0
- package/dist/runner-utils.js.map +1 -0
- package/dist/types.d.ts +121 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/worker-labels.d.ts +50 -0
- package/dist/worker-labels.d.ts.map +1 -0
- package/dist/worker-labels.js +83 -0
- package/dist/worker-labels.js.map +1 -0
- package/package.json +71 -0
- package/src/docker-engine-client.ts +86 -0
- package/src/docker-engine-http-client.ts +275 -0
- package/src/docker-worker-runner.ts +296 -0
- package/src/fake-docker-engine-client.ts +182 -0
- package/src/index.ts +102 -0
- package/src/kubernetes-api-client.ts +231 -0
- package/src/kubernetes-http-client.ts +402 -0
- package/src/kubernetes-manifests.ts +609 -0
- package/src/kubernetes-worker-runner.ts +228 -0
- package/src/local-worker-runner.ts +145 -0
- package/src/process-volume-retention.ts +72 -0
- package/src/runner-utils.ts +37 -0
- package/src/types.ts +130 -0
- package/src/worker-labels.ts +112 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared labelling for worker units across runner modes.
|
|
3
|
+
*
|
|
4
|
+
* Labels are how the server reconciles which workers exist after a restart:
|
|
5
|
+
* there is no pid registry, the container/pod runtime is the source of truth.
|
|
6
|
+
* Both the Docker and Kubernetes runners stamp these labels at start and read
|
|
7
|
+
* them back during the adoption scan, so the keys and parse rules live here
|
|
8
|
+
* rather than in a runtime-specific body.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const WORKER_LABEL_MANAGED_BY = "leitwerk.dev/managed-by";
|
|
12
|
+
export const WORKER_LABEL_COMPONENT = "leitwerk.dev/component";
|
|
13
|
+
export const WORKER_LABEL_INSTANCE_ID = "leitwerk.dev/instance-id";
|
|
14
|
+
export const WORKER_LABEL_WORKER_ID = "leitwerk.dev/worker-id";
|
|
15
|
+
export const WORKER_LABEL_SERVER_EPOCH = "leitwerk.dev/server-epoch";
|
|
16
|
+
|
|
17
|
+
export const WORKER_LABEL_MANAGED_BY_VALUE = "leitwerk";
|
|
18
|
+
export const WORKER_LABEL_COMPONENT_VALUE = "worker";
|
|
19
|
+
export const PROCESS_NAMESPACE_COMPONENT_VALUE = "process-namespace";
|
|
20
|
+
export const PROCESS_VOLUME_COMPONENT_VALUE = "process-volume";
|
|
21
|
+
export const PROCESS_SERVER_CA_COMPONENT_VALUE = "server-ca";
|
|
22
|
+
export const PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE = "image-pull-secret";
|
|
23
|
+
|
|
24
|
+
export interface WorkerUnitIdentity {
|
|
25
|
+
instanceId: string;
|
|
26
|
+
workerId: string;
|
|
27
|
+
serverEpoch: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Builds the canonical label set for a worker unit. Extra labels are merged in
|
|
32
|
+
* but can never override the managed identity keys.
|
|
33
|
+
*/
|
|
34
|
+
export function buildWorkerUnitLabels(
|
|
35
|
+
identity: WorkerUnitIdentity,
|
|
36
|
+
extra: Record<string, string> = {},
|
|
37
|
+
): Record<string, string> {
|
|
38
|
+
return {
|
|
39
|
+
...extra,
|
|
40
|
+
[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,
|
|
41
|
+
[WORKER_LABEL_COMPONENT]: WORKER_LABEL_COMPONENT_VALUE,
|
|
42
|
+
[WORKER_LABEL_INSTANCE_ID]: identity.instanceId,
|
|
43
|
+
[WORKER_LABEL_WORKER_ID]: identity.workerId,
|
|
44
|
+
[WORKER_LABEL_SERVER_EPOCH]: identity.serverEpoch,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Builds labels for durable process-scoped resources (namespace/PVC). These
|
|
50
|
+
* intentionally omit worker-id and server-epoch because the resources outlive a
|
|
51
|
+
* specific worker lease and are not adoption targets.
|
|
52
|
+
*/
|
|
53
|
+
export function buildProcessResourceLabels(
|
|
54
|
+
args: {
|
|
55
|
+
instanceId: string;
|
|
56
|
+
component:
|
|
57
|
+
| typeof PROCESS_NAMESPACE_COMPONENT_VALUE
|
|
58
|
+
| typeof PROCESS_VOLUME_COMPONENT_VALUE
|
|
59
|
+
| typeof PROCESS_SERVER_CA_COMPONENT_VALUE
|
|
60
|
+
| typeof PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE;
|
|
61
|
+
},
|
|
62
|
+
extra: Record<string, string> = {},
|
|
63
|
+
): Record<string, string> {
|
|
64
|
+
return {
|
|
65
|
+
...extra,
|
|
66
|
+
[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,
|
|
67
|
+
[WORKER_LABEL_COMPONENT]: args.component,
|
|
68
|
+
[WORKER_LABEL_INSTANCE_ID]: args.instanceId,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Selector for the two managed-by/component keys shared by every managed resource. */
|
|
73
|
+
function managedResourceLabelSelector(component: string): Record<string, string> {
|
|
74
|
+
return {
|
|
75
|
+
[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,
|
|
76
|
+
[WORKER_LABEL_COMPONENT]: component,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function managedProcessNamespaceLabelSelector(): Record<string, string> {
|
|
81
|
+
return managedResourceLabelSelector(PROCESS_NAMESPACE_COMPONENT_VALUE);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** True when the labels identify an leitwerk-managed worker unit. */
|
|
85
|
+
export function isManagedWorkerUnitLabels(labels: Record<string, string>): boolean {
|
|
86
|
+
return (
|
|
87
|
+
labels[WORKER_LABEL_MANAGED_BY] === WORKER_LABEL_MANAGED_BY_VALUE &&
|
|
88
|
+
labels[WORKER_LABEL_COMPONENT] === WORKER_LABEL_COMPONENT_VALUE
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Recovers the worker identity from a unit's labels, or `null` when the labels
|
|
94
|
+
* do not describe a complete leitwerk-managed worker.
|
|
95
|
+
*/
|
|
96
|
+
export function parseWorkerUnitIdentity(labels: Record<string, string>): WorkerUnitIdentity | null {
|
|
97
|
+
if (!isManagedWorkerUnitLabels(labels)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const instanceId = labels[WORKER_LABEL_INSTANCE_ID];
|
|
101
|
+
const workerId = labels[WORKER_LABEL_WORKER_ID];
|
|
102
|
+
const serverEpoch = labels[WORKER_LABEL_SERVER_EPOCH];
|
|
103
|
+
if (!instanceId || !workerId || !serverEpoch) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return { instanceId, workerId, serverEpoch };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Label selector for listing managed worker units in a runtime query. */
|
|
110
|
+
export function managedWorkerLabelSelector(): Record<string, string> {
|
|
111
|
+
return managedResourceLabelSelector(WORKER_LABEL_COMPONENT_VALUE);
|
|
112
|
+
}
|