@firestartr/cli 1.50.1-snapshot-43 → 1.50.1-snapshot-44

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
  });
@@ -358996,7 +358995,14 @@ async function loadInitializers(claim, initializersPath = config_getPath('initia
358996
358995
  return loadedInitializers;
358997
358996
  }
358998
358997
  function loadClaimDefaults() {
358999
- return catalog_common.io.fromYaml(external_fs_.readFileSync(`${config_getPath('claimsDefaults')}/claims_defaults.yaml`, 'utf-8'));
358998
+ try {
358999
+ return catalog_common.io.fromYaml(external_fs_.readFileSync(`${config_getPath('claimsDefaults')}/claims_defaults.yaml`, 'utf-8'));
359000
+ }
359001
+ catch (error) {
359002
+ const errMsg = `Could not read claims defaults file in path ${config_getPath('claimsDefaults')}/claims_defaults.yaml: ${error}`;
359003
+ cdk8s_renderer_src_logger.error(errMsg);
359004
+ throw new Error(errMsg);
359005
+ }
359000
359006
  }
359001
359007
  /*
359002
359008
  * Using fast-json-patch, compares a claim to its kind's defaults, then patches it.
@@ -365289,12 +365295,19 @@ function getConfigPath() {
365289
365295
  getConfigPath,
365290
365296
  });
365291
365297
 
365298
+ ;// CONCATENATED MODULE: ../importer/src/logger.ts
365299
+
365300
+ /* harmony default export */ const importer_src_logger = (catalog_common.logger);
365301
+
365292
365302
  ;// CONCATENATED MODULE: ../importer/src/decanter/base.ts
365293
365303
 
365294
365304
 
365295
365305
 
365296
365306
 
365297
365307
 
365308
+
365309
+
365310
+
365298
365311
  class Decanter {
365299
365312
  set github(githubInstance) {
365300
365313
  this._github = githubInstance;
@@ -365416,6 +365429,20 @@ class Decanter {
365416
365429
  adapt() {
365417
365430
  return this._adapt();
365418
365431
  }
365432
+ async __loadInitializer(initDefaultPath, isAbsolute = false) {
365433
+ let initPath;
365434
+ try {
365435
+ initPath = isAbsolute
365436
+ ? initDefaultPath
365437
+ : external_path_.join(getConfigPath(), 'resources', initDefaultPath);
365438
+ const adapter = catalog_common.io.fromYaml(external_fs_.readFileSync(initPath, 'utf-8'));
365439
+ return new InitializerDefault(adapter);
365440
+ }
365441
+ catch (e) {
365442
+ importer_src_logger.error(`Loading ${initPath}: ${e}`);
365443
+ throw new Error(`Loading ${initPath}: ${e}`);
365444
+ }
365445
+ }
365419
365446
  }
365420
365447
  Decanter.collectionKind = '';
365421
365448
  /* harmony default export */ const decanter_base = (Decanter);
@@ -365433,19 +365460,9 @@ class GithubDecanter extends decanter_base {
365433
365460
  }
365434
365461
  }
365435
365462
 
365436
- ;// CONCATENATED MODULE: ../importer/src/logger.ts
365437
-
365438
- /* harmony default export */ const importer_src_logger = (catalog_common.logger);
365439
-
365440
365463
  ;// CONCATENATED MODULE: ../importer/src/decanter/gh/github_group.ts
365441
365464
 
365442
365465
 
365443
-
365444
-
365445
-
365446
-
365447
-
365448
-
365449
365466
  class GroupGithubDecanter extends GithubDecanter {
365450
365467
  constructor() {
365451
365468
  super(...arguments);
@@ -365504,43 +365521,7 @@ class GroupGithubDecanter extends GithubDecanter {
365504
365521
  return this.__validateEqual(members, this.data.members);
365505
365522
  }
365506
365523
  async __adaptInitializerBase(_claim) {
365507
- let githubGroupDefaultsFilePath;
365508
- try {
365509
- githubGroupDefaultsFilePath = external_path_.join(getConfigPath(), 'resources', 'defaults_github_group.yaml');
365510
- }
365511
- catch (e) {
365512
- importer_src_logger.warn('No config path set, using built-in defaults');
365513
- githubGroupDefaultsFilePath = '';
365514
- }
365515
- let adapter;
365516
- if (githubGroupDefaultsFilePath &&
365517
- external_fs_.existsSync(githubGroupDefaultsFilePath)) {
365518
- adapter = catalog_common.io.fromYaml(external_fs_.readFileSync(githubGroupDefaultsFilePath, 'utf-8'));
365519
- }
365520
- else {
365521
- adapter = {
365522
- name: 'base',
365523
- apiVersion: 'firestartr.dev/v1',
365524
- kind: 'FirestartrGithubGroup',
365525
- defaultValues: {
365526
- context: {
365527
- backend: {
365528
- ref: {
365529
- kind: 'FirestartrProviderConfig',
365530
- name: 'firestartr-terraform-state',
365531
- },
365532
- },
365533
- provider: {
365534
- ref: {
365535
- kind: 'FirestartrProviderConfig',
365536
- name: 'github-app',
365537
- },
365538
- },
365539
- },
365540
- },
365541
- };
365542
- }
365543
- return new InitializerDefault(adapter);
365524
+ return await this.__loadInitializer('defaults_github_group.yaml');
365544
365525
  }
365545
365526
  __validateKind(cr) {
365546
365527
  return true;
@@ -365636,12 +365617,6 @@ applyCollectionMixins(GroupCollectionGithubDecanter);
365636
365617
  ;// CONCATENATED MODULE: ../importer/src/decanter/gh/github_member.ts
365637
365618
 
365638
365619
 
365639
-
365640
-
365641
-
365642
-
365643
-
365644
-
365645
365620
  class MemberGithubDecanter extends GithubDecanter {
365646
365621
  constructor() {
365647
365622
  super(...arguments);
@@ -365679,43 +365654,7 @@ class MemberGithubDecanter extends GithubDecanter {
365679
365654
  });
365680
365655
  }
365681
365656
  async __adaptInitializerBase(_claim) {
365682
- let githubMemberDefaultsFilePath;
365683
- try {
365684
- githubMemberDefaultsFilePath = external_path_.join(getConfigPath(), 'resources', 'defaults_github_membership.yaml');
365685
- }
365686
- catch (e) {
365687
- importer_src_logger.warn('No config path set, using built-in defaults');
365688
- githubMemberDefaultsFilePath = '';
365689
- }
365690
- let adapter;
365691
- if (githubMemberDefaultsFilePath &&
365692
- external_fs_.existsSync(githubMemberDefaultsFilePath)) {
365693
- adapter = catalog_common.io.fromYaml(external_fs_.readFileSync(githubMemberDefaultsFilePath, 'utf-8'));
365694
- }
365695
- else {
365696
- adapter = {
365697
- name: 'base',
365698
- apiVersion: 'firestartr.dev/v1',
365699
- kind: 'FirestartrGithubMembership',
365700
- defaultValues: {
365701
- context: {
365702
- backend: {
365703
- ref: {
365704
- kind: 'FirestartrProviderConfig',
365705
- name: 'firestartr-terraform-state',
365706
- },
365707
- },
365708
- provider: {
365709
- ref: {
365710
- kind: 'FirestartrProviderConfig',
365711
- name: 'github-app',
365712
- },
365713
- },
365714
- },
365715
- },
365716
- };
365717
- }
365718
- return new InitializerDefault(adapter);
365657
+ return await this.__loadInitializer('defaults_github_membership.yaml');
365719
365658
  }
365720
365659
  }
365721
365660
 
@@ -365748,11 +365687,6 @@ applyCollectionMixins(MemberCollectionGithubDecanter);
365748
365687
 
365749
365688
 
365750
365689
 
365751
-
365752
-
365753
-
365754
-
365755
-
365756
365690
  const TYPE_MAP = {
365757
365691
  User: 'user',
365758
365692
  Team: 'group',
@@ -366010,74 +365944,7 @@ class RepoGithubDecanter extends GithubDecanter {
366010
365944
  return null;
366011
365945
  }
366012
365946
  async __adaptInitializerBase(_claim) {
366013
- let githubRepoDefaultsFilePath;
366014
- try {
366015
- githubRepoDefaultsFilePath = external_path_.join(getConfigPath(), 'resources', 'defaults_github_repository.yaml');
366016
- }
366017
- catch (e) {
366018
- importer_src_logger.warn('No config path set, using built-in defaults');
366019
- githubRepoDefaultsFilePath = '';
366020
- }
366021
- let adapter;
366022
- if (githubRepoDefaultsFilePath &&
366023
- external_fs_.existsSync(githubRepoDefaultsFilePath)) {
366024
- adapter = catalog_common.io.fromYaml(external_fs_.readFileSync(githubRepoDefaultsFilePath, 'utf-8'));
366025
- }
366026
- else {
366027
- adapter = {
366028
- name: 'base',
366029
- apiVersion: 'firestartr.dev/v1',
366030
- kind: 'FirestartrGithubRepository',
366031
- defaultValues: {
366032
- context: {
366033
- backend: {
366034
- ref: {
366035
- kind: 'FirestartrProviderConfig',
366036
- name: 'firestartr-terraform-state',
366037
- },
366038
- },
366039
- provider: {
366040
- ref: {
366041
- kind: 'FirestartrProviderConfig',
366042
- name: 'github-app',
366043
- },
366044
- },
366045
- },
366046
- name: this.data.repoDetails.name,
366047
- description: this.data.repoDetails.description,
366048
- org: this.org,
366049
- firestartr: {
366050
- technology: { stack: 'none', version: 'none' },
366051
- },
366052
- repo: {
366053
- description: this.data.repoDetails.description,
366054
- allowMergeCommit: this.data.repoDetails.allow_merge_commit,
366055
- allowSquashMerge: this.data.repoDetails.allow_squash_merge,
366056
- allowRebaseMerge: this.data.repoDetails.allow_rebase_merge,
366057
- allowAutoMerge: this.data.repoDetails.allow_auto_merge,
366058
- deleteBranchOnMerge: this.data.repoDetails.delete_branch_on_merge,
366059
- autoInit: true,
366060
- archiveOnDestroy: true,
366061
- allowUpdateBranch: this.data.repoDetails.allow_update_branch,
366062
- hasIssues: this.data.repoDetails.has_issues,
366063
- visibility: this.data.repoDetails.visibility,
366064
- defaultBranch: this.data.repoDetails.default_branch,
366065
- },
366066
- permissions: [],
366067
- actions: {
366068
- oidc: this.data.oidc.use_default
366069
- ? undefined
366070
- : {
366071
- useDefault: this.data.oidc.use_default,
366072
- includeClaimKeys: this.data.oidc.include_claim_keys
366073
- ? this.data.oidc.include_claim_keys
366074
- : [],
366075
- },
366076
- },
366077
- },
366078
- };
366079
- }
366080
- return new InitializerDefault(adapter);
365947
+ return await this.__loadInitializer('defaults_github_repository.yaml');
366081
365948
  }
366082
365949
  async __adaptOverriderRepo(_claim) {
366083
365950
  return new GithubRepositoryOverrider();
@@ -366321,22 +366188,17 @@ function compileReg(value) {
366321
366188
  });
366322
366189
 
366323
366190
 
366324
-
366325
366191
  // const MAP_COLLECTION_KIND_CR_KIND: any = {
366326
366192
  // gh-members: 'FirestartrGithubMembership',
366327
366193
  // gh-group: 'FirestartrGithubGroup',
366328
366194
  // gh-repo: 'FirestartrGithubRepository',
366329
366195
  // }
366330
- async function runImporter(force, generateDefaults, skipPlan, claimsPath, crsPath, configPath, claimsDefaultsPath, org, filters, provider = AllowedProviders.all) {
366196
+ async function runImporter(force, skipPlan, claimsPath, crsPath, configPath, claimsDefaultsPath, org, filters, provider = AllowedProviders.all) {
366331
366197
  configureProvider(provider);
366332
366198
  let generatedFilters = [];
366333
366199
  //gh-repo,REGEXP=.*vite.*
366334
366200
  cdk8s_renderer.setPath('claimsDefaults', claimsDefaultsPath);
366335
366201
  generatedFilters = buildFilters(filters, force, crsPath, generatedFilters);
366336
- if (generateDefaults) {
366337
- generateClaimsDefaults(org, claimsDefaultsPath);
366338
- generateDefaultsFn(org, configPath);
366339
- }
366340
366202
  await importGithubGitopsRepository(org, skipPlan, claimsPath, crsPath, configPath, generatedFilters);
366341
366203
  }
366342
366204
  function buildFilters(filters, force, crsPath, generatedFilters) {
@@ -366372,97 +366234,6 @@ function createSkipFilters(filters) {
366372
366234
  }
366373
366235
  return filters;
366374
366236
  }
366375
- function generateDefaultsFn(org, defaultsPath) {
366376
- generateDefaultsForGithubGroups(org, defaultsPath);
366377
- generateDefaultsForGithubRepos(org, defaultsPath);
366378
- generateDefaultsForGithubRepos(org, defaultsPath);
366379
- }
366380
- function generateDefaultsForGithubGroups(org, defaultsPath) {
366381
- const defaultGroups = {
366382
- name: 'group_base',
366383
- apiVersion: 'firestartr.dev/v1',
366384
- kind: 'FirestartrGithubGroup',
366385
- defaultValues: {
366386
- org: org,
366387
- },
366388
- };
366389
- catalog_common.io.writeYamlFile('defaults_github_group', defaultGroups, defaultsPath);
366390
- }
366391
- function generateDefaultsForGithubRepos(org, defaultsPath) {
366392
- const defaultRepos = {
366393
- name: 'repo_base',
366394
- apiVersion: 'firestartr.dev/v1',
366395
- kind: 'FirestartrGithubRepository',
366396
- defaultValues: {
366397
- firestartr: {
366398
- technology: {
366399
- stack: 'none',
366400
- version: 'none',
366401
- },
366402
- },
366403
- repo: {
366404
- allowAutoMerge: true,
366405
- codeowners: ' - ',
366406
- allowMergeCommit: true,
366407
- allowSquashMerge: true,
366408
- allowRebaseMerge: true,
366409
- deleteBranchOnMerge: true,
366410
- autoInit: true,
366411
- archiveOnDestroy: true,
366412
- allowUpdateBranch: true,
366413
- hasIssues: true,
366414
- },
366415
- },
366416
- };
366417
- catalog_common.io.writeYamlFile('defaults_github_repository', defaultRepos, defaultsPath);
366418
- }
366419
- function generateClaimsDefaults(org, defaultsPath) {
366420
- const defaultClaims = {
366421
- ComponentClaim: {
366422
- version: '1.0',
366423
- type: 'service',
366424
- lifecycle: 'production',
366425
- system: 'system:firestartr-test-system',
366426
- maintainedBy: [],
366427
- platformOwner: `group:${org}-all`,
366428
- providers: {
366429
- github: {
366430
- org: org,
366431
- branchStrategy: {
366432
- name: 'trunkBasedDevelopment',
366433
- defaultBranch: 'main',
366434
- },
366435
- orgPermissions: 'none',
366436
- visibility: 'private',
366437
- technology: {
366438
- stack: 'none',
366439
- version: 'none',
366440
- },
366441
- features: [],
366442
- },
366443
- },
366444
- },
366445
- GroupClaim: {
366446
- providers: {
366447
- github: {
366448
- org: org,
366449
- privacy: 'closed',
366450
- },
366451
- },
366452
- },
366453
- SystemClaim: {
366454
- providers: {
366455
- catalog: null,
366456
- },
366457
- },
366458
- DomainClaim: {
366459
- providers: {
366460
- catalog: null,
366461
- },
366462
- },
366463
- };
366464
- catalog_common.io.writeYamlFile('claims_defaults', defaultClaims, defaultsPath);
366465
- }
366466
366237
 
366467
366238
  ;// CONCATENATED MODULE: ./src/subcommands/importer-subcommands.ts
366468
366239
 
@@ -366471,7 +366242,6 @@ const importSubcommand = {
366471
366242
  requiredEnv: [],
366472
366243
  subparameters: [
366473
366244
  { name: 'force', type: Boolean },
366474
- { name: 'generateDefaults', type: Boolean },
366475
366245
  { name: 'skipPlan', type: Boolean },
366476
366246
  { name: 'claims', type: String },
366477
366247
  { name: 'crs', type: String },
@@ -366482,7 +366252,7 @@ const importSubcommand = {
366482
366252
  ],
366483
366253
  run: async (options) => {
366484
366254
  console.table(options);
366485
- await runImporter(options.force, options.generateDefaults, options.skipPlan, options.claims, options.crs, options.config, options.claimsDefaults, options.org, options.filters);
366255
+ await runImporter(options.force, options.skipPlan, options.claims, options.crs, options.config, options.claimsDefaults, options.org, options.filters);
366486
366256
  },
366487
366257
  };
366488
366258
 
@@ -367339,28 +367109,6 @@ async function needsProvisioningOnCreate(cr) {
367339
367109
  operator_src_logger.debug(`Skipping the provisioning process for custom resource '${cr.kind}/${cr.metadata.name}' because its current state is not handled.`);
367340
367110
  return false;
367341
367111
  }
367342
- async function updateSyncTransition(itemPath, reason, lastSyncTime, nextSyncTime, message, status) {
367343
- 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}'.`);
367344
- const k8sItem = await getItemByItemPath(itemPath);
367345
- if (!('status' in k8sItem))
367346
- k8sItem.status = {};
367347
- if (!('conditions' in k8sItem.status))
367348
- k8sItem.status.conditions = [];
367349
- let conditionObject = getRelevantCondition(k8sItem.status.conditions, 'SYNCHRONIZED');
367350
- conditionObject = {
367351
- ...conditionObject,
367352
- reason,
367353
- status,
367354
- message,
367355
- observedGeneration: k8sItem.metadata.generation,
367356
- lastSyncTime,
367357
- lastUpdateTime: new Date().toJSON(),
367358
- nextSyncTime,
367359
- };
367360
- k8sItem.status.conditions = updateConditionByType(k8sItem.status.conditions, 'SYNCHRONIZED', conditionObject);
367361
- const itemParameters = itemPath.split('/');
367362
- await writeStatus(itemParameters[1], itemParameters[0], k8sItem);
367363
- }
367364
367112
  async function updateTransition(itemPath, reason, type, statusValue, message = '', updateStatusOnly = false) {
367365
367113
  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}'.`);
367366
367114
  const k8sItem = await getItemByItemPath(itemPath);
@@ -367421,115 +367169,12 @@ function updateConditionByType(conditionList, type, newCondition) {
367421
367169
  return conditionList;
367422
367170
  }
367423
367171
 
367424
- ;// CONCATENATED MODULE: ../operator/src/syncCtl.ts
367425
- // Machinery for syncing
367426
-
367427
-
367172
+ ;// CONCATENATED MODULE: ../operator/src/syncer.ts
367428
367173
 
367429
367174
 
367175
+ const syncWatchers = {};
367176
+ const FORCE_REVISION_TIME = 60 * 1000;
367430
367177
  const DEFAULT_REVISION_TIME = '1m';
367431
- async function createWatcherForItem(itemPath, itemCR) {
367432
- const item = itemCR ?? await getItemByItemPath(itemPath);
367433
- const syncStatus = await getSyncStatus(itemPath, item);
367434
- let nextTimeoutInMS = syncStatus.nextTimeoutInMS;
367435
- // we have lapsed last interval
367436
- // we calculate from the lastSyncTime
367437
- if (syncStatus.intervalLapsed) {
367438
- operator_src_logger.debug(`Next sync interval have been lapsed for ${itemPath}`);
367439
- if (syncStatus.syncMode === 'Period') {
367440
- operator_src_logger.debug(`Next sync interval have been lapsed for ${itemPath} the sync will start now`);
367441
- nextTimeoutInMS = -1;
367442
- }
367443
- }
367444
- const watcher = {
367445
- itemPath,
367446
- lastRevision: setTimeout(() => {
367447
- operator_src_logger.debug(`Item ${itemPath} needs revision`);
367448
- watcher.needsRevision = true;
367449
- }, nextTimeoutInMS),
367450
- needsRevision: false,
367451
- };
367452
- return watcher;
367453
- }
367454
- async function destroyWatcherForItem(watcher) {
367455
- clearTimeout(watcher.lastRevision);
367456
- operator_src_logger.debug(`Disabled SyncWatcher for ${watcher.itemPath}`);
367457
- }
367458
- async function getSyncSpecs(itemPath, itemCR) {
367459
- const item = itemCR ?? await getItemByItemPath(itemPath);
367460
- return {
367461
- item,
367462
- syncable: item.metadata.annotations &&
367463
- item.metadata.annotations['firestartr.dev/sync-enabled'] &&
367464
- item.metadata.annotations['firestartr.dev/sync-enabled'] === 'true',
367465
- period: item.metadata.annotations['firestartr.dev/sync-period'] ||
367466
- DEFAULT_REVISION_TIME,
367467
- schedule: item.metadata.annotations['firestartr.dev/sync-schedule'] || false,
367468
- scheduleTZ: item.metadata.annotations['firestartr.dev/sync-schedule-timezone'] ||
367469
- 'Europe/Madrid',
367470
- };
367471
- }
367472
- async function getSyncStatus(itemPath, itemCR) {
367473
- const item = itemCR ?? await getItemByItemPath(itemPath);
367474
- const syncCondition = getConditionByType(item.status?.conditions ?? [], 'SYNCHRONIZED');
367475
- // no sync condition present
367476
- if (!syncCondition) {
367477
- return {
367478
- syncStatusPresent: false,
367479
- };
367480
- }
367481
- else {
367482
- const nextSyncDate = new Date(syncCondition.nextSyncTime);
367483
- const isLapsed = Date.now() >= nextSyncDate.getTime();
367484
- const mode = (await getSyncSpecs(itemPath, item)).schedule
367485
- ? 'Scheduled'
367486
- : 'Period';
367487
- return {
367488
- itemPath,
367489
- syncMode: mode,
367490
- conditions: [syncCondition],
367491
- syncStatusPresent: true,
367492
- nextTimeoutInMS: isLapsed ? -1 : nextSyncDate.getTime() - Date.now(),
367493
- intervalLapsed: isLapsed,
367494
- };
367495
- }
367496
- }
367497
- async function setSyncStatus(itemPath, reason, status, message) {
367498
- const item = await getItemByItemPath(itemPath);
367499
- const machinery = assessSyncCalculationMachinery(item);
367500
- const syncStatus = await machinery(item, reason, status, message);
367501
- syncStatus.itemPath = itemPath;
367502
- syncStatus.syncStatusPresent = true;
367503
- operator_src_logger.info(`Setting sync status for ${itemPath}: ${JSON.stringify(syncStatus)}`);
367504
- const syncTransition = syncStatus.conditions[0];
367505
- await updateSyncTransition(itemPath, syncTransition.reason, syncTransition.lastSyncTime, syncTransition.nextSyncTime, syncTransition.message, syncTransition.status);
367506
- return syncStatus;
367507
- }
367508
- function assessSyncCalculationMachinery(item) {
367509
- if (item.metadata.annotations['firestartr.dev/sync-schedule'] ?? false) {
367510
- return processScheduledSync;
367511
- }
367512
- else {
367513
- return processPeriodSync;
367514
- }
367515
- }
367516
- async function processPeriodSync(item, reason, status, message) {
367517
- const period = item.metadata.annotations['firestartr.dev/sync-period'];
367518
- const periodMS = helperCalculateRevisionTime(period);
367519
- return {
367520
- syncMode: 'Period',
367521
- conditions: [
367522
- {
367523
- reason,
367524
- type: 'SYNCHRONIZED',
367525
- message,
367526
- status,
367527
- lastSyncTime: new Date().toISOString(),
367528
- nextSyncTime: new Date(Date.now() + periodMS).toISOString(),
367529
- },
367530
- ],
367531
- };
367532
- }
367533
367178
  function helperCalculateRevisionTime(period) {
367534
367179
  const [_, scalar, dimension] = period.split(/(\d+)/);
367535
367180
  const multiplier = dimension === 's'
@@ -367543,50 +367188,24 @@ function helperCalculateRevisionTime(period) {
367543
367188
  : 1;
367544
367189
  return Number(scalar) * multiplier * 1000;
367545
367190
  }
367546
- async function processScheduledSync(item, reason, status, message) {
367547
- const nextPeriod = catalog_common.cron.getCronNextInterval(item.metadata.annotations['firestartr.dev/sync-schedule'], item.metadata.annotations['firestartr.dev/sync-schedule-timezone'] ||
367548
- undefined);
367549
- const nextPeriodDate = new Date(nextPeriod);
367550
- return {
367551
- syncMode: 'Scheduled',
367552
- conditions: [
367553
- {
367554
- reason,
367555
- type: 'SYNCHRONIZED',
367556
- message,
367557
- status,
367558
- lastSyncTime: new Date().toISOString(),
367559
- nextSyncTime: nextPeriodDate.toISOString(),
367560
- },
367561
- ],
367562
- };
367563
- }
367564
-
367565
- ;// CONCATENATED MODULE: ../operator/src/syncer.ts
367566
-
367567
-
367568
-
367569
- const syncWatchers = {};
367570
- const FORCE_REVISION_TIME = (/* unused pure expression or super */ null && (60 * 1000));
367571
367191
  async function syncer(enqueue) {
367572
367192
  // fork
367573
367193
  void loop(enqueue);
367574
367194
  return {
367575
367195
  addItem(itemPath) {
367576
367196
  operator_src_logger.info(`Added item of path '${itemPath}' for synchronization`);
367577
- getSyncSpecs(itemPath)
367578
- .then(async (itemSyncInfo) => {
367197
+ void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367579
367198
  if (!itemSyncInfo.syncable) {
367580
367199
  return;
367581
367200
  }
367582
- const syncCtl = await getSyncStatus(itemPath, itemSyncInfo.item);
367583
- syncWatchers[itemPath] = await createWatcherForItem(itemPath, itemSyncInfo.item);
367201
+ syncWatchers[itemPath] = {
367202
+ itemPath,
367203
+ lastRevision: setInterval(() => {
367204
+ syncWatchers[itemPath].needsRevision = true;
367205
+ }, helperCalculateRevisionTime(itemSyncInfo.period)),
367206
+ needsRevision: false,
367207
+ };
367584
367208
  operator_src_logger.info(`Configured synchronization for item at path '${itemPath}'`);
367585
- operator_src_logger.debug(`Sync information for '${itemPath}': ${JSON.stringify({ ...itemSyncInfo, item: null }, null)}`);
367586
- })
367587
- .catch((err) => {
367588
- operator_src_logger.error(`Error on sync [add item]: ${err}`);
367589
- throw `Error on sync [add item]: ${err}`;
367590
367209
  });
367591
367210
  },
367592
367211
  updateItem(itemPath) {
@@ -367595,24 +367214,27 @@ async function syncer(enqueue) {
367595
367214
  // return
367596
367215
  //}
367597
367216
  operator_src_logger.debug(`Updated item of path '${itemPath}' during synchronization`);
367598
- getSyncSpecs(itemPath)
367599
- .then(async (itemSyncInfo) => {
367600
- if (syncWatchers[itemPath]) {
367601
- await destroyWatcherForItem(syncWatchers[itemPath]);
367602
- delete syncWatchers[itemPath];
367603
- }
367604
- // we need to chedk if the item is not syncable anymore
367217
+ void itemIsSyncable(itemPath).then((itemSyncInfo) => {
367605
367218
  if (!itemSyncInfo.syncable) {
367606
- operator_src_logger.info(`Removed item of path '${itemPath}' from synchronization`);
367607
- return;
367219
+ if (syncWatchers[itemPath]) {
367220
+ clearInterval(syncWatchers[itemPath].lastRevision);
367221
+ delete syncWatchers[itemPath];
367222
+ operator_src_logger.info(`Removed item of path '${itemPath}' from synchronization`);
367223
+ }
367224
+ }
367225
+ else {
367226
+ if (itemSyncInfo.syncable && syncWatchers[itemPath]) {
367227
+ clearInterval(syncWatchers[itemPath].lastRevision);
367228
+ }
367229
+ syncWatchers[itemPath] = {
367230
+ itemPath,
367231
+ lastRevision: setInterval(() => {
367232
+ syncWatchers[itemPath].needsRevision = true;
367233
+ }, helperCalculateRevisionTime(itemSyncInfo.period)),
367234
+ needsRevision: false,
367235
+ };
367236
+ operator_src_logger.debug(`Configured synchronization for item at path '${itemPath}' with watcher '${syncWatchers[itemPath]}'`);
367608
367237
  }
367609
- // if it is syncable we need to recalculate everything
367610
- syncWatchers[itemPath] = await createWatcherForItem(itemPath);
367611
- operator_src_logger.info(`Configured synchronization for item at path '${itemPath}' with watcher`);
367612
- })
367613
- .catch((err) => {
367614
- operator_src_logger.error(`Error on sync [updateItem]: ${err}`);
367615
- throw `Error on sync [updateItem]: ${err}`;
367616
367238
  });
367617
367239
  },
367618
367240
  deleteItem(itemPath) {
@@ -367620,15 +367242,10 @@ async function syncer(enqueue) {
367620
367242
  operator_src_logger.debug(`Ignored deletion attempt for item at path '${itemPath}' as it was not found during synchronization`);
367621
367243
  return;
367622
367244
  }
367623
- destroyWatcherForItem(syncWatchers[itemPath])
367624
- .then(() => {
367625
- operator_src_logger.debug(`Deleted item of path '${itemPath}' during synchronization`);
367626
- delete syncWatchers[itemPath];
367627
- })
367628
- .catch((err) => {
367629
- operator_src_logger.error(`Error deleting item of path ${itemPath} for synchronization: ${err}`);
367630
- throw `Error deleting item of path ${itemPath} for synchronization: ${err}`;
367631
- });
367245
+ operator_src_logger.debug(`Deleted item of path '${itemPath}' during synchronization`);
367246
+ clearInterval(syncWatchers[itemPath].lastRevision);
367247
+ delete syncWatchers[itemPath];
367248
+ operator_src_logger.debug(`Successfully deleted item at path '${itemPath}' during synchronization`);
367632
367249
  },
367633
367250
  };
367634
367251
  }
@@ -367638,14 +367255,23 @@ async function loop(enqueueIfNeeded) {
367638
367255
  const needRevisionItems = Object.values(syncWatchers).filter((watcher) => watcher.needsRevision);
367639
367256
  for (const watcher of needRevisionItems) {
367640
367257
  const item = await getItemIfNeededSync(watcher);
367641
- operator_src_logger.debug(`Item needs revision ${watcher.itemPath}`);
367642
367258
  if (item !== null) {
367643
367259
  enqueueIfNeeded(item);
367260
+ watcher.needsRevision = false;
367644
367261
  }
367645
- watcher.needsRevision = false;
367646
367262
  }
367647
367263
  }
367648
367264
  }
367265
+ async function itemIsSyncable(itemPath) {
367266
+ const item = await getItemByItemPath(itemPath);
367267
+ return {
367268
+ syncable: item.metadata.annotations &&
367269
+ item.metadata.annotations['firestartr.dev/sync-enabled'] &&
367270
+ item.metadata.annotations['firestartr.dev/sync-enabled'] === 'true',
367271
+ period: item.metadata.annotations['firestartr.dev/sync-period'] ||
367272
+ DEFAULT_REVISION_TIME,
367273
+ };
367274
+ }
367649
367275
  async function getItemIfNeededSync(watcher) {
367650
367276
  const item = await getItemByItemPath(watcher.itemPath);
367651
367277
  const isProvisioning = item.status?.conditions?.find((condition) => condition.type === 'PROVISIONING' && condition.status === 'True');
@@ -367654,7 +367280,13 @@ async function getItemIfNeededSync(watcher) {
367654
367280
  const isDeleting = item.status?.conditions?.find((condition) => condition.type === 'DELETING' && condition.status === 'True');
367655
367281
  if (isDeleting)
367656
367282
  return null;
367657
- return item;
367283
+ const synchronizedCondition = item.status?.conditions?.find((condition) => condition.type === 'SYNCHRONIZED' && condition.status === 'True');
367284
+ if (!synchronizedCondition)
367285
+ return item;
367286
+ const lastSync = new Date(synchronizedCondition.lastUpdateTime).getTime();
367287
+ if (lastSync <= Date.now() - FORCE_REVISION_TIME)
367288
+ return item;
367289
+ return null;
367658
367290
  }
367659
367291
  function fWait(segs = 1) {
367660
367292
  return new Promise((ok) => {
@@ -367910,7 +367542,6 @@ var WorkStatus;
367910
367542
 
367911
367543
 
367912
367544
 
367913
-
367914
367545
  const kindsWithFinalizer = [
367915
367546
  'FirestartrTerraformWorkspace',
367916
367547
  'FirestartrGithubGroup',
@@ -368030,17 +367661,14 @@ function enqueue(pluralKind, workItem, queue, compute, syncCtl, retryCtl) {
368030
367661
  success: () => retryCtl.successReconciling(informer_itemPath(pluralKind, workItem.item)),
368031
367662
  };
368032
367663
  workItem.process = async function* (item, operation, handler) {
368033
- const needsUpdateSyncContidions = operation === OperationType.RENAMED ||
368034
- operation === OperationType.UPDATED ||
368035
- operation === OperationType.SYNC ||
368036
- operation === OperationType.CREATED ||
368037
- operation === OperationType.RETRY;
368038
- await setSyncStatus(workItem.handler.itemPath(), operation, 'False', 'Sync process started');
368039
367664
  for await (const transition of compute(item, operation, handler)) {
368040
367665
  yield transition;
368041
367666
  }
368042
- if (needsUpdateSyncContidions) {
368043
- await setSyncStatus(workItem.handler.itemPath(), operation, operation === OperationType.SYNC ? 'True' : 'False', 'Sync process finished');
367667
+ if (operation === OperationType.RENAMED ||
367668
+ operation === OperationType.UPDATED ||
367669
+ operation === OperationType.SYNC ||
367670
+ operation === OperationType.CREATED ||
367671
+ operation === OperationType.RETRY) {
368044
367672
  syncCtl.updateItem(informer_itemPath(pluralKind, item));
368045
367673
  }
368046
367674
  else {
@@ -372166,6 +371794,13 @@ function isDestroyRetry(item) {
372166
371794
  return false;
372167
371795
  }
372168
371796
  async function* process_operation_sync(item, op, handler, syncPolicy, generalPolicy) {
371797
+ yield {
371798
+ item,
371799
+ reason: op,
371800
+ type: 'SYNCHRONIZED',
371801
+ status: 'False',
371802
+ message: 'Sync process started',
371803
+ };
372169
371804
  if (!syncPolicy) {
372170
371805
  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}'.`);
372171
371806
  yield* doPlanJSONFormat(item, op, handler);
@@ -6,4 +6,4 @@ declare const _default: {
6
6
  };
7
7
  export default _default;
8
8
  import { AllowedProviders } from 'cdk8s_renderer';
9
- export declare function runImporter(force: boolean, generateDefaults: boolean, skipPlan: boolean, claimsPath: string, crsPath: string, configPath: string, claimsDefaultsPath: string, org: string, filters: string[], provider?: AllowedProviders): Promise<void>;
9
+ export declare function runImporter(force: boolean, skipPlan: boolean, claimsPath: string, crsPath: string, configPath: string, claimsDefaultsPath: string, org: string, filters: string[], provider?: AllowedProviders): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ImportInitializer, UUIDInitializer, NameNormalizer, InitializerClaimRef } from 'cdk8s_renderer';
1
+ import { ImportInitializer, UUIDInitializer, NameNormalizer, InitializerClaimRef, InitializerDefault } from 'cdk8s_renderer';
2
2
  export default class Decanter {
3
3
  data: any;
4
4
  claimKind: string | undefined;
@@ -78,4 +78,5 @@ export default class Decanter {
78
78
  normalizers: NameNormalizer[];
79
79
  };
80
80
  }>;
81
+ __loadInitializer(initDefaultPath: string, isAbsolute?: boolean): Promise<InitializerDefault>;
81
82
  }
@@ -1,9 +1,8 @@
1
1
  import { GithubDecanter } from './base';
2
- import { InitializerDefault } from 'cdk8s_renderer';
3
2
  export default class MemberGithubDecanter extends GithubDecanter {
4
3
  claimKind: string;
5
4
  __decantStart(): void;
6
5
  __gatherRoleInOrg(): Promise<void>;
7
6
  __decantProviders(): void;
8
- __adaptInitializerBase(_claim: any): Promise<InitializerDefault>;
7
+ __adaptInitializerBase(_claim: any): Promise<import("../../../../cdk8s_renderer").InitializerDefault>;
9
8
  }
@@ -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.50.1-snapshot-43",
3
+ "version": "1.50.1-snapshot-44",
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>;