@firestartr/cli 1.51.1-snapshot-02 → 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
  });
@@ -358187,11 +358186,7 @@ const GithubSchemas = [
358187
358186
  schedule_timezone: {
358188
358187
  type: 'string',
358189
358188
  },
358190
- policy: {
358191
- type: 'string',
358192
- }
358193
358189
  },
358194
- additionalProperties: false,
358195
358190
  required: ['enabled'],
358196
358191
  oneOf: [
358197
358192
  {
@@ -366171,7 +366166,7 @@ async function moveCRsAndClaims(crs, org, claimsPath, resourcesPath) {
366171
366166
  const failedImportedResources = [];
366172
366167
  for (const k of Object.keys(crs)) {
366173
366168
  if (crs[k].kind === 'FirestartrGithubGroup' &&
366174
- crs[k].metadata.name === `${org}-all`) {
366169
+ crs[k].metadata.name.includes(`${org}-all-`)) {
366175
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}`);
366176
366171
  continue;
366177
366172
  }
@@ -367343,28 +367338,6 @@ async function needsProvisioningOnCreate(cr) {
367343
367338
  operator_src_logger.debug(`Skipping the provisioning process for custom resource '${cr.kind}/${cr.metadata.name}' because its current state is not handled.`);
367344
367339
  return false;
367345
367340
  }
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
- }
367368
367341
  async function updateTransition(itemPath, reason, type, statusValue, message = '', updateStatusOnly = false) {
367369
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}'.`);
367370
367343
  const k8sItem = await getItemByItemPath(itemPath);
@@ -367425,115 +367398,12 @@ function updateConditionByType(conditionList, type, newCondition) {
367425
367398
  return conditionList;
367426
367399
  }
367427
367400
 
367428
- ;// CONCATENATED MODULE: ../operator/src/syncCtl.ts
367429
- // Machinery for syncing
367430
-
367431
-
367401
+ ;// CONCATENATED MODULE: ../operator/src/syncer.ts
367432
367402
 
367433
367403
 
367404
+ const syncWatchers = {};
367405
+ const FORCE_REVISION_TIME = 60 * 1000;
367434
367406
  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
- }
367537
367407
  function helperCalculateRevisionTime(period) {
367538
367408
  const [_, scalar, dimension] = period.split(/(\d+)/);
367539
367409
  const multiplier = dimension === 's'
@@ -367547,50 +367417,24 @@ function helperCalculateRevisionTime(period) {
367547
367417
  : 1;
367548
367418
  return Number(scalar) * multiplier * 1000;
367549
367419
  }
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));
367575
367420
  async function syncer(enqueue) {
367576
367421
  // fork
367577
367422
  void loop(enqueue);
367578
367423
  return {
367579
367424
  addItem(itemPath) {
367580
367425
  operator_src_logger.info(`Added item of path '${itemPath}' for synchronization`);
367581
- getSyncSpecs(itemPath)
367582
- .then(async (itemSyncInfo) => {
367426
+ void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367583
367427
  if (!itemSyncInfo.syncable) {
367584
367428
  return;
367585
367429
  }
367586
- const syncCtl = await getSyncStatus(itemPath, itemSyncInfo.item);
367587
- 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
+ };
367588
367437
  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}`;
367594
367438
  });
367595
367439
  },
367596
367440
  updateItem(itemPath) {
@@ -367599,24 +367443,27 @@ async function syncer(enqueue) {
367599
367443
  // return
367600
367444
  //}
367601
367445
  operator_src_logger.debug(`Updated item of path '${itemPath}' during synchronization`);
367602
- getSyncSpecs(itemPath)
367603
- .then(async (itemSyncInfo) => {
367604
- if (syncWatchers[itemPath]) {
367605
- await destroyWatcherForItem(syncWatchers[itemPath]);
367606
- delete syncWatchers[itemPath];
367607
- }
367608
- // we need to chedk if the item is not syncable anymore
367446
+ void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367609
367447
  if (!itemSyncInfo.syncable) {
367610
- operator_src_logger.info(`Removed item of path '${itemPath}' from synchronization`);
367611
- 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]}'`);
367612
367466
  }
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}`;
367620
367467
  });
367621
367468
  },
367622
367469
  deleteItem(itemPath) {
@@ -367624,15 +367471,10 @@ async function syncer(enqueue) {
367624
367471
  operator_src_logger.debug(`Ignored deletion attempt for item at path '${itemPath}' as it was not found during synchronization`);
367625
367472
  return;
367626
367473
  }
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
- });
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`);
367636
367478
  },
367637
367479
  };
367638
367480
  }
@@ -367642,14 +367484,23 @@ async function loop(enqueueIfNeeded) {
367642
367484
  const needRevisionItems = Object.values(syncWatchers).filter((watcher) => watcher.needsRevision);
367643
367485
  for (const watcher of needRevisionItems) {
367644
367486
  const item = await getItemIfNeededSync(watcher);
367645
- operator_src_logger.debug(`Item needs revision ${watcher.itemPath}`);
367646
367487
  if (item !== null) {
367647
367488
  enqueueIfNeeded(item);
367489
+ watcher.needsRevision = false;
367648
367490
  }
367649
- watcher.needsRevision = false;
367650
367491
  }
367651
367492
  }
367652
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
+ }
367653
367504
  async function getItemIfNeededSync(watcher) {
367654
367505
  const item = await getItemByItemPath(watcher.itemPath);
367655
367506
  const isProvisioning = item.status?.conditions?.find((condition) => condition.type === 'PROVISIONING' && condition.status === 'True');
@@ -367658,7 +367509,13 @@ async function getItemIfNeededSync(watcher) {
367658
367509
  const isDeleting = item.status?.conditions?.find((condition) => condition.type === 'DELETING' && condition.status === 'True');
367659
367510
  if (isDeleting)
367660
367511
  return null;
367661
- 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;
367662
367519
  }
367663
367520
  function fWait(segs = 1) {
367664
367521
  return new Promise((ok) => {
@@ -367914,7 +367771,6 @@ var WorkStatus;
367914
367771
 
367915
367772
 
367916
367773
 
367917
-
367918
367774
  const kindsWithFinalizer = [
367919
367775
  'FirestartrTerraformWorkspace',
367920
367776
  'FirestartrGithubGroup',
@@ -368034,17 +367890,14 @@ function enqueue(pluralKind, workItem, queue, compute, syncCtl, retryCtl) {
368034
367890
  success: () => retryCtl.successReconciling(informer_itemPath(pluralKind, workItem.item)),
368035
367891
  };
368036
367892
  workItem.process = async function* (item, operation, handler) {
368037
- const needsUpdateSyncContidions = operation === OperationType.RENAMED ||
368038
- operation === OperationType.UPDATED ||
368039
- operation === OperationType.SYNC ||
368040
- operation === OperationType.CREATED ||
368041
- operation === OperationType.RETRY;
368042
- await setSyncStatus(workItem.handler.itemPath(), operation, 'False', 'Sync process started');
368043
367893
  for await (const transition of compute(item, operation, handler)) {
368044
367894
  yield transition;
368045
367895
  }
368046
- if (needsUpdateSyncContidions) {
368047
- 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) {
368048
367901
  syncCtl.updateItem(informer_itemPath(pluralKind, item));
368049
367902
  }
368050
367903
  else {
@@ -372170,6 +372023,13 @@ function isDestroyRetry(item) {
372170
372023
  return false;
372171
372024
  }
372172
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
+ };
372173
372033
  if (!syncPolicy) {
372174
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}'.`);
372175
372035
  yield* doPlanJSONFormat(item, op, handler);
@@ -685,11 +685,7 @@ declare const schemas: {
685
685
  schedule_timezone: {
686
686
  type: string;
687
687
  };
688
- policy: {
689
- type: string;
690
- };
691
688
  };
692
- additionalProperties: boolean;
693
689
  required: string[];
694
690
  oneOf: ({
695
691
  required: string[];
@@ -40,11 +40,7 @@ export declare const TerraformSchemas: {
40
40
  schedule_timezone: {
41
41
  type: string;
42
42
  };
43
- policy: {
44
- type: string;
45
- };
46
43
  };
47
- additionalProperties: boolean;
48
44
  required: string[];
49
45
  oneOf: ({
50
46
  required: string[];
@@ -40,11 +40,7 @@ declare const _default: {
40
40
  schedule_timezone: {
41
41
  type: string;
42
42
  };
43
- policy: {
44
- type: string;
45
- };
46
43
  };
47
- additionalProperties: boolean;
48
44
  required: string[];
49
45
  oneOf: ({
50
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-02",
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>;