mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
improved port-forward error reporting (#4108)
* improved port-forward error reporting Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * satisfy lint and some autoformatting Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
1 parent
169f443c3b
commit
bbfb8372f3
5 files changed
+52
-39
No files matched your search
@@ -30,7 +30,6 @@ import { Notifications } from "../notifications";
|
||||
import { Button } from "../button";
|
||||
import { addPortForward, getPortForward, openPortForward, PortForwardDialog, portForwardStore, removePortForward } from "../../port-forward";
|
||||
import type { ForwardedPort } from "../../port-forward";
|
||||
import logger from "../../../common/logger";
|
||||
import { Spinner } from "../spinner";
|
||||
|
||||
interface Props {
|
||||
@@ -51,21 +50,15 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
this.init();
|
||||
this.checkExistingPortForwarding();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
reaction(() => [ portForwardStore.portForwards, this.props.pod ], () => this.init()),
|
||||
reaction(() => [portForwardStore.portForwards, this.props.pod], () => this.checkExistingPortForwarding()),
|
||||
]);
|
||||
}
|
||||
|
||||
init() {
|
||||
this.checkExistingPortForwarding().catch(error => {
|
||||
logger.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
async checkExistingPortForwarding() {
|
||||
const { pod, port } = this.props;
|
||||
const portForward: ForwardedPort = {
|
||||
@@ -75,7 +68,16 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
port: port.containerPort,
|
||||
forwardPort: this.forwardPort,
|
||||
};
|
||||
const activePort = await getPortForward(portForward) ?? 0;
|
||||
|
||||
let activePort: number;
|
||||
|
||||
try {
|
||||
activePort = await getPortForward(portForward) ?? 0;
|
||||
} catch (error) {
|
||||
this.isPortForwarded = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.forwardPort = activePort;
|
||||
this.isPortForwarded = activePort ? true : false;
|
||||
@@ -92,7 +94,6 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
};
|
||||
|
||||
this.waiting = true;
|
||||
this.isPortForwarded = false;
|
||||
|
||||
try {
|
||||
this.forwardPort = await addPortForward(portForward);
|
||||
@@ -103,7 +104,8 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
this.isPortForwarded = true;
|
||||
}
|
||||
} catch (error) {
|
||||
Notifications.error(error);
|
||||
Notifications.error("Error occurred starting port-forward, the local port may not be available");
|
||||
this.checkExistingPortForwarding();
|
||||
} finally {
|
||||
this.waiting = false;
|
||||
}
|
||||
@@ -125,7 +127,8 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
await removePortForward(portForward);
|
||||
this.isPortForwarded = false;
|
||||
} catch (error) {
|
||||
Notifications.error(error);
|
||||
Notifications.error(`Error occurred stopping the port-forward from port ${portForward.forwardPort}.`);
|
||||
this.checkExistingPortForwarding();
|
||||
} finally {
|
||||
this.waiting = false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user