Improve k8s logging accuracy
parent
ac9288231e
commit
7f14855a64
|
@ -3312,6 +3312,13 @@ class Kubernetes {
|
|||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
try {
|
||||
const existsAlready = yield this.doesJobExist(this.jobName);
|
||||
if (!existsAlready) {
|
||||
cloud_runner_logger_1.default.log('Job does not exist');
|
||||
yield this.createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets);
|
||||
cloud_runner_logger_1.default.log('Watching pod until running');
|
||||
yield kubernetes_task_runner_1.default.watchUntilPodRunning(this.kubeClient, this.podName, this.namespace);
|
||||
}
|
||||
cloud_runner_logger_1.default.log('Pod running, streaming logs');
|
||||
output = yield kubernetes_task_runner_1.default.runTask(this.kubeConfig, this.kubeClient, this.jobName, this.podName, 'main', this.namespace);
|
||||
const running = yield kubernetes_pods_1.default.IsPodRunning(this.podName, this.namespace, this.kubeClient);
|
||||
|
@ -3360,17 +3367,24 @@ class Kubernetes {
|
|||
}
|
||||
});
|
||||
}
|
||||
doesJobExist(name) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const jobs = yield this.kubeClientBatch.listNamespacedJob(this.namespace);
|
||||
return jobs.body.items.some((x) => { var _a; return ((_a = x.metadata) === null || _a === void 0 ? void 0 : _a.name) === name; });
|
||||
});
|
||||
}
|
||||
createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
for (let index = 0; index < 3; index++) {
|
||||
try {
|
||||
const jobSpec = kubernetes_job_spec_factory_1.default.getJobSpec(commands, image, mountdir, workingdir, environment, secrets, this.buildGuid, this.buildParameters, this.secretName, this.pvcName, this.jobName, k8s);
|
||||
yield new Promise((promise) => setTimeout(promise, 15000));
|
||||
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||
const result = yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||
cloud_runner_logger_1.default.log(`Build job created`);
|
||||
yield new Promise((promise) => setTimeout(promise, 5000));
|
||||
cloud_runner_logger_1.default.log('Job created');
|
||||
return;
|
||||
return (_a = result.body.metadata) === null || _a === void 0 ? void 0 : _a.name;
|
||||
}
|
||||
catch (error) {
|
||||
cloud_runner_logger_1.default.log(`Error occured creating job: ${error}`);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -137,6 +137,13 @@ class Kubernetes implements ProviderInterface {
|
|||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
try {
|
||||
const existsAlready = await this.doesJobExist(this.jobName);
|
||||
if (!existsAlready) {
|
||||
CloudRunnerLogger.log('Job does not exist');
|
||||
await this.createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets);
|
||||
CloudRunnerLogger.log('Watching pod until running');
|
||||
await KubernetesTaskRunner.watchUntilPodRunning(this.kubeClient, this.podName, this.namespace);
|
||||
}
|
||||
CloudRunnerLogger.log('Pod running, streaming logs');
|
||||
output = await KubernetesTaskRunner.runTask(
|
||||
this.kubeConfig,
|
||||
|
@ -193,6 +200,12 @@ class Kubernetes implements ProviderInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private async doesJobExist(name) {
|
||||
const jobs = await this.kubeClientBatch.listNamespacedJob(this.namespace);
|
||||
|
||||
return jobs.body.items.some((x) => x.metadata?.name === name);
|
||||
}
|
||||
|
||||
private async createNamespacedJob(
|
||||
commands: string,
|
||||
image: string,
|
||||
|
@ -218,12 +231,12 @@ class Kubernetes implements ProviderInterface {
|
|||
k8s,
|
||||
);
|
||||
await new Promise((promise) => setTimeout(promise, 15000));
|
||||
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||
const result = await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||
CloudRunnerLogger.log(`Build job created`);
|
||||
await new Promise((promise) => setTimeout(promise, 5000));
|
||||
CloudRunnerLogger.log('Job created');
|
||||
|
||||
return;
|
||||
return result.body.metadata?.name;
|
||||
} catch (error) {
|
||||
CloudRunnerLogger.log(`Error occured creating job: ${error}`);
|
||||
throw error;
|
||||
|
|
Loading…
Reference in New Issue