Added exception for null kubectl commands

This commit is contained in:
Shivam Gupta 2020-01-17 10:15:28 +05:30
Родитель fdacb8e073
Коммит e7d77ef817
4 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -1,9 +1,10 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
@ -72,6 +73,8 @@ class Kubectl {
return results;
}
executeCommand(customCommand, args) {
if (!customCommand)
throw new Error('NullCommandForKubectl');
return args ? this.execute([customCommand, args]) : this.execute([customCommand]);
}
delete(args) {

Просмотреть файл

@ -74,7 +74,7 @@ exports.downloadKubectl = downloadKubectl;
function getTrafficSplitAPIVersion(kubectl) {
const result = kubectl.executeCommand('api-versions');
const trafficSplitAPIVersion = result.stdout.split('\n').find(version => version.startsWith(trafficSplitAPIVersionPrefix));
if (trafficSplitAPIVersion == null || typeof trafficSplitAPIVersion == 'undefined') {
if (!trafficSplitAPIVersion) {
throw new Error('UnableToCreateTrafficSplitManifestFile');
}
return trafficSplitAPIVersion;

Просмотреть файл

@ -80,6 +80,8 @@ export class Kubectl {
}
public executeCommand(customCommand: string, args?: string) {
if(!customCommand)
throw new Error('NullCommandForKubectl');
return args ? this.execute([customCommand, args]) : this.execute([customCommand]);
}

Просмотреть файл

@ -69,7 +69,7 @@ export async function downloadKubectl(version: string): Promise<string> {
export function getTrafficSplitAPIVersion(kubectl: Kubectl): string {
const result = kubectl.executeCommand('api-versions');
const trafficSplitAPIVersion = result.stdout.split('\n').find(version => version.startsWith(trafficSplitAPIVersionPrefix));
if (trafficSplitAPIVersion == null || typeof trafficSplitAPIVersion == 'undefined') {
if (!trafficSplitAPIVersion) {
throw new Error('UnableToCreateTrafficSplitManifestFile');
}