@fbl-plugins/k8s-kubectl
Version:
FBL plugin for K8s Kubectl CLI
94 lines • 4.33 kB
JavaScript
"use strict";
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.DeleteActionProcessor = void 0;
const Joi = require("joi");
const BaseActionProcessor_1 = require("./BaseActionProcessor");
const K8sObjectJoiValidationSchema_1 = require("../joi/K8sObjectJoiValidationSchema");
const fbl_1 = require("fbl");
class DeleteActionProcessor extends BaseActionProcessor_1.BaseActionProcessor {
/**
* @inheritdoc
*/
getValidationSchema() {
return DeleteActionProcessor.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 = ['delete']; // TODO: handle case when kubectl requests confirmation for removal
this.pushWithValue(args, '-n', this.options.namespace);
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);
}
if (this.options.resources && this.options.resources.length) {
args.push(this.options.resources.join(','));
}
if (this.options.names && this.options.names.length) {
args.push(this.options.names.join(' '));
}
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);
}));
this.pushWithoutValue(args, '--all', this.options.all);
return args;
});
}
}
exports.DeleteActionProcessor = DeleteActionProcessor;
DeleteActionProcessor.validationSchema = Joi.object({
resources: Joi.array().items(Joi.string().min(1).required()).min(1),
names: Joi.array().items(Joi.string().min(1).required()),
paths: Joi.array().items(Joi.string().min(1).required()),
inline: Joi.array().items(K8sObjectJoiValidationSchema_1.K8sObjectJoiValidationSchema),
labels: Joi.object().pattern(Joi.string().min(1).required(), Joi.string().required().min(1)),
// Delete all resources, including uninitialized ones, in the namespace of the specified resource types.
all: Joi.boolean(),
// Namespace
namespace: Joi.string(),
// enable verbose output
debug: Joi.boolean(),
// extra arguments to append to the command
// refer to `kubectl apply --help` for all available options
extra: Joi.array().items(Joi.string()),
})
.with('names', 'resources')
.without('paths', 'resources')
.without('labels', 'names')
.or('names', 'paths', 'inline', 'labels', 'all')
.required()
.options({ abortEarly: true, allowUnknown: false });
//# sourceMappingURL=DeleteActionProcessor.js.map