hammerkit 2.1.0-next.3 → 2.1.0-next.4
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.
|
@@ -88,7 +88,8 @@ function isInitOf(item, service) {
|
|
|
88
88
|
// Everything that makes a service what a task needing it talks to: its definition, the ids of
|
|
89
89
|
// the tasks it depends on and of its init task, and the services it needs in turn. The source
|
|
90
90
|
// of those tasks and of the service is in the state key (computeStateKey), like a dependency's.
|
|
91
|
-
// Not the service id, which leaves out what a service runs
|
|
91
|
+
// Not the service id, which leaves out what a service runs, and without its name: to a task,
|
|
92
|
+
// a renamed service is the same (getUnnamedWorkServiceId).
|
|
92
93
|
function getWorkServiceCacheIdentity(item, visiting = new Set()) {
|
|
93
94
|
const service = item.data;
|
|
94
95
|
const definition = (0, work_service_1.isContainerWorkService)(service)
|
|
@@ -110,7 +111,7 @@ function getWorkServiceCacheIdentity(item, visiting = new Set()) {
|
|
|
110
111
|
: { namespace: service.namespace };
|
|
111
112
|
return (0, crypto_1.createHash)('sha256')
|
|
112
113
|
.update(JSON.stringify({
|
|
113
|
-
id: (0, work_service_id_1.
|
|
114
|
+
id: (0, work_service_id_1.getUnnamedWorkServiceId)(service),
|
|
114
115
|
...definition,
|
|
115
116
|
ports: service.ports.map((port) => `${port.hostPort ?? ''}:${port.containerPort}`).sort(),
|
|
116
117
|
deps: item.deps.map((dep) => dep.id()).sort(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dockerServiceRuntime = exports.getCacheHelperOptions = exports.dockerTaskRuntime = void 0;
|
|
3
|
+
exports.removeLegacyService = exports.dockerServiceRuntime = exports.getCacheHelperOptions = exports.dockerTaskRuntime = void 0;
|
|
4
4
|
const run_labels_1 = require("../docker/run-labels");
|
|
5
5
|
const execute_docker_1 = require("../executer/execute-docker");
|
|
6
6
|
const remove_container_1 = require("../docker/remove-container");
|
|
@@ -14,6 +14,7 @@ const path_1 = require("path");
|
|
|
14
14
|
const tar_1 = require("../utils/tar");
|
|
15
15
|
const plan_work_volume_1 = require("./utils/plan-work-volume");
|
|
16
16
|
const work_instance_id_1 = require("./work-instance-id");
|
|
17
|
+
const work_service_id_1 = require("./work-service-id");
|
|
17
18
|
const stream_1 = require("stream");
|
|
18
19
|
const service_definition_1 = require("./service-definition");
|
|
19
20
|
const image_build_1 = require("./image-build");
|
|
@@ -204,6 +205,7 @@ function dockerServiceRuntime(service, workEnvironment) {
|
|
|
204
205
|
const docker = (0, execute_docker_1.getContainerCli)(workEnvironment);
|
|
205
206
|
return {
|
|
206
207
|
async initialize(state) {
|
|
208
|
+
await removeLegacyService(docker, service);
|
|
207
209
|
const currentServices = await docker.listContainers({
|
|
208
210
|
filters: {
|
|
209
211
|
label: [`hammerkit-id=${(0, work_instance_id_1.getWorkInstanceId)(service)}`],
|
|
@@ -292,6 +294,27 @@ function dockerServiceRuntime(service, workEnvironment) {
|
|
|
292
294
|
};
|
|
293
295
|
}
|
|
294
296
|
exports.dockerServiceRuntime = dockerServiceRuntime;
|
|
297
|
+
// A service an earlier version started, labeled with the id it had then: it goes with its
|
|
298
|
+
// network and secrets, and is recreated under its own id (getLegacyServiceItem).
|
|
299
|
+
async function removeLegacyService(docker, service) {
|
|
300
|
+
const legacy = (0, work_service_id_1.getLegacyServiceItem)(service);
|
|
301
|
+
const containers = await docker.listContainers({
|
|
302
|
+
all: true,
|
|
303
|
+
filters: {
|
|
304
|
+
label: [`hammerkit-id=${(0, work_instance_id_1.getWorkInstanceId)(legacy)}`, 'hammerkit-type=service'],
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
if (containers.length === 0) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
service.status.write('info', `${service.name} was started by an earlier version of hammerkit, recreating it`);
|
|
311
|
+
for (const container of containers) {
|
|
312
|
+
await (0, remove_container_1.removeContainer)(docker.getContainer(container.Id));
|
|
313
|
+
}
|
|
314
|
+
await (0, item_network_1.removeItemNetworks)(docker, legacy);
|
|
315
|
+
await (0, container_secrets_1.removeContainerSecrets)((0, work_instance_id_1.getWorkInstanceId)(legacy));
|
|
316
|
+
}
|
|
317
|
+
exports.removeLegacyService = removeLegacyService;
|
|
295
318
|
async function archiveContainer(docker, environment, item, path) {
|
|
296
319
|
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
297
320
|
await (0, using_container_1.usingContainer)(docker, item, getCacheHelperOptions(item, environment), async (container) => {
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.kubernetesForwardRuntime = exports.isRolledOut = exports.kubernetesServiceRuntime = exports.kubernetesTaskRuntime = exports.getTaskJobContainers = exports.describeFailedJob = exports.recordJobExecution = void 0;
|
|
6
|
+
exports.kubernetesForwardRuntime = exports.isRolledOut = exports.kubernetesServiceRuntime = exports.removeLegacyKubernetesService = exports.kubernetesTaskRuntime = exports.getTaskJobContainers = exports.describeFailedJob = exports.recordJobExecution = void 0;
|
|
7
7
|
const abort_1 = require("../executer/abort");
|
|
8
8
|
const kubernetes_service_1 = require("../executer/kubernetes-service");
|
|
9
9
|
const kubernetes_instance_1 = require("../kubernetes/kubernetes-instance");
|
|
@@ -14,6 +14,7 @@ const ensure_kubernetes_deployment_exists_1 = require("../kubernetes/ensure-kube
|
|
|
14
14
|
const follow_pod_logs_1 = require("../kubernetes/follow-pod-logs");
|
|
15
15
|
const work_item_executions_1 = require("./work-item-executions");
|
|
16
16
|
const service_definition_1 = require("./service-definition");
|
|
17
|
+
const work_service_id_1 = require("./work-service-id");
|
|
17
18
|
const ensure_namespace_1 = require("../kubernetes/ensure-namespace");
|
|
18
19
|
const ensure_persistent_data_1 = require("../kubernetes/ensure-persistent-data");
|
|
19
20
|
const network_gate_1 = require("../kubernetes/network-gate");
|
|
@@ -530,6 +531,35 @@ function kubernetesTaskRuntime(task, kubernetes) {
|
|
|
530
531
|
};
|
|
531
532
|
}
|
|
532
533
|
exports.kubernetesTaskRuntime = kubernetesTaskRuntime;
|
|
534
|
+
async function stopKubernetesService(instance, kubernetes, service) {
|
|
535
|
+
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
536
|
+
namespace: kubernetes.namespace,
|
|
537
|
+
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
538
|
+
});
|
|
539
|
+
for (const deployment of deployments.items) {
|
|
540
|
+
if (deployment.metadata?.name) {
|
|
541
|
+
await instance.appsApi.deleteNamespacedDeployment({
|
|
542
|
+
name: deployment.metadata.name,
|
|
543
|
+
namespace: kubernetes.namespace,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
await (0, secrets_1.removeKubernetesSecret)(instance, kubernetes, service);
|
|
548
|
+
// the limits go last, once the service's pods ended
|
|
549
|
+
await (0, network_policy_1.removeAllKubernetesItemNetworks)(instance, kubernetes, service);
|
|
550
|
+
}
|
|
551
|
+
async function removeLegacyKubernetesService(instance, kubernetes, service) {
|
|
552
|
+
const legacy = (0, work_service_id_1.getLegacyServiceItem)(service);
|
|
553
|
+
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
554
|
+
namespace: kubernetes.namespace,
|
|
555
|
+
labelSelector: (0, resources_1.getItemSelector)(legacy, kubernetes),
|
|
556
|
+
});
|
|
557
|
+
if (deployments.items.length > 0) {
|
|
558
|
+
service.status.write('info', `${service.name} was started by an earlier version of hammerkit, recreating it`);
|
|
559
|
+
await stopKubernetesService(instance, kubernetes, legacy);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
exports.removeLegacyKubernetesService = removeLegacyKubernetesService;
|
|
533
563
|
function kubernetesServiceRuntime(service, kubernetes) {
|
|
534
564
|
const instance = (0, kubernetes_instance_1.createKubernetesInstances)(kubernetes);
|
|
535
565
|
return {
|
|
@@ -541,6 +571,11 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
541
571
|
// a service run starts every service: one that did not change stays as it is (execute)
|
|
542
572
|
return;
|
|
543
573
|
}
|
|
574
|
+
// one an earlier version started, under the id it had then (getLegacyServiceItem); on a
|
|
575
|
+
// server a run finds only objects of its own
|
|
576
|
+
if (!kubernetes.server) {
|
|
577
|
+
await removeLegacyKubernetesService(instance, kubernetes, service);
|
|
578
|
+
}
|
|
544
579
|
const deployments = await instance.appsApi.listNamespacedDeployment({
|
|
545
580
|
namespace: kubernetes.namespace,
|
|
546
581
|
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
@@ -568,21 +603,7 @@ function kubernetesServiceRuntime(service, kubernetes) {
|
|
|
568
603
|
await (0, store_kubernetes_data_1.storeKubernetesData)(service, kubernetes, instance, environment, path);
|
|
569
604
|
},
|
|
570
605
|
async stop() {
|
|
571
|
-
|
|
572
|
-
namespace: kubernetes.namespace,
|
|
573
|
-
labelSelector: (0, resources_1.getItemSelector)(service, kubernetes),
|
|
574
|
-
});
|
|
575
|
-
for (const deployment of deployments.items) {
|
|
576
|
-
if (deployment.metadata?.name) {
|
|
577
|
-
await instance.appsApi.deleteNamespacedDeployment({
|
|
578
|
-
name: deployment.metadata.name,
|
|
579
|
-
namespace: kubernetes.namespace,
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
await (0, secrets_1.removeKubernetesSecret)(instance, kubernetes, service);
|
|
584
|
-
// the limits go last, once the service's pods ended
|
|
585
|
-
await (0, network_policy_1.removeAllKubernetesItemNetworks)(instance, kubernetes, service);
|
|
606
|
+
await stopKubernetesService(instance, kubernetes, service);
|
|
586
607
|
},
|
|
587
608
|
async execute(environment, options) {
|
|
588
609
|
const name = (0, resources_1.getResourceName)(service, kubernetes);
|
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWorkServiceId = void 0;
|
|
3
|
+
exports.getLegacyServiceItem = exports.getUnnamedWorkServiceId = exports.getWorkServiceId = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const work_service_1 = require("./work-service");
|
|
6
6
|
const portable_path_1 = require("./utils/portable-path");
|
|
7
7
|
const plan_work_volume_1 = require("./utils/plan-work-volume");
|
|
8
|
+
// The id of a service: its name in the work tree and what it runs from. Two services of
|
|
9
|
+
// one build file may run the same image from the same directory and differ only in their
|
|
10
|
+
// command, envs or network (an app's api and its worker); the name gives each its own
|
|
11
|
+
// container, Deployment, claim and NetworkPolicy. What the service runs is left out, so
|
|
12
|
+
// a service whose command changed is found again and recreated (getServiceDefinitionHash).
|
|
13
|
+
function getWorkServiceId(service) {
|
|
14
|
+
return hashServiceId({ name: service.name, ...getServiceShape(service) });
|
|
15
|
+
}
|
|
16
|
+
exports.getWorkServiceId = getWorkServiceId;
|
|
17
|
+
// The id without the name, which is all the id was up to 2.0. A task that needs the service
|
|
18
|
+
// caches by it (getWorkServiceCacheIdentity): to the task, a renamed service is the same.
|
|
19
|
+
// A container or Deployment an earlier version started carries it (getLegacyServiceItem).
|
|
20
|
+
function getUnnamedWorkServiceId(service) {
|
|
21
|
+
return hashServiceId(getServiceShape(service));
|
|
22
|
+
}
|
|
23
|
+
exports.getUnnamedWorkServiceId = getUnnamedWorkServiceId;
|
|
24
|
+
// The service under the id an earlier version labeled what it started with. A container or
|
|
25
|
+
// Deployment of it goes once, and the service starts anew under its own id, instead of
|
|
26
|
+
// beside the old one on the same host ports, where neither `up` nor `down` would find it.
|
|
27
|
+
function getLegacyServiceItem(item) {
|
|
28
|
+
return { ...item, id: () => getUnnamedWorkServiceId(item.data) };
|
|
29
|
+
}
|
|
30
|
+
exports.getLegacyServiceItem = getLegacyServiceItem;
|
|
31
|
+
function hashServiceId(shape) {
|
|
32
|
+
return (0, crypto_1.createHash)('sha1').update(JSON.stringify(shape)).digest('hex');
|
|
33
|
+
}
|
|
8
34
|
// Paths are made project-relative (portablePath) so a service id is identical
|
|
9
35
|
// wherever the project is checked out, like a task id.
|
|
10
|
-
function
|
|
36
|
+
function getServiceShape(service) {
|
|
11
37
|
const portable = (path) => (0, portable_path_1.portablePath)(service.projectRoot, path);
|
|
12
|
-
|
|
38
|
+
return (0, work_service_1.isContainerWorkService)(service)
|
|
13
39
|
? {
|
|
14
40
|
cwd: portable(service.cwd),
|
|
15
41
|
image: service.image,
|
|
@@ -31,8 +57,6 @@ function getWorkServiceId(service) {
|
|
|
31
57
|
context: service.context,
|
|
32
58
|
selector: service.selector,
|
|
33
59
|
kubeconfig: portable(service.kubeconfig),
|
|
34
|
-
}
|
|
35
|
-
return (0, crypto_1.createHash)('sha1').update(jsonData).digest('hex');
|
|
60
|
+
};
|
|
36
61
|
}
|
|
37
|
-
exports.getWorkServiceId = getWorkServiceId;
|
|
38
62
|
//# sourceMappingURL=work-service-id.js.map
|
package/package.json
CHANGED