@firestartr/cli 0.1.26 → 0.1.27
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 +50 -15
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -237047,20 +237047,19 @@ exports.operatorSubcommands = {
|
|
|
237047
237047
|
{ name: "observeMode", type: Boolean, defaultValue: false },
|
|
237048
237048
|
{ name: "plan", type: Boolean },
|
|
237049
237049
|
{ name: "apply", type: Boolean },
|
|
237050
|
-
{ name: "
|
|
237050
|
+
{ name: "claim", alias: "c", type: String },
|
|
237051
237051
|
{ name: "namespace", alias: "n", type: String },
|
|
237052
237052
|
],
|
|
237053
237053
|
run: async (options) => {
|
|
237054
237054
|
// This will show the command line options passed to the command
|
|
237055
237055
|
console.table(options);
|
|
237056
237056
|
if (options["plan"] || options["apply"]) {
|
|
237057
|
-
if (!options["
|
|
237058
|
-
throw `Error: Missing arg: --
|
|
237057
|
+
if (!options["claim"])
|
|
237058
|
+
throw `Error: Missing arg: --claim`;
|
|
237059
237059
|
if (!options["namespace"])
|
|
237060
237060
|
throw `Error: Missing arg: --namespace`;
|
|
237061
|
-
const claimContentFile = Buffer.from(options["cr"], 'base64').toString('utf8');
|
|
237062
237061
|
const command = options["plan"] ? "plan" : "apply";
|
|
237063
|
-
await (0, operator_1.execTfCommand)(command,
|
|
237062
|
+
await (0, operator_1.execTfCommand)(command, options["claim"], options["namespace"] || "default");
|
|
237064
237063
|
return;
|
|
237065
237064
|
}
|
|
237066
237065
|
if (!options["start"]) {
|
|
@@ -240299,14 +240298,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
240299
240298
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
240300
240299
|
};
|
|
240301
240300
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
240302
|
-
exports.tfPlanner = void 0;
|
|
240301
|
+
exports.kubectlCp = exports.tfPlanner = void 0;
|
|
240303
240302
|
const client = __importStar(__nccwpck_require__(54851));
|
|
240304
240303
|
const stream = __importStar(__nccwpck_require__(12781));
|
|
240305
240304
|
const ctl_1 = __nccwpck_require__(46679);
|
|
240306
240305
|
const catalog_common_1 = __importDefault(__nccwpck_require__(74100));
|
|
240306
|
+
const child_process_1 = __nccwpck_require__(32081);
|
|
240307
240307
|
const deploymentName = catalog_common_1.default.environment.getFromEnvironment(catalog_common_1.default.types.envVars.operatorDeploymentName || "firestartr-firestartr-controller");
|
|
240308
240308
|
const DEFAULT_OPERATOR_DEPLOY = deploymentName;
|
|
240309
|
-
async function tfPlanner(claim, namespace, debug, jobTtl, cmd = "plan") {
|
|
240309
|
+
async function tfPlanner(claimFilePath, claim, namespace, debug, jobTtl, cmd = "plan") {
|
|
240310
240310
|
const { kc } = await (0, ctl_1.getConnection)();
|
|
240311
240311
|
const k8sApi = kc.makeApiClient(client.AppsV1Api);
|
|
240312
240312
|
const batchV1Api = kc.makeApiClient(client.BatchV1Api);
|
|
@@ -240330,7 +240330,7 @@ async function tfPlanner(claim, namespace, debug, jobTtl, cmd = "plan") {
|
|
|
240330
240330
|
job.spec.template.spec.containers[0].command = [
|
|
240331
240331
|
"sh",
|
|
240332
240332
|
"-c",
|
|
240333
|
-
`${executablePath} operator --${cmd} --
|
|
240333
|
+
`${executablePath} operator --${cmd} --claim /tmp/claim.yaml --namespace ${namespace}`,
|
|
240334
240334
|
];
|
|
240335
240335
|
if (debug) {
|
|
240336
240336
|
job.spec.template.spec.containers[0].command[2] = job
|
|
@@ -240344,11 +240344,11 @@ async function tfPlanner(claim, namespace, debug, jobTtl, cmd = "plan") {
|
|
|
240344
240344
|
job.spec.template.spec.restartPolicy = "Never";
|
|
240345
240345
|
job.metadata = metadata;
|
|
240346
240346
|
const createJobRes = await batchV1Api.createNamespacedJob(namespace, job);
|
|
240347
|
-
await
|
|
240347
|
+
await copyClaimAndGetLogs(namespace, job.metadata.name, claimFilePath);
|
|
240348
240348
|
await batchV1Api.deleteNamespacedJob(job.metadata.name, namespace);
|
|
240349
240349
|
}
|
|
240350
240350
|
exports.tfPlanner = tfPlanner;
|
|
240351
|
-
async function
|
|
240351
|
+
async function copyClaimAndGetLogs(namespace, jobName, sourcePath) {
|
|
240352
240352
|
const { kc } = await (0, ctl_1.getConnection)();
|
|
240353
240353
|
const k8sApi = kc.makeApiClient(client.CoreV1Api);
|
|
240354
240354
|
const log = new client.Log(kc);
|
|
@@ -240375,7 +240375,12 @@ async function getLogs(namespace, jobName) {
|
|
|
240375
240375
|
}
|
|
240376
240376
|
}
|
|
240377
240377
|
}
|
|
240378
|
+
console.log("Waiting for pod to be running");
|
|
240378
240379
|
await awaitPodStatus((phase) => phase != "Pending");
|
|
240380
|
+
console.log("Pod is running");
|
|
240381
|
+
console.log("Copying claim to pod");
|
|
240382
|
+
await kubectlCp(sourcePath, namespace, pod.metadata.name);
|
|
240383
|
+
console.log("Claim copied to pod");
|
|
240379
240384
|
try {
|
|
240380
240385
|
const req = await log.log(namespace, pod.metadata.name, pod.spec.containers[0].name, logStream, {
|
|
240381
240386
|
follow: true,
|
|
@@ -240406,6 +240411,11 @@ async function getLogs(namespace, jobName) {
|
|
|
240406
240411
|
return;
|
|
240407
240412
|
}
|
|
240408
240413
|
}
|
|
240414
|
+
function kubectlCp(sourcePath, namespace, podName) {
|
|
240415
|
+
const command = `kubectl cp -n ${namespace} ${sourcePath} ${podName}:/tmp/claim.yaml`;
|
|
240416
|
+
(0, child_process_1.execSync)(command);
|
|
240417
|
+
}
|
|
240418
|
+
exports.kubectlCp = kubectlCp;
|
|
240409
240419
|
|
|
240410
240420
|
|
|
240411
240421
|
/***/ }),
|
|
@@ -240996,9 +241006,17 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
240996
241006
|
exports.execTfCommand = void 0;
|
|
240997
241007
|
const yaml = __importStar(__nccwpck_require__(26264));
|
|
240998
241008
|
const ctx_1 = __nccwpck_require__(29296);
|
|
240999
|
-
|
|
241000
|
-
|
|
241001
|
-
|
|
241009
|
+
const fs = __importStar(__nccwpck_require__(57147));
|
|
241010
|
+
async function execTfCommand(command, filePath, namespace = "default") {
|
|
241011
|
+
console.log(`execTfCommand: ${command} claim file path: ${filePath} namespace: ${namespace}`);
|
|
241012
|
+
// The claim will be copied to the pod's filesystem
|
|
241013
|
+
// and the operator will read it from there
|
|
241014
|
+
// The operator should wait fort the claim file to be written
|
|
241015
|
+
// before reading it
|
|
241016
|
+
console.log(`Waiting for file ${filePath}`);
|
|
241017
|
+
await waitForFile(filePath);
|
|
241018
|
+
console.log(`File ${filePath} found`);
|
|
241019
|
+
const claim = yaml.load(fs.readFileSync(filePath, 'utf8'));
|
|
241002
241020
|
let ctx = null;
|
|
241003
241021
|
switch (claim.kind) {
|
|
241004
241022
|
case "TFWorkspaceClaim":
|
|
@@ -241015,6 +241033,23 @@ async function execTfCommand(command, fileContent, namespace = "default") {
|
|
|
241015
241033
|
await ctx.exec("runProvision");
|
|
241016
241034
|
}
|
|
241017
241035
|
exports.execTfCommand = execTfCommand;
|
|
241036
|
+
function waitForFile(filePath) {
|
|
241037
|
+
return new Promise((resolve, reject) => {
|
|
241038
|
+
const timeout = setTimeout(() => {
|
|
241039
|
+
reject(new Error(`File not found within 60 seconds: ${filePath}`));
|
|
241040
|
+
}, 65000);
|
|
241041
|
+
const interval = setInterval(() => {
|
|
241042
|
+
if (fs.existsSync(filePath)) {
|
|
241043
|
+
clearInterval(interval);
|
|
241044
|
+
clearTimeout(timeout);
|
|
241045
|
+
// wait a bit more to make sure the file is fully written
|
|
241046
|
+
setTimeout(() => {
|
|
241047
|
+
resolve();
|
|
241048
|
+
}, 5000);
|
|
241049
|
+
}
|
|
241050
|
+
}, 500);
|
|
241051
|
+
});
|
|
241052
|
+
}
|
|
241018
241053
|
|
|
241019
241054
|
|
|
241020
241055
|
/***/ }),
|
|
@@ -245440,10 +245475,10 @@ class TFProjectManagerRemote {
|
|
|
245440
245475
|
this.tfVarsJsonWriter.writeToTerraformProject(path.join(this.projectPath, "terraform.tfvars.json"));
|
|
245441
245476
|
}
|
|
245442
245477
|
async __configGit() {
|
|
245443
|
-
fs.existsSync("/
|
|
245478
|
+
fs.existsSync("/home/node/.gitconfig") && fs.rmSync("/home/node/.gitconfig");
|
|
245444
245479
|
const org = catalog_common_1.default.environment.getFromEnvironment(catalog_common_1.default.types.envVars.org);
|
|
245445
245480
|
const ghToken = await github_1.default.getGithubAppToken(org);
|
|
245446
|
-
fs.writeFileSync("/
|
|
245481
|
+
fs.writeFileSync("/home/node/.gitconfig", `[url "https://firestartr:${ghToken}@github.com"]
|
|
245447
245482
|
insteadOf = https://github.com`);
|
|
245448
245483
|
}
|
|
245449
245484
|
async __init() {
|