@firestartr/cli 1.57.1-snapshot-3 → 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
 
@@ -358161,6 +358181,9 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358161
358181
  type: 'object',
358162
358182
  properties: {
358163
358183
  system: { $ref: 'firestartr.dev://common/FirestartrSystemRef' },
358184
+ owner: {
358185
+ $ref: 'firestartr.dev://common/FirestartrOwnerRef',
358186
+ },
358164
358187
  providers: {
358165
358188
  type: 'object',
358166
358189
  properties: {
@@ -358171,6 +358194,7 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358171
358194
  required: ['external_secrets'],
358172
358195
  },
358173
358196
  },
358197
+ required: ['owner'],
358174
358198
  },
358175
358199
  ],
358176
358200
  },
@@ -358193,6 +358217,12 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358193
358217
  {
358194
358218
  type: 'object',
358195
358219
  properties: {
358220
+ system: {
358221
+ $ref: 'firestartr.dev://common/FirestartrSystemRef',
358222
+ },
358223
+ owner: {
358224
+ $ref: 'firestartr.dev://common/FirestartrOwnerRef',
358225
+ },
358196
358226
  providers: {
358197
358227
  type: 'object',
358198
358228
  properties: {
@@ -358202,6 +358232,7 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
358202
358232
  },
358203
358233
  },
358204
358234
  },
358235
+ required: ['owner'],
358205
358236
  },
358206
358237
  ],
358207
358238
  },
@@ -365180,7 +365211,11 @@ class CatalogOrgWebhookChart extends BaseCatalogChart {
365180
365211
  name: catalog_common.generic.normalizeName(`orgWebhook-${claim.name}`),
365181
365212
  annotations: claim.annotations || {},
365182
365213
  },
365183
- spec: {},
365214
+ spec: {
365215
+ type: 'webhook',
365216
+ owner: claim.owner || 'nobody',
365217
+ system: claim.system,
365218
+ },
365184
365219
  };
365185
365220
  }
