@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
82 lines (81 loc) • 4.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.execKubectl = void 0;
const log_1 = require("diginext-utils/dist/xconsole/log");
const yargs_1 = __importDefault(require("yargs"));
const ask_for_cluster_1 = require("../cluster/ask-for-cluster");
const ask_for_deployment_1 = require("./ask-for-deployment");
const ask_for_namespace_1 = require("./ask-for-namespace");
const ask_for_new_value_1 = require("./ask-for-new-value");
const ask_for_target_prop_1 = require("./ask-for-target-prop");
const index_1 = __importDefault(require("./index"));
const kubectlCommand = (resource) => { };
const execKubectl = async (options) => {
const { secondAction: action, thirdAction: resource, namespace } = options;
const cluster = await (0, ask_for_cluster_1.askForCluster)();
if (!cluster)
return;
const { contextName: context, slug } = cluster;
switch (action) {
case "ls":
case "list":
(0, log_1.logWarn)(`This feature is under development.`);
break;
case "get":
(0, log_1.logWarn)(`This feature is under development.`);
break;
case "set":
switch (resource) {
case "deploy":
case "deployment":
const targetNamespace = namespace !== null && namespace !== void 0 ? namespace : (await (0, ask_for_namespace_1.askForNamespace)(cluster));
const targetDeployment = await (0, ask_for_deployment_1.askForDeployment)(cluster, targetNamespace);
if (!targetDeployment)
return;
const targetProp = await (0, ask_for_target_prop_1.askForTargetProp)("deployment");
switch (targetProp) {
case "image":
let { imageURL } = options;
if (!imageURL)
imageURL = await (0, ask_for_new_value_1.askForNewValue)();
const imgRes = await index_1.default.setDeployImageAll(targetDeployment, imageURL, targetNamespace, { context });
if (imgRes)
(0, log_1.logSuccess)(`[DX_KB] Successfully set new image (${imageURL}) to "${targetDeployment}" deployment of "${targetNamespace}" namespace on "${slug}" cluster.`);
break;
case "imagePullSecrets":
let { key: imagePullSecret } = options;
if (!imagePullSecret)
imagePullSecret = await (0, ask_for_new_value_1.askForNewValue)();
const imgPullRes = await index_1.default.setDeployImagePullSecretByFilter(imagePullSecret, targetNamespace, { context });
if (imgPullRes)
(0, log_1.logSuccess)(`[DX_KB] Successfully set new imagePullSecret (${imagePullSecret}) to "${targetDeployment}" deployment of "${targetNamespace}" namespace on "${slug}" cluster.`);
break;
case "port":
let { port } = options;
if (typeof port === "undefined")
port = await (0, ask_for_new_value_1.askForNewValue)();
const portRes = await index_1.default.setDeployPortAll(targetDeployment, port.toString(), targetNamespace, { context });
if (portRes)
(0, log_1.logSuccess)(`[DX_KB] Successfully set new port (${port}) to "${targetDeployment}" deployment of "${targetNamespace}" namespace on "${slug}" cluster.`);
break;
}
break;
default:
yargs_1.default.showHelp();
break;
}
break;
case "rm":
case "del":
case "delete":
(0, log_1.logWarn)(`This feature is under development.`);
break;
default:
(0, log_1.logError)(`Action "${action}" in "${resource}" resource is invalid.`);
break;
}
};
exports.execKubectl = execKubectl;