push k8s logs to LOG SERVICE IP
parent
e404132a7d
commit
c77d0baa04
|
@ -3275,6 +3275,7 @@ class Kubernetes {
|
|||
this.containerName = '';
|
||||
this.cleanupCronJobName = '';
|
||||
this.serviceAccountName = '';
|
||||
this.ip = '';
|
||||
Kubernetes.Instance = this;
|
||||
this.kubeConfig = new k8s.KubeConfig();
|
||||
this.kubeConfig.loadFromDefault();
|
||||
|
@ -3367,6 +3368,8 @@ class Kubernetes {
|
|||
await kubernetes_secret_1.default.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
|
||||
let output = '';
|
||||
try {
|
||||
this.ip =
|
||||
(await kubernetes_log_service_1.default.createLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient)) || ``;
|
||||
cloud_runner_logger_1.default.log('Job does not exist');
|
||||
await this.createJob(commands, image, mountdir, workingdir, environment, secrets);
|
||||
cloud_runner_logger_1.default.log('Watching pod until running');
|
||||
|
@ -3416,14 +3419,14 @@ class Kubernetes {
|
|||
async createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets) {
|
||||
for (let index = 0; index < 3; index++) {
|
||||
try {
|
||||
const ip = await kubernetes_log_service_1.default.createLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
|
||||
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, this.containerName, ip);
|
||||
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, this.containerName, this.ip);
|
||||
await new Promise((promise) => setTimeout(promise, 15000));
|
||||
// await KubernetesRole.createRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api);
|
||||
const result = await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||
cloud_runner_logger_1.default.log(`Build job created`);
|
||||
await new Promise((promise) => setTimeout(promise, 5000));
|
||||
cloud_runner_logger_1.default.log('Job created');
|
||||
await kubernetes_log_service_1.default.cleanupLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
|
||||
return result.body.metadata?.name;
|
||||
}
|
||||
catch (error) {
|
||||
|
@ -3442,6 +3445,7 @@ class Kubernetes {
|
|||
await this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace);
|
||||
await this.kubeClient.deleteNamespacedPod(this.podName, this.namespace);
|
||||
await kubernetes_role_1.KubernetesRole.deleteRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api);
|
||||
await kubernetes_log_service_1.default.cleanupLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
|
||||
}
|
||||
catch (error) {
|
||||
cloud_runner_logger_1.default.log(`Failed to cleanup`);
|
||||
|
@ -3635,7 +3639,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const k8s = __importStar(__nccwpck_require__(89679));
|
||||
class KubernetesLogService {
|
||||
// static async function, creates a deployment and service
|
||||
static async cleanupLogDeployment(namespace, kubeClientApps, kubeClient) {
|
||||
await kubeClient.deleteNamespacedService('http-fileserver', namespace);
|
||||
await kubeClientApps.deleteNamespacedDeployment('http-fileserver', namespace);
|
||||
}
|
||||
static async createLogService(serviceAccountName, namespace, kubeClient) {
|
||||
const serviceAccount = new k8s.V1ServiceAccount();
|
||||
serviceAccount.apiVersion = 'v1';
|
||||
|
@ -3646,9 +3653,6 @@ class KubernetesLogService {
|
|||
serviceAccount.automountServiceAccountToken = true;
|
||||
return kubeClient.createNamespacedServiceAccount(namespace, serviceAccount);
|
||||
}
|
||||
static async deleteLogService(serviceAccountName, namespace, kubeClient) {
|
||||
await kubeClient.deleteNamespacedServiceAccount(serviceAccountName, namespace);
|
||||
}
|
||||
static async createLogDeployment(namespace, kubeClient, kubeClientCore) {
|
||||
// json
|
||||
/*
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -36,6 +36,7 @@ class Kubernetes implements ProviderInterface {
|
|||
public containerName: string = '';
|
||||
public cleanupCronJobName: string = '';
|
||||
public serviceAccountName: string = '';
|
||||
public ip: string = '';
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
constructor(buildParameters: BuildParameters) {
|
||||
|
@ -154,6 +155,8 @@ class Kubernetes implements ProviderInterface {
|
|||
await KubernetesSecret.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
|
||||
let output = '';
|
||||
try {
|
||||
this.ip =
|
||||
(await KubernetesLogService.createLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient)) || ``;
|
||||
CloudRunnerLogger.log('Job does not exist');
|
||||
await this.createJob(commands, image, mountdir, workingdir, environment, secrets);
|
||||
CloudRunnerLogger.log('Watching pod until running');
|
||||
|
@ -240,7 +243,6 @@ class Kubernetes implements ProviderInterface {
|
|||
) {
|
||||
for (let index = 0; index < 3; index++) {
|
||||
try {
|
||||
const ip = await KubernetesLogService.createLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
|
||||
const jobSpec = KubernetesJobSpecFactory.getJobSpec(
|
||||
commands,
|
||||
image,
|
||||
|
@ -255,7 +257,7 @@ class Kubernetes implements ProviderInterface {
|
|||
this.jobName,
|
||||
k8s,
|
||||
this.containerName,
|
||||
ip,
|
||||
this.ip,
|
||||
);
|
||||
await new Promise((promise) => setTimeout(promise, 15000));
|
||||
|
||||
|
@ -265,6 +267,7 @@ class Kubernetes implements ProviderInterface {
|
|||
CloudRunnerLogger.log(`Build job created`);
|
||||
await new Promise((promise) => setTimeout(promise, 5000));
|
||||
CloudRunnerLogger.log('Job created');
|
||||
await KubernetesLogService.cleanupLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
|
||||
|
||||
return result.body.metadata?.name;
|
||||
} catch (error) {
|
||||
|
@ -285,6 +288,7 @@ class Kubernetes implements ProviderInterface {
|
|||
await this.kubeClientBatch.deleteNamespacedJob(this.jobName, this.namespace);
|
||||
await this.kubeClient.deleteNamespacedPod(this.podName, this.namespace);
|
||||
await KubernetesRole.deleteRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api);
|
||||
await KubernetesLogService.cleanupLogDeployment(this.namespace, this.kubeClientApps, this.kubeClient);
|
||||
} catch (error: any) {
|
||||
CloudRunnerLogger.log(`Failed to cleanup`);
|
||||
if (error.response.body.reason !== `NotFound`) {
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import { CoreV1Api } from '@kubernetes/client-node';
|
||||
import * as k8s from '@kubernetes/client-node';
|
||||
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) {
|
||||
const serviceAccount = new k8s.V1ServiceAccount();
|
||||
serviceAccount.apiVersion = 'v1';
|
||||
|
@ -14,10 +18,6 @@ class KubernetesLogService {
|
|||
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) {
|
||||
// json
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue