From 26db38d22150948e5ba054740edd55315ec19ecc Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Tue, 20 Aug 2024 18:06:58 -0700 Subject: [PATCH] Kube client: fix port forwarding - When we create an error, we need to throw in, not drop it on the floor. - If the host port is not specified, and an existing server is found, return that server's port instead of 0. --- pkg/rancher-desktop/backend/kube/client.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/rancher-desktop/backend/kube/client.ts b/pkg/rancher-desktop/backend/kube/client.ts index 1addad15613..d52d3ce3a1a 100644 --- a/pkg/rancher-desktop/backend/kube/client.ts +++ b/pkg/rancher-desktop/backend/kube/client.ts @@ -472,7 +472,7 @@ export class KubeClient extends events.EventEmitter { // check if server is still valid if (!this.servers.has(namespace, endpoint, k8sPort)) { - new Error('Server is no longer valid'); + throw new Error('Server is no longer valid'); } // forward the port @@ -525,15 +525,15 @@ export class KubeClient extends events.EventEmitter { let server = this.servers.get(namespace, endpoint, k8sPort); if (server) { - console.log(`Found existing server for ${ targetName }.`); + console.debug(`Found existing server for ${ targetName }.`); const currentHostPort = (server.address() as net.AddressInfo).port; - if (currentHostPort === hostPort) { - console.log(`Server listening on ${ hostPort }, which is what we want.`); + if (hostPort === 0 || currentHostPort === hostPort) { + console.debug(`Server listening on ${ hostPort }, which is what we want.`); - return hostPort; + return hostPort || currentHostPort; } else { - console.log(`Server listening on ${ currentHostPort }, but we want ${ hostPort }. Closing it.`); + console.debug(`Server listening on ${ currentHostPort }, but we want ${ hostPort }. Closing it.`); await this.closeServerAndConns(namespace, endpoint, k8sPort); } }