Using Log class from k8s client to stream
parent
0d1f360db7
commit
b3dee76d5a
|
|
@ -731,6 +731,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const k8s = __importStar(__webpack_require__(89679));
|
const k8s = __importStar(__webpack_require__(89679));
|
||||||
const core = __importStar(__webpack_require__(42186));
|
const core = __importStar(__webpack_require__(42186));
|
||||||
|
const client_node_1 = __webpack_require__(89679);
|
||||||
|
const stream_1 = __webpack_require__(92413);
|
||||||
const base64 = __webpack_require__(85848);
|
const base64 = __webpack_require__(85848);
|
||||||
const pollInterval = 20000;
|
const pollInterval = 20000;
|
||||||
class Kubernetes {
|
class Kubernetes {
|
||||||
|
|
@ -747,6 +749,7 @@ class Kubernetes {
|
||||||
const secretName = `build-credentials-${buildId}`;
|
const secretName = `build-credentials-${buildId}`;
|
||||||
const jobName = `unity-builder-job-${buildId}`;
|
const jobName = `unity-builder-job-${buildId}`;
|
||||||
const namespace = 'default';
|
const namespace = 'default';
|
||||||
|
this.kubeConfig = kc;
|
||||||
this.kubeClient = k8sApi;
|
this.kubeClient = k8sApi;
|
||||||
this.kubeClientBatch = k8sBatchApi;
|
this.kubeClientBatch = k8sBatchApi;
|
||||||
this.buildId = buildId;
|
this.buildId = buildId;
|
||||||
|
|
@ -1048,12 +1051,12 @@ class Kubernetes {
|
||||||
running = ((_a = pod.body.status) === null || _a === void 0 ? void 0 : _a.phase) === 'Running';
|
running = ((_a = pod.body.status) === null || _a === void 0 ? void 0 : _a.phase) === 'Running';
|
||||||
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
|
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||||
core.info('Polling logs...');
|
core.info('Polling logs...');
|
||||||
const logs = yield this.kubeClient.readNamespacedPodLog(name, namespace, container, true, undefined, undefined, undefined, undefined, undefined, undefined, true);
|
const stream = new stream_1.Writable();
|
||||||
logs.response.on('data', (data) => {
|
stream._write = (chunk, encoding, next) => {
|
||||||
core.info('LOGS RECEIVED');
|
core.info(chunk.toString());
|
||||||
core.info(data);
|
next();
|
||||||
});
|
};
|
||||||
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
|
yield new Promise((resolve) => new client_node_1.Log(this.kubeConfig).log(namespace, name, container, stream, resolve));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,11 +1,14 @@
|
||||||
import * as k8s from '@kubernetes/client-node';
|
import * as k8s from '@kubernetes/client-node';
|
||||||
import { BuildParameters } from '.';
|
import { BuildParameters } from '.';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import { KubeConfig, Log } from '@kubernetes/client-node';
|
||||||
|
import { Writable } from 'stream';
|
||||||
const base64 = require('base-64');
|
const base64 = require('base-64');
|
||||||
|
|
||||||
const pollInterval = 20000;
|
const pollInterval = 20000;
|
||||||
|
|
||||||
class Kubernetes {
|
class Kubernetes {
|
||||||
|
private static kubeConfig: KubeConfig;
|
||||||
private static kubeClient: k8s.CoreV1Api;
|
private static kubeClient: k8s.CoreV1Api;
|
||||||
private static kubeClientBatch: k8s.BatchV1Api;
|
private static kubeClientBatch: k8s.BatchV1Api;
|
||||||
private static buildId: string;
|
private static buildId: string;
|
||||||
|
|
@ -32,6 +35,7 @@ class Kubernetes {
|
||||||
const jobName = `unity-builder-job-${buildId}`;
|
const jobName = `unity-builder-job-${buildId}`;
|
||||||
const namespace = 'default';
|
const namespace = 'default';
|
||||||
|
|
||||||
|
this.kubeConfig = kc;
|
||||||
this.kubeClient = k8sApi;
|
this.kubeClient = k8sApi;
|
||||||
this.kubeClientBatch = k8sBatchApi;
|
this.kubeClientBatch = k8sBatchApi;
|
||||||
this.buildId = buildId;
|
this.buildId = buildId;
|
||||||
|
|
@ -336,24 +340,12 @@ class Kubernetes {
|
||||||
running = pod.body.status?.phase === 'Running';
|
running = pod.body.status?.phase === 'Running';
|
||||||
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||||
core.info('Polling logs...');
|
core.info('Polling logs...');
|
||||||
const logs = await this.kubeClient.readNamespacedPodLog(
|
const stream = new Writable();
|
||||||
name,
|
stream._write = (chunk, encoding, next) => {
|
||||||
namespace,
|
core.info(chunk.toString());
|
||||||
container,
|
next();
|
||||||
true,
|
};
|
||||||
undefined,
|
await new Promise((resolve) => new Log(this.kubeConfig).log(namespace, name, container, stream, resolve));
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
logs.response.on('data', (data) => {
|
|
||||||
core.info('LOGS RECEIVED');
|
|
||||||
core.info(data);
|
|
||||||
});
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(JSON.stringify(error, undefined, 4));
|
core.error(JSON.stringify(error, undefined, 4));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue