@firestartr/cli 1.51.1-snapshot-01 → 1.51.1-snapshot-03

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