@firestartr/cli 1.57.1-snapshot-2 → 1.58.0

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
@@ -346496,6 +346496,23 @@ function removeRepeatedObjectsFromArrayByProp(array, propiedad) {
346496
346496
  return array.filter((item) => uniqueSet.has(item[propiedad]));
346497
346497
  }
346498
346498
 
346499
+ ;// CONCATENATED MODULE: ../catalog_common/src/generic/command_error.ts
346500
+ function buildCommandExecutionError(output, exitCode, command, opts = {}) {
346501
+ const label = opts.label ?? 'Command';
346502
+ const errorName = opts.errorName ?? 'CommandExecutionError';
346503
+ const message = output ||
346504
+ `${label} '${command.join(' ')}' failed with exit code ${exitCode}`;
346505
+ return Object.assign(new Error(message), {
346506
+ name: errorName,
346507
+ output,
346508
+ exitCode,
346509
+ command,
346510
+ });
346511
+ }
346512
+ function normalizeExitCode(code) {
346513
+ return typeof code === 'number' ? code : -1;
346514
+ }
346515
+
346499
346516
  ;// CONCATENATED MODULE: ../catalog_common/src/generic/index.ts
346500
346517
 
346501
346518
 
@@ -346506,6 +346523,7 @@ function removeRepeatedObjectsFromArrayByProp(array, propiedad) {
346506
346523
 
346507
346524
 
346508
346525
 
346526
+
346509
346527
  /* harmony default export */ const generic = ({
346510
346528
  randomString: randomString,
346511
346529
  shuffleArray: shuffleArray,
@@ -346523,6 +346541,8 @@ function removeRepeatedObjectsFromArrayByProp(array, propiedad) {
346523
346541
  getFirestartrLabel: getFirestartrLabel,
346524
346542
  normalizeLabel: normalizeLabel,
346525
346543
  removeRepeatedObjectsFromArrayByProp: removeRepeatedObjectsFromArrayByProp,
346544
+ buildCommandExecutionError: buildCommandExecutionError,
346545
+ normalizeExitCode: normalizeExitCode,
346526
346546
  toMd5: toMd5,
346527
346547
  });
346528
346548
 
@@ -357883,6 +357903,11 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
357883
357903
  OwnerReference: {
357884
357904
  $id: 'firestartr.dev://common/FirestartrOwnerRef',
357885
357905
  type: 'string',
357906
+ pattern: '^(user|group):([a-z0-9]([a-z0-9._-]*[a-z0-9])?/)?[a-z0-9]([a-z0-9._-]*[a-z0-9])?$',
357907
+ },
357908
+ MaintainerReference: {
357909
+ $id: 'firestartr.dev://common/FirestartrMaintainerRef',
357910
+ type: 'string',
357886
357911
  pattern: '^(user|group|collaborator):([a-z0-9]([a-z0-9._-]*[a-z0-9])?/)?[a-z0-9]([a-z0-9._-]*[a-z0-9])?$',
357887
357912
  },
357888
357913
  Annotations: {
@@ -357988,7 +358013,7 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
357988
358013
  maintainedBy: {
357989
358014
  type: 'array',
357990
358015
  items: {
357991
- $ref: 'firestartr.dev://common/FirestartrOwnerRef',
358016
+ $ref: 'firestartr.dev://common/FirestartrMaintainerRef',
357992
358017
  },
357993
358018
  },
357994
358019
  platformOwner: {
@@ -358156,6 +358181,9 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358156
358181
  type: 'object',
358157
358182
  properties: {
358158
358183
  system: { $ref: 'firestartr.dev://common/FirestartrSystemRef' },
358184
+ owner: {
358185
+ $ref: 'firestartr.dev://common/FirestartrOwnerRef',
358186
+ },
358159
358187
  providers: {
358160
358188
  type: 'object',
358161
358189
  properties: {
@@ -358166,6 +358194,7 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358166
358194
  required: ['external_secrets'],
358167
358195
  },
358168
358196
  },
358197
+ required: ['owner'],
358169
358198
  },
358170
358199
  ],
358171
358200
  },
@@ -358188,6 +358217,12 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358188
358217
  {
358189
358218
  type: 'object',
358190
358219
  properties: {
358220
+ system: {
358221
+ $ref: 'firestartr.dev://common/FirestartrSystemRef',
358222
+ },
358223
+ owner: {
358224
+ $ref: 'firestartr.dev://common/FirestartrOwnerRef',
358225
+ },
358191
358226
  providers: {
358192
358227
  type: 'object',
358193
358228
  properties: {
@@ -358197,6 +358232,7 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358197
358232
  },
358198
358233
  },
358199
358234
  },
358235
+ required: ['owner'],
358200
358236
  },
358201
358237
  ],
358202
358238
  },
@@ -365175,7 +365211,11 @@ class CatalogOrgWebhookChart extends BaseCatalogChart {
365175
365211
  name: catalog_common.generic.normalizeName(`orgWebhook-${claim.name}`),
365176
365212
  annotations: claim.annotations || {},
365177
365213
  },
365178
- spec: {},
365214
+ spec: {
365215
+ type: 'webhook',
365216
+ owner: claim.owner || 'nobody',
365217
+ system: claim.system,
365218
+ },
365179
365219
  };
365180
365220
  }
365181
365221
  instanceApiObject(template) {
@@ -367853,14 +367893,22 @@ async function upsertFinalizer(kind, namespace, item, finalizer) {
367853
367893
  */
367854
367894
  async function unsetFinalizer(kind, namespace, item, finalizer) {
367855
367895
  const { kc, opts } = await ctl_getConnection();
367856
- const name = typeof item === 'string' ? item : item.metadata.name;
367896
+ let itemObj;
367897
+ if (typeof item === 'string') {
367898
+ itemObj = await getItemByItemPath([namespace, kind, item].join('/'));
367899
+ }
367900
+ else {
367901
+ itemObj = item;
367902
+ }
367903
+ const name = itemObj.metadata.name;
367857
367904
  operator_src_logger.debug(`The ctl is removing the finalizer '${finalizer}' from '${kind}/${name}' in namespace '${namespace}'.`);
367858
367905
  const url = `${kc.getCurrentCluster().server}/apis/firestartr.dev/v1/namespaces/${namespace}/${kind}/${name}`;
367859
367906
  opts.headers['Content-Type'] = 'application/json-patch+json';
367860
367907
  opts.headers['Accept'] = '*';
367861
367908
  const patch = {
367862
- op: 'remove',
367909
+ op: 'replace',
367863
367910
  path: '/metadata/finalizers',
367911
+ value: itemObj.metadata.finalizers.filter((f) => f !== finalizer),
367864
367912
  };
367865
367913
  const r = await fetch(url, {
367866
367914
  method: 'PATCH',
@@ -369026,12 +369074,25 @@ function enqueue(pluralKind, workItem, queue, compute, syncCtl, retryCtl) {
369026
369074
  itemPath: () => informer_itemPath(pluralKind, workItem.item),
369027
369075
  error: () => retryCtl.errorReconciling(informer_itemPath(pluralKind, workItem.item)),
369028
369076
  success: () => retryCtl.successReconciling(informer_itemPath(pluralKind, workItem.item)),
369029
- needsBlocking: (item) => {
369077
+ needsBlocking: (item, operation) => {
369030
369078
  if (kindsWithDependants.indexOf(item.kind) === -1) {
369031
369079
  return false;
369032
369080
  }
369081
+ // only for delete operations
369082
+ if (operation !== OperationType.MARKED_TO_DELETION) {
369083
+ if (operation === OperationType.RETRY) {
369084
+ // is the retry a delete operation?
369085
+ if (!('deletionTimestamp' in workItem.item.metadata)) {
369086
+ return false;
369087
+ }
369088
+ }
369089
+ else {
369090
+ return false;
369091
+ }
369092
+ }
369033
369093
  if (item.metadata.finalizers &&
369034
- item.metadata.finalizers.indexOf('foregroundDeletion') !== -1) {
369094
+ (item.metadata.finalizers.indexOf('foregroundDeletion') !== -1 ||
369095
+ item.metadata.finalizers.indexOf('firestartr.dev/foreground-deletion') !== -1)) {
369035
369096
  // it will block for five seconds
369036
369097
  workItem.isBlocked = true;
369037
369098
  const tTimeout = setTimeout(() => {
@@ -369312,7 +369373,7 @@ function dummy_fWait(ms) {
369312
369373
  async function getOwnerReferences(item) {
369313
369374
  return item.metadata?.ownerReferences || [];
369314
369375
  }
369315
- async function setOwnerReference(itemPath, namespace, ownerKind, ownerName, blockOwnerDeletion = true) {
369376
+ async function ownership_setOwnerReference(itemPath, namespace, ownerKind, ownerName, blockOwnerDeletion = true) {
369316
369377
  let item = null;
369317
369378
  try {
369318
369379
  // we need to search for the owner's uuid
@@ -369412,7 +369473,7 @@ async function* created(item, op, handler) {
369412
369473
  async function handleOwnerReferences(item, handler) {
369413
369474
  if ('needs' in item.spec) {
369414
369475
  const needs = item.spec.needs;
369415
- await setOwnerReference(handler.itemPath(), item.metadata.namespace, definitions_getPluralFromKind(needs.kind), needs.name);
369476
+ await ownership_setOwnerReference(handler.itemPath(), item.metadata.namespace, definitions_getPluralFromKind(needs.kind), needs.name);
369416
369477
  }
369417
369478
  }
369418
369479
  async function renamed() {
@@ -369973,7 +370034,7 @@ async function runWorkItem(workItem) {
369973
370034
  // if it does need it we return because we cannot
369974
370035
  // process this item
369975
370036
  if ('needsBlocking' in workItem.handler &&
369976
- workItem.handler.needsBlocking(item)) {
370037
+ workItem.handler.needsBlocking(item, workItem.operation)) {
369977
370038
  operator_src_logger.debug(`Item ${item.kind}/${item.metadata.namespace} needs blocking`);
369978
370039
  return;
369979
370040
  }
@@ -371352,7 +371413,10 @@ async function runTerraform(entity, command, stream) {
371352
371413
  terraformProcess.on('exit', async (code) => {
371353
371414
  console.log(`child process exited with code ${code}`);
371354
371415
  if (code !== 0) {
371355
- ko(output);
371416
+ ko(catalog_common.generic.buildCommandExecutionError(output, catalog_common.generic.normalizeExitCode(code), command, {
371417
+ errorName: 'TerraformCommandError',
371418
+ label: 'Terraform command',
371419
+ }));
371356
371420
  }
371357
371421
  else {
371358
371422
  ok(output);
@@ -372015,7 +372079,7 @@ if (process.env.RUN_PROVISIONER) {
372015
372079
 
372016
372080
 
372017
372081
  const LAST_STATE_PR_ANNOTATION = 'firestartr.dev/last-state-pr';
372018
- async function tryPublishApply(item, planOutput, isSuccess = true) {
372082
+ async function tryPublishApply(item, planOutput, isSuccess = true, exitCode) {
372019
372083
  const kind = item.kind;
372020
372084
  const metadataName = item.metadata?.name ?? 'unknown';
372021
372085
  try {
@@ -372024,7 +372088,11 @@ async function tryPublishApply(item, planOutput, isSuccess = true) {
372024
372088
  operator_src_logger.debug(`The user feedback for the '${kind}/${metadataName}' apply operation could not be published because the last state was not found.`);
372025
372089
  return;
372026
372090
  }
372027
- await publishApply(item, planOutput, isSuccess);
372091
+ const effectiveSuccess = isSuccess && (exitCode === undefined || exitCode === 0);
372092
+ if (isSuccess && exitCode !== undefined && exitCode !== 0) {
372093
+ operator_src_logger.warn(`The user feedback for the '${kind}/${metadataName}' apply operation was downgraded to failure because terraform exited with code '${exitCode}'.`);
372094
+ }
372095
+ await publishApply(item, planOutput, effectiveSuccess);
372028
372096
  }
372029
372097
  catch (e) {
372030
372098
  operator_src_logger.error(`The user feedback for the '${kind}/${metadataName}' apply operation failed to publish due to an error: '${e}'.`);
@@ -372239,17 +372307,205 @@ function helperCreateCheckRunName(cmd, item) {
372239
372307
  return `${item.kind} - ${cmd}`;
372240
372308
  }
372241
372309
 
372310
+ ;// CONCATENATED MODULE: ../operator/src/utils/index.ts
372311
+ const secretRegex = /\$\{\{ secrets\.(.*?) \}\}/g;
372312
+ function isRecord(value) {
372313
+ return typeof value === 'object' && value !== null;
372314
+ }
372315
+ function getFirstNonEmptyString(...values) {
372316
+ return values.find((value) => typeof value === 'string' && value !== '');
372317
+ }
372318
+ function replaceConfigSecrets(config, secrets) {
372319
+ for (const key in config) {
372320
+ if (typeof config[key] === 'object' && config[key] !== null) {
372321
+ // If the property is an object, call this function recursively
372322
+ replaceConfigSecrets(config[key], secrets);
372323
+ }
372324
+ else if (typeof config[key] === 'string') {
372325
+ // If the property is a string and its value is equal to secrets.something,
372326
+ // replace the value with the value of the 'something' key in the secrets object
372327
+ config[key] = config[key].replace(secretRegex, (_, group1) => {
372328
+ if (!secrets[group1]) {
372329
+ throw new Error(`Secret ${group1} not found in secrets`);
372330
+ }
372331
+ return secrets[group1];
372332
+ });
372333
+ }
372334
+ }
372335
+ return config;
372336
+ }
372337
+ function replaceInlineSecrets(inline, secrets) {
372338
+ if (typeof inline !== 'string' || !inline)
372339
+ return inline;
372340
+ let result = inline;
372341
+ result = result.replace(secretRegex, (_, group1) => {
372342
+ if (!secrets[group1]) {
372343
+ throw new Error(`Secret ${group1} not found in secrets`);
372344
+ }
372345
+ return secrets[group1];
372346
+ });
372347
+ return result;
372348
+ }
372349
+ function extractErrorDetails(error) {
372350
+ const exitCode = isRecord(error) && typeof error.exitCode === 'number'
372351
+ ? error.exitCode
372352
+ : undefined;
372353
+ if (typeof error === 'string') {
372354
+ return { output: error, exitCode };
372355
+ }
372356
+ if (error instanceof Error) {
372357
+ const errorWithOutput = error;
372358
+ const output = getFirstNonEmptyString(errorWithOutput.output, error.message);
372359
+ return { output: output ?? String(error), exitCode };
372360
+ }
372361
+ if (isRecord(error)) {
372362
+ const output = getFirstNonEmptyString(error.output, error.message, error.error);
372363
+ if (output !== undefined) {
372364
+ return { output, exitCode };
372365
+ }
372366
+ try {
372367
+ return { output: JSON.stringify(error), exitCode };
372368
+ }
372369
+ catch {
372370
+ return { output: String(error), exitCode };
372371
+ }
372372
+ }
372373
+ return { output: String(error), exitCode };
372374
+ }
372375
+
372376
+ ;// CONCATENATED MODULE: ../operator/src/ctl_collections.ts
372377
+
372378
+
372379
+
372380
+ // generator function to traverse elements
372381
+ // it is async and iterable
372382
+ async function* traverseCRCollection(pluralKind, namespace, options = {}, apiGroup = 'firestartr.dev', apiVersion = 'v1') {
372383
+ const { limit = 300 } = options; // between 250-300
372384
+ try {
372385
+ let continueToken = undefined;
372386
+ const { kc, opts } = await ctl_getConnection();
372387
+ const k8sApi = kc.makeApiClient(client_node_dist.CustomObjectsApi);
372388
+ const apiGroup = 'firestartr.dev';
372389
+ const apiVersion = 'v1';
372390
+ const apiPaths = `/apis/${apiGroup}/${apiVersion}/namespaces/${namespace}/${pluralKind}`;
372391
+ do {
372392
+ const res = await k8sApi.listNamespacedCustomObject(apiGroup, apiVersion, namespace, pluralKind, undefined, // pretty
372393
+ undefined, // allowWatchBookmarks
372394
+ continueToken, // _continue
372395
+ undefined, // fieldSelector
372396
+ undefined, // labelSelector
372397
+ limit);
372398
+ const body = res.body;
372399
+ const items = body.items || [];
372400
+ for (const item of items) {
372401
+ yield item;
372402
+ }
372403
+ continueToken = body.metadata?.continue;
372404
+ } while (continueToken);
372405
+ }
372406
+ catch (err) {
372407
+ operator_src_logger.error(`Error traversing ${namespace}/${pluralKind}: ${err}`);
372408
+ throw new Error(`Error traversing ${namespace}/${pluralKind}: ${err}`);
372409
+ }
372410
+ }
372411
+
372412
+ ;// CONCATENATED MODULE: ../operator/src/children.ts
372413
+
372414
+
372415
+ async function findCRsWithReference(kind, item) {
372416
+ try {
372417
+ const crChildren = [];
372418
+ for await (const crItem of traverseCRCollection(kind, item.metadata.namespace)) {
372419
+ if ('repositoryTarget' in crItem.spec) {
372420
+ const repositoryTarget = crItem.spec.repositoryTarget;
372421
+ if (repositoryTarget.ref.name === item.metadata.name &&
372422
+ repositoryTarget.ref.kind === item.kind) {
372423
+ crChildren.push(crItem);
372424
+ }
372425
+ }
372426
+ }
372427
+ return crChildren;
372428
+ }
372429
+ catch (err) {
372430
+ operator_src_logger.error(`Error finding Crs with reference for ${item.kind}/${item.metadata.name}: ${err}`);
372431
+ throw new Error(`Error finding Crs with reference for ${item.kind}/${item.metadata.name}: ${err}`);
372432
+ }
372433
+ }
372434
+
372242
372435
  ;// CONCATENATED MODULE: ../operator/src/cdktf/ownership.ts
372243
372436
 
372244
372437
 
372245
372438
 
372439
+
372440
+
372246
372441
  const kindsWithFirestartrGithubRepositoryDependence = [
372247
372442
  'FirestartrGithubRepositorySecretsSection',
372248
372443
  'FirestartrGithubRepositoryFeature',
372249
372444
  ];
372445
+ const kindsWithChildren = ['FirestartrGithubRepository'];
372250
372446
  async function manageOwnershipReferences(item, handler, op) {
372447
+ /*********************************************************************************
372448
+ // suspended due to https://github.com/prefapp/gitops-k8s/issues/1767
372449
+ if (kindsWithFirestartrGithubRepositoryDependence.indexOf(item.kind) !== -1) {
372450
+ // await manageOwnershipReferencesForRepo(item, handler, op);
372451
+
372452
+ }
372453
+ *******************************************************************************/
372454
+ if (kindsWithFirestartrGithubRepositoryDependence.indexOf(item.kind) !== -1) {
372455
+ // we need the parent
372456
+ const parentItem = await getItemByItemPath([
372457
+ item.metadata.namespace,
372458
+ definitions_getPluralFromKind('FirestartrGithubRepository'),
372459
+ item.spec.repositoryTarget.ref.name,
372460
+ ].join('/'));
372461
+ await installDependencesFinalizer(parentItem, handler, op);
372462
+ }
372463
+ }
372464
+ async function manageOwnershipReferencesPostDeletion(item, handler, op) {
372465
+ // We will check if the repo has still some references left
372251
372466
  if (kindsWithFirestartrGithubRepositoryDependence.indexOf(item.kind) !== -1) {
372252
- await manageOwnershipReferencesForRepo(item, handler, op);
372467
+ await manageChildrenReferences(item, handler, op);
372468
+ }
372469
+ // if the parent is being deleted is ok to control there are no more children
372470
+ // for preventing a stuck deletion
372471
+ else if (kindsWithChildren.indexOf(item.kind) !== -1) {
372472
+ await removeFinalizerIfNoMoreChildren(item, handler, op);
372473
+ }
372474
+ }
372475
+ async function manageChildrenReferences(item, handler, op) {
372476
+ // for now is only FirestartrGithubRepository
372477
+ const parentItem = await getItemByItemPath([
372478
+ item.metadata.namespace,
372479
+ definitions_getPluralFromKind('FirestartrGithubRepository'),
372480
+ item.spec.repositoryTarget.ref.name,
372481
+ ].join('/'));
372482
+ await removeFinalizerIfNoMoreChildren(parentItem, handler, op);
372483
+ }
372484
+ async function removeFinalizerIfNoMoreChildren(parentItem, handler, op) {
372485
+ try {
372486
+ let numberOfChildren = 0;
372487
+ for (const child of kindsWithFirestartrGithubRepositoryDependence) {
372488
+ const children = await findCRsWithReference(definitions_getPluralFromKind(child), parentItem);
372489
+ numberOfChildren += children.length;
372490
+ }
372491
+ operator_src_logger.error(`Number of children ${numberOfChildren}`);
372492
+ if (numberOfChildren === 0) {
372493
+ operator_src_logger.info(`${parentItem.kind}/${parentItem.metadata.name} has no more children. Removing finalizer of foreground-deletion`);
372494
+ await unsetFinalizer(definitions_getPluralFromKind(parentItem.kind), parentItem.metadata.namespace, parentItem, 'firestartr.dev/foreground-deletion');
372495
+ }
372496
+ }
372497
+ catch (err) {
372498
+ operator_src_logger.error(`Error managing children references in item: ${parentItem.kind}/${parentItem.metadata.name}: ${err}`);
372499
+ throw new Error(`Error managing children references in item: ${parentItem.kind}/${parentItem.metadata.name}: ${err}`);
372500
+ }
372501
+ }
372502
+ async function installDependencesFinalizer(item, handler, op) {
372503
+ try {
372504
+ await upsertFinalizer(definitions_getPluralFromKind(item.kind), item.metadata.namespace, item, 'firestartr.dev/foreground-deletion');
372505
+ }
372506
+ catch (err) {
372507
+ operator_src_logger.error(`Error inserting finalizer for children dependencies ${item.kind}/${item.metadata.name}`);
372508
+ throw new Error(`Error inserting finalizer for children dependencies ${item.kind}/${item.metadata.name}`);
372253
372509
  }
372254
372510
  }
372255
372511
  async function manageOwnershipReferencesForRepo(item, handler, op) {
@@ -372258,10 +372514,10 @@ async function manageOwnershipReferencesForRepo(item, handler, op) {
372258
372514
  if (!repositoryTarget) {
372259
372515
  throw `Item ${item.kind}/${item.metadata.namespace} is not correct: it does not have a repositoryTarget`;
372260
372516
  }
372261
- await setOwnerReference(handler.itemPath(), item.metadata.namespace, definitions_getPluralFromKind(repositoryTarget.kind), repositoryTarget.name);
372517
+ await setOwnerReference(handler.itemPath(), item.metadata.namespace, getPluralFromKind(repositoryTarget.kind), repositoryTarget.name);
372262
372518
  }
372263
372519
  catch (err) {
372264
- operator_src_logger.error(`Handling ownership for ${item.kind}/${item.metadata.name}: ${err}`);
372520
+ log.error(`Handling ownership for ${item.kind}/${item.metadata.name}: ${err}`);
372265
372521
  throw new Error(`Handling ownership for ${item.kind}/${item.metadata.name}: ${err}`);
372266
372522
  }
372267
372523
  }
@@ -372277,6 +372533,7 @@ async function manageOwnershipReferencesForRepo(item, handler, op) {
372277
372533
 
372278
372534
 
372279
372535
 
372536
+
372280
372537
  function processOperation(item, op, handler) {
372281
372538
  operator_src_logger.info(`Processing operation ${op} on ${item.kind}/${item.metadata?.name}`);
372282
372539
  try {
@@ -372429,17 +372686,12 @@ async function* cdktf_markedToDeletion(item, op, handler) {
372429
372686
  await addDestroyCommitStatus(item, 'success', 'Destroy operation completed', `Terraform Destroy ${item.metadata.name}`);
372430
372687
  }
372431
372688
  await tryPublishDestroy(item, output, true);
372689
+ await manageOwnershipReferencesPostDeletion(item, handler, op);
372432
372690
  void handler.success();
372433
372691
  }
372434
372692
  catch (e) {
372435
372693
  error = true;
372436
- let errorMsg;
372437
- if (typeof e === 'object' && 'output' in e) {
372438
- errorMsg = e.output;
372439
- }
372440
- else {
372441
- errorMsg = e;
372442
- }
372694
+ const { output: errorMsg } = extractErrorDetails(e);
372443
372695
  // if there is a current checkRun working
372444
372696
  // we close it with an error
372445
372697
  if (checkRunCtl)
@@ -372584,19 +372836,13 @@ async function* doApply(item, op, handler) {
372584
372836
  message: 'doApply',
372585
372837
  };
372586
372838
  await handler.writeTerraformOutputInTfResult(item, output);
372587
- await tryPublishApply(item, applyOutput?.data?.output, true);
372839
+ await tryPublishApply(item, applyOutput?.data?.output, true, 0);
372588
372840
  void handler.success();
372589
372841
  }
372590
372842
  catch (e) {
372591
372843
  error = true;
372592
- let errorMsg;
372593
- if (typeof e === 'object' && 'output' in e) {
372594
- errorMsg = e.output;
372595
- }
372596
- else {
372597
- errorMsg = e;
372598
- }
372599
- await tryPublishApply(item, errorMsg, false);
372844
+ const { output: errorMsg, exitCode } = extractErrorDetails(e);
372845
+ await tryPublishApply(item, errorMsg, false, exitCode);
372600
372846
  // if there is a current checkRun working
372601
372847
  // we close it with an error
372602
372848
  if (checkRunCtl)
@@ -372819,7 +373065,10 @@ async function tfExec(path, args, secrets, extraArgs = ['-input=false'], stream)
372819
373065
  if (code !== 0) {
372820
373066
  terraform_provisioner_src_logger.error(`Terraform output ${path}: ${output + outputErrors}`);
372821
373067
  terraform_provisioner_src_logger.error(`Terraform output ${path}: ${[output, outputErrors].join('')}`);
372822
- ko([output, outputErrors].join(''));
373068
+ ko(catalog_common.generic.buildCommandExecutionError([output, outputErrors].join(''), catalog_common.generic.normalizeExitCode(code), args.concat(extraArgs), {
373069
+ errorName: 'TerraformCommandError',
373070
+ label: 'Terraform command',
373071
+ }));
372823
373072
  }
372824
373073
  else {
372825
373074
  terraform_provisioner_src_logger.info(`Terraform output ${path}: ${output}`);
@@ -373762,40 +374011,6 @@ function tf_checkrun_helperCreateCheckRunName(cmd) {
373762
374011
  return `TFWorkspace - ${cmd}`;
373763
374012
  }
373764
374013
 
373765
- ;// CONCATENATED MODULE: ../operator/src/utils/index.ts
373766
- const secretRegex = /\$\{\{ secrets\.(.*?) \}\}/g;
373767
- function replaceConfigSecrets(config, secrets) {
373768
- for (const key in config) {
373769
- if (typeof config[key] === 'object' && config[key] !== null) {
373770
- // If the property is an object, call this function recursively
373771
- replaceConfigSecrets(config[key], secrets);
373772
- }
373773
- else if (typeof config[key] === 'string') {
373774
- // If the property is a string and its value is equal to secrets.something,
373775
- // replace the value with the value of the 'something' key in the secrets object
373776
- config[key] = config[key].replace(secretRegex, (_, group1) => {
373777
- if (!secrets[group1]) {
373778
- throw new Error(`Secret ${group1} not found in secrets`);
373779
- }
373780
- return secrets[group1];
373781
- });
373782
- }
373783
- }
373784
- return config;
373785
- }
373786
- function replaceInlineSecrets(inline, secrets) {
373787
- if (typeof inline !== 'string' || !inline)
373788
- return inline;
373789
- let result = inline;
373790
- result = result.replace(secretRegex, (_, group1) => {
373791
- if (!secrets[group1]) {
373792
- throw new Error(`Secret ${group1} not found in secrets`);
373793
- }
373794
- return secrets[group1];
373795
- });
373796
- return result;
373797
- }
373798
-
373799
374014
  ;// CONCATENATED MODULE: ../operator/src/tfworkspaces/process-operation.ts
373800
374015
 
373801
374016
 
@@ -373939,15 +374154,16 @@ async function* doPlanJSONFormat(item, op, handler, setResult = function (_r) {
373939
374154
  }
373940
374155
  catch (e) {
373941
374156
  error = true;
374157
+ const { output: errorMsg } = extractErrorDetails(e);
373942
374158
  console.error(e);
373943
- operator_src_logger.error(`The Terraform processor encountered an error while observing the plan for item '${item.kind}/${item.metadata.name}': '${e}'.`);
373944
- const summaryText = tryCreateErrorSummary('Terraform Plan failed', e);
374159
+ operator_src_logger.error(`The Terraform processor encountered an error while observing the plan for item '${item.kind}/${item.metadata.name}': '${errorMsg}'.`);
374160
+ const summaryText = tryCreateErrorSummary('Terraform Plan failed', errorMsg);
373945
374161
  if (item.metadata.annotations['firestartr.dev/last-state-pr'] || false) {
373946
374162
  await addPlanStatusCheck(item.metadata.annotations['firestartr.dev/last-state-pr'], summaryText, 'completed', true);
373947
374163
  }
373948
374164
  void handler.error();
373949
- if (e) {
373950
- await handler.writeTerraformOutputInTfResult(item, e);
374165
+ if (errorMsg) {
374166
+ await handler.writeTerraformOutputInTfResult(item, errorMsg);
373951
374167
  }
373952
374168
  }
373953
374169
  finally {
@@ -374196,13 +374412,7 @@ async function* process_operation_markedToDeletion(item, op, handler) {
374196
374412
  }
374197
374413
  catch (e) {
374198
374414
  error = true;
374199
- let errorMsg;
374200
- if (typeof e === 'object' && 'output' in e) {
374201
- errorMsg = e.output;
374202
- }
374203
- else {
374204
- errorMsg = e;
374205
- }
374415
+ const { output: errorMsg } = extractErrorDetails(e);
374206
374416
  await tryPublishDestroy(item, errorMsg, false);
374207
374417
  await handler.writeTerraformOutputInTfResult(item, errorMsg);
374208
374418
  if (item.metadata.annotations['firestartr.dev/last-state-pr'] || false) {
@@ -374319,21 +374529,15 @@ async function* process_operation_doApply(item, op, handler) {
374319
374529
  message: 'doApply',
374320
374530
  };
374321
374531
  await handler.writeTerraformOutputInTfResult(item, output);
374322
- await tryPublishApply(item, applyOutput, true);
374532
+ await tryPublishApply(item, applyOutput, true, 0);
374323
374533
  handler.success();
374324
374534
  }
374325
374535
  catch (e) {
374326
374536
  error = true;
374327
- let errorMsg;
374328
- if (typeof e === 'object' && 'output' in e) {
374329
- errorMsg = e.output;
374330
- }
374331
- else {
374332
- errorMsg = e;
374333
- }
374537
+ const { output: errorMsg, exitCode } = extractErrorDetails(e);
374334
374538
  checkRunCtl.fnOnError(errorMsg);
374335
374539
  console.error(e);
374336
- await tryPublishApply(item, errorMsg, false);
374540
+ await tryPublishApply(item, errorMsg, false, exitCode);
374337
374541
  operator_src_logger.error(`The Terraform processor encountered an error during operation '${op}' for item '${item.kind}/${item.metadata.name}': '${e}'.`);
374338
374542
  handler.error();
374339
374543
  if (errorMsg) {
@@ -374831,18 +375035,19 @@ async function* doPlanPlainTextFormat(item, op, handler, action) {
374831
375035
  }
374832
375036
  catch (e) {
374833
375037
  error = true;
375038
+ const { output: errorMsg } = extractErrorDetails(e);
374834
375039
  const { prNumber, repo, org } = extractPrInfo(item, 'firestartr.dev/pull-request-plan');
374835
- await publishPlan(item, JSON.stringify(e), prNumber, repo, org, false);
375040
+ await publishPlan(item, errorMsg, prNumber, repo, org, false);
374836
375041
  operator_src_logger.error('TFWORKSPACE_PROCESSOR_PLAN_OBSERVING_ERROR', {
374837
375042
  metadata: { item, error: e },
374838
375043
  });
374839
- const summaryText = tryCreateErrorSummary('Terraform Plan failed', e);
375044
+ const summaryText = tryCreateErrorSummary('Terraform Plan failed', errorMsg);
374840
375045
  if (item.metadata.annotations['firestartr.dev/last-state-pr'] || false) {
374841
375046
  await addPlanStatusCheck(item.metadata.annotations['firestartr.dev/last-state-pr'], summaryText, 'completed', true);
374842
375047
  }
374843
375048
  void handler.error();
374844
- if (e) {
374845
- await handler.writeTerraformOutputInTfResult(item, e);
375049
+ if (errorMsg) {
375050
+ await handler.writeTerraformOutputInTfResult(item, errorMsg);
374846
375051
  }
374847
375052
  }
374848
375053
  finally {
@@ -374956,13 +375161,14 @@ async function* processOperationPlan_doPlanJSONFormat(item, op, handler, action)
374956
375161
  }
374957
375162
  catch (e) {
374958
375163
  error = true;
375164
+ const { output: errorMsg } = extractErrorDetails(e);
374959
375165
  console.error(e);
374960
375166
  operator_src_logger.error('TFWORKSPACE_PROCESSOR_PLAN_DO_PLAN_ERROR', {
374961
375167
  metadata: { item, error: e },
374962
375168
  });
374963
375169
  void handler.error();
374964
- if (e) {
374965
- await handler.writeTerraformOutputInTfResult(item, e);
375170
+ if (errorMsg) {
375171
+ await handler.writeTerraformOutputInTfResult(item, errorMsg);
374966
375172
  }
374967
375173
  }
374968
375174
  finally {
@@ -375374,6 +375580,7 @@ function waitForFile(filePath) {
375374
375580
 
375375
375581
 
375376
375582
 
375583
+
375377
375584
  var FileStatus;
375378
375585
  (function (FileStatus) {
375379
375586
  FileStatus["DELETED"] = "removed";
@@ -375431,16 +375638,7 @@ async function tfWorkspacePlan(opts) {
375431
375638
  }
375432
375639
  catch (e) {
375433
375640
  console.error(e);
375434
- let message = '';
375435
- if (e && typeof e === 'string') {
375436
- message = e;
375437
- }
375438
- else if (e && typeof e === 'object' && e.message) {
375439
- message = e.message;
375440
- }
375441
- else {
375442
- message = 'An unknown error occurred';
375443
- }
375641
+ const { output: message } = extractErrorDetails(e);
375444
375642
  fDebug(`Error: ${message}`, 'error');
375445
375643
  await addPlanStatusCheck(pull, message, 'completed', true);
375446
375644
  fDebug('Publishing plan');
@@ -376439,9 +376637,9 @@ const crs_analyzerSubcommand = {
376439
376637
  };
376440
376638
 
376441
376639
  ;// CONCATENATED MODULE: ./package.json
376442
- const package_namespaceObject = JSON.parse('{"i8":"1.57.1-snapshot-2"}');
376640
+ const package_namespaceObject = {"i8":"1.58.0"};
376443
376641
  ;// CONCATENATED MODULE: ../../package.json
376444
- const package_namespaceObject_1 = {"i8":"1.57.0"};
376642
+ const package_namespaceObject_1 = {"i8":"1.58.0"};
376445
376643
  ;// CONCATENATED MODULE: ./src/subcommands/index.ts
376446
376644
 
376447
376645
 
@@ -39,6 +39,8 @@ declare const _default: {
39
39
  getFirestartrLabel: typeof import("./src/generic/labels").getFirestartrLabel;
40
40
  normalizeLabel: typeof import("./src/generic/labels").normalizeLabel;
41
41
  removeRepeatedObjectsFromArrayByProp: typeof import("./src/generic/arrays").removeRepeatedObjectsFromArrayByProp;
42
+ buildCommandExecutionError: typeof import("./src/generic/command_error").buildCommandExecutionError;
43
+ normalizeExitCode: typeof import("./src/generic/command_error").normalizeExitCode;
42
44
  toMd5: typeof import("./src/generic/nomicon").toMd5;
43
45
  };
44
46
  types: {
@@ -0,0 +1,10 @@
1
+ export declare function buildCommandExecutionError(output: string, exitCode: number, command: Array<string>, opts?: {
2
+ errorName?: string;
3
+ label?: string;
4
+ }): Error & {
5
+ name: string;
6
+ output: string;
7
+ exitCode: number;
8
+ command: string[];
9
+ };
10
+ export declare function normalizeExitCode(code: number | null): number;
@@ -7,6 +7,7 @@ import { normalizeName, transformKeysToCamelCase } from './name';
7
7
  import { getFirestartrAnnotation, getOwnerRepoPrNumberFromAnnotationValue, getPrLinkFromAnnotationValue } from './annotations';
8
8
  import { getFirestartrLabel, normalizeLabel } from './labels';
9
9
  import { removeRepeatedObjectsFromArrayByProp } from './arrays';
10
+ import { buildCommandExecutionError, normalizeExitCode } from './command_error';
10
11
  declare const _default: {
11
12
  randomString: typeof randomString;
12
13
  shuffleArray: typeof shuffleArray;
@@ -24,6 +25,8 @@ declare const _default: {
24
25
  getFirestartrLabel: typeof getFirestartrLabel;
25
26
  normalizeLabel: typeof normalizeLabel;
26
27
  removeRepeatedObjectsFromArrayByProp: typeof removeRepeatedObjectsFromArrayByProp;
28
+ buildCommandExecutionError: typeof buildCommandExecutionError;
29
+ normalizeExitCode: typeof normalizeExitCode;
27
30
  toMd5: typeof toMd5;
28
31
  };
29
32
  export default _default;
@@ -10,7 +10,11 @@ export declare class CatalogOrgWebhookChart extends BaseCatalogChart {
10
10
  [key: string]: string;
11
11
  };
12
12
  };
13
- spec: {};
13
+ spec: {
14
+ type: string;
15
+ owner: string;
16
+ system: string;
17
+ };
14
18
  };
15
19
  instanceApiObject(template: any): ApiObject;
16
20
  gvk(): GroupVersionKind;
@@ -2,6 +2,8 @@ import { IClaim } from '../base';
2
2
  export interface IOrgWebhookClaim extends IClaim {
3
3
  org: string;
4
4
  displayName: string;
5
+ system?: string;
6
+ owner: string;
5
7
  providers: object;
6
8
  }
7
9
  export declare const schema = "firestartr.dev://common/OrgWebhookClaim";
@@ -98,6 +98,11 @@ declare const _default: {
98
98
  type: string;
99
99
  pattern: string;
100
100
  };
101
+ MaintainerReference: {
102
+ $id: string;
103
+ type: string;
104
+ pattern: string;
105
+ };
101
106
  Annotations: {
102
107
  $id: string;
103
108
  type: string;
@@ -102,6 +102,11 @@ declare const schemas: {
102
102
  type: string;
103
103
  pattern: string;
104
104
  };
105
+ MaintainerReference: {
106
+ $id: string;
107
+ type: string;
108
+ pattern: string;
109
+ };
105
110
  Annotations: {
106
111
  $id: string;
107
112
  type: string;
@@ -1040,12 +1045,16 @@ declare const schemas: {
1040
1045
  $ref: string;
1041
1046
  type?: undefined;
1042
1047
  properties?: undefined;
1048
+ required?: undefined;
1043
1049
  } | {
1044
1050
  type: string;
1045
1051
  properties: {
1046
1052
  system: {
1047
1053
  $ref: string;
1048
1054
  };
1055
+ owner: {
1056
+ $ref: string;
1057
+ };
1049
1058
  providers: {
1050
1059
  type: string;
1051
1060
  properties: {
@@ -1056,6 +1065,7 @@ declare const schemas: {
1056
1065
  required: string[];
1057
1066
  };
1058
1067
  };
1068
+ required: string[];
1059
1069
  $ref?: undefined;
1060
1070
  })[];
1061
1071
  };
@@ -1073,9 +1083,16 @@ declare const schemas: {
1073
1083
  $ref: string;
1074
1084
  type?: undefined;
1075
1085
  properties?: undefined;
1086
+ required?: undefined;
1076
1087
  } | {
1077
1088
  type: string;
1078
1089
  properties: {
1090
+ system: {
1091
+ $ref: string;
1092
+ };
1093
+ owner: {
1094
+ $ref: string;
1095
+ };
1079
1096
  providers: {
1080
1097
  type: string;
1081
1098
  properties: {
@@ -1085,6 +1102,7 @@ declare const schemas: {
1085
1102
  };
1086
1103
  };
1087
1104
  };
1105
+ required: string[];
1088
1106
  $ref?: undefined;
1089
1107
  })[];
1090
1108
  };
@@ -11,9 +11,16 @@ declare const _default: {
11
11
  $ref: string;
12
12
  type?: undefined;
13
13
  properties?: undefined;
14
+ required?: undefined;
14
15
  } | {
15
16
  type: string;
16
17
  properties: {
18
+ system: {
19
+ $ref: string;
20
+ };
21
+ owner: {
22
+ $ref: string;
23
+ };
17
24
  providers: {
18
25
  type: string;
19
26
  properties: {
@@ -23,6 +30,7 @@ declare const _default: {
23
30
  };
24
31
  };
25
32
  };
33
+ required: string[];
26
34
  $ref?: undefined;
27
35
  })[];
28
36
  };
@@ -11,12 +11,16 @@ declare const _default: {
11
11
  $ref: string;
12
12
  type?: undefined;
13
13
  properties?: undefined;
14
+ required?: undefined;
14
15
  } | {
15
16
  type: string;
16
17
  properties: {
17
18
  system: {
18
19
  $ref: string;
19
20
  };
21
+ owner: {
22
+ $ref: string;
23
+ };
20
24
  providers: {
21
25
  type: string;
22
26
  properties: {
@@ -27,6 +31,7 @@ declare const _default: {
27
31
  required: string[];
28
32
  };
29
33
  };
34
+ required: string[];
30
35
  $ref?: undefined;
31
36
  })[];
32
37
  };
@@ -5,5 +5,6 @@ export interface ISecretsClaim extends IClaim {
5
5
  system: string;
6
6
  name: string;
7
7
  providers: any;
8
+ owner: `${string}:${string}`;
8
9
  }
9
10
  export declare const schema = "firestartr.dev://common/SecretsClaim";
@@ -1,2 +1,3 @@
1
1
  import { OperationType } from '../informer';
2
2
  export declare function manageOwnershipReferences(item: any, handler: any, op: OperationType): Promise<void>;
3
+ export declare function manageOwnershipReferencesPostDeletion(item: any, handler: any, op: OperationType): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function findCRsWithReference(kind: string, item: any): Promise<any[]>;
@@ -0,0 +1,3 @@
1
+ export declare function traverseCRCollection<T = any>(pluralKind: string, namespace: string, options?: {
2
+ limit?: number;
3
+ }, apiGroup?: string, apiVersion?: string): AsyncGenerator<T>;
@@ -48,7 +48,7 @@ export type WorkItemHandler = {
48
48
  error: ErrorFn;
49
49
  success: SuccessFn;
50
50
  isBlocked?: boolean;
51
- needsBlocking?: (item: any) => boolean;
51
+ needsBlocking?: (item: any, operation: OperationType) => boolean;
52
52
  fUnblock?: Function;
53
53
  };
54
54
  /**
@@ -1,4 +1,4 @@
1
- export declare function tryPublishApply(item: any, planOutput: string, isSuccess?: boolean): Promise<void>;
1
+ export declare function tryPublishApply(item: any, planOutput: string, isSuccess?: boolean, exitCode?: number): Promise<void>;
2
2
  export declare function tryPublishDestroy(item: any, destroyOutput: string, isSuccess?: boolean): Promise<void>;
3
3
  export declare function publishApply(item: any, applyOutput: string, isSuccess?: boolean): Promise<void>;
4
4
  export declare function tryCreateErrorSummary(title: string, errorMsg: string): string;
@@ -1,2 +1,6 @@
1
1
  export declare function replaceConfigSecrets(config: any, secrets: any): any;
2
2
  export declare function replaceInlineSecrets(inline: string, secrets: any): string;
3
+ export declare function extractErrorDetails(error: unknown): {
4
+ output: string;
5
+ exitCode?: number;
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firestartr/cli",
3
- "version": "1.57.1-snapshot-2",
3
+ "version": "1.58.0",
4
4
  "private": false,
5
5
  "description": "Commandline tool",
6
6
  "main": "build/main.js",