From bf3cc134eb2d68ec70f41c63587c312393b0aa22 Mon Sep 17 00:00:00 2001 From: Matteo Silvestri Date: Thu, 1 Sep 2022 15:13:31 +0200 Subject: [PATCH] add changeset Signed-off-by: Matteo Silvestri --- .changeset/late-turtles-listen.md | 51 +++++++++++++++++++ .../util/KubernetesContainerRunner.test.ts | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .changeset/late-turtles-listen.md diff --git a/.changeset/late-turtles-listen.md b/.changeset/late-turtles-listen.md new file mode 100644 index 0000000000..117737a064 --- /dev/null +++ b/.changeset/late-turtles-listen.md @@ -0,0 +1,51 @@ +--- +'@backstage/backend-common': patch +--- + +Implemented KubernetesContainerRunner: a ContainerRunner implementation that leverages Jobs on a kubernetes cluster + +```ts +const kubeConfig = new KubeConfig(); +kubeConfig.loadFromDefault(); + +const options: KubernetesContainerRunnerOptions = { + kubeConfig, + // namespace where Jobs will be created + namespace: 'default', + // Jobs name will be prefixed with this name + name: 'my-runner', + // An existing Kubernetes volume that will be used + // as base for mounts + mountBase: { + volumeName: 'workdir', + // Every mount must start with the base path + // see example below + basePath: '/workdir', + }, + // Define a Pod template for the Jobs. It has to include + // a volume definition named as the mountBase volumeName + podTemplate: { + spec: { + containers: [], + volumes: [ + { + name: 'workdir', + persistentVolumeClaim: { + claimName: 'workdir-claim', + }, + }, + ], + }, + }, +}; +const containerRunner = new KubernetesContainerRunner(options); + +const runOptions: RunContainerOptions = { + imageName: 'golang:1.17', + args: ['echo', 'hello world'], + mountDirs: { + '/workdir/app': '/app', + }, +}; +containerRunner.runContainer(runOptions); +``` diff --git a/packages/backend-common/src/util/KubernetesContainerRunner.test.ts b/packages/backend-common/src/util/KubernetesContainerRunner.test.ts index d914bc7742..9ac5e244fd 100644 --- a/packages/backend-common/src/util/KubernetesContainerRunner.test.ts +++ b/packages/backend-common/src/util/KubernetesContainerRunner.test.ts @@ -109,7 +109,7 @@ describeIfKubernetes('KubernetesContainerRunner', () => { args: ['echo', 'hello world'], logStream, mountDirs: { - '/notWorkdir/app': '/app', + hostdir: '/app', }, }; await expect(containerRunner.runContainer(runOptions)).rejects.toThrow(