@firestartr/cli 1.32.0 → 1.33.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
|
@@ -237679,6 +237679,11 @@ exports.operatorSubcommands = {
|
|
|
237679
237679
|
{ name: 'apply', type: Boolean },
|
|
237680
237680
|
{ name: 'claim', alias: 'c', type: String },
|
|
237681
237681
|
{ name: 'namespace', alias: 'n', type: String },
|
|
237682
|
+
{ name: 'pull-request-plan', type: Boolean, defaultValue: false },
|
|
237683
|
+
{ name: 'repo', type: String },
|
|
237684
|
+
{ name: 'owner', type: String },
|
|
237685
|
+
{ name: 'ref', type: String },
|
|
237686
|
+
{ name: 'prNumber', type: String },
|
|
237682
237687
|
],
|
|
237683
237688
|
run: async (options) => {
|
|
237684
237689
|
// This will show the command line options passed to the command
|
|
@@ -237710,6 +237715,15 @@ exports.operatorSubcommands = {
|
|
|
237710
237715
|
...options,
|
|
237711
237716
|
});
|
|
237712
237717
|
}
|
|
237718
|
+
if (options['pull-request-plan']) {
|
|
237719
|
+
await (0, operator_1.tfWorkspacePlan)({
|
|
237720
|
+
prNumber: parseInt(options['prNumber']),
|
|
237721
|
+
repo: options['repo'],
|
|
237722
|
+
owner: options['owner'],
|
|
237723
|
+
namespace: options['namespace'] || 'default',
|
|
237724
|
+
ref: options['ref'],
|
|
237725
|
+
});
|
|
237726
|
+
}
|
|
237713
237727
|
},
|
|
237714
237728
|
};
|
|
237715
237729
|
|
|
@@ -244721,14 +244735,18 @@ async function getFileFromGithub(path, repo, owner = 'prefapp') {
|
|
|
244721
244735
|
const octokit = await (0, auth_1.getOctokitForOrg)(owner);
|
|
244722
244736
|
return await octokit.rest.repos.getContent({ owner, repo, path });
|
|
244723
244737
|
}
|
|
244724
|
-
async function getContent(path, repo, owner = 'prefapp') {
|
|
244738
|
+
async function getContent(path, repo, owner = 'prefapp', ref = '') {
|
|
244725
244739
|
messageLog(`Getting content for ${owner}/${repo}/${path}`);
|
|
244726
244740
|
const octokit = await (0, auth_1.getOctokitForOrg)(owner);
|
|
244727
|
-
const
|
|
244741
|
+
const opts = {
|
|
244728
244742
|
owner,
|
|
244729
244743
|
repo,
|
|
244730
244744
|
path,
|
|
244731
|
-
}
|
|
244745
|
+
};
|
|
244746
|
+
if (ref) {
|
|
244747
|
+
opts.ref = ref;
|
|
244748
|
+
}
|
|
244749
|
+
const content = await octokit.rest.repos.getContent(opts);
|
|
244732
244750
|
return Buffer.from(content.data.content, 'base64').toString('utf8');
|
|
244733
244751
|
}
|
|
244734
244752
|
exports.getContent = getContent;
|
|
@@ -246860,7 +246878,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
246860
246878
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
246861
246879
|
};
|
|
246862
246880
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
246863
|
-
exports.runOperator = exports.isObserveModeActive = exports.isImportModeSkipPlan = exports.isImportMode = exports.cmd = exports.execTfCommand = void 0;
|
|
246881
|
+
exports.runOperator = exports.isObserveModeActive = exports.isImportModeSkipPlan = exports.isImportMode = exports.cmd = exports.tfWorkspacePlan = exports.execTfCommand = void 0;
|
|
246864
246882
|
const informer_1 = __nccwpck_require__(41151);
|
|
246865
246883
|
const dummy_1 = __nccwpck_require__(73490);
|
|
246866
246884
|
const processItem_1 = __nccwpck_require__(84766);
|
|
@@ -246871,6 +246889,8 @@ const catalog_common_1 = __importDefault(__nccwpck_require__(74100));
|
|
|
246871
246889
|
const processOperationPlan_1 = __nccwpck_require__(79980);
|
|
246872
246890
|
var execTfCmd_1 = __nccwpck_require__(5959);
|
|
246873
246891
|
Object.defineProperty(exports, "execTfCommand", ({ enumerable: true, get: function () { return execTfCmd_1.execTfCommand; } }));
|
|
246892
|
+
var tfworkspaceplans_1 = __nccwpck_require__(49262);
|
|
246893
|
+
Object.defineProperty(exports, "tfWorkspacePlan", ({ enumerable: true, get: function () { return tfworkspaceplans_1.tfWorkspacePlan; } }));
|
|
246874
246894
|
const metricsServer_1 = __importDefault(__nccwpck_require__(7883));
|
|
246875
246895
|
let importModeActive = false;
|
|
246876
246896
|
let withMetricsMode = false;
|
|
@@ -247224,20 +247244,26 @@ async function getItem(kind, namespace, item) {
|
|
|
247224
247244
|
}
|
|
247225
247245
|
exports.getItem = getItem;
|
|
247226
247246
|
async function getItemByItemPath(itemPath, apiGroup = catalog_common_1.default.types.controller.FirestartrApiGroup, apiVersion = 'v1') {
|
|
247227
|
-
|
|
247228
|
-
|
|
247229
|
-
|
|
247230
|
-
|
|
247231
|
-
|
|
247232
|
-
|
|
247233
|
-
|
|
247234
|
-
|
|
247235
|
-
|
|
247236
|
-
|
|
247237
|
-
|
|
247238
|
-
|
|
247247
|
+
try {
|
|
247248
|
+
fDebug(`Getting ${itemPath}`);
|
|
247249
|
+
const { kc, opts } = await getConnection();
|
|
247250
|
+
opts.headers['Content-Type'] = 'application/json';
|
|
247251
|
+
opts.headers['Accept'] = 'application/json';
|
|
247252
|
+
const url = apiGroup === catalog_common_1.default.types.controller.KubernetesApiGroup
|
|
247253
|
+
? `${kc.getCurrentCluster().server}/api/v1/namespaces/${itemPath}`
|
|
247254
|
+
: `${kc.getCurrentCluster().server}/apis/${apiGroup}/${apiVersion}/namespaces/${itemPath}`;
|
|
247255
|
+
const r = await fetch(url, { method: 'get', headers: opts.headers });
|
|
247256
|
+
if (!r.ok) {
|
|
247257
|
+
const err = new Error(`Error on getItemByItemPath: ${itemPath}: ${r.statusText}`);
|
|
247258
|
+
console.log(err.stack);
|
|
247259
|
+
throw err;
|
|
247260
|
+
}
|
|
247261
|
+
return r.json();
|
|
247262
|
+
}
|
|
247263
|
+
catch (e) {
|
|
247264
|
+
console.dir(e, { depth: null });
|
|
247265
|
+
throw e;
|
|
247239
247266
|
}
|
|
247240
|
-
return r.json();
|
|
247241
247267
|
}
|
|
247242
247268
|
exports.getItemByItemPath = getItemByItemPath;
|
|
247243
247269
|
async function writeManifest(kind, namespace, item, apiSlug) {
|
|
@@ -249288,6 +249314,101 @@ function fWait(segs = 1) {
|
|
|
249288
249314
|
}
|
|
249289
249315
|
|
|
249290
249316
|
|
|
249317
|
+
/***/ }),
|
|
249318
|
+
|
|
249319
|
+
/***/ 49262:
|
|
249320
|
+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
|
249321
|
+
|
|
249322
|
+
"use strict";
|
|
249323
|
+
|
|
249324
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
249325
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
249326
|
+
};
|
|
249327
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
249328
|
+
exports.tfWorkspacePlan = void 0;
|
|
249329
|
+
const github_1 = __importDefault(__nccwpck_require__(39759));
|
|
249330
|
+
const catalog_common_1 = __importDefault(__nccwpck_require__(74100));
|
|
249331
|
+
const resolver_1 = __nccwpck_require__(31022);
|
|
249332
|
+
const ctl_1 = __nccwpck_require__(46679);
|
|
249333
|
+
const terraform_provisioner_1 = __nccwpck_require__(6777);
|
|
249334
|
+
const process_operation_1 = __nccwpck_require__(3937);
|
|
249335
|
+
const user_feedback_ops_1 = __nccwpck_require__(704);
|
|
249336
|
+
var FileStatus;
|
|
249337
|
+
(function (FileStatus) {
|
|
249338
|
+
FileStatus["DELETED"] = "removed";
|
|
249339
|
+
FileStatus["ADDED"] = "added";
|
|
249340
|
+
FileStatus["MODIFIED"] = "modified";
|
|
249341
|
+
})(FileStatus || (FileStatus = {}));
|
|
249342
|
+
function fDebug(message, level = 'info') {
|
|
249343
|
+
console.log(JSON.stringify({ message, level }));
|
|
249344
|
+
}
|
|
249345
|
+
async function tfWorkspacePlan(opts) {
|
|
249346
|
+
const { repo, owner, prNumber, namespace, ref } = opts;
|
|
249347
|
+
const pull = `${owner}/${repo}#${prNumber}`;
|
|
249348
|
+
let cr = null;
|
|
249349
|
+
try {
|
|
249350
|
+
fDebug(`Starting plan for ${pull}`, 'info');
|
|
249351
|
+
await (0, ctl_1.addPlanStatusCheck)(pull, 'Terraform plan in progress...');
|
|
249352
|
+
fDebug(`Getting PR ${prNumber} in ${repo}`, 'info');
|
|
249353
|
+
const resp = await github_1.default.pulls.getPrFiles(prNumber, repo, owner);
|
|
249354
|
+
const { data } = resp;
|
|
249355
|
+
if (data.length !== 1) {
|
|
249356
|
+
throw new Error(`One file expected in PR ${opts.prNumber} in ${opts.repo}, but found ${data.length}`);
|
|
249357
|
+
}
|
|
249358
|
+
const [file] = data;
|
|
249359
|
+
if (!file) {
|
|
249360
|
+
throw new Error(`No data found for PR ${opts.prNumber} in ${opts.repo}`);
|
|
249361
|
+
}
|
|
249362
|
+
const { filename, status } = file;
|
|
249363
|
+
let content = '';
|
|
249364
|
+
fDebug(`Getting content for ${filename} in ${repo}`);
|
|
249365
|
+
if (status === FileStatus.DELETED) {
|
|
249366
|
+
content = await github_1.default.repo.getContent(filename, repo, owner);
|
|
249367
|
+
}
|
|
249368
|
+
else if (status === FileStatus.ADDED || status === FileStatus.MODIFIED) {
|
|
249369
|
+
content = await github_1.default.repo.getContent(filename, repo, owner, ref);
|
|
249370
|
+
}
|
|
249371
|
+
else {
|
|
249372
|
+
throw new Error(`Unknown status ${status} for file ${filename} in PR ${opts.prNumber} in ${opts.repo}`);
|
|
249373
|
+
}
|
|
249374
|
+
cr = catalog_common_1.default.io.fromYaml(content);
|
|
249375
|
+
if (cr.kind !== 'FirestartrTerraformWorkspace') {
|
|
249376
|
+
throw new Error(`No FirestartrTerraformWorkspace found in PR ${opts.prNumber} in ${opts.repo}`);
|
|
249377
|
+
}
|
|
249378
|
+
fDebug('Resolving references');
|
|
249379
|
+
const deps = await (0, resolver_1.resolve)(cr, ctl_1.getItemByItemPath, ctl_1.getSecret, namespace);
|
|
249380
|
+
fDebug('Building context');
|
|
249381
|
+
const ctx = await (0, process_operation_1.buildProvisionerContext)(cr, deps);
|
|
249382
|
+
fDebug('Context built');
|
|
249383
|
+
const command = getCommandByStatus(status);
|
|
249384
|
+
fDebug('Running terraform provisioner');
|
|
249385
|
+
const tfOutput = await (0, terraform_provisioner_1.runTerraformProvisioner)(ctx, command);
|
|
249386
|
+
fDebug('Terraform provisioner finished');
|
|
249387
|
+
fDebug('Publishing plan');
|
|
249388
|
+
await (0, user_feedback_ops_1.publishPlan)(cr, tfOutput, prNumber, repo, owner);
|
|
249389
|
+
await (0, ctl_1.addPlanStatusCheck)(pull, tfOutput, 'completed');
|
|
249390
|
+
}
|
|
249391
|
+
catch (e) {
|
|
249392
|
+
fDebug(`Error: ${e}`, 'error');
|
|
249393
|
+
await (0, ctl_1.addPlanStatusCheck)(pull, e, 'completed', true);
|
|
249394
|
+
fDebug('Publishing plan');
|
|
249395
|
+
await (0, user_feedback_ops_1.publishPlan)(cr, e, prNumber, repo, owner);
|
|
249396
|
+
}
|
|
249397
|
+
}
|
|
249398
|
+
exports.tfWorkspacePlan = tfWorkspacePlan;
|
|
249399
|
+
function getCommandByStatus(status) {
|
|
249400
|
+
switch (status) {
|
|
249401
|
+
case FileStatus.MODIFIED:
|
|
249402
|
+
case FileStatus.ADDED:
|
|
249403
|
+
return 'plan';
|
|
249404
|
+
case FileStatus.DELETED:
|
|
249405
|
+
return 'plan-destroy';
|
|
249406
|
+
default:
|
|
249407
|
+
throw new Error(`Unknown status: ${status}`);
|
|
249408
|
+
}
|
|
249409
|
+
}
|
|
249410
|
+
|
|
249411
|
+
|
|
249291
249412
|
/***/ }),
|
|
249292
249413
|
|
|
249293
249414
|
/***/ 79980:
|
|
@@ -250879,7 +251000,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
250879
251000
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
250880
251001
|
};
|
|
250881
251002
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
250882
|
-
exports.publishError = exports.tryPublishError = exports.tryCreateErrorSummary = exports.publishApply = exports.tryPublishDestroy = exports.tryPublishApply = void 0;
|
|
251003
|
+
exports.publishPlan = exports.publishError = exports.tryPublishError = exports.tryCreateErrorSummary = exports.publishApply = exports.tryPublishDestroy = exports.tryPublishApply = void 0;
|
|
250883
251004
|
const github_1 = __importDefault(__nccwpck_require__(39759));
|
|
250884
251005
|
const debug_1 = __importDefault(__nccwpck_require__(67984));
|
|
250885
251006
|
const log = (0, debug_1.default)('firestartr:operator:terraform');
|
|
@@ -251011,6 +251132,32 @@ ${message}
|
|
|
251011
251132
|
await github_1.default.pulls.commentInPR(comment, parseInt(prNumber), repo, org);
|
|
251012
251133
|
}
|
|
251013
251134
|
exports.publishError = publishError;
|
|
251135
|
+
async function publishPlan(item, planOutput, prNumber, repo, org) {
|
|
251136
|
+
try {
|
|
251137
|
+
const dividedOutput = github_1.default.pulls.divideCommentIntoChunks(planOutput, 250);
|
|
251138
|
+
let currentCommentNo = 1;
|
|
251139
|
+
dividedOutput.forEach(async (commentContent) => {
|
|
251140
|
+
const comment = `<h1>
|
|
251141
|
+
<img width="25" src="https://static-00.iconduck.com/assets.00/file-type-terraform-icon-1821x2048-mbxeegff.png"> Terraform plan
|
|
251142
|
+
</h1>
|
|
251143
|
+
<p><b>TFWorkspace: </b>${item.metadata.name}</p>
|
|
251144
|
+
|
|
251145
|
+
<details id=github>
|
|
251146
|
+
<summary>PLAN LOGS ${dividedOutput.length > 1 ? '(Part ' + currentCommentNo + ')' : ''}</summary>
|
|
251147
|
+
|
|
251148
|
+
\`\`\`shell
|
|
251149
|
+
${commentContent}
|
|
251150
|
+
\`\`\`
|
|
251151
|
+
</details>`;
|
|
251152
|
+
await github_1.default.pulls.commentInPR(comment, prNumber, repo, org);
|
|
251153
|
+
currentCommentNo += 1;
|
|
251154
|
+
});
|
|
251155
|
+
}
|
|
251156
|
+
catch (e) {
|
|
251157
|
+
console.error(e);
|
|
251158
|
+
}
|
|
251159
|
+
}
|
|
251160
|
+
exports.publishPlan = publishPlan;
|
|
251014
251161
|
|
|
251015
251162
|
|
|
251016
251163
|
/***/ }),
|
|
@@ -55973,14 +55973,18 @@ async function getFileFromGithub(path, repo, owner = 'prefapp') {
|
|
|
55973
55973
|
const octokit = await (0, auth_1.getOctokitForOrg)(owner);
|
|
55974
55974
|
return await octokit.rest.repos.getContent({ owner, repo, path });
|
|
55975
55975
|
}
|
|
55976
|
-
async function getContent(path, repo, owner = 'prefapp') {
|
|
55976
|
+
async function getContent(path, repo, owner = 'prefapp', ref = '') {
|
|
55977
55977
|
messageLog(`Getting content for ${owner}/${repo}/${path}`);
|
|
55978
55978
|
const octokit = await (0, auth_1.getOctokitForOrg)(owner);
|
|
55979
|
-
const
|
|
55979
|
+
const opts = {
|
|
55980
55980
|
owner,
|
|
55981
55981
|
repo,
|
|
55982
55982
|
path,
|
|
55983
|
-
}
|
|
55983
|
+
};
|
|
55984
|
+
if (ref) {
|
|
55985
|
+
opts.ref = ref;
|
|
55986
|
+
}
|
|
55987
|
+
const content = await octokit.rest.repos.getContent(opts);
|
|
55984
55988
|
return Buffer.from(content.data.content, 'base64').toString('utf8');
|
|
55985
55989
|
}
|
|
55986
55990
|
exports.getContent = getContent;
|