error handling

pull/265/head
Frostebite 2021-05-28 18:54:54 +01:00
parent 292f787c26
commit 1051a8c125
3 changed files with 82 additions and 62 deletions

55
dist/index.js vendored
View File

@ -731,7 +731,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
// @ts-ignore // @ts-ignore
const k8s = __importStar(__webpack_require__(89679)); const k8s = __importStar(__webpack_require__(89679));
const core = __webpack_require__(42186); const core = __importStar(__webpack_require__(42186));
const base64 = __webpack_require__(85848); const base64 = __webpack_require__(85848);
const pollInterval = 50000; const pollInterval = 50000;
class Kubernetes { class Kubernetes {
@ -1037,35 +1037,46 @@ class Kubernetes {
static watchBuildJobUntilFinished() { static watchBuildJobUntilFinished() {
var _a, _b, _c, _d; var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const pod = (yield Kubernetes.watchPodUntilReadyAndRead('Pending')) || {}; try {
core.info(`Watching build job ${(_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name} ${JSON.stringify((_c = (_b = pod.status) === null || _b === void 0 ? void 0 : _b.containerStatuses) === null || _c === void 0 ? void 0 : _c[0].state, undefined, 4)}`); const pod = (yield Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
yield Kubernetes.streamLogs(((_d = pod.metadata) === null || _d === void 0 ? void 0 : _d.name) || '', this.namespace); core.info(`Watching build job ${(_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name} ${JSON.stringify((_c = (_b = pod.status) === null || _b === void 0 ? void 0 : _b.containerStatuses) === null || _c === void 0 ? void 0 : _c[0].state, undefined, 4)}`);
yield Kubernetes.streamLogs(((_d = pod.metadata) === null || _d === void 0 ? void 0 : _d.name) || '', this.namespace);
}
catch (error) {
core.error('Failed while watching build job');
throw error;
}
}); });
} }
static streamLogs(name, namespace) { static streamLogs(name, namespace) {
var _a, _b; var _a, _b;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let running = true; try {
let logQueryTime; let running = true;
while (running) { let logQueryTime;
yield new Promise((resolve) => setTimeout(resolve, pollInterval)); while (running) {
core.info('Polling logs...'); yield new Promise((resolve) => setTimeout(resolve, pollInterval));
const logs = yield this.kubeClient.readNamespacedPodLog(name, namespace, undefined, undefined, undefined, undefined, undefined, undefined, logQueryTime, undefined, true); core.info('Polling logs...');
const arrayOfLines = (_a = logs.body.match(/[^\n\r]+/g)) === null || _a === void 0 ? void 0 : _a.reverse(); const logs = yield this.kubeClient.readNamespacedPodLog(name, namespace, undefined, undefined, undefined, undefined, undefined, undefined, logQueryTime, undefined, true);
if (arrayOfLines) { const arrayOfLines = (_a = logs.body.match(/[^\n\r]+/g)) === null || _a === void 0 ? void 0 : _a.reverse();
for (const element of arrayOfLines) { if (arrayOfLines) {
const [time, ...line] = element.split(' '); for (const element of arrayOfLines) {
if (time !== logQueryTime) { const [time, ...line] = element.split(' ');
core.info(line.join(' ')); if (time !== logQueryTime) {
} core.info(line.join(' '));
else { }
break; else {
break;
}
} }
logQueryTime = arrayOfLines[0].split(' ')[0];
} }
logQueryTime = arrayOfLines[0].split(' ')[0]; const pod = yield this.kubeClient.readNamespacedPod(name, namespace);
running = ((_b = pod.body.status) === null || _b === void 0 ? void 0 : _b.phase) === 'Running';
} }
const pod = yield this.kubeClient.readNamespacedPod(name, namespace); }
running = ((_b = pod.body.status) === null || _b === void 0 ? void 0 : _b.phase) === 'Running'; catch (error) {
throw error;
} }
}); });
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
// @ts-ignore // @ts-ignore
import * as k8s from '@kubernetes/client-node'; import * as k8s from '@kubernetes/client-node';
import { BuildParameters } from '.'; import { BuildParameters } from '.';
const core = require('@actions/core'); import * as core from '@actions/core';
const base64 = require('base-64'); const base64 = require('base-64');
const pollInterval = 50000; const pollInterval = 50000;
@ -319,51 +319,60 @@ class Kubernetes {
} }
static async watchBuildJobUntilFinished() { static async watchBuildJobUntilFinished() {
const pod = (await Kubernetes.watchPodUntilReadyAndRead('Pending')) || {}; try {
const pod = (await Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
core.info( core.info(
`Watching build job ${pod.metadata?.name} ${JSON.stringify( `Watching build job ${pod.metadata?.name} ${JSON.stringify(
pod.status?.containerStatuses?.[0].state, pod.status?.containerStatuses?.[0].state,
undefined, undefined,
4, 4,
)}`, )}`,
); );
await Kubernetes.streamLogs(pod.metadata?.name || '', this.namespace); await Kubernetes.streamLogs(pod.metadata?.name || '', this.namespace);
} catch (error) {
core.error('Failed while watching build job');
throw error;
}
} }
static async streamLogs(name: string, namespace: string) { static async streamLogs(name: string, namespace: string) {
let running = true; try {
let logQueryTime; let running = true;
while (running) { let logQueryTime;
await new Promise((resolve) => setTimeout(resolve, pollInterval)); while (running) {
core.info('Polling logs...'); await new Promise((resolve) => setTimeout(resolve, pollInterval));
const logs = await this.kubeClient.readNamespacedPodLog( core.info('Polling logs...');
name, const logs = await this.kubeClient.readNamespacedPodLog(
namespace, name,
undefined, namespace,
undefined, undefined,
undefined, undefined,
undefined, undefined,
undefined, undefined,
undefined, undefined,
logQueryTime, undefined,
undefined, logQueryTime,
true, undefined,
); true,
const arrayOfLines = logs.body.match(/[^\n\r]+/g)?.reverse(); );
if (arrayOfLines) { const arrayOfLines = logs.body.match(/[^\n\r]+/g)?.reverse();
for (const element of arrayOfLines) { if (arrayOfLines) {
const [time, ...line] = element.split(' '); for (const element of arrayOfLines) {
if (time !== logQueryTime) { const [time, ...line] = element.split(' ');
core.info(line.join(' ')); if (time !== logQueryTime) {
} else { core.info(line.join(' '));
break; } else {
break;
}
} }
logQueryTime = arrayOfLines[0].split(' ')[0];
} }
logQueryTime = arrayOfLines[0].split(' ')[0]; const pod = await this.kubeClient.readNamespacedPod(name, namespace);
running = pod.body.status?.phase === 'Running';
} }
const pod = await this.kubeClient.readNamespacedPod(name, namespace); } catch (error) {
running = pod.body.status?.phase === 'Running'; throw error;
} }
} }