follow logs

pull/265/head
Frostebite 2021-05-23 22:00:50 +01:00
parent 645ce0ff06
commit 6136d05e28
3 changed files with 42 additions and 14 deletions

25
dist/index.js vendored
View File

@ -1010,11 +1010,17 @@ class Kubernetes {
core.info('Job created');
});
}
static watchBuildJobUntilFinished() {
var _a, _b, _c, _d, _e, _f;
static watchPodUntilReadyAndRead() {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () {
let podname, containerId;
let ready = false;
new Promise(() => setTimeout(() => {
if (!ready) {
const error = new Error('failed to find pod - timeout');
core.error(error);
throw error;
}
}, pollInterval * 15));
while (!ready) {
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
const pods = yield this.kubeClient.listNamespacedPod(this.namespace);
@ -1029,14 +1035,19 @@ class Kubernetes {
}
else {
ready = true;
podname = (_d = element.metadata) === null || _d === void 0 ? void 0 : _d.name;
containerId = (_f = (_e = element.status) === null || _e === void 0 ? void 0 : _e.containerStatuses) === null || _f === void 0 ? void 0 : _f[0].containerID;
return element;
}
}
}
}
core.info(`Watching build job ${podname}`);
const logs = yield this.kubeClient.readNamespacedPodLog(podname, this.namespace, containerId, true);
});
}
static watchBuildJobUntilFinished() {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function* () {
const pod = (yield Kubernetes.watchPodUntilReadyAndRead()) || {};
core.info(`Watching build job ${(_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name}`);
const logs = yield this.kubeClient.readNamespacedPodLog(((_b = pod.metadata) === null || _b === void 0 ? void 0 : _b.name) || '', this.namespace, (_d = (_c = pod.status) === null || _c === void 0 ? void 0 : _c.containerStatuses) === null || _d === void 0 ? void 0 : _d[0].containerID, true);
yield new Promise((resolve, reject) => {
logs.response.on('data', (chunk) => {
core.info(chunk);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -296,9 +296,18 @@ class Kubernetes {
core.info('Job created');
}
static async watchBuildJobUntilFinished() {
let podname, containerId;
static async watchPodUntilReadyAndRead() {
let ready = false;
new Promise(() =>
setTimeout(() => {
if (!ready) {
const error = new Error('failed to find pod - timeout');
core.error(error);
throw error;
}
}, pollInterval * 15),
);
while (!ready) {
await new Promise((resolve) => setTimeout(resolve, pollInterval));
const pods = await this.kubeClient.listNamespacedPod(this.namespace);
@ -312,16 +321,24 @@ class Kubernetes {
core.error('Kubernetes job failed');
} else {
ready = true;
podname = element.metadata?.name;
containerId = element.status?.containerStatuses?.[0].containerID;
return element;
}
}
}
}
}
core.info(`Watching build job ${podname}`);
static async watchBuildJobUntilFinished() {
const pod = (await Kubernetes.watchPodUntilReadyAndRead()) || {};
const logs = await this.kubeClient.readNamespacedPodLog(podname, this.namespace, containerId, true);
core.info(`Watching build job ${pod.metadata?.name}`);
const logs = await this.kubeClient.readNamespacedPodLog(
pod.metadata?.name || '',
this.namespace,
pod.status?.containerStatuses?.[0].containerID,
true,
);
await new Promise((resolve, reject) => {
logs.response.on('data', (chunk) => {
core.info(chunk);