Merge pull request #23798 from ovalice/fix/keep-k8s-log-stream-open

Keep log stream open when running a container with KubernetesContainerRunner
This commit is contained in:
Fredrik Adelöw
2024-04-09 10:17:46 +02:00
committed by GitHub
3 changed files with 32 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
KubernetesContainerRunner.runContainer no longer closes the `logStream` it receives as input.
@@ -187,6 +187,26 @@ 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.writableEnded).toBe(false);
expect(logStream.destroyed).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) {