push k8s logs to LOG SERVICE IP

This commit is contained in:
Frostebite 2023-07-17 19:35:16 +01:00
parent e404132a7d
commit c77d0baa04
4 changed files with 11 additions and 7 deletions

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -36,6 +36,7 @@ class Kubernetes implements ProviderInterface {
public containerName: string = ''; public containerName: string = '';
public cleanupCronJobName: string = ''; public cleanupCronJobName: string = '';
public serviceAccountName: string = ''; public serviceAccountName: string = '';
public ip: string = '';
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
constructor(buildParameters: BuildParameters) { constructor(buildParameters: BuildParameters) {
@ -154,6 +155,8 @@ class Kubernetes implements ProviderInterface {
await KubernetesSecret.createSecret(secrets, this.secretName, this.namespace, this.kubeClient); await KubernetesSecret.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
let output = ''; let output = '';
try { try {
this.ip =
(await KubernetesLogService.createLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient)) || ``;
CloudRunnerLogger.log('Job does not exist'); CloudRunnerLogger.log('Job does not exist');
await this.createJob(commands, image, mountdir, workingdir, environment, secrets); await this.createJob(commands, image, mountdir, workingdir, environment, secrets);
CloudRunnerLogger.log('Watching pod until running'); CloudRunnerLogger.log('Watching pod until running');
@ -240,7 +243,6 @@ class Kubernetes implements ProviderInterface {
) { ) {
for (let index = 0; index < 3; index++) { for (let index = 0; index < 3; index++) {
try { try {
const ip = await KubernetesLogService.createLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
const jobSpec = KubernetesJobSpecFactory.getJobSpec( const jobSpec = KubernetesJobSpecFactory.getJobSpec(
commands, commands,
image, image,
@ -255,7 +257,7 @@ class Kubernetes implements ProviderInterface {
this.jobName, this.jobName,
k8s, k8s,
this.containerName, this.containerName,
ip, this.ip,
); );
await new Promise((promise) => setTimeout(promise, 15000)); await new Promise((promise) => setTimeout(promise, 15000));
@ -265,6 +267,7 @@ class Kubernetes implements ProviderInterface {
CloudRunnerLogger.log(`Build job created`); CloudRunnerLogger.log(`Build job created`);
await new Promise((promise) => setTimeout(promise, 5000)); await new Promise((promise) => setTimeout(promise, 5000));
CloudRunnerLogger.log('Job created'); CloudRunnerLogger.log('Job created');
await KubernetesLogService.cleanupLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
return result.body.metadata?.name; return result.body.metadata?.name;
} catch (error) { } catch (error) {
@ -285,6 +288,7 @@ class Kubernetes implements ProviderInterface {
await this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace); await this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace);
await this.kubeClient.deleteNamespacedPod(this.podName, this.namespace); await this.kubeClient.deleteNamespacedPod(this.podName, this.namespace);
await KubernetesRole.deleteRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api); await KubernetesRole.deleteRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api);
await KubernetesLogService.cleanupLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
} catch (error: any) { } catch (error: any) {
CloudRunnerLogger.log(`Failed to cleanup`); CloudRunnerLogger.log(`Failed to cleanup`);
if (error.response.body.reason !== `NotFound`) { if (error.response.body.reason !== `NotFound`) {

View File

@ -1,7 +1,11 @@
import { CoreV1Api } from '@kubernetes/client-node'; import { CoreV1Api } from '@kubernetes/client-node';
import * as k8s from '@kubernetes/client-node'; import * as k8s from '@kubernetes/client-node';
class KubernetesLogService { class KubernetesLogService {
// static async function, creates a deployment and service static async cleanupLogDeployment(namespace: string, kubeClientApps: k8s.AppsV1Api, kubeClient: CoreV1Api) {
await kubeClient.deleteNamespacedService('http-fileserver', namespace);
await kubeClientApps.deleteNamespacedDeployment('http-fileserver', namespace);
}
static async createLogService(serviceAccountName: string, namespace: string, kubeClient: CoreV1Api) { static async createLogService(serviceAccountName: string, namespace: string, kubeClient: CoreV1Api) {
const serviceAccount = new k8s.V1ServiceAccount(); const serviceAccount = new k8s.V1ServiceAccount();
serviceAccount.apiVersion = 'v1'; serviceAccount.apiVersion = 'v1';
@ -14,10 +18,6 @@ class KubernetesLogService {
return kubeClient.createNamespacedServiceAccount(namespace, serviceAccount); return kubeClient.createNamespacedServiceAccount(namespace, serviceAccount);
} }
static async deleteLogService(serviceAccountName: string, namespace: string, kubeClient: CoreV1Api) {
await kubeClient.deleteNamespacedServiceAccount(serviceAccountName, namespace);
}
static async createLogDeployment(namespace: string, kubeClient: k8s.AppsV1Api, kubeClientCore: CoreV1Api) { static async createLogDeployment(namespace: string, kubeClient: k8s.AppsV1Api, kubeClientCore: CoreV1Api) {
// json // json
/* /*