365186
365221
  instanceApiObject(template) {
@@ -367858,14 +367893,22 @@ async function upsertFinalizer(kind, namespace, item, finalizer) {
367858
367893
  */
367859
367894
  async function unsetFinalizer(kind, namespace, item, finalizer) {
367860
367895
  const { kc, opts } = await ctl_getConnection();
367861
- 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;
367862
367904
  operator_src_logger.debug(`The ctl is removing the finalizer '${finalizer}' from '${kind}/${name}' in namespace '${namespace}'.`);
367863
367905
  const url = `${kc.getCurrentCluster().server}/apis/firestartr.dev/v1/namespaces/${namespace}/${kind}/${name}`;
367864
367906
  opts.headers['Content-Type'] = 'application/json-patch+json';
367865
367907
  opts.headers['Accept'] = '*';
367866
367908
  const patch = {
367867
- op: 'remove',
367909
+ op: 'replace',
367868
367910
  path: '/metadata/finalizers',
367911
+ value: itemObj.metadata.finalizers.filter((f) => f !== finalizer),
367869
367912
  };
367870
367913
  const r = await fetch(url, {
367871
367914
  method: 'PATCH',
@@ -369031,12 +369074,25 @@ function enqueue(pluralKind, workItem, queue, compute, syncCtl, retryCtl) {
369031
369074
  itemPath: () => informer_itemPath(pluralKind, workItem.item),
369032
369075
  error: () => retryCtl.errorReconciling(informer_itemPath(pluralKind, workItem.item)),
369033
369076
  success: () => retryCtl.successReconciling(informer_itemPath(pluralKind, workItem.item)),
369034
- needsBlocking: (item) => {
369077
+ needsBlocking: (item, operation) => {
369035
369078
  if (kindsWithDependants.indexOf(item.kind) === -1) {
369036
369079
  return false;
369037
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
+ }
369038
369093
  if (item.metadata.finalizers &&
369039
- item.metadata.finalizers.indexOf('foregroundDeletion') !== -1) {
369094
+ (item.metadata.finalizers.indexOf('foregroundDeletion') !== -1 ||
369095
+ item.metadata.finalizers.indexOf('firestartr.dev/foreground-deletion') !== -1)) {
369040
369096
  // it will block for five seconds
369041
369097
  workItem.isBlocked = true;
369042
369098
  const tTimeout = setTimeout(() => {
@@ -369317,7 +369373,7 @@ function dummy_fWait(ms) {
369317
369373
  async function getOwnerReferences(item) {
369318
369374
  return item.metadata?.ownerReferences || [];
369319
369375
  }
369320
- async function setOwnerReference(itemPath, namespace, ownerKind, ownerName, blockOwnerDeletion = true) {
369376
+ async function ownership_setOwnerReference(itemPath, namespace, ownerKind, ownerName, blockOwnerDeletion = true) {
369321
369377
  let item = null;
369322
369378
  try {
369323
369379
  // we need to search for the owner's uuid
@@ -369417,7 +369473,7 @@ async function* created(item, op, handler) {
369417
369473
  async function handleOwnerReferences(item, handler) {
369418
369474
  if ('needs' in item.spec) {
369419
369475
  const needs = item.spec.needs;
369420
- 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);
369421
369477
  }
369422
369478
  }
369423
369479
  async function renamed() {
@@ -369978,7 +370034,7 @@ async function runWorkItem(workItem) {
369978
370034
  // if it does need it we return because we cannot
369979
370035
  // process this item
369980
370036
  if ('needsBlocking' in workItem.handler &&
369981
- workItem.handler.needsBlocking(item)) {
370037
+ workItem.handler.needsBlocking(item, workItem.operation)) {
369982
370038
  operator_src_logger.debug(`Item ${item.kind}/${item.metadata.namespace} needs blocking`);
369983
370039
  return;
369984
370040
  }
@@ -371357,7 +371413,10 @@ async function runTerraform(entity, command, stream) {
371357
371413
  terraformProcess.on('exit', async (code) => {
371358
371414
  console.log(`child process exited with code ${code}`);
371359
371415
  if (code !== 0) {
371360
- ko(output);
371416
+ ko(catalog_common.generic.buildCommandExecutionError(output, catalog_common.generic.normalizeExitCode(code), command, {
371417
+ errorName: 'TerraformCommandError',
371418
+ label: 'Terraform command',
371419
+ }));
371361
371420
  }
371362
371421
  else {
371363
371422
  ok(output);
@@ -372020,7 +372079,7 @@ if (process.env.RUN_PROVISIONER) {
372020
372079
 
372021
372080
 
372022
372081
  const LAST_STATE_PR_ANNOTATION = 'firestartr.dev/last-state-pr';
372023
- async function tryPublishApply(item, planOutput, isSuccess = true) {
372082
+ async function tryPublishApply(item, planOutput, isSuccess = true, exitCode) {
372024
372083
  const kind = item.kind;
372025
372084
  const metadataName = item.metadata?.name ?? 'unknown';
372026
372085
  try {
@@ -372029,7 +372088,11 @@ async function tryPublishApply(item, planOutput, isSuccess = true) {
372029
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.`);
372030
372089
  return;
372031
372090
  }
372032
- 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);
372033
372096
  }
372034
372097
  catch (e) {
372035
372098
  operator_src_logger.error(`The user feedback for the '${kind}/${metadataName}' apply operation failed to publish due to an error: '${e}'.`);
@@ -372244,17 +372307,205 @@ function helperCreateCheckRunName(cmd, item) {
372244
372307
  return `${item.kind} - ${cmd}`;
372245
372308
  }
372246
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
+
372247
372435
  ;// CONCATENATED MODULE: ../operator/src/cdktf/ownership.ts
372248
372436
 
372249
372437
 
372250
372438
 
372439
+
372440
+
372251
372441
  const kindsWithFirestartrGithubRepositoryDependence = [
372252
372442
  'FirestartrGithubRepositorySecretsSection',
372253
372443
  'FirestartrGithubRepositoryFeature',
372254
372444
  ];
372445
+ const kindsWithChildren = ['FirestartrGithubRepository'];
372255
372446
  async function manageOwnershipReferences(item, handler, op) {
372447
+ /*********************************************************************************
372448
+ // suspended due to https://github.com/prefapp/gitops-k8s/issues/1767
372256
372449
  if (kindsWithFirestartrGithubRepositoryDependence.indexOf(item.kind) !== -1) {
372257
- await manageOwnershipReferencesForRepo(item, handler, op);
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
372466
+ if (kindsWithFirestartrGithubRepositoryDependence.indexOf(item.kind) !== -1) {
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}`);
372258
372509
  }
372259
372510
  }
372260
372511
  async function manageOwnershipReferencesForRepo(item, handler, op) {
@@ -372263,10 +372514,10 @@ async function manageOwnershipReferencesForRepo(item, handler, op) {
372263
372514
  if (!repositoryTarget) {
372264
372515
  throw `Item ${item.kind}/${item.metadata.namespace} is not correct: it does not have a repositoryTarget`;
372265
372516
  }
372266
- 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);
372267
372518
  }
372268
372519
  catch (err) {
372269
- 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}`);
372270
372521
  throw new Error(`Handling ownership for ${item.kind}/${item.metadata.name}: ${err}`);
372271
372522
  }
372272
372523
  }
@@ -372282,6 +372533,7 @@ async function manageOwnershipReferencesForRepo(item, handler, op) {
372282
372533
 
372283
372534
 
372284
372535
 
372536
+
372285
372537
  function processOperation(item, op, handler) {
372286
372538
  operator_src_logger.info(`Processing operation ${op} on ${item.kind}/${item.metadata?.name}`);
372287
372539
  try {
@@ -372434,17 +372686,12 @@ async function* cdktf_markedToDeletion(item, op, handler) {
372434
372686
  await addDestroyCommitStatus(item, 'success', 'Destroy operation completed', `Terraform Destroy ${item.metadata.name}`);
372435
372687
  }
372436
372688
  await tryPublishDestroy(item, output, true);
372689
+ await manageOwnershipReferencesPostDeletion(item, handler, op);
372437
372690
  void handler.success();
372438
372691
  }
372439
372692
  catch (e) {
372440
372693
  error = true;
372441
- let errorMsg;
372442
- if (typeof e === 'object' && 'output' in e) {
372443
- errorMsg = e.output;
372444
- }
372445
- else {
372446
- errorMsg = e;
372447
- }
372694
+ const { output: errorMsg } = extractErrorDetails(e);
372448
372695
  // if there is a current checkRun working
372449
372696
  // we close it with an error
372450
372697
  if (checkRunCtl)
@@ -372589,19 +372836,13 @@ async function* doApply(item, op, handler) {
372589
372836
  message: 'doApply',
372590
372837
  };
372591
372838
  await handler.writeTerraformOutputInTfResult(item, output);
372592
- await tryPublishApply(item, applyOutput?.data?.output, true);
372839
+ await tryPublishApply(item, applyOutput?.data?.output, true, 0);
372593
372840
  void handler.success();
372594
372841
  }
372595
372842
  catch (e) {
372596
372843
  error = true;
372597
- let errorMsg;
372598
- if (typeof e === 'object' && 'output' in e) {
372599
- errorMsg = e.output;
372600
- }
372601
- else {
372602
- errorMsg = e;
372603
- }
372604
- await tryPublishApply(item, errorMsg, false);
372844
+ const { output: errorMsg, exitCode } = extractErrorDetails(e);
372845
+ await tryPublishApply(item, errorMsg, false, exitCode);
372605
372846
  // if there is a current checkRun working
372606
372847
  // we close it with an error
372607
372848
  if (checkRunCtl)
@@ -372824,7 +373065,10 @@ async function tfExec(path, args, secrets, extraArgs = ['-input=false'], stream)
372824
373065
  if (code !== 0) {
372825
373066
  terraform_provisioner_src_logger.error(`Terraform output ${path}: ${output + outputErrors}`);
372826
373067
  terraform_provisioner_src_logger.error(`Terraform output ${path}: ${[output, outputErrors].join('')}`);
372827
- 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
+ }));
372828
373072
  }
372829
373073
  else {
372830
373074
  terraform_provisioner_src_logger.info(`Terraform output ${path}: ${output}`);
@@ -373767,40 +374011,6 @@ function tf_checkrun_helperCreateCheckRunName(cmd) {
373767
374011
  return `TFWorkspace - ${cmd}`;
373768
374012
  }
373769
374013
 
373770
- ;// CONCATENATED MODULE: ../operator/src/utils/index.ts
373771
- const secretRegex = /\$\{\{ secrets\.(.*?) \}\}/g;
373772
- function replaceConfigSecrets(config, secrets) {
373773
- for (const key in config) {
373774
- if (typeof config[key] === 'object' && config[key] !== null) {
373775
- // If the property is an object, call this function recursively
373776
- replaceConfigSecrets(config[key], secrets);
373777
- }
373778
- else if (typeof config[key] === 'string') {
373779
- // If the property is a string and its value is equal to secrets.something,
373780
- // replace the value with the value of the 'something' key in the secrets object
373781
- config[key] = config[key].replace(secretRegex, (_, group1) => {
373782
- if (!secrets[group1]) {
373783
- throw new Error(`Secret ${group1} not found in secrets`);
373784
- }
373785
- return secrets[group1];
373786
- });
373787
- }
373788
- }
373789
- return config;
373790
- }
373791
- function replaceInlineSecrets(inline, secrets) {
373792
- if (typeof inline !== 'string' || !inline)
373793
- return inline;
373794
- let result = inline;
373795
- result = result.replace(secretRegex, (_, group1) => {
373796
- if (!secrets[group1]) {
373797
- throw new Error(`Secret ${group1} not found in secrets`);
373798
- }
373799
- return secrets[group1];
373800
- });
373801
- return result;
373802
- }
373803
-
373804
374014
  ;// CONCATENATED MODULE: ../operator/src/tfworkspaces/process-operation.ts
373805
374015
 
373806
374016
 
@@ -373944,15 +374154,16 @@ async function* doPlanJSONFormat(item, op, handler, setResult = function (_r) {
373944
374154
  }
373945
374155
  catch (e) {
373946
374156
  error = true;
374157
+ const { output: errorMsg } = extractErrorDetails(e);
373947
374158
  console.error(e);
373948
- operator_src_logger.error(`The Terraform processor encountered an error while observing the plan for item '${item.kind}/${item.metadata.name}': '${e}'.`);
373949
- 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);
373950
374161
  if (item.metadata.annotations['firestartr.dev/last-state-pr'] || false) {
373951
374162
  await addPlanStatusCheck(item.metadata.annotations['firestartr.dev/last-state-pr'], summaryText, 'completed', true);
373952
374163
  }
373953
374164
  void handler.error();
373954
- if (e) {
373955
- await handler.writeTerraformOutputInTfResult(item, e);
374165
+ if (errorMsg) {
374166
+ await handler.writeTerraformOutputInTfResult(item, errorMsg);
373956
374167
  }
373957
374168
  }
373958
374169
  finally {
@@ -374201,13 +374412,7 @@ async function* process_operation_markedToDeletion(item, op, handler) {
374201
374412
  }
374202
374413
  catch (e) {
374203
374414
  error = true;
374204
- let errorMsg;
374205
- if (typeof e === 'object' && 'output' in e) {
374206
- errorMsg = e.output;
374207
- }
374208
- else {
374209
- errorMsg = e;
374210
- }
374415
+ const { output: errorMsg } = extractErrorDetails(e);
374211
374416
  await tryPublishDestroy(item, errorMsg, false);
374212
374417
  await handler.writeTerraformOutputInTfResult(item, errorMsg);
374213
374418
  if (item.metadata.annotations['firestartr.dev/last-state-pr'] || false) {
@@ -374324,21 +374529,15 @@ async function* process_operation_doApply(item, op, handler) {
374324
374529
  message: 'doApply',
374325
374530
  };
374326
374531
  await handler.writeTerraformOutputInTfResult(item, output);
374327
- await tryPublishApply(item, applyOutput, true);
374532
+ await tryPublishApply(item, applyOutput, true, 0);
374328
374533
  handler.success();
374329
374534
  }
374330
374535
  catch (e) {
374331
374536
  error = true;
374332
- let errorMsg;
374333
- if (typeof e === 'object' && 'output' in e) {
374334
- errorMsg = e.output;
374335
- }
374336
- else {
374337
- errorMsg = e;
374338
- }
374537
+ const { output: errorMsg, exitCode } = extractErrorDetails(e);
374339
374538
  checkRunCtl.fnOnError(errorMsg);
374340
374539
  console.error(e);
374341
- await tryPublishApply(item, errorMsg, false);
374540
+ await tryPublishApply(item, errorMsg, false, exitCode);
374342
374541
  operator_src_logger.error(`The Terraform processor encountered an error during operation '${op}' for item '${item.kind}/${item.metadata.name}': '${e}'.`);
374343
374542
  handler.error();
374344
374543
  if (errorMsg) {
@@ -374836,18 +375035,19 @@ async function* doPlanPlainTextFormat(item, op, handler, action) {
374836
375035
  }
374837
375036
  catch (e) {
374838
375037
  error = true;
375038
+ const { output: errorMsg } = extractErrorDetails(e);
374839
375039
  const { prNumber, repo, org } = extractPrInfo(item, 'firestartr.dev/pull-request-plan');
374840
- await publishPlan(item, JSON.stringify(e), prNumber, repo, org, false);
375040
+ await publishPlan(item, errorMsg, prNumber, repo, org, false);
374841
375041
  operator_src_logger.error('TFWORKSPACE_PROCESSOR_PLAN_OBSERVING_ERROR', {
374842
375042
  metadata: { item, error: e },
374843
375043
  });
374844
- const summaryText = tryCreateErrorSummary('Terraform Plan failed', e);
375044
+ const summaryText = tryCreateErrorSummary('Terraform Plan failed', errorMsg);
374845
375045
  if (item.metadata.annotations['firestartr.dev/last-state-pr'] || false) {
374846
375046
  await addPlanStatusCheck(item.metadata.annotations['firestartr.dev/last-state-pr'], summaryText, 'completed', true);
374847
375047
  }
374848
375048
  void handler.error();
374849
- if (e) {
374850
- await handler.writeTerraformOutputInTfResult(item, e);
375049
+ if (errorMsg) {
375050
+ await handler.writeTerraformOutputInTfResult(item, errorMsg);
374851
375051
  }
374852
375052
  }
374853
375053
  finally {
@@ -374961,13 +375161,14 @@ async function* processOperationPlan_doPlanJSONFormat(item, op, handler, action)
374961
375161
  }
374962
375162
  catch (e) {
374963
375163
  error = true;
375164
+ const { output: errorMsg } = extractErrorDetails(e);
374964
375165
  console.error(e);
374965
375166
  operator_src_logger.error('TFWORKSPACE_PROCESSOR_PLAN_DO_PLAN_ERROR', {
374966
375167
  metadata: { item, error: e },
374967
375168
  });
374968
375169
  void handler.error();
374969
- if (e) {
374970
- await handler.writeTerraformOutputInTfResult(item, e);
375170
+ if (errorMsg) {
375171
+ await handler.writeTerraformOutputInTfResult(item, errorMsg);
374971
375172
  }
374972
375173
  }
374973
375174
  finally {
@@ -375379,6 +375580,7 @@ function waitForFile(filePath) {
375379
375580
 
375380
375581
 
375381
375582
 
375583
+
375382
375584
  var FileStatus;
375383
375585
  (function (FileStatus) {
375384
375586
  FileStatus["DELETED"] = "removed";
@@ -375436,16 +375638,7 @@ async function tfWorkspacePlan(opts) {
375436
375638
  }
375437
375639
  catch (e) {
375438
375640
  console.error(e);
375439
- let message = '';
375440
- if (e && typeof e === 'string') {
375441
- message = e;
375442
- }
375443
- else if (e && typeof e === 'object' && e.message) {
375444
- message = e.message;
375445
- }
375446
- else {
375447
- message = 'An unknown error occurred';
375448
- }
375641
+ const { output: message } = extractErrorDetails(e);
375449
375642
  fDebug(`Error: ${message}`, 'error');
375450
375643
  await addPlanStatusCheck(pull, message, 'completed', true);
375451
375644
  fDebug('Publishing plan');
@@ -376444,9 +376637,9 @@ const crs_analyzerSubcommand = {
376444
376637
  };
376445
376638
 
376446
376639
  ;// CONCATENATED MODULE: ./package.json
376447
- const package_namespaceObject = JSON.parse('{"i8":"1.57.1-snapshot-3"}');
376640
+ const package_namespaceObject = {"i8":"1.58.0"};
376448
376641
  ;// CONCATENATED MODULE: ../../package.json
376449
- const package_namespaceObject_1 = {"i8":"1.57.0"};
376642
+ const package_namespaceObject_1 = {"i8":"1.58.0"};
376450
376643
  ;// CONCATENATED MODULE: ./src/subcommands/index.ts
376451
376644
 
376452
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";
@@ -1045,12 +1045,16 @@ declare const schemas: {
1045
1045
  $ref: string;
1046
1046
  type?: undefined;
1047
1047
  properties?: undefined;
1048
+ required?: undefined;
1048
1049
  } | {
1049
1050
  type: string;
1050
1051
  properties: {
1051
1052
  system: {
1052
1053
  $ref: string;
1053
1054
  };
1055
+ owner: {
1056
+ $ref: string;
1057
+ };
1054
1058
  providers: {
1055
1059
  type: string;
1056
1060
  properties: {
@@ -1061,6 +1065,7 @@ declare const schemas: {
1061
1065
  required: string[];
1062
1066
  };
1063
1067
  };
1068
+ required: string[];
1064
1069
  $ref?: undefined;
1065
1070
  })[];
1066
1071
  };
@@ -1078,9 +1083,16 @@ declare const schemas: {
1078
1083
  $ref: string;
1079
1084
  type?: undefined;
1080
1085
  properties?: undefined;
1086
+ required?: undefined;
1081
1087
  } | {
1082
1088
  type: string;
1083
1089
  properties: {
1090
+ system: {
1091
+ $ref: string;
1092
+ };
1093
+ owner: {
1094
+ $ref: string;
1095
+ };
1084
1096
  providers: {
1085
1097
  type: string;
1086
1098
  properties: {
@@ -1090,6 +1102,7 @@ declare const schemas: {
1090
1102
  };
1091
1103
  };
1092
1104
  };
1105
+ required: string[];
1093
1106
  $ref?: undefined;
1094
1107
  })[];
1095
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-3",
3
+ "version": "1.58.0",
4
4
  "private": false,
5
5
  "description": "Commandline tool",
6
6
  "main": "build/main.js",