@fbl-plugins/k8s-kubectl
Version:
FBL plugin for K8s Kubectl CLI
80 lines • 3.52 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateActionProcessor = void 0;
const Joi = require("joi");
const BaseActionProcessor_1 = require("./BaseActionProcessor");
const K8sObjectJoiValidationSchema_1 = require("../joi/K8sObjectJoiValidationSchema");
const fbl_1 = require("fbl");
class CreateActionProcessor extends BaseActionProcessor_1.BaseActionProcessor {
/**
* @inheritdoc
*/
getValidationSchema() {
return CreateActionProcessor.validationSchema;
}
/**
* @inheritdoc
*/
execute() {
return __awaiter(this, void 0, void 0, function* () {
const args = yield this.prepareCLIArgs();
yield this.execKubectlCommand(args, this.options.debug);
});
}
/**
* Prepare CLI args
*/
prepareCLIArgs() {
return __awaiter(this, void 0, void 0, function* () {
const args = ['create'];
this.pushWithValue(args, '-n', this.options.namespace);
if (this.options.paths && this.options.paths.length) {
const tempPathsRegistry = fbl_1.TempPathsRegistry.instance;
const targetDir = yield tempPathsRegistry.createTempDir();
args.push('-R', '-f', targetDir);
for (const path of this.options.paths) {
yield this.processGlobPath(path, targetDir);
}
}
yield this.pushMultipleWithValue(args, '-f', this.options.inline, (config) => __awaiter(this, void 0, void 0, function* () {
return yield this.writeYamlToTempFile(config);
}));
if (this.options.labels) {
for (const label of Object.keys(this.options.labels)) {
const value = this.options.labels[label];
args.push('-l', `${label}=${value}`);
}
}
if (this.options.extra) {
args.push(...this.options.extra);
}
return args;
});
}
}
exports.CreateActionProcessor = CreateActionProcessor;
CreateActionProcessor.validationSchema = Joi.object({
paths: Joi.array().items(Joi.string().min(1)).min(1),
inline: Joi.array().items(K8sObjectJoiValidationSchema_1.K8sObjectJoiValidationSchema).min(1),
labels: Joi.object().pattern(Joi.string().min(1).required(), Joi.string().required().min(1)),
// enable verbose output
debug: Joi.boolean(),
// Namespace
namespace: Joi.string(),
// extra arguments to append to the command
// refer to `kubectl apply --help` for all available options
extra: Joi.array().items(Joi.string()),
})
.or('paths', 'inline')
.required()
.options({ abortEarly: true, allowUnknown: false });
//# sourceMappingURL=CreateActionProcessor.js.map