@kapeta/local-cluster-service 0.16.7 → 0.16.8

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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.16.8](https://github.com/kapetacom/local-cluster-service/compare/v0.16.7...v0.16.8) (2023-08-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Gracefully handled instances that have been deleted ([#64](https://github.com/kapetacom/local-cluster-service/issues/64)) ([e26ed35](https://github.com/kapetacom/local-cluster-service/commit/e26ed353e474b7417939008fb1eadec891d5ead9))
7
+
1
8
  ## [0.16.7](https://github.com/kapetacom/local-cluster-service/compare/v0.16.6...v0.16.7) (2023-08-24)
2
9
 
3
10
 
@@ -480,6 +480,36 @@ class InstanceManager {
480
480
  if (instance.ref) {
481
481
  instance.ref = (0, utils_1.normalizeKapetaUri)(instance.ref);
482
482
  }
483
+ if (instance.desiredStatus === types_1.DesiredInstanceStatus.RUN) {
484
+ // Check if the plan still exists and the instance is still in the plan
485
+ // - and that the block definition exists
486
+ try {
487
+ const plan = await assetManager_1.assetManager.getAsset(instance.systemId, true, false);
488
+ if (!plan) {
489
+ instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
490
+ changed = true;
491
+ return;
492
+ }
493
+ const planData = plan.data;
494
+ const planInstance = planData?.spec?.blocks?.find((b) => b.id === instance.instanceId);
495
+ if (!planInstance || !planInstance?.block?.ref) {
496
+ instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
497
+ changed = true;
498
+ return;
499
+ }
500
+ const blockDef = await assetManager_1.assetManager.getAsset(instance.ref, true, false);
501
+ if (!blockDef) {
502
+ instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
503
+ changed = true;
504
+ return;
505
+ }
506
+ }
507
+ catch (e) {
508
+ console.warn('Failed to check assets', instance.systemId, e);
509
+ instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
510
+ return;
511
+ }
512
+ }
483
513
  const newStatus = await this.requestInstanceStatus(instance);
484
514
  /*
485
515
  console.log('Check instance %s %s: [current: %s, new: %s, desired: %s]',
@@ -3,7 +3,7 @@ import request from 'request';
3
3
  import AsyncLock from 'async-lock';
4
4
  import { BlockInstanceRunner } from './utils/BlockInstanceRunner';
5
5
  import { storageService } from './storageService';
6
- import { EVENT_INSTANCE_CREATED, EVENT_INSTANCE_EXITED, EVENT_STATUS_CHANGED, socketManager, } from './socketManager';
6
+ import { EVENT_INSTANCE_CREATED, EVENT_INSTANCE_EXITED, EVENT_STATUS_CHANGED, socketManager } from './socketManager';
7
7
  import { serviceManager } from './serviceManager';
8
8
  import { assetManager } from './assetManager';
9
9
  import { containerManager, HEALTH_CHECK_TIMEOUT } from './containerManager';
@@ -474,6 +474,36 @@ export class InstanceManager {
474
474
  if (instance.ref) {
475
475
  instance.ref = normalizeKapetaUri(instance.ref);
476
476
  }
477
+ if (instance.desiredStatus === DesiredInstanceStatus.RUN) {
478
+ // Check if the plan still exists and the instance is still in the plan
479
+ // - and that the block definition exists
480
+ try {
481
+ const plan = await assetManager.getAsset(instance.systemId, true, false);
482
+ if (!plan) {
483
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
484
+ changed = true;
485
+ return;
486
+ }
487
+ const planData = plan.data;
488
+ const planInstance = planData?.spec?.blocks?.find((b) => b.id === instance.instanceId);
489
+ if (!planInstance || !planInstance?.block?.ref) {
490
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
491
+ changed = true;
492
+ return;
493
+ }
494
+ const blockDef = await assetManager.getAsset(instance.ref, true, false);
495
+ if (!blockDef) {
496
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
497
+ changed = true;
498
+ return;
499
+ }
500
+ }
501
+ catch (e) {
502
+ console.warn('Failed to check assets', instance.systemId, e);
503
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
504
+ return;
505
+ }
506
+ }
477
507
  const newStatus = await this.requestInstanceStatus(instance);
478
508
  /*
479
509
  console.log('Check instance %s %s: [current: %s, new: %s, desired: %s]',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.16.7",
3
+ "version": "0.16.8",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -3,13 +3,7 @@ import request from 'request';
3
3
  import AsyncLock from 'async-lock';
4
4
  import { BlockInstanceRunner } from './utils/BlockInstanceRunner';
5
5
  import { storageService } from './storageService';
6
- import {
7
- EVENT_INSTANCE_CREATED,
8
- EVENT_INSTANCE_EXITED,
9
- EVENT_INSTANCE_LOG,
10
- EVENT_STATUS_CHANGED,
11
- socketManager,
12
- } from './socketManager';
6
+ import { EVENT_INSTANCE_CREATED, EVENT_INSTANCE_EXITED, EVENT_STATUS_CHANGED, socketManager } from './socketManager';
13
7
  import { serviceManager } from './serviceManager';
14
8
  import { assetManager } from './assetManager';
15
9
  import { containerManager, HEALTH_CHECK_TIMEOUT } from './containerManager';
@@ -606,6 +600,38 @@ export class InstanceManager {
606
600
  instance.ref = normalizeKapetaUri(instance.ref);
607
601
  }
608
602
 
603
+ if (instance.desiredStatus === DesiredInstanceStatus.RUN) {
604
+ // Check if the plan still exists and the instance is still in the plan
605
+ // - and that the block definition exists
606
+ try {
607
+ const plan = await assetManager.getAsset(instance.systemId, true, false);
608
+ if (!plan) {
609
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
610
+ changed = true;
611
+ return;
612
+ }
613
+
614
+ const planData = plan.data as Plan;
615
+ const planInstance = planData?.spec?.blocks?.find((b) => b.id === instance.instanceId);
616
+ if (!planInstance || !planInstance?.block?.ref) {
617
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
618
+ changed = true;
619
+ return;
620
+ }
621
+
622
+ const blockDef = await assetManager.getAsset(instance.ref, true, false);
623
+ if (!blockDef) {
624
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
625
+ changed = true;
626
+ return;
627
+ }
628
+ } catch (e) {
629
+ console.warn('Failed to check assets', instance.systemId, e);
630
+ instance.desiredStatus = DesiredInstanceStatus.STOP;
631
+ return;
632
+ }
633
+ }
634
+
609
635
  const newStatus = await this.requestInstanceStatus(instance);
610
636
  /*
611
637
  console.log('Check instance %s %s: [current: %s, new: %s, desired: %s]',