Merge branch 'backstage:master' into NS-648_configurable-engineer-threshold

This commit is contained in:
Chris Langhout
2022-11-25 11:21:25 +01:00
committed by GitHub
5 changed files with 92 additions and 36 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
exported KubernetesContainerRunner, KubernetesContainerRunnerOptions, KubernetesContainerRunnerMountBase
+25
View File
@@ -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';
+43 -22
View File
@@ -18007,7 +18007,7 @@ __metadata:
languageName: node
linkType: hard
"colorette@npm:2.0.19, colorette@npm:^2.0.10, colorette@npm:^2.0.16, colorette@npm:^2.0.17":
"colorette@npm:2.0.19, colorette@npm:^2.0.10, colorette@npm:^2.0.16, colorette@npm:^2.0.19":
version: 2.0.19
resolution: "colorette@npm:2.0.19"
checksum: 888cf5493f781e5fcf54ce4d49e9d7d698f96ea2b2ef67906834bb319a392c667f9ec69f4a10e268d2946d13a9503d2d19b3abaaaf174e3451bfe91fb9d82427
@@ -18075,7 +18075,7 @@ __metadata:
languageName: node
linkType: hard
"commander@npm:*, commander@npm:^9.1.0, commander@npm:^9.3.0":
"commander@npm:*, commander@npm:^9.1.0, commander@npm:^9.4.1":
version: 9.4.1
resolution: "commander@npm:9.4.1"
checksum: bfb18e325a5bdf772763c2213d5c7d9e77144d944124e988bcd8e5e65fb6d45d5d4e86b09155d0f2556c9a59c31e428720e57968bcd050b2306e910a0bf3cf13
@@ -26641,10 +26641,10 @@ __metadata:
languageName: node
linkType: hard
"lilconfig@npm:2.0.5, lilconfig@npm:^2.0.3":
version: 2.0.5
resolution: "lilconfig@npm:2.0.5"
checksum: f7bb9e42656f06930ad04e583026f087508ae408d3526b8b54895e934eb2a966b7aafae569656f2c79a29fe6d779b3ec44ba577e80814734c8655d6f71cdf2d1
"lilconfig@npm:2.0.6, lilconfig@npm:^2.0.3":
version: 2.0.6
resolution: "lilconfig@npm:2.0.6"
checksum: 40a3cd72f103b1be5975f2ac1850810b61d4053e20ab09be8d3aeddfe042187e1ba70b4651a7e70f95efa1642e7dc8b2ae395b317b7d7753b241b43cef7c0f7d
languageName: node
linkType: hard
@@ -26665,25 +26665,25 @@ __metadata:
linkType: hard
"lint-staged@npm:^13.0.0":
version: 13.0.3
resolution: "lint-staged@npm:13.0.3"
version: 13.0.4
resolution: "lint-staged@npm:13.0.4"
dependencies:
cli-truncate: ^3.1.0
colorette: ^2.0.17
commander: ^9.3.0
colorette: ^2.0.19
commander: ^9.4.1
debug: ^4.3.4
execa: ^6.1.0
lilconfig: 2.0.5
listr2: ^4.0.5
lilconfig: 2.0.6
listr2: ^5.0.5
micromatch: ^4.0.5
normalize-path: ^3.0.0
object-inspect: ^1.12.2
pidtree: ^0.6.0
string-argv: ^0.3.1
yaml: ^2.1.1
yaml: ^2.1.3
bin:
lint-staged: bin/lint-staged.js
checksum: 53d585007df06e162febab6b0836b55016d902586a267823c8a1158529d8c742dc7297e523f7023dff02250bef3eb0d6934f4ec4f9961adfc2ebbed5f54162d0
checksum: 4676172df5dc734a7f409ad786a72d39bd2239de8b2e5eb1d99eaa751479f60f7b4ef85c8508698855b51b125a512f395ac6a3c7d2d57de8e8221e0aaaab6f4f
languageName: node
linkType: hard
@@ -26729,6 +26729,27 @@ __metadata:
languageName: node
linkType: hard
"listr2@npm:^5.0.5":
version: 5.0.5
resolution: "listr2@npm:5.0.5"
dependencies:
cli-truncate: ^2.1.0
colorette: ^2.0.19
log-update: ^4.0.0
p-map: ^4.0.0
rfdc: ^1.3.0
rxjs: ^7.5.6
through: ^2.3.8
wrap-ansi: ^7.0.0
peerDependencies:
enquirer: ">= 2.3.0 < 3"
peerDependenciesMeta:
enquirer:
optional: true
checksum: 71c44eb648405d2725f248747ef8d5e192dd16938ec81df854c4a7e74ff1b3f4c3149461b1cff31c761bfbdf110f7f2603c9957c908294a1c6db299c9168608c
languageName: node
linkType: hard
"load-bmfont@npm:^1.3.1, load-bmfont@npm:^1.4.0":
version: 1.4.1
resolution: "load-bmfont@npm:1.4.1"
@@ -33456,12 +33477,12 @@ __metadata:
languageName: node
linkType: hard
"rxjs@npm:^7.0.0, rxjs@npm:^7.1.0, rxjs@npm:^7.5.1, rxjs@npm:^7.5.5":
version: 7.5.6
resolution: "rxjs@npm:7.5.6"
"rxjs@npm:^7.0.0, rxjs@npm:^7.1.0, rxjs@npm:^7.5.1, rxjs@npm:^7.5.5, rxjs@npm:^7.5.6":
version: 7.5.7
resolution: "rxjs@npm:7.5.7"
dependencies:
tslib: ^2.1.0
checksum: fc05f01364a74dac57490fb3e07ea63b422af04017fae1db641a009073f902ef69f285c5daac31359620dc8d9aee7d81e42b370ca2a8573d1feae0b04329383b
checksum: edabcdb73b0f7e0f5f6e05c2077aff8c52222ac939069729704357d6406438acca831c24210db320aba269e86dbe1a400f3769c89101791885121a342fb15d9c
languageName: node
linkType: hard
@@ -37891,10 +37912,10 @@ __metadata:
languageName: node
linkType: hard
"yaml@npm:^2.0.0, yaml@npm:^2.1.1":
version: 2.1.1
resolution: "yaml@npm:2.1.1"
checksum: f48bb209918aa57cfaf78ef6448d1a1f8187f45c746f933268b7023dc59e5456004611879126c9bb5ea55b0a2b1c2b392dfde436931ece0c703a3d754562bb96
"yaml@npm:^2.0.0, yaml@npm:^2.1.1, yaml@npm:^2.1.3":
version: 2.1.3
resolution: "yaml@npm:2.1.3"
checksum: 91316062324a93f9cb547469092392e7d004ff8f70c40fecb420f042a4870b2181557350da56c92f07bd44b8f7a252b0be26e6ade1f548e1f4351bdd01c9d3c7
languageName: node
linkType: hard