push k8s logs to LOG SERVICE IP
parent
e404132a7d
commit
c77d0baa04
|
|
@ -3275,6 +3275,7 @@ class Kubernetes {
|
||||||
this.containerName = '';
|
this.containerName = '';
|
||||||
this.cleanupCronJobName = '';
|
this.cleanupCronJobName = '';
|
||||||
this.serviceAccountName = '';
|
this.serviceAccountName = '';
|
||||||
|
this.ip = '';
|
||||||
Kubernetes.Instance = this;
|
Kubernetes.Instance = this;
|
||||||
this.kubeConfig = new k8s.KubeConfig();
|
this.kubeConfig = new k8s.KubeConfig();
|
||||||
this.kubeConfig.loadFromDefault();
|
this.kubeConfig.loadFromDefault();
|
||||||
|
|
@ -3367,6 +3368,8 @@ class Kubernetes {
|
||||||
await kubernetes_secret_1.default.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
|
await kubernetes_secret_1.default.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
|
||||||
let output = '';
|
let output = '';
|
||||||
try {
|
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');
|
cloud_runner_logger_1.default.log('Job does not exist');
|
||||||
await this.createJob(commands, image, mountdir, workingdir, environment, secrets);
|
await this.createJob(commands, image, mountdir, workingdir, environment, secrets);
|
||||||
cloud_runner_logger_1.default.log('Watching pod until running');
|
cloud_runner_logger_1.default.log('Watching pod until running');
|
||||||
|
|
@ -3416,14 +3419,14 @@ class Kubernetes {
|
||||||
async createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets) {
|
async createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets) {
|
||||||
for (let index = 0; index < 3; index++) {
|
for (let index = 0; index < 3; index++) {
|
||||||
try {
|
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, this.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, ip);
|
|
||||||
await new Promise((promise) => setTimeout(promise, 15000));
|
await new Promise((promise) => setTimeout(promise, 15000));
|
||||||
// await KubernetesRole.createRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api);
|
// await KubernetesRole.createRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api);
|
||||||
const result = await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
const result = await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||||
cloud_runner_logger_1.default.log(`Build job created`);
|
cloud_runner_logger_1.default.log(`Build job created`);
|
||||||
await new Promise((promise) => setTimeout(promise, 5000));
|
await new Promise((promise) => setTimeout(promise, 5000));
|
||||||
cloud_runner_logger_1.default.log('Job created');
|
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;
|
return result.body.metadata?.name;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
@ -3442,6 +3445,7 @@ class Kubernetes {
|
||||||
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 kubernetes_role_1.KubernetesRole.deleteRole(this.serviceAccountName, this.namespace, this.rbacAuthorizationV1Api);
|
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) {
|
catch (error) {
|
||||||
cloud_runner_logger_1.default.log(`Failed to cleanup`);
|
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 }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const k8s = __importStar(__nccwpck_require__(89679));
|
const k8s = __importStar(__nccwpck_require__(89679));
|
||||||
class KubernetesLogService {
|
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) {
|
static async createLogService(serviceAccountName, namespace, kubeClient) {
|
||||||
const serviceAccount = new k8s.V1ServiceAccount();
|
const serviceAccount = new k8s.V1ServiceAccount();
|
||||||
serviceAccount.apiVersion = 'v1';
|
serviceAccount.apiVersion = 'v1';
|
||||||
|
|
@ -3646,9 +3653,6 @@ class KubernetesLogService {
|
||||||
serviceAccount.automountServiceAccountToken = true;
|
serviceAccount.automountServiceAccountToken = true;
|
||||||
return kubeClient.createNamespacedServiceAccount(namespace, serviceAccount);
|
return kubeClient.createNamespacedServiceAccount(namespace, serviceAccount);
|
||||||
}
|
}
|
||||||
static async deleteLogService(serviceAccountName, namespace, kubeClient) {
|
|
||||||
await kubeClient.deleteNamespacedServiceAccount(serviceAccountName, namespace);
|
|
||||||
}
|
|
||||||
static async createLogDeployment(namespace, kubeClient, kubeClientCore) {
|
static async createLogDeployment(namespace, kubeClient, kubeClientCore) {
|
||||||
// json
|
// json
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -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`) {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue