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 }));
// @ts-ignore
const k8s = __importStar(__webpack_require__(89679));
const core = __webpack_require__(42186);
const core = __importStar(__webpack_require__(42186));
const base64 = __webpack_require__(85848);
const pollInterval = 50000;
class Kubernetes {
@ -1037,35 +1037,46 @@ class Kubernetes {
static watchBuildJobUntilFinished() {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function* () {
const pod = (yield Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
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);
try {
const pod = (yield Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
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) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
let running = true;
let logQueryTime;
while (running) {
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
core.info('Polling logs...');
const logs = yield this.kubeClient.readNamespacedPodLog(name, namespace, undefined, undefined, undefined, undefined, undefined, undefined, logQueryTime, undefined, true);
const arrayOfLines = (_a = logs.body.match(/[^\n\r]+/g)) === null || _a === void 0 ? void 0 : _a.reverse();
if (arrayOfLines) {
for (const element of arrayOfLines) {
const [time, ...line] = element.split(' ');
if (time !== logQueryTime) {
core.info(line.join(' '));
}
else {
break;
try {
let running = true;
let logQueryTime;
while (running) {
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
core.info('Polling logs...');
const logs = yield this.kubeClient.readNamespacedPodLog(name, namespace, undefined, undefined, undefined, undefined, undefined, undefined, logQueryTime, undefined, true);
const arrayOfLines = (_a = logs.body.match(/[^\n\r]+/g)) === null || _a === void 0 ? void 0 : _a.reverse();
if (arrayOfLines) {
for (const element of arrayOfLines) {
const [time, ...line] = element.split(' ');
if (time !== logQueryTime) {
core.info(line.join(' '));
}
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
import * as k8s from '@kubernetes/client-node';
import { BuildParameters } from '.';
const core = require('@actions/core');
import * as core from '@actions/core';
const base64 = require('base-64');
const pollInterval = 50000;
@ -319,51 +319,60 @@ class Kubernetes {
}
static async watchBuildJobUntilFinished() {
const pod = (await Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
try {
const pod = (await Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
core.info(
`Watching build job ${pod.metadata?.name} ${JSON.stringify(
pod.status?.containerStatuses?.[0].state,
undefined,
4,
)}`,
);
await Kubernetes.streamLogs(pod.metadata?.name || '', this.namespace);
core.info(
`Watching build job ${pod.metadata?.name} ${JSON.stringify(
pod.status?.containerStatuses?.[0].state,
undefined,
4,
)}`,
);
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) {
let running = true;
let logQueryTime;
while (running) {
await new Promise((resolve) => setTimeout(resolve, pollInterval));
core.info('Polling logs...');
const logs = await this.kubeClient.readNamespacedPodLog(
name,
namespace,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
logQueryTime,
undefined,
true,
);
const arrayOfLines = logs.body.match(/[^\n\r]+/g)?.reverse();
if (arrayOfLines) {
for (const element of arrayOfLines) {
const [time, ...line] = element.split(' ');
if (time !== logQueryTime) {
core.info(line.join(' '));
} else {
break;
try {
let running = true;
let logQueryTime;
while (running) {
await new Promise((resolve) => setTimeout(resolve, pollInterval));
core.info('Polling logs...');
const logs = await this.kubeClient.readNamespacedPodLog(
name,
namespace,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
logQueryTime,
undefined,
true,
);
const arrayOfLines = logs.body.match(/[^\n\r]+/g)?.reverse();
if (arrayOfLines) {
for (const element of arrayOfLines) {
const [time, ...line] = element.split(' ');
if (time !== logQueryTime) {
core.info(line.join(' '));
} 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);
running = pod.body.status?.phase === 'Running';
} catch (error) {
throw error;
}
}