@kapeta/local-cluster-service 0.38.0 → 0.39.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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/src/config/routes.js +2 -2
- package/dist/cjs/src/containerManager.js +5 -3
- package/dist/cjs/src/instanceManager.d.ts +4 -2
- package/dist/cjs/src/instanceManager.js +60 -28
- package/dist/cjs/src/operatorManager.d.ts +4 -2
- package/dist/cjs/src/operatorManager.js +32 -23
- package/dist/cjs/src/serviceManager.d.ts +0 -1
- package/dist/cjs/src/serviceManager.js +2 -8
- package/dist/cjs/src/types.d.ts +1 -29
- package/dist/cjs/src/types.js +2 -1
- package/dist/cjs/src/utils/BlockInstanceRunner.js +30 -30
- package/dist/cjs/src/utils/InternalConfigProvider.d.ts +38 -0
- package/dist/cjs/src/utils/InternalConfigProvider.js +146 -0
- package/dist/cjs/src/utils/utils.d.ts +25 -3
- package/dist/cjs/src/utils/utils.js +46 -7
- package/dist/esm/index.js +4 -1
- package/dist/esm/src/config/routes.js +2 -2
- package/dist/esm/src/containerManager.js +5 -3
- package/dist/esm/src/instanceManager.d.ts +4 -2
- package/dist/esm/src/instanceManager.js +60 -28
- package/dist/esm/src/operatorManager.d.ts +4 -2
- package/dist/esm/src/operatorManager.js +32 -23
- package/dist/esm/src/serviceManager.d.ts +0 -1
- package/dist/esm/src/serviceManager.js +2 -8
- package/dist/esm/src/types.d.ts +1 -29
- package/dist/esm/src/types.js +2 -1
- package/dist/esm/src/utils/BlockInstanceRunner.js +30 -30
- package/dist/esm/src/utils/InternalConfigProvider.d.ts +38 -0
- package/dist/esm/src/utils/InternalConfigProvider.js +146 -0
- package/dist/esm/src/utils/utils.d.ts +25 -3
- package/dist/esm/src/utils/utils.js +46 -7
- package/index.ts +5 -2
- package/package.json +6 -6
- package/src/config/routes.ts +4 -2
- package/src/containerManager.ts +6 -4
- package/src/instanceManager.ts +74 -38
- package/src/operatorManager.ts +46 -37
- package/src/serviceManager.ts +3 -11
- package/src/types.ts +2 -31
- package/src/utils/BlockInstanceRunner.ts +48 -38
- package/src/utils/InternalConfigProvider.ts +214 -0
- package/src/utils/utils.ts +51 -8
package/index.ts
CHANGED
@@ -24,7 +24,7 @@ import AttachmentRoutes from './src/attachments/routes';
|
|
24
24
|
import TaskRoutes from './src/tasks/routes';
|
25
25
|
import APIRoutes from './src/api';
|
26
26
|
import AIRoutes from './src/ai/routes';
|
27
|
-
import {
|
27
|
+
import { isLinux } from './src/utils/utils';
|
28
28
|
import request from 'request';
|
29
29
|
import { repositoryManager } from './src/repositoryManager';
|
30
30
|
import { taskManager } from './src/taskManager';
|
@@ -223,7 +223,10 @@ export default {
|
|
223
223
|
reject(err);
|
224
224
|
});
|
225
225
|
|
226
|
-
|
226
|
+
// On Linux we need to bind to 0.0.0.0 to be able to connect to it from docker containers.
|
227
|
+
// TODO: This might pose a security risk - so we should authenticate all requests using a
|
228
|
+
// shared secret/nonce that we pass around.
|
229
|
+
const bindHost = isLinux() ? '0.0.0.0' : host;
|
227
230
|
|
228
231
|
currentServer.listen(port, bindHost, async () => {
|
229
232
|
try {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kapeta/local-cluster-service",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.39.1",
|
4
4
|
"description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
|
5
5
|
"type": "commonjs",
|
6
6
|
"exports": {
|
@@ -53,12 +53,11 @@
|
|
53
53
|
"@kapeta/local-cluster-config": "^0.4.0",
|
54
54
|
"@kapeta/nodejs-api-client": ">=0.2.0 <2",
|
55
55
|
"@kapeta/nodejs-process": "^1.2.0",
|
56
|
-
"@kapeta/nodejs-registry-utils": ">=0.
|
56
|
+
"@kapeta/nodejs-registry-utils": ">=0.11.1 <2",
|
57
57
|
"@kapeta/nodejs-utils": "<2",
|
58
|
-
"@kapeta/schemas": "^3.
|
59
|
-
"@kapeta/sdk-config": "^2.1.
|
58
|
+
"@kapeta/schemas": "^3.5.0",
|
59
|
+
"@kapeta/sdk-config": "^2.1.1",
|
60
60
|
"@kapeta/ui-web-components": "^3.1.0",
|
61
|
-
"@kapeta/ui-web-plan-editor": "^2.3.1",
|
62
61
|
"@kapeta/ui-web-types": "^1.3.1",
|
63
62
|
"@kapeta/web-microfrontend": "^1.2.5",
|
64
63
|
"@sentry/node": "^7.94.1",
|
@@ -83,7 +82,8 @@
|
|
83
82
|
"stream-json": "^1.8.0",
|
84
83
|
"tar-stream": "^3.1.6",
|
85
84
|
"typescript": "^5.1.6",
|
86
|
-
"yaml": "^1.6.0"
|
85
|
+
"yaml": "^1.6.0",
|
86
|
+
"@kapeta/config-mapper": "^1.1.1"
|
87
87
|
},
|
88
88
|
"devDependencies": {
|
89
89
|
"@kapeta/eslint-config": "^0.7.0",
|
package/src/config/routes.ts
CHANGED
@@ -157,7 +157,8 @@ router.get('/consumes/resource/:resourceType/:portType/:name', async (req: Kapet
|
|
157
157
|
req.params.resourceType,
|
158
158
|
req.params.portType,
|
159
159
|
req.params.name,
|
160
|
-
req.kapeta!.environment
|
160
|
+
req.kapeta!.environment,
|
161
|
+
req.query.ensure !== 'false'
|
161
162
|
);
|
162
163
|
|
163
164
|
res.send(operatorInfo);
|
@@ -190,7 +191,8 @@ router.get('/operator/:instanceId', async (req: KapetaRequest, res) => {
|
|
190
191
|
const operatorInfo = await instanceManager.getInstanceOperator(
|
191
192
|
req.kapeta!.systemId,
|
192
193
|
req.params.instanceId,
|
193
|
-
req.kapeta!.environment
|
194
|
+
req.kapeta!.environment,
|
195
|
+
req.query.ensure !== 'false'
|
194
196
|
);
|
195
197
|
|
196
198
|
res.send(operatorInfo);
|
package/src/containerManager.ts
CHANGED
@@ -14,7 +14,7 @@ import ClusterConfiguration from '@kapeta/local-cluster-config';
|
|
14
14
|
import uuid from 'node-uuid';
|
15
15
|
import md5 from 'md5';
|
16
16
|
import { getBlockInstanceContainerName } from './utils/utils';
|
17
|
-
import { InstanceInfo, LogEntry, LogSource } from './types';
|
17
|
+
import { DOCKER_HOST_INTERNAL, InstanceInfo, LogEntry, LogSource } from './types';
|
18
18
|
import { KapetaAPI } from '@kapeta/nodejs-api-client';
|
19
19
|
import { taskManager, Task } from './taskManager';
|
20
20
|
import { EventEmitter } from 'node:events';
|
@@ -665,7 +665,9 @@ class ContainerManager {
|
|
665
665
|
const newName = 'deleting-' + uuid.v4();
|
666
666
|
// Rename the container first to avoid name conflicts if people start the same container
|
667
667
|
await container.rename({ name: newName });
|
668
|
-
|
668
|
+
|
669
|
+
const newContainer = this.docker().getContainer(newName);
|
670
|
+
await newContainer.remove({ force: !!opts?.force });
|
669
671
|
}
|
670
672
|
|
671
673
|
/**
|
@@ -1144,11 +1146,11 @@ export function getExtraHosts(dockerVersion: string): string[] | undefined {
|
|
1144
1146
|
const [major, minor] = dockerVersion.split('.');
|
1145
1147
|
if (parseInt(major) >= 20 && parseInt(minor) >= 10) {
|
1146
1148
|
// Docker 20.10+ on Linux supports adding host.docker.internal to point to host-gateway
|
1147
|
-
return [
|
1149
|
+
return [`${DOCKER_HOST_INTERNAL}:host-gateway`];
|
1148
1150
|
}
|
1149
1151
|
// Docker versions lower than 20.10 needs an actual IP address. We use the default network bridge which
|
1150
1152
|
// is always 172.17.0.1
|
1151
|
-
return [
|
1153
|
+
return [`${DOCKER_HOST_INTERNAL}:172.17.0.1`];
|
1152
1154
|
}
|
1153
1155
|
|
1154
1156
|
return undefined;
|
package/src/instanceManager.ts
CHANGED
@@ -29,15 +29,19 @@ import {
|
|
29
29
|
KIND_BLOCK_TYPE_OPERATOR,
|
30
30
|
KIND_RESOURCE_OPERATOR,
|
31
31
|
LogEntry,
|
32
|
-
OperatorInstanceInfo,
|
33
|
-
OperatorInstancePort,
|
34
32
|
} from './types';
|
35
33
|
import { BlockDefinitionSpec, LocalInstance, Plan } from '@kapeta/schemas';
|
36
|
-
import {
|
34
|
+
import {
|
35
|
+
getBlockInstanceContainerName,
|
36
|
+
getOperatorInstancePorts,
|
37
|
+
getRemoteHostForEnvironment,
|
38
|
+
getResolvedConfiguration,
|
39
|
+
} from './utils/utils';
|
37
40
|
import { operatorManager } from './operatorManager';
|
38
41
|
import { normalizeKapetaUri, parseKapetaUri } from '@kapeta/nodejs-utils';
|
39
42
|
import { definitionsManager } from './definitionsManager';
|
40
43
|
import { Task, taskManager } from './taskManager';
|
44
|
+
import { InstanceOperator, InstanceOperatorPort } from '@kapeta/sdk-config';
|
41
45
|
|
42
46
|
const CHECK_INTERVAL = 5000;
|
43
47
|
const DEFAULT_HEALTH_PORT_TYPE = 'http';
|
@@ -117,6 +121,10 @@ export class InstanceManager {
|
|
117
121
|
return result;
|
118
122
|
}
|
119
123
|
|
124
|
+
private isLocked(systemId: string, instanceId: string) {
|
125
|
+
return this.instanceLocks.isBusy(`${systemId}/${instanceId}`);
|
126
|
+
}
|
127
|
+
|
120
128
|
public async getLogs(systemId: string, instanceId: string): Promise<LogEntry[]> {
|
121
129
|
const instance = this.getInstance(systemId, instanceId);
|
122
130
|
if (!instance) {
|
@@ -368,8 +376,9 @@ export class InstanceManager {
|
|
368
376
|
public async getInstanceOperator(
|
369
377
|
systemId: string,
|
370
378
|
instanceId: string,
|
371
|
-
environment?: EnvironmentType
|
372
|
-
|
379
|
+
environment?: EnvironmentType,
|
380
|
+
ensureContainer: boolean = true
|
381
|
+
): Promise<InstanceOperator<any, any>> {
|
373
382
|
const blockInstance = await assetManager.getBlockInstance(systemId, instanceId);
|
374
383
|
if (!blockInstance) {
|
375
384
|
throw new Error(`Instance not found: ${systemId}/${instanceId}`);
|
@@ -382,36 +391,55 @@ export class InstanceManager {
|
|
382
391
|
|
383
392
|
const operatorDefinition = await definitionsManager.getDefinition(block.kind);
|
384
393
|
|
385
|
-
if (!operatorDefinition
|
394
|
+
if (!operatorDefinition) {
|
395
|
+
throw new Error(`Operator not found: ${block.kind}`);
|
396
|
+
}
|
397
|
+
|
398
|
+
if (operatorDefinition.definition.kind !== KIND_BLOCK_TYPE_OPERATOR) {
|
399
|
+
throw new Error(`Block is not an operator: ${blockRef}`);
|
400
|
+
}
|
401
|
+
|
402
|
+
if (!operatorDefinition.definition.spec.local) {
|
386
403
|
throw new Error(`Operator block has no local definition: ${blockRef}`);
|
387
404
|
}
|
388
405
|
|
389
406
|
const localConfig = operatorDefinition.definition.spec.local as LocalInstance;
|
407
|
+
const ports: { [key: string]: InstanceOperatorPort } = {};
|
390
408
|
|
391
|
-
|
392
|
-
|
393
|
-
instance
|
394
|
-
|
409
|
+
if (ensureContainer) {
|
410
|
+
let instance = await this.start(systemId, instanceId);
|
411
|
+
if (instance instanceof Task) {
|
412
|
+
instance = await instance.wait();
|
413
|
+
}
|
395
414
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
415
|
+
const container = await containerManager.get(instance.pid as string);
|
416
|
+
if (!container) {
|
417
|
+
throw new Error(`Container not found: ${instance.pid}`);
|
418
|
+
}
|
400
419
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
420
|
+
const portInfo = await container.getPorts();
|
421
|
+
if (!portInfo) {
|
422
|
+
throw new Error(`No ports found for instance: ${instanceId}`);
|
423
|
+
}
|
405
424
|
|
406
|
-
|
407
|
-
|
425
|
+
Object.entries(portInfo).forEach(([key, value]) => {
|
426
|
+
ports[key] = {
|
427
|
+
protocol: value.protocol as 'udp' | 'tcp',
|
428
|
+
port: parseInt(value.hostPort),
|
429
|
+
};
|
430
|
+
});
|
431
|
+
} else {
|
432
|
+
// If we're not ensuring the container is running we just get the ports from the local config
|
433
|
+
const instancePorts = await getOperatorInstancePorts(systemId, instanceId, localConfig);
|
434
|
+
instancePorts.forEach((port) => {
|
435
|
+
ports[port.portType] = {
|
436
|
+
protocol: port.protocol as 'udp' | 'tcp',
|
437
|
+
port: port.hostPort,
|
438
|
+
};
|
439
|
+
});
|
440
|
+
}
|
408
441
|
|
409
|
-
|
410
|
-
ports[key] = {
|
411
|
-
protocol: value.protocol,
|
412
|
-
port: parseInt(value.hostPort),
|
413
|
-
};
|
414
|
-
});
|
442
|
+
const hostname = getRemoteHostForEnvironment(environment);
|
415
443
|
|
416
444
|
return {
|
417
445
|
hostname,
|
@@ -472,6 +500,8 @@ export class InstanceManager {
|
|
472
500
|
instance.desiredStatus = DesiredInstanceStatus.STOP;
|
473
501
|
}
|
474
502
|
|
503
|
+
const wasFailed = instance.status === InstanceStatus.FAILED;
|
504
|
+
|
475
505
|
instance.status = InstanceStatus.STOPPING;
|
476
506
|
|
477
507
|
socketManager.emitSystemEvent(systemId, EVENT_STATUS_CHANGED, instance);
|
@@ -490,7 +520,11 @@ export class InstanceManager {
|
|
490
520
|
const container = await containerManager.getContainerByName(containerName);
|
491
521
|
if (container) {
|
492
522
|
try {
|
493
|
-
|
523
|
+
if (wasFailed) {
|
524
|
+
await container.remove();
|
525
|
+
} else {
|
526
|
+
await container.stop();
|
527
|
+
}
|
494
528
|
instance.status = InstanceStatus.STOPPED;
|
495
529
|
socketManager.emitSystemEvent(systemId, EVENT_STATUS_CHANGED, instance);
|
496
530
|
this.save();
|
@@ -556,7 +590,7 @@ export class InstanceManager {
|
|
556
590
|
}
|
557
591
|
}
|
558
592
|
|
559
|
-
if (existingInstance
|
593
|
+
if (existingInstance && existingInstance.pid) {
|
560
594
|
if (existingInstance.status === InstanceStatus.READY) {
|
561
595
|
// Instance is already running
|
562
596
|
return existingInstance;
|
@@ -624,18 +658,15 @@ export class InstanceManager {
|
|
624
658
|
if (existingInstance) {
|
625
659
|
// Check if the instance is already running - but after we've commmuicated the desired status
|
626
660
|
const currentStatus = await this.requestInstanceStatus(existingInstance);
|
661
|
+
|
627
662
|
if (currentStatus === InstanceStatus.READY) {
|
628
663
|
// Instance is already running
|
629
664
|
return existingInstance;
|
630
665
|
}
|
631
666
|
}
|
632
667
|
|
633
|
-
const
|
634
|
-
|
635
|
-
blockSpec.configuration,
|
636
|
-
instanceConfig,
|
637
|
-
blockInstance.defaultConfiguration
|
638
|
-
);
|
668
|
+
const resolvedConfig = await configManager.getConfigForBlockInstance(systemId, instanceId);
|
669
|
+
|
639
670
|
const task = taskManager.add(
|
640
671
|
`instance:start:${systemId}:${instanceId}`,
|
641
672
|
async () => {
|
@@ -927,15 +958,20 @@ export class InstanceManager {
|
|
927
958
|
}
|
928
959
|
|
929
960
|
if (statusType === 'created') {
|
930
|
-
if (state.ExitCode !== 0) {
|
931
|
-
// Failed during creation
|
932
|
-
|
961
|
+
if (state.ExitCode !== undefined && state.ExitCode !== 0) {
|
962
|
+
// Failed during creation. Exit code is not always reliable though
|
963
|
+
if (state.Error) {
|
964
|
+
return InstanceStatus.FAILED;
|
965
|
+
} else {
|
966
|
+
return InstanceStatus.STOPPED;
|
967
|
+
}
|
933
968
|
}
|
934
969
|
return InstanceStatus.STARTING;
|
935
970
|
}
|
936
971
|
|
937
972
|
if (statusType === 'exited' || statusType === 'dead') {
|
938
|
-
if (state.
|
973
|
+
if (!state.Error) {
|
974
|
+
// Exit code is not always reliable - if there is no error we assume it's stopped
|
939
975
|
return InstanceStatus.STOPPED;
|
940
976
|
}
|
941
977
|
return InstanceStatus.FAILED;
|
package/src/operatorManager.ts
CHANGED
@@ -16,21 +16,15 @@ import {
|
|
16
16
|
containerManager,
|
17
17
|
} from './containerManager';
|
18
18
|
import FSExtra from 'fs-extra';
|
19
|
-
import {
|
20
|
-
AnyMap,
|
21
|
-
EnvironmentType,
|
22
|
-
KIND_BLOCK_TYPE_OPERATOR,
|
23
|
-
KIND_RESOURCE_OPERATOR,
|
24
|
-
OperatorInfo,
|
25
|
-
StringMap,
|
26
|
-
} from './types';
|
19
|
+
import { AnyMap, EnvironmentType, KIND_BLOCK_TYPE_OPERATOR, KIND_RESOURCE_OPERATOR, StringMap } from './types';
|
27
20
|
import { BlockInstance, LocalInstance, Resource } from '@kapeta/schemas';
|
28
21
|
import { definitionsManager } from './definitionsManager';
|
29
|
-
import {
|
22
|
+
import { getDockerHostIp, getRemoteHostForEnvironment, toPortInfo } from './utils/utils';
|
30
23
|
import { parseKapetaUri, normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
31
24
|
import _ from 'lodash';
|
32
25
|
import AsyncLock from 'async-lock';
|
33
26
|
import { taskManager } from './taskManager';
|
27
|
+
import { ResourceInfo } from '@kapeta/sdk-config';
|
34
28
|
|
35
29
|
const KIND_PLAN = 'core/plan';
|
36
30
|
|
@@ -104,8 +98,9 @@ class OperatorManager {
|
|
104
98
|
resourceType: string,
|
105
99
|
portType: string,
|
106
100
|
name: string,
|
107
|
-
environment?: EnvironmentType
|
108
|
-
|
101
|
+
environment?: EnvironmentType,
|
102
|
+
ensureContainer: boolean = true
|
103
|
+
): Promise<ResourceInfo<any, any>> {
|
109
104
|
systemId = normalizeKapetaUri(systemId);
|
110
105
|
const plans = await definitionsManager.getDefinitions(KIND_PLAN);
|
111
106
|
|
@@ -144,10 +139,13 @@ class OperatorManager {
|
|
144
139
|
const kindUri = parseKapetaUri(blockResource.kind);
|
145
140
|
const operator = await this.getOperator(resourceType, kindUri.version);
|
146
141
|
const credentials = operator.getCredentials();
|
147
|
-
|
148
|
-
|
142
|
+
if (ensureContainer) {
|
143
|
+
await this.ensureOperator(systemId, resourceType, kindUri.version);
|
144
|
+
}
|
145
|
+
|
146
|
+
const hostPort = await serviceManager.ensureServicePort(systemId, resourceType, portType);
|
149
147
|
|
150
|
-
if (!
|
148
|
+
if (!hostPort) {
|
151
149
|
throw new Error('Unknown resource port type : ' + resourceType + '#' + portType);
|
152
150
|
}
|
153
151
|
|
@@ -155,10 +153,10 @@ class OperatorManager {
|
|
155
153
|
const safeName = dbName.replace('_', '-');
|
156
154
|
|
157
155
|
return {
|
158
|
-
host: environment
|
159
|
-
port:
|
156
|
+
host: getRemoteHostForEnvironment(environment),
|
157
|
+
port: hostPort,
|
160
158
|
type: portType,
|
161
|
-
protocol:
|
159
|
+
protocol: 'tcp',
|
162
160
|
options: {
|
163
161
|
// expose as fullName since that is not operator specific, but unique
|
164
162
|
fullName: safeName,
|
@@ -168,6 +166,34 @@ class OperatorManager {
|
|
168
166
|
};
|
169
167
|
}
|
170
168
|
|
169
|
+
async getOperatorPorts(systemId: string, kind: string, version: string) {
|
170
|
+
const operator = await this.getOperator(kind, version);
|
171
|
+
|
172
|
+
const operatorData = operator.getLocalData();
|
173
|
+
|
174
|
+
const portTypes = Object.keys(operatorData.ports);
|
175
|
+
|
176
|
+
portTypes.sort();
|
177
|
+
|
178
|
+
const ports: AnyMap = {};
|
179
|
+
|
180
|
+
for (let i = 0; i < portTypes.length; i++) {
|
181
|
+
const portType = portTypes[i];
|
182
|
+
let containerPortInfo = operatorData.ports[portType];
|
183
|
+
const hostPort = await serviceManager.ensureServicePort(systemId, kind, portType);
|
184
|
+
const portInfo = toPortInfo(containerPortInfo);
|
185
|
+
const portId = portInfo.port + '/' + portInfo.type;
|
186
|
+
|
187
|
+
ports[portId] = {
|
188
|
+
type: portType,
|
189
|
+
hostPort,
|
190
|
+
protocol: portInfo.type,
|
191
|
+
};
|
192
|
+
}
|
193
|
+
|
194
|
+
return ports;
|
195
|
+
}
|
196
|
+
|
171
197
|
/**
|
172
198
|
* Ensure we have a running operator of given type
|
173
199
|
*
|
@@ -185,24 +211,7 @@ class OperatorManager {
|
|
185
211
|
|
186
212
|
const operatorData = operator.getLocalData();
|
187
213
|
|
188
|
-
const
|
189
|
-
|
190
|
-
portTypes.sort();
|
191
|
-
|
192
|
-
const ports: AnyMap = {};
|
193
|
-
|
194
|
-
for (let i = 0; i < portTypes.length; i++) {
|
195
|
-
const portType = portTypes[i];
|
196
|
-
let containerPortInfo = operatorData.ports[portType];
|
197
|
-
const hostPort = await serviceManager.ensureServicePort(systemId, kind, portType);
|
198
|
-
const portInfo = toPortInfo(containerPortInfo);
|
199
|
-
const portId = portInfo.port + '/' + portInfo.type;
|
200
|
-
|
201
|
-
ports[portId] = {
|
202
|
-
type: portType,
|
203
|
-
hostPort,
|
204
|
-
};
|
205
|
-
}
|
214
|
+
const ports = await this.getOperatorPorts(systemId, kind, version);
|
206
215
|
|
207
216
|
const nameParts = [systemId, kind.toLowerCase(), version];
|
208
217
|
|
@@ -221,7 +230,7 @@ class OperatorManager {
|
|
221
230
|
|
222
231
|
const operatorMetadata = operator.getDefinitionInfo().definition.metadata;
|
223
232
|
|
224
|
-
const
|
233
|
+
const hostIp = getDockerHostIp();
|
225
234
|
|
226
235
|
const ExposedPorts: { [key: string]: any } = {};
|
227
236
|
|
@@ -230,7 +239,7 @@ class OperatorManager {
|
|
230
239
|
PortBindings['' + containerPort] = [
|
231
240
|
{
|
232
241
|
HostPort: '' + portInfo.hostPort,
|
233
|
-
HostIp:
|
242
|
+
HostIp: hostIp,
|
234
243
|
},
|
235
244
|
];
|
236
245
|
|
package/src/serviceManager.ts
CHANGED
@@ -6,9 +6,10 @@
|
|
6
6
|
import _ from 'lodash';
|
7
7
|
import { clusterService } from './clusterService';
|
8
8
|
import { storageService } from './storageService';
|
9
|
-
import { EnvironmentType } from './types';
|
9
|
+
import { DOCKER_HOST_INTERNAL, EnvironmentType } from './types';
|
10
10
|
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
11
11
|
import { resolvePortType } from './utils/BlockInstanceRunner';
|
12
|
+
import { getRemoteHostForEnvironment } from './utils/utils';
|
12
13
|
|
13
14
|
export const HTTP_PORT_TYPE = 'http';
|
14
15
|
|
@@ -34,20 +35,11 @@ class ServiceManager {
|
|
34
35
|
});
|
35
36
|
}
|
36
37
|
|
37
|
-
public getLocalHost(environmentType?: EnvironmentType) {
|
38
|
-
if (environmentType === 'docker') {
|
39
|
-
//We're inside a docker container, so we can use this special host name to access the host machine
|
40
|
-
return 'host.docker.internal';
|
41
|
-
}
|
42
|
-
|
43
|
-
return clusterService.getClusterServiceHost();
|
44
|
-
}
|
45
|
-
|
46
38
|
_forLocal(port: string | number, path?: string, environmentType?: EnvironmentType) {
|
47
39
|
if (!path) {
|
48
40
|
path = '';
|
49
41
|
}
|
50
|
-
const hostname =
|
42
|
+
const hostname = getRemoteHostForEnvironment(environmentType);
|
51
43
|
|
52
44
|
if (path.startsWith('/')) {
|
53
45
|
path = path.substring(1);
|
package/src/types.ts
CHANGED
@@ -21,6 +21,8 @@ export type LogLevel = 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'TRACE' | 'FATAL';
|
|
21
21
|
export type LogSource = 'stdout' | 'stderr';
|
22
22
|
export type EnvironmentType = 'docker' | 'process';
|
23
23
|
|
24
|
+
export const DOCKER_HOST_INTERNAL = 'host.docker.internal';
|
25
|
+
|
24
26
|
export interface LogEntry {
|
25
27
|
source: LogSource;
|
26
28
|
level: LogLevel;
|
@@ -66,13 +68,6 @@ export type ProcessInfo = {
|
|
66
68
|
portType?: string;
|
67
69
|
};
|
68
70
|
|
69
|
-
export interface Health {
|
70
|
-
cmd: string;
|
71
|
-
interval?: number;
|
72
|
-
timeout?: number;
|
73
|
-
retries?: number;
|
74
|
-
}
|
75
|
-
|
76
71
|
export type InstanceInfo = {
|
77
72
|
systemId: string;
|
78
73
|
instanceId: string;
|
@@ -93,30 +88,6 @@ export type InstanceInfo = {
|
|
93
88
|
|
94
89
|
export type ProxyRequestHandler = (req: StringBodyRequest, res: express.Response, info: ProxyRequestInfo) => void;
|
95
90
|
|
96
|
-
export interface OperatorInstancePort {
|
97
|
-
protocol: string;
|
98
|
-
port: number;
|
99
|
-
}
|
100
|
-
|
101
|
-
export interface OperatorInstanceInfo {
|
102
|
-
hostname: string;
|
103
|
-
ports: { [portType: string]: OperatorInstancePort };
|
104
|
-
path?: string;
|
105
|
-
query?: string;
|
106
|
-
hash?: string;
|
107
|
-
options?: AnyMap;
|
108
|
-
credentials?: AnyMap;
|
109
|
-
}
|
110
|
-
|
111
|
-
export interface OperatorInfo {
|
112
|
-
host: string;
|
113
|
-
port: string;
|
114
|
-
type: string;
|
115
|
-
protocol: string;
|
116
|
-
options: AnyMap;
|
117
|
-
credentials: AnyMap;
|
118
|
-
}
|
119
|
-
|
120
91
|
export interface ProxyRequestInfo {
|
121
92
|
address: string;
|
122
93
|
connection: Connection;
|