Keep log stream open when running a container with KubernetesContainerRunner

Signed-off-by: ovalice <31350208+ovalice@users.noreply.github.com>
This commit is contained in:
ovalice
2024-03-22 15:57:41 +01:00
parent 177a41a2ee
commit 75a53b838a
3 changed files with 31 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
KubernetesContainerRunner.runContainer no longer closes the `logStream` is receives as input.
@@ -187,6 +187,25 @@ describeIfKubernetes('KubernetesContainerRunner', () => {
);
});
it('should not close the original log stream', async () => {
const options: KubernetesContainerRunnerOptions = {
kubeConfig,
name,
namespace: 'default',
};
const containerRunner = new KubernetesContainerRunner(options);
const logStream = new PassThrough();
const runOptions: RunContainerOptions = {
imageName: 'alpine',
args: ['echo', 'hello world'],
logStream,
};
await containerRunner.runContainer(runOptions);
expect(logStream.closed).toBe(false);
});
describe('with namespace test', () => {
let api: CoreV1Api;
let authApi: RbacAuthorizationV1Api;
@@ -132,12 +132,17 @@ export class KubernetesContainerRunner implements ContainerRunner {
imageName,
command,
args,
logStream = new PassThrough(),
logStream,
mountDirs = {},
workingDir,
envVars = {},
} = options;
const containerLogStream = new PassThrough();
if (logStream) {
containerLogStream.pipe(logStream, { end: false });
}
const commandArr = typeof command === 'string' ? [command] : command;
const volumeMounts: V1VolumeMount[] = [];
@@ -209,7 +214,7 @@ export class KubernetesContainerRunner implements ContainerRunner {
},
};
await this.runJob(jobSpec, taskId, logStream);
await this.runJob(jobSpec, taskId, containerLogStream);
}
private handleError(err: any, errorCallback: (reason: any) => void) {