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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user