Cleanup error logging
parent
a67902498b
commit
536d0aaf66
|
|
@ -2001,6 +2001,25 @@ exports.default = KubernetesJobSpecFactory;
|
|||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
|
|
@ -2018,6 +2037,7 @@ const client_node_1 = __webpack_require__(89679);
|
|||
const stream_1 = __webpack_require__(92413);
|
||||
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
|
||||
const cloud_runner_state_1 = __webpack_require__(70912);
|
||||
const core = __importStar(__webpack_require__(42186));
|
||||
const fs_1 = __importDefault(__webpack_require__(35747));
|
||||
const cloud_runner_statics_1 = __webpack_require__(90828);
|
||||
class KubernetesLogging {
|
||||
|
|
@ -2047,8 +2067,8 @@ class KubernetesLogging {
|
|||
throw resultError;
|
||||
}
|
||||
if (!didStreamAnyLogs) {
|
||||
throw new Error(JSON.stringify({
|
||||
message: 'Failed to stream any logs, listing namespace events, check for an error with the container',
|
||||
core.error('Failed to stream any logs, listing namespace events, check for an error with the container');
|
||||
core.error(JSON.stringify({
|
||||
events: (yield kubeClient.listNamespacedEvent(namespace)).body.items
|
||||
.filter((x) => {
|
||||
return x.involvedObject.name === podName || x.involvedObject.name === jobName;
|
||||
|
|
@ -2061,6 +2081,7 @@ class KubernetesLogging {
|
|||
};
|
||||
}),
|
||||
}, undefined, 4));
|
||||
throw new Error(`No logs streamed from k8s`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
|
@ -2354,8 +2375,8 @@ const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
|
|||
class KubernetesUtilities {
|
||||
static findPodFromJob(kubeClient, jobName, namespace) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const newLocal = yield kubeClient.listNamespacedPod(namespace);
|
||||
const pod = (newLocal).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']) === jobName; });
|
||||
const namespacedPods = yield kubeClient.listNamespacedPod(namespace);
|
||||
const pod = namespacedPods.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']) === jobName; });
|
||||
if (pod === undefined) {
|
||||
throw new Error("pod with job-name label doesn't exist");
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -54,6 +54,9 @@
|
|||
"typescript": "^4.1.3",
|
||||
"ts-node": "^10.4.0"
|
||||
},
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged && yarn build && git add dist/index.*"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,jsx,ts,tsx}": [
|
||||
"prettier --write",
|
||||
|
|
@ -67,7 +70,6 @@
|
|||
],
|
||||
"*.sh": [
|
||||
"git update-index --chmod=+x"
|
||||
],
|
||||
"*.js": "eslint --cache --fix"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,11 +34,13 @@ describe('Cloud Runner', () => {
|
|||
expect(file).toContain(JSON.stringify(buildParameter));
|
||||
expect(file).toContain(`${testSecretName}=${testSecretValue}`);
|
||||
const inputKeys = Object.getOwnPropertyNames(Input);
|
||||
const newLinePurgedFile = file
|
||||
.replace(/\s+/g, '')
|
||||
.replace(new RegExp(`\\[${CloudRunnerStatics.logPrefix}\\]`, 'g'), '');
|
||||
for (const element of inputKeys) {
|
||||
if (Input[element] !== undefined && typeof Input[element] !== 'function') {
|
||||
expect(
|
||||
file.replace(/\s+/g, '').replace(new RegExp(`\\[${CloudRunnerStatics.logPrefix}\\]`, 'g'), ''),
|
||||
).toContain(`${element}=${Input[element].toString().replace(/\s+/g, '')}`);
|
||||
const newLinePurgedValue = Input[element].toString().replace(/\s+/g, '');
|
||||
expect(newLinePurgedFile).toContain(`${element}=${newLinePurgedValue}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { CoreV1Api, KubeConfig, Log } from '@kubernetes/client-node';
|
|||
import { Writable } from 'stream';
|
||||
import CloudRunnerLogger from '../services/cloud-runner-logger';
|
||||
import { CloudRunnerState } from '../state/cloud-runner-state';
|
||||
import * as core from '@actions/core';
|
||||
import fs from 'fs';
|
||||
import { CloudRunnerStatics } from '../cloud-runner-statics';
|
||||
|
||||
|
|
@ -41,10 +42,10 @@ class KubernetesLogging {
|
|||
throw resultError;
|
||||
}
|
||||
if (!didStreamAnyLogs) {
|
||||
throw new Error(
|
||||
core.error('Failed to stream any logs, listing namespace events, check for an error with the container');
|
||||
core.error(
|
||||
JSON.stringify(
|
||||
{
|
||||
message: 'Failed to stream any logs, listing namespace events, check for an error with the container',
|
||||
events: (await kubeClient.listNamespacedEvent(namespace)).body.items
|
||||
.filter((x) => {
|
||||
return x.involvedObject.name === podName || x.involvedObject.name === jobName;
|
||||
|
|
@ -61,6 +62,7 @@ class KubernetesLogging {
|
|||
4,
|
||||
),
|
||||
);
|
||||
throw new Error(`No logs streamed from k8s`);
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ import CloudRunnerLogger from '../services/cloud-runner-logger';
|
|||
|
||||
class KubernetesUtilities {
|
||||
static async findPodFromJob(kubeClient: CoreV1Api, jobName: string, namespace: string) {
|
||||
const pod = (await kubeClient.listNamespacedPod(namespace)).body.items.find(
|
||||
(x) => x.metadata?.labels?.['job-name'] === jobName,
|
||||
);
|
||||
const namespacedPods = await kubeClient.listNamespacedPod(namespace);
|
||||
const pod = namespacedPods.body.items.find((x) => x.metadata?.labels?.['job-name'] === jobName);
|
||||
if (pod === undefined) {
|
||||
throw new Error("pod with job-name label doesn't exist");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue