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

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
  {
@@ -365474,11 +365469,16 @@ class GroupGithubDecanter extends GithubDecanter {
365474
365469
  });
365475
365470
  }
365476
365471
  __decantMembers() {
365477
- this.__patchClaim({
365478
- op: 'add',
365479
- value: this.data.members.map((member) => `user:${member.name}`),
365480
- path: '/members',
365481
- });
365472
+ if (this.data.groupDetails.name.includes(`${this.org}-all`)) {
365473
+ importer_src_logger.debug(`Skipping adding members for virtual ${this.data.groupDetails.name} group`);
365474
+ }
365475
+ else {
365476
+ this.__patchClaim({
365477
+ op: 'add',
365478
+ value: this.data.members.map((member) => `user:${member.name}`),
365479
+ path: '/members',
365480
+ });
365481
+ }
365482
365482
  }
365483
365483
  __decantProviders() {
365484
365484
  this.__patchClaim({
@@ -367343,28 +367343,6 @@ async function needsProvisioningOnCreate(cr) {
367343
367343
  operator_src_logger.debug(`Skipping the provisioning process for custom resource '${cr.kind}/${cr.metadata.name}' because its current state is not handled.`);
367344
367344
  return false;
367345
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
- }
367368
367346
  async function updateTransition(itemPath, reason, type, statusValue, message = '', updateStatusOnly = false) {
367369
367347
  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
367348
  const k8sItem = await getItemByItemPath(itemPath);
@@ -367425,115 +367403,12 @@ function updateConditionByType(conditionList, type, newCondition) {
367425
367403
  return conditionList;
367426
367404
  }
367427
367405
 
367428
- ;// CONCATENATED MODULE: ../operator/src/syncCtl.ts
367429
- // Machinery for syncing
367430
-
367431
-
367406
+ ;// CONCATENATED MODULE: ../operator/src/syncer.ts
367432
367407
 
367433
367408
 
367409
+ const syncWatchers = {};
367410
+ const FORCE_REVISION_TIME = 60 * 1000;
367434
367411
  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
367412
  function helperCalculateRevisionTime(period) {
367538
367413
  const [_, scalar, dimension] = period.split(/(\d+)/);
367539
367414
  const multiplier = dimension === 's'
@@ -367547,50 +367422,24 @@ function helperCalculateRevisionTime(period) {
367547
367422
  : 1;
367548
367423
  return Number(scalar) * multiplier * 1000;
367549
367424
  }
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
367425
  async function syncer(enqueue) {
367576
367426
  // fork
367577
367427
  void loop(enqueue);
367578
367428
  return {
367579
367429
  addItem(itemPath) {
367580
367430
  operator_src_logger.info(`Added item of path '${itemPath}' for synchronization`);
367581
- getSyncSpecs(itemPath)
367582
- .then(async (itemSyncInfo) => {
367431
+ void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367583
367432
  if (!itemSyncInfo.syncable) {
367584
367433
  return;
367585
367434
  }
367586
- const syncCtl = await getSyncStatus(itemPath, itemSyncInfo.item);
367587
- syncWatchers[itemPath] = await createWatcherForItem(itemPath, itemSyncInfo.item);
367435
+ syncWatchers[itemPath] = {
367436
+ itemPath,
367437
+ lastRevision: setInterval(() => {
367438
+ syncWatchers[itemPath].needsRevision = true;
367439
+ }, helperCalculateRevisionTime(itemSyncInfo.period)),
367440
+ needsRevision: false,
367441
+ };
367588
367442
  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
367443
  });
367595
367444
  },
367596
367445
  updateItem(itemPath) {
@@ -367599,24 +367448,27 @@ async function syncer(enqueue) {
367599
367448
  // return
367600
367449
  //}
367601
367450
  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
367451
+ void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367609
367452
  if (!itemSyncInfo.syncable) {
367610
- operator_src_logger.info(`Removed item of path '${itemPath}' from synchronization`);
367611
- return;
367453
+ if (syncWatchers[itemPath]) {
367454
+ clearInterval(syncWatchers[itemPath].lastRevision);
367455
+ delete syncWatchers[itemPath];
367456
+ operator_src_logger.info(`Removed item of path '${itemPath}' from synchronization`);
367457
+ }
367458
+ }
367459
+ else {
367460
+ if (itemSyncInfo.syncable && syncWatchers[itemPath]) {
367461
+ clearInterval(syncWatchers[itemPath].lastRevision);
367462
+ }
367463
+ syncWatchers[itemPath] = {
367464
+ itemPath,
367465
+ lastRevision: setInterval(() => {
367466
+ syncWatchers[itemPath].needsRevision = true;
367467
+ }, helperCalculateRevisionTime(itemSyncInfo.period)),
367468
+ needsRevision: false,
367469
+ };
367470
+ operator_src_logger.debug(`Configured synchronization for item at path '${itemPath}' with watcher '${syncWatchers[itemPath]}'`);
367612
367471
  }
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
367472
  });
367621
367473
  },
367622
367474
  deleteItem(itemPath) {
@@ -367624,15 +367476,10 @@ async function syncer(enqueue) {
367624
367476
  operator_src_logger.debug(`Ignored deletion attempt for item at path '${itemPath}' as it was not found during synchronization`);
367625
367477
  return;
367626
367478
  }
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
- });
367479
+ operator_src_logger.debug(`Deleted item of path '${itemPath}' during synchronization`);
367480
+ clearInterval(syncWatchers[itemPath].lastRevision);
367481
+ delete syncWatchers[itemPath];
367482
+ operator_src_logger.debug(`Successfully deleted item at path '${itemPath}' during synchronization`);
367636
367483
  },
367637
367484
  };
367638
367485
  }
@@ -367642,14 +367489,23 @@ async function loop(enqueueIfNeeded) {
367642
367489
  const needRevisionItems = Object.values(syncWatchers).filter((watcher) => watcher.needsRevision);
367643
367490
  for (const watcher of needRevisionItems) {
367644
367491
  const item = await getItemIfNeededSync(watcher);
367645
- operator_src_logger.debug(`Item needs revision ${watcher.itemPath}`);
367646
367492
  if (item !== null) {
367647
367493
  enqueueIfNeeded(item);
367494
+ watcher.needsRevision = false;
367648
367495
  }
367649
- watcher.needsRevision = false;
367650
367496
  }
367651
367497
  }
367652
367498
  }
367499
+ async function itemIsSyncable(itemPath) {
367500
+ const item = await getItemByItemPath(itemPath);
367501
+ return {
367502
+ syncable: item.metadata.annotations &&
367503
+ item.metadata.annotations['firestartr.dev/sync-enabled'] &&
367504
+ item.metadata.annotations['firestartr.dev/sync-enabled'] === 'true',
367505
+ period: item.metadata.annotations['firestartr.dev/sync-period'] ||
367506
+ DEFAULT_REVISION_TIME,
367507
+ };
367508
+ }
367653
367509
  async function getItemIfNeededSync(watcher) {
367654
367510
  const item = await getItemByItemPath(watcher.itemPath);
367655
367511
  const isProvisioning = item.status?.conditions?.find((condition) => condition.type === 'PROVISIONING' && condition.status === 'True');
@@ -367658,7 +367514,13 @@ async function getItemIfNeededSync(watcher) {
367658
367514
  const isDeleting = item.status?.conditions?.find((condition) => condition.type === 'DELETING' && condition.status === 'True');
367659
367515
  if (isDeleting)
367660
367516
  return null;
367661
- return item;
367517
+ const synchronizedCondition = item.status?.conditions?.find((condition) => condition.type === 'SYNCHRONIZED' && condition.status === 'True');
367518
+ if (!synchronizedCondition)
367519
+ return item;
367520
+ const lastSync = new Date(synchronizedCondition.lastUpdateTime).getTime();
367521
+ if (lastSync <= Date.now() - FORCE_REVISION_TIME)
367522
+ return item;
367523
+ return null;
367662
367524
  }
367663
367525
  function fWait(segs = 1) {
367664
367526
  return new Promise((ok) => {
@@ -367914,7 +367776,6 @@ var WorkStatus;
367914
367776
 
367915
367777
 
367916
367778
 
367917
-
367918
367779
  const kindsWithFinalizer = [
367919
367780
  'FirestartrTerraformWorkspace',
367920
367781
  'FirestartrGithubGroup',
@@ -368034,17 +367895,14 @@ function enqueue(pluralKind, workItem, queue, compute, syncCtl, retryCtl) {
368034
367895
  success: () => retryCtl.successReconciling(informer_itemPath(pluralKind, workItem.item)),
368035
367896
  };
368036
367897
  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
367898
  for await (const transition of compute(item, operation, handler)) {
368044
367899
  yield transition;
368045
367900
  }
368046
- if (needsUpdateSyncContidions) {
368047
- await setSyncStatus(workItem.handler.itemPath(), operation, operation === OperationType.SYNC ? 'True' : 'False', 'Sync process finished');
367901
+ if (operation === OperationType.RENAMED ||
367902
+ operation === OperationType.UPDATED ||
367903
+ operation === OperationType.SYNC ||
367904
+ operation === OperationType.CREATED ||
367905
+ operation === OperationType.RETRY) {
368048
367906
  syncCtl.updateItem(informer_itemPath(pluralKind, item));
368049
367907
  }
368050
367908
  else {
@@ -372170,6 +372028,13 @@ function isDestroyRetry(item) {
372170
372028
  return false;
372171
372029
  }
372172
372030
  async function* process_operation_sync(item, op, handler, syncPolicy, generalPolicy) {
372031
+ yield {
372032
+ item,
372033
+ reason: op,
372034
+ type: 'SYNCHRONIZED',
372035
+ status: 'False',
372036
+ message: 'Sync process started',
372037
+ };
372173
372038
  if (!syncPolicy) {
372174
372039
  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
372040
  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-04",
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>;