Log stream attempt #3 - get podname

pull/273/head
Frostebite 2021-06-06 03:28:42 +01:00
parent 464e5f0caa
commit 792dbec1a5
3 changed files with 18 additions and 8 deletions

13
dist/index.js vendored
View File

@ -732,7 +732,7 @@ 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 base64 = __webpack_require__(85848); const base64 = __webpack_require__(85848);
const pollInterval = 10000; const pollInterval = 20000;
class Kubernetes { class Kubernetes {
static run(buildParameters, baseImage) { static run(buildParameters, baseImage) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -1005,7 +1005,7 @@ class Kubernetes {
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 pod = (_a = (yield this.kubeClient.readNamespacedPod(this.name, this.namespace))) === null || _a === void 0 ? void 0 : _a.body; const pod = (_a = (yield this.kubeClient.readNamespacedPod(this.podName, this.namespace))) === null || _a === void 0 ? void 0 : _a.body;
if (pod === undefined) { if (pod === undefined) {
throw new Error('no pod found'); throw new Error('no pod found');
} }
@ -1022,12 +1022,15 @@ class Kubernetes {
}); });
} }
static watchBuildJobUntilFinished() { static watchBuildJobUntilFinished() {
var _a, _b, _c, _d; var _a, _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
this.podName =
((_b = (_a = (yield this.kubeClient.listNamespacedPod(this.namespace)).body.items.find((x) => { var _a, _b; return ((_b = (_a = x.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b['job-name']) === this.jobName; })) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.name) || '';
core.info(this.podName);
const pod = yield Kubernetes.watchPodUntilRunningAndRead(); const pod = yield Kubernetes.watchPodUntilRunningAndRead();
core.info(`Watching build job ${(_a = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _a === void 0 ? void 0 : _a.name}`); core.info(`Watching build job ${(_c = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _c === void 0 ? void 0 : _c.name}`);
yield Kubernetes.streamLogs(((_b = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _b === void 0 ? void 0 : _b.name) || '', this.namespace, ((_d = (_c = pod === null || pod === void 0 ? void 0 : pod.status) === null || _c === void 0 ? void 0 : _c.containerStatuses) === null || _d === void 0 ? void 0 : _d[0].name) || ''); yield Kubernetes.streamLogs(((_d = pod === null || pod === void 0 ? void 0 : pod.metadata) === null || _d === void 0 ? void 0 : _d.name) || '', this.namespace, ((_f = (_e = pod === null || pod === void 0 ? void 0 : pod.status) === null || _e === void 0 ? void 0 : _e.containerStatuses) === null || _f === void 0 ? void 0 : _f[0].name) || '');
} }
catch (error) { catch (error) {
core.error('Failed while watching build job'); core.error('Failed while watching build job');

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ import { BuildParameters } from '.';
import * as core from '@actions/core'; import * as core from '@actions/core';
const base64 = require('base-64'); const base64 = require('base-64');
const pollInterval = 10000; const pollInterval = 20000;
class Kubernetes { class Kubernetes {
private static kubeClient: k8s.CoreV1Api; private static kubeClient: k8s.CoreV1Api;
@ -14,6 +14,8 @@ class Kubernetes {
private static pvcName: string; private static pvcName: string;
private static secretName: string; private static secretName: string;
private static jobName: string; private static jobName: string;
private static podName: string;
private static containerName: string;
private static namespace: string; private static namespace: string;
static async run(buildParameters: BuildParameters, baseImage) { static async run(buildParameters: BuildParameters, baseImage) {
@ -290,7 +292,7 @@ class Kubernetes {
while (!ready) { while (!ready) {
await new Promise((resolve) => setTimeout(resolve, pollInterval)); await new Promise((resolve) => setTimeout(resolve, pollInterval));
const pod = (await this.kubeClient.readNamespacedPod(this.name, this.namespace))?.body; const pod = (await this.kubeClient.readNamespacedPod(this.podName, this.namespace))?.body;
if (pod === undefined) { if (pod === undefined) {
throw new Error('no pod found'); throw new Error('no pod found');
} }
@ -308,6 +310,11 @@ class Kubernetes {
static async watchBuildJobUntilFinished() { static async watchBuildJobUntilFinished() {
try { try {
this.podName =
(await this.kubeClient.listNamespacedPod(this.namespace)).body.items.find(
(x) => x.metadata?.labels?.['job-name'] === this.jobName,
)?.metadata?.name || '';
core.info(this.podName);
const pod = await Kubernetes.watchPodUntilRunningAndRead(); const pod = await Kubernetes.watchPodUntilRunningAndRead();
core.info(`Watching build job ${pod?.metadata?.name}`); core.info(`Watching build job ${pod?.metadata?.name}`);
await Kubernetes.streamLogs( await Kubernetes.streamLogs(