exported KubernetesContainerRunner, KubernetesContainerRunnerOptions, KubernetesContainerRunnerMountBase
Signed-off-by: Matteo Silvestri <matteosilv@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-common': patch
|
||||
---
|
||||
|
||||
exported KubernetesContainerRunner, KubernetesContainerRunnerOptions, KubernetesContainerRunnerMountBase
|
||||
@@ -28,6 +28,7 @@ import { GitLabIntegration } from '@backstage/integration';
|
||||
import { isChildPath } from '@backstage/cli-common';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { Knex } from 'knex';
|
||||
import { KubeConfig } from '@kubernetes/client-node';
|
||||
import { LoadConfigOptionsRemote } from '@backstage/config-loader';
|
||||
import { Logger } from 'winston';
|
||||
import { MergeResult } from 'isomorphic-git';
|
||||
@@ -37,6 +38,7 @@ import { ReadCommitResult } from 'isomorphic-git';
|
||||
import { RequestHandler } from 'express';
|
||||
import { Router } from 'express';
|
||||
import { Server } from 'http';
|
||||
import { V1PodTemplateSpec } from '@kubernetes/client-node';
|
||||
import * as winston from 'winston';
|
||||
import { Writable } from 'stream';
|
||||
|
||||
@@ -474,6 +476,29 @@ export { isChildPath };
|
||||
// @public
|
||||
export function isDatabaseConflictError(e: unknown): boolean;
|
||||
|
||||
// @public
|
||||
export class KubernetesContainerRunner implements ContainerRunner {
|
||||
constructor(options: KubernetesContainerRunnerOptions);
|
||||
// (undocumented)
|
||||
runContainer(options: RunContainerOptions): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type KubernetesContainerRunnerMountBase = {
|
||||
volumeName: string;
|
||||
basePath: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type KubernetesContainerRunnerOptions = {
|
||||
kubeConfig: KubeConfig;
|
||||
name: string;
|
||||
namespace?: string;
|
||||
mountBase?: KubernetesContainerRunnerMountBase;
|
||||
podTemplate?: V1PodTemplateSpec;
|
||||
timeoutMs?: number;
|
||||
};
|
||||
|
||||
// @public
|
||||
export function loadBackendConfig(options: {
|
||||
logger: Logger;
|
||||
|
||||
@@ -39,7 +39,7 @@ import { Request } from 'request';
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type MountBaseOptions = {
|
||||
export type KubernetesContainerRunnerMountBase = {
|
||||
volumeName: string;
|
||||
basePath: string;
|
||||
};
|
||||
@@ -51,7 +51,7 @@ export type MountBaseOptions = {
|
||||
* and their names will be prefixed with the provided 'name'.
|
||||
*
|
||||
* 'podTemplate' defines a Pod template for the Jobs. It has to include
|
||||
* a volume definition named as the {@link MountBaseOptions} 'volumeName'.
|
||||
* a volume definition named as the {@link KubernetesContainerRunnerMountBase} 'volumeName'.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
@@ -59,7 +59,7 @@ export type KubernetesContainerRunnerOptions = {
|
||||
kubeConfig: KubeConfig;
|
||||
name: string;
|
||||
namespace?: string;
|
||||
mountBase?: MountBaseOptions;
|
||||
mountBase?: KubernetesContainerRunnerMountBase;
|
||||
podTemplate?: V1PodTemplateSpec;
|
||||
timeoutMs?: number;
|
||||
};
|
||||
@@ -77,12 +77,12 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
private readonly log: Log;
|
||||
private readonly name: string;
|
||||
private readonly namespace: string;
|
||||
private readonly mountBase?: MountBaseOptions;
|
||||
private readonly mountBase?: KubernetesContainerRunnerMountBase;
|
||||
private readonly podTemplate?: V1PodTemplateSpec;
|
||||
private readonly timeoutMs: number;
|
||||
private readonly containerName = 'executor';
|
||||
|
||||
getNamespace(kubeConfig: KubeConfig, namespace?: string): string {
|
||||
private getNamespace(kubeConfig: KubeConfig, namespace?: string): string {
|
||||
let _namespace = namespace;
|
||||
if (!_namespace) {
|
||||
_namespace = kubeConfig.getContextObject(
|
||||
@@ -95,10 +95,10 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
return _namespace;
|
||||
}
|
||||
|
||||
validateMountBase(
|
||||
mountBase: MountBaseOptions,
|
||||
private validateMountBase(
|
||||
mountBase: KubernetesContainerRunnerMountBase,
|
||||
podTemplate?: V1PodTemplateSpec,
|
||||
): MountBaseOptions {
|
||||
): KubernetesContainerRunnerMountBase {
|
||||
if (
|
||||
!podTemplate?.spec?.volumes?.filter(v => v.name === mountBase.volumeName)
|
||||
.length
|
||||
@@ -213,7 +213,7 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
await this.runJob(jobSpec, taskId, logStream);
|
||||
}
|
||||
|
||||
handleError(err: any, errorCallback: (reason: any) => void) {
|
||||
private handleError(err: any, errorCallback: (reason: any) => void) {
|
||||
if (err.code !== 'ECONNRESET' && err.message !== 'aborted') {
|
||||
errorCallback(
|
||||
handleKubernetesError(
|
||||
@@ -224,7 +224,7 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
}
|
||||
}
|
||||
|
||||
watchPod(
|
||||
private watchPod(
|
||||
taskId: string,
|
||||
callback: (pod: V1Pod) => void,
|
||||
errorCallback: (reason: any) => void,
|
||||
@@ -247,7 +247,7 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
);
|
||||
}
|
||||
|
||||
tailLogs(
|
||||
private tailLogs(
|
||||
taskId: string,
|
||||
logStream: Writable,
|
||||
): { promise: Promise<void>; close: () => Promise<void> } {
|
||||
@@ -295,7 +295,7 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
return { promise: Promise.race([watchPromise, logPromise]), close };
|
||||
}
|
||||
|
||||
waitPod(taskId: string): {
|
||||
private waitPod(taskId: string): {
|
||||
promise: Promise<void>;
|
||||
close: () => Promise<void>;
|
||||
} {
|
||||
@@ -322,7 +322,7 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
return { promise, close };
|
||||
}
|
||||
|
||||
async createJob(jobSpec: V1Job): Promise<any> {
|
||||
private async createJob(jobSpec: V1Job): Promise<any> {
|
||||
return this.batchV1Api
|
||||
.createNamespacedJob(this.namespace, jobSpec)
|
||||
.catch(err => {
|
||||
@@ -333,7 +333,7 @@ export class KubernetesContainerRunner implements ContainerRunner {
|
||||
});
|
||||
}
|
||||
|
||||
async runJob(
|
||||
private async runJob(
|
||||
jobSpec: V1Job,
|
||||
taskId: string,
|
||||
logStream: Writable,
|
||||
|
||||
@@ -16,3 +16,8 @@
|
||||
|
||||
export type { ContainerRunner, RunContainerOptions } from './ContainerRunner';
|
||||
export { DockerContainerRunner } from './DockerContainerRunner';
|
||||
export type {
|
||||
KubernetesContainerRunnerOptions,
|
||||
KubernetesContainerRunnerMountBase,
|
||||
} from './KubernetesContainerRunner';
|
||||
export { KubernetesContainerRunner } from './KubernetesContainerRunner';
|
||||
|
||||
Reference in New Issue
Block a user