Run build with input commands

pull/265/head
Frostebite 2021-05-28 21:20:04 +01:00
parent 821b9eeddf
commit fce88635b8
3 changed files with 39 additions and 39 deletions

40
dist/index.js vendored
View File

@ -1005,27 +1005,26 @@ class Kubernetes {
} }
}); });
} }
static watchPodUntilReadyAndRead(statusFilter) { static watchPodUntilRunningAndRead() {
var _a, _b, _c; var _a, _b;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let ready = false; let ready = false;
while (!ready) { while (!ready) {
yield new Promise((resolve) => setTimeout(resolve, pollInterval)); yield new Promise((resolve) => setTimeout(resolve, pollInterval));
const pods = yield this.kubeClient.listNamespacedPod(this.namespace); const pod = (_a = (yield this.kubeClient.readNamespacedPod(this.name, this.namespace))) === null || _a === void 0 ? void 0 : _a.body;
for (let index = 0; index < pods.body.items.length; index++) { if (pod === undefined) {
const element = pods.body.items[index]; throw new Error('no pod found');
const jobname = (_b = (_a = element.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b['job-name']; }
const phase = (_c = element.status) === null || _c === void 0 ? void 0 : _c.phase; const phase = (_b = pod.status) === null || _b === void 0 ? void 0 : _b.phase;
if (jobname === this.jobName && phase !== statusFilter) { if (phase === 'Running') {
core.info('Pod no longer pending'); core.info('Pod no longer pending');
if (phase === 'Failure') { }
core.error('Kubernetes job failed'); if (phase !== 'Pending') {
} core.error('Kubernetes job failed');
else { }
ready = true; else {
return element; ready = true;
} return pod;
}
} }
} }
}); });
@ -1034,9 +1033,9 @@ class Kubernetes {
var _a, _b; var _a, _b;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const pod = (yield Kubernetes.watchPodUntilReadyAndRead('Pending')) || {}; const pod = yield Kubernetes.watchPodUntilRunningAndRead();
core.info(`Watching build job ${(_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name}`); core.info(`Watching build job ${(_a = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _a === void 0 ? void 0 : _a.name}`);
yield Kubernetes.streamLogs(((_b = pod.metadata) === null || _b === void 0 ? void 0 : _b.name) || '', this.namespace); yield Kubernetes.streamLogs(((_b = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _b === void 0 ? void 0 : _b.name) || '', this.namespace);
} }
catch (error) { catch (error) {
core.error('Failed while watching build job'); core.error('Failed while watching build job');
@ -1092,6 +1091,7 @@ class Kubernetes {
} }
static cleanup() { static cleanup() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info('cleaning up');
yield this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace); yield this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace);
yield this.kubeClient.deletePersistentVolume(this.pvcName, this.namespace); yield this.kubeClient.deletePersistentVolume(this.pvcName, this.namespace);
yield this.kubeClient.deleteNamespacedSecret(this.secretName, this.namespace); yield this.kubeClient.deleteNamespacedSecret(this.secretName, this.namespace);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -292,34 +292,33 @@ class Kubernetes {
} }
} }
static async watchPodUntilReadyAndRead(statusFilter: string) { static async watchPodUntilRunningAndRead() {
let ready = false; let ready = false;
while (!ready) { while (!ready) {
await new Promise((resolve) => setTimeout(resolve, pollInterval)); await new Promise((resolve) => setTimeout(resolve, pollInterval));
const pods = await this.kubeClient.listNamespacedPod(this.namespace); const pod = (await this.kubeClient.readNamespacedPod(this.name, this.namespace))?.body;
for (let index = 0; index < pods.body.items.length; index++) { if (pod === undefined) {
const element = pods.body.items[index]; throw new Error('no pod found');
const jobname = element.metadata?.labels?.['job-name']; }
const phase = element.status?.phase; const phase = pod.status?.phase;
if (jobname === this.jobName && phase !== statusFilter) { if (phase === 'Running') {
core.info('Pod no longer pending'); core.info('Pod no longer pending');
if (phase === 'Failure') { }
core.error('Kubernetes job failed'); if (phase !== 'Pending') {
} else { core.error('Kubernetes job failed');
ready = true; } else {
return element; ready = true;
} return pod;
}
} }
} }
} }
static async watchBuildJobUntilFinished() { static async watchBuildJobUntilFinished() {
try { try {
const pod = (await Kubernetes.watchPodUntilReadyAndRead('Pending')) || {}; const pod = await Kubernetes.watchPodUntilRunningAndRead();
core.info(`Watching build job ${pod.metadata?.name}`); core.info(`Watching build job ${pod?.metadata?.name}`);
await Kubernetes.streamLogs(pod.metadata?.name || '', this.namespace); await Kubernetes.streamLogs(pod?.metadata?.name || '', this.namespace);
} catch (error) { } catch (error) {
core.error('Failed while watching build job'); core.error('Failed while watching build job');
throw error; throw error;
@ -380,6 +379,7 @@ class Kubernetes {
} }
static async cleanup() { static async cleanup() {
core.info('cleaning up');
await this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace); await this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace);
await this.kubeClient.deletePersistentVolume(this.pvcName, this.namespace); await this.kubeClient.deletePersistentVolume(this.pvcName, this.namespace);
await this.kubeClient.deleteNamespacedSecret(this.secretName, this.namespace); await this.kubeClient.deleteNamespacedSecret(this.secretName, this.namespace);