Skip to content

Commit

Permalink
Kube client: fix port forwarding
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
mook-as committed Aug 21, 2024
1 parent 39fabbd commit 26db38d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/rancher-desktop/backend/kube/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 26db38d

Please sign in to comment.