@firestartr/cli 1.51.1-snapshot-0 → 1.51.1-snapshot-02

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/build/index.js CHANGED
@@ -346931,6 +346931,7 @@ const DEFAULT_TIME_ZONE = 'Europe/Madrid';
346931
346931
  function validateCron(cronLine, tz = DEFAULT_TIME_ZONE) {
346932
346932
  try {
346933
346933
  const interval = cron_parser_dist.CronExpressionParser.parse(cronLine, {
346934
+ // to enable the only minutes cron
346934
346935
  strict: false,
346935
346936
  tz,
346936
346937
  });
@@ -358186,7 +358187,11 @@ const GithubSchemas = [
358186
358187
  schedule_timezone: {
358187
358188
  type: 'string',
358188
358189
  },
358190
+ policy: {
358191
+ type: 'string',
358192
+ }
358189
358193
  },
358194
+ additionalProperties: false,
358190
358195
  required: ['enabled'],
358191
358196
  oneOf: [
358192
358197
  {
@@ -367338,6 +367343,28 @@ async function needsProvisioningOnCreate(cr) {
367338
367343
  operator_src_logger.debug(`Skipping the provisioning process for custom resource '${cr.kind}/${cr.metadata.name}' because its current state is not handled.`);
367339
367344
  return false;
367340
367345
  }
367346
+ async function updateSyncTransition(itemPath, reason, lastSyncTime, nextSyncTime, message, status) {
367347
+ operator_src_logger.info(`The item at '${itemPath}' transitioned to a new SYNCHRONIZED condition of '${status}'. The reason for the change is '${reason}' with the message: '${message}'.`);
367348
+ const k8sItem = await getItemByItemPath(itemPath);
367349
+ if (!('status' in k8sItem))
367350
+ k8sItem.status = {};
367351
+ if (!('conditions' in k8sItem.status))
367352
+ k8sItem.status.conditions = [];
367353
+ let conditionObject = getRelevantCondition(k8sItem.status.conditions, 'SYNCHRONIZED');
367354
+ conditionObject = {
367355
+ ...conditionObject,
367356
+ reason,
367357
+ status,
367358
+ message,
367359
+ observedGeneration: k8sItem.metadata.generation,
367360
+ lastSyncTime,
367361
+ lastUpdateTime: new Date().toJSON(),
367362
+ nextSyncTime,
367363
+ };
367364
+ k8sItem.status.conditions = updateConditionByType(k8sItem.status.conditions, 'SYNCHRONIZED', conditionObject);
367365
+ const itemParameters = itemPath.split('/');
367366
+ await writeStatus(itemParameters[1], itemParameters[0], k8sItem);
367367
+ }
367341
367368
  async function updateTransition(itemPath, reason, type, statusValue, message = '', updateStatusOnly = false) {
367342
367369
  operator_src_logger.info(`The item at '${itemPath}' transitioned to a new status of '${statusValue}' (type: '${type}'). The reason for the change is '${reason}' with the message: '${message}'. This was a status-only update: '${updateStatusOnly}'.`);
367343
367370
  const k8sItem = await getItemByItemPath(itemPath);
@@ -367398,12 +367425,115 @@ function updateConditionByType(conditionList, type, newCondition) {
367398
367425
  return conditionList;
367399
367426
  }
367400
367427
 
367401
- ;// CONCATENATED MODULE: ../operator/src/syncer.ts
367428
+ ;// CONCATENATED MODULE: ../operator/src/syncCtl.ts
367429
+ // Machinery for syncing
367430
+
367431
+
367402
367432
 
367403
367433
 
367404
- const syncWatchers = {};
367405
- const FORCE_REVISION_TIME = 60 * 1000;
367406
367434
  const DEFAULT_REVISION_TIME = '1m';
367435
+ async function createWatcherForItem(itemPath, itemCR) {
367436
+ const item = itemCR ?? await getItemByItemPath(itemPath);
367437
+ const syncStatus = await getSyncStatus(itemPath, item);
367438
+ let nextTimeoutInMS = syncStatus.nextTimeoutInMS;
367439
+ // we have lapsed last interval
367440
+ // we calculate from the lastSyncTime
367441
+ if (syncStatus.intervalLapsed) {
367442
+ operator_src_logger.debug(`Next sync interval have been lapsed for ${itemPath}`);
367443
+ if (syncStatus.syncMode === 'Period') {
367444
+ operator_src_logger.debug(`Next sync interval have been lapsed for ${itemPath} the sync will start now`);
367445
+ nextTimeoutInMS = -1;
367446
+ }
367447
+ }
367448
+ const watcher = {
367449
+ itemPath,
367450
+ lastRevision: setTimeout(() => {
367451
+ operator_src_logger.debug(`Item ${itemPath} needs revision`);
367452
+ watcher.needsRevision = true;
367453
+ }, nextTimeoutInMS),
367454
+ needsRevision: false,
367455
+ };
367456
+ return watcher;
367457
+ }
367458
+ async function destroyWatcherForItem(watcher) {
367459
+ clearTimeout(watcher.lastRevision);
367460
+ operator_src_logger.debug(`Disabled SyncWatcher for ${watcher.itemPath}`);
367461
+ }
367462
+ async function getSyncSpecs(itemPath, itemCR) {
367463
+ const item = itemCR ?? await getItemByItemPath(itemPath);
367464
+ return {
367465
+ item,
367466
+ syncable: item.metadata.annotations &&
367467
+ item.metadata.annotations['firestartr.dev/sync-enabled'] &&
367468
+ item.metadata.annotations['firestartr.dev/sync-enabled'] === 'true',
367469
+ period: item.metadata.annotations['firestartr.dev/sync-period'] ||
367470
+ DEFAULT_REVISION_TIME,
367471
+ schedule: item.metadata.annotations['firestartr.dev/sync-schedule'] || false,
367472
+ scheduleTZ: item.metadata.annotations['firestartr.dev/sync-schedule-timezone'] ||
367473
+ 'Europe/Madrid',
367474
+ };
367475
+ }
367476
+ async function getSyncStatus(itemPath, itemCR) {
367477
+ const item = itemCR ?? await getItemByItemPath(itemPath);
367478
+ const syncCondition = getConditionByType(item.status?.conditions ?? [], 'SYNCHRONIZED');
367479
+ // no sync condition present
367480
+ if (!syncCondition) {
367481
+ return {
367482
+ syncStatusPresent: false,
367483
+ };
367484
+ }
367485
+ else {
367486
+ const nextSyncDate = new Date(syncCondition.nextSyncTime);
367487
+ const isLapsed = Date.now() >= nextSyncDate.getTime();
367488
+ const mode = (await getSyncSpecs(itemPath, item)).schedule
367489
+ ? 'Scheduled'
367490
+ : 'Period';
367491
+ return {
367492
+ itemPath,
367493
+ syncMode: mode,
367494
+ conditions: [syncCondition],
367495
+ syncStatusPresent: true,
367496
+ nextTimeoutInMS: isLapsed ? -1 : nextSyncDate.getTime() - Date.now(),
367497
+ intervalLapsed: isLapsed,
367498
+ };
367499
+ }
367500
+ }
367501
+ async function setSyncStatus(itemPath, reason, status, message) {
367502
+ const item = await getItemByItemPath(itemPath);
367503
+ const machinery = assessSyncCalculationMachinery(item);
367504
+ const syncStatus = await machinery(item, reason, status, message);
367505
+ syncStatus.itemPath = itemPath;
367506
+ syncStatus.syncStatusPresent = true;
367507
+ operator_src_logger.info(`Setting sync status for ${itemPath}: ${JSON.stringify(syncStatus)}`);
367508
+ const syncTransition = syncStatus.conditions[0];
367509
+ await updateSyncTransition(itemPath, syncTransition.reason, syncTransition.lastSyncTime, syncTransition.nextSyncTime, syncTransition.message, syncTransition.status);
367510
+ return syncStatus;
367511
+ }
367512
+ function assessSyncCalculationMachinery(item) {
367513
+ if (item.metadata.annotations['firestartr.dev/sync-schedule'] ?? false) {
367514
+ return processScheduledSync;
367515
+ }
367516
+ else {
367517
+ return processPeriodSync;
367518
+ }
367519
+ }
367520
+ async function processPeriodSync(item, reason, status, message) {
367521
+ const period = item.metadata.annotations['firestartr.dev/sync-period'];
367522
+ const periodMS = helperCalculateRevisionTime(period);
367523
+ return {
367524
+ syncMode: 'Period',
367525
+ conditions: [
367526
+ {
367527
+ reason,
367528
+ type: 'SYNCHRONIZED',
367529
+ message,
367530
+ status,
367531
+ lastSyncTime: new Date().toISOString(),
367532
+ nextSyncTime: new Date(Date.now() + periodMS).toISOString(),
367533
+ },
367534
+ ],
367535
+ };
367536
+ }
367407
367537
  function helperCalculateRevisionTime(period) {
367408
367538
  const [_, scalar, dimension] = period.split(/(\d+)/);
367409
367539
  const multiplier = dimension === 's'
@@ -367417,24 +367547,50 @@ function helperCalculateRevisionTime(period) {
367417
367547
  : 1;
367418
367548
  return Number(scalar) * multiplier * 1000;
367419
367549
  }
367550
+ async function processScheduledSync(item, reason, status, message) {
367551
+ const nextPeriod = catalog_common.cron.getCronNextInterval(item.metadata.annotations['firestartr.dev/sync-schedule'], item.metadata.annotations['firestartr.dev/sync-schedule-timezone'] ||
367552
+ undefined);
367553
+ const nextPeriodDate = new Date(nextPeriod);
367554
+ return {
367555
+ syncMode: 'Scheduled',
367556
+ conditions: [
367557
+ {
367558
+ reason,
367559
+ type: 'SYNCHRONIZED',
367560
+ message,
367561
+ status,
367562
+ lastSyncTime: new Date().toISOString(),
367563
+ nextSyncTime: nextPeriodDate.toISOString(),
367564
+ },
367565
+ ],
367566
+ };
367567
+ }
367568
+
367569
+ ;// CONCATENATED MODULE: ../operator/src/syncer.ts
367570
+
367571
+
367572
+
367573
+ const syncWatchers = {};
367574
+ const FORCE_REVISION_TIME = (/* unused pure expression or super */ null && (60 * 1000));
367420
367575
  async function syncer(enqueue) {
367421
367576
  // fork
367422
367577
  void loop(enqueue);
367423
367578
  return {
367424
367579
  addItem(itemPath) {
367425
367580
  operator_src_logger.info(`Added item of path '${itemPath}' for synchronization`);
367426
- void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367581
+ getSyncSpecs(itemPath)
367582
+ .then(async (itemSyncInfo) => {
367427
367583
  if (!itemSyncInfo.syncable) {
367428
367584
  return;
367429
367585
  }
367430
- syncWatchers[itemPath] = {
367431
- itemPath,
367432
- lastRevision: setInterval(() => {
367433
- syncWatchers[itemPath].needsRevision = true;
367434
- }, helperCalculateRevisionTime(itemSyncInfo.period)),
367435
- needsRevision: false,
367436
- };
367586
+ const syncCtl = await getSyncStatus(itemPath, itemSyncInfo.item);
367587
+ syncWatchers[itemPath] = await createWatcherForItem(itemPath, itemSyncInfo.item);
367437
367588
  operator_src_logger.info(`Configured synchronization for item at path '${itemPath}'`);
367589
+ operator_src_logger.debug(`Sync information for '${itemPath}': ${JSON.stringify({ ...itemSyncInfo, item: null }, null)}`);
367590
+ })
367591
+ .catch((err) => {
367592
+ operator_src_logger.error(`Error on sync [add item]: ${err}`);
367593
+ throw `Error on sync [add item]: ${err}`;
367438
367594
  });
367439
367595
  },
367440
367596
  updateItem(itemPath) {
@@ -367443,27 +367599,24 @@ async function syncer(enqueue) {
367443
367599
  // return
367444
367600
  //}
367445
367601
  operator_src_logger.debug(`Updated item of path '${itemPath}' during synchronization`);
367446
- void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367447
- if (!itemSyncInfo.syncable) {
367448
- if (syncWatchers[itemPath]) {
367449
- clearInterval(syncWatchers[itemPath].lastRevision);
367450
- delete syncWatchers[itemPath];
367451
- operator_src_logger.info(`Removed item of path '${itemPath}' from synchronization`);
367452
- }
367602
+ getSyncSpecs(itemPath)
367603
+ .then(async (itemSyncInfo) => {
367604
+ if (syncWatchers[itemPath]) {
367605
+ await destroyWatcherForItem(syncWatchers[itemPath]);
367606
+ delete syncWatchers[itemPath];
367453
367607
  }
367454
- else {
367455
- if (itemSyncInfo.syncable && syncWatchers[itemPath]) {
367456
- clearInterval(syncWatchers[itemPath].lastRevision);
367457
- }
367458
- syncWatchers[itemPath] = {
367459
- itemPath,
367460
- lastRevision: setInterval(() => {
367461
- syncWatchers[itemPath].needsRevision = true;
367462
- }, helperCalculateRevisionTime(itemSyncInfo.period)),
367463
- needsRevision: false,
367464
- };
367465
- operator_src_logger.debug(`Configured synchronization for item at path '${itemPath}' with watcher '${syncWatchers[itemPath]}'`);
367608
+ // we need to chedk if the item is not syncable anymore
367609
+ if (!itemSyncInfo.syncable) {
367610
+ operator_src_logger.info(`Removed item of path '${itemPath}' from synchronization`);
367611
+ return;
367466
367612
  }
367613
+ // if it is syncable we need to recalculate everything
367614
+ syncWatchers[itemPath] = await createWatcherForItem(itemPath);
367615
+ operator_src_logger.info(`Configured synchronization for item at path '${itemPath}' with watcher`);
367616
+ })
367617
+ .catch((err) => {
367618
+ operator_src_logger.error(`Error on sync [updateItem]: ${err}`);
367619
+ throw `Error on sync [updateItem]: ${err}`;
367467
367620
  });
367468
367621
  },
367469
367622
  deleteItem(itemPath) {
@@ -367471,10 +367624,15 @@ async function syncer(enqueue) {
367471
367624
  operator_src_logger.debug(`Ignored deletion attempt for item at path '${itemPath}' as it was not found during synchronization`);
367472
367625
  return;
367473
367626
  }
367474
- operator_src_logger.debug(`Deleted item of path '${itemPath}' during synchronization`);
367475
- clearInterval(syncWatchers[itemPath].lastRevision);
367476
- delete syncWatchers[itemPath];
367477
- operator_src_logger.debug(`Successfully deleted item at path '${itemPath}' during synchronization`);
367627
+ destroyWatcherForItem(syncWatchers[itemPath])
367628
+ .then(() => {
367629
+ operator_src_logger.debug(`Deleted item of path '${itemPath}' during synchronization`);
367630
+ delete syncWatchers[itemPath];
367631
+ })
367632
+ .catch((err) => {
367633
+ operator_src_logger.error(`Error deleting item of path ${itemPath} for synchronization: ${err}`);
367634
+ throw `Error deleting item of path ${itemPath} for synchronization: ${err}`;
367635
+ });
367478
367636
  },
367479
367637
  };
367480
367638
  }
@@ -367484,23 +367642,14 @@ async function loop(enqueueIfNeeded) {
367484
367642
  const needRevisionItems = Object.values(syncWatchers).filter((watcher) => watcher.needsRevision);
367485
367643
  for (const watcher of needRevisionItems) {
367486
367644
  const item = await getItemIfNeededSync(watcher);
367645
+ operator_src_logger.debug(`Item needs revision ${watcher.itemPath}`);
367487
367646
  if (item !== null) {
367488
367647
  enqueueIfNeeded(item);
367489
- watcher.needsRevision = false;
367490
367648
  }
367649
+ watcher.needsRevision = false;
367491
367650
  }
367492
367651
  }
367493
367652
  }
367494
- async function itemIsSyncable(itemPath) {
367495
- const item = await getItemByItemPath(itemPath);
367496
- return {
367497
- syncable: item.metadata.annotations &&
367498
- item.metadata.annotations['firestartr.dev/sync-enabled'] &&
367499
- item.metadata.annotations['firestartr.dev/sync-enabled'] === 'true',
367500
- period: item.metadata.annotations['firestartr.dev/sync-period'] ||
367501
- DEFAULT_REVISION_TIME,
367502
- };
367503
- }
367504
367653
  async function getItemIfNeededSync(watcher) {
367505
367654
  const item = await getItemByItemPath(watcher.itemPath);
367506
367655
  const isProvisioning = item.status?.conditions?.find((condition) => condition.type === 'PROVISIONING' && condition.status === 'True');
@@ -367509,13 +367658,7 @@ async function getItemIfNeededSync(watcher) {
367509
367658
  const isDeleting = item.status?.conditions?.find((condition) => condition.type === 'DELETING' && condition.status === 'True');
367510
367659
  if (isDeleting)
367511
367660
  return null;
367512
- const synchronizedCondition = item.status?.conditions?.find((condition) => condition.type === 'SYNCHRONIZED' && condition.status === 'True');
367513
- if (!synchronizedCondition)
367514
- return item;
367515
- const lastSync = new Date(synchronizedCondition.lastUpdateTime).getTime();
367516
- if (lastSync <= Date.now() - FORCE_REVISION_TIME)
367517
- return item;
367518
- return null;
367661
+ return item;
367519
367662
  }
367520
367663
  function fWait(segs = 1) {
367521
367664
  return new Promise((ok) => {
@@ -367771,6 +367914,7 @@ var WorkStatus;
367771
367914
 
367772
367915
 
367773
367916
 
367917
+
367774
367918
  const kindsWithFinalizer = [
367775
367919
  'FirestartrTerraformWorkspace',
367776
367920
  'FirestartrGithubGroup',
@@ -367890,14 +368034,17 @@ function enqueue(pluralKind, workItem, queue, compute, syncCtl, retryCtl) {
367890
368034
  success: () => retryCtl.successReconciling(informer_itemPath(pluralKind, workItem.item)),
367891
368035
  };
367892
368036
  workItem.process = async function* (item, operation, handler) {
367893
- for await (const transition of compute(item, operation, handler)) {
367894
- yield transition;
367895
- }
367896
- if (operation === OperationType.RENAMED ||
368037
+ const needsUpdateSyncContidions = operation === OperationType.RENAMED ||
367897
368038
  operation === OperationType.UPDATED ||
367898
368039
  operation === OperationType.SYNC ||
367899
368040
  operation === OperationType.CREATED ||
367900
- operation === OperationType.RETRY) {
368041
+ operation === OperationType.RETRY;
368042
+ await setSyncStatus(workItem.handler.itemPath(), operation, 'False', 'Sync process started');
368043
+ for await (const transition of compute(item, operation, handler)) {
368044
+ yield transition;
368045
+ }
368046
+ if (needsUpdateSyncContidions) {
368047
+ await setSyncStatus(workItem.handler.itemPath(), operation, operation === OperationType.SYNC ? 'True' : 'False', 'Sync process finished');
367901
368048
  syncCtl.updateItem(informer_itemPath(pluralKind, item));
367902
368049
  }
367903
368050
  else {
@@ -372023,13 +372170,6 @@ function isDestroyRetry(item) {
372023
372170
  return false;
372024
372171
  }
372025
372172
  async function* process_operation_sync(item, op, handler, syncPolicy, generalPolicy) {
372026
- yield {
372027
- item,
372028
- reason: op,
372029
- type: 'SYNCHRONIZED',
372030
- status: 'False',
372031
- message: 'Sync process started',
372032
- };
372033
372173
  if (!syncPolicy) {
372034
372174
  operator_src_logger.debug(`The Terraform processor is only observing item '${item.kind}/${item.metadata.name}' because no sync policy was found for operation '${op}'.`);
372035
372175
  yield* doPlanJSONFormat(item, op, handler);
@@ -685,7 +685,11 @@ declare const schemas: {
685
685
  schedule_timezone: {
686
686
  type: string;
687
687
  };
688
+ policy: {
689
+ type: string;
690
+ };
688
691
  };
692
+ additionalProperties: boolean;
689
693
  required: string[];
690
694
  oneOf: ({
691
695
  required: string[];
@@ -40,7 +40,11 @@ export declare const TerraformSchemas: {
40
40
  schedule_timezone: {
41
41
  type: string;
42
42
  };
43
+ policy: {
44
+ type: string;
45
+ };
43
46
  };
47
+ additionalProperties: boolean;
44
48
  required: string[];
45
49
  oneOf: ({
46
50
  required: string[];
@@ -40,7 +40,11 @@ declare const _default: {
40
40
  schedule_timezone: {
41
41
  type: string;
42
42
  };
43
+ policy: {
44
+ type: string;
45
+ };
43
46
  };
47
+ additionalProperties: boolean;
44
48
  required: string[];
45
49
  oneOf: ({
46
50
  required: string[];
@@ -1,2 +1,4 @@
1
1
  export declare function needsProvisioningOnCreate(cr: any): Promise<boolean>;
2
+ export declare function updateSyncTransition(itemPath: string, reason: string, lastSyncTime: string, nextSyncTime: string, message: string, status: string): Promise<void>;
2
3
  export declare function updateTransition(itemPath: string, reason: string, type: string, statusValue: string, message?: string, updateStatusOnly?: boolean): Promise<void>;
4
+ export declare function getConditionByType(conditionList: Array<any>, type: string): any;
@@ -0,0 +1,26 @@
1
+ export type Condition = {
2
+ type: string;
3
+ status: 'True' | 'False' | 'Unknown';
4
+ reason: string;
5
+ message: string;
6
+ lastSyncTime?: string;
7
+ nextSyncTime?: string;
8
+ };
9
+ export type SyncStatus = {
10
+ itemPath?: string;
11
+ conditions?: Condition[];
12
+ nextTimeoutInMS?: number;
13
+ syncStatusPresent?: boolean;
14
+ intervalLapsed?: boolean;
15
+ syncMode?: 'Scheduled' | 'Period';
16
+ };
17
+ export type SyncWatcher = {
18
+ itemPath: string;
19
+ lastRevision: any;
20
+ needsRevision: boolean;
21
+ };
22
+ export declare function createWatcherForItem(itemPath: string, itemCR?: any): Promise<SyncWatcher>;
23
+ export declare function destroyWatcherForItem(watcher: SyncWatcher): Promise<void>;
24
+ export declare function getSyncSpecs(itemPath: string, itemCR?: any): Promise<any>;
25
+ export declare function getSyncStatus(itemPath: string, itemCR?: any): Promise<SyncStatus>;
26
+ export declare function setSyncStatus(itemPath: string, reason: string, status: 'True' | 'False' | 'Unknown', message: string): Promise<SyncStatus>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firestartr/cli",
3
- "version": "1.51.1-snapshot-0",
3
+ "version": "1.51.1-snapshot-02",
4
4
  "private": false,
5
5
  "description": "Commandline tool",
6
6
  "main": "build/main.js",