mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into feature/port-forward-https
This commit is contained in:
commit
b6fb9c1f64
@ -26,6 +26,7 @@ import { MenuActions, MenuActionsProps } from "../menu/menu-actions";
|
|||||||
import { MenuItem } from "../menu";
|
import { MenuItem } from "../menu";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { PortForwardDialog } from "../../port-forward";
|
import { PortForwardDialog } from "../../port-forward";
|
||||||
|
import { Notifications } from "../notifications";
|
||||||
|
|
||||||
interface Props extends MenuActionsProps {
|
interface Props extends MenuActionsProps {
|
||||||
portForward: PortForwardItem;
|
portForward: PortForwardItem;
|
||||||
@ -35,7 +36,13 @@ interface Props extends MenuActionsProps {
|
|||||||
export class PortForwardMenu extends React.Component<Props> {
|
export class PortForwardMenu extends React.Component<Props> {
|
||||||
@boundMethod
|
@boundMethod
|
||||||
remove() {
|
remove() {
|
||||||
return removePortForward(this.props.portForward);
|
const { portForward } = this.props;
|
||||||
|
|
||||||
|
try {
|
||||||
|
removePortForward(portForward);
|
||||||
|
} catch (error) {
|
||||||
|
Notifications.error(`Error occurred stopping the port-forward from port ${portForward.forwardPort}. The port-forward may still be active.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderContent() {
|
renderContent() {
|
||||||
|
|||||||
@ -30,7 +30,6 @@ import { Notifications } from "../notifications";
|
|||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { addPortForward, getPortForward, openPortForward, PortForwardDialog, portForwardStore, predictProtocol, removePortForward } from "../../port-forward";
|
import { addPortForward, getPortForward, openPortForward, PortForwardDialog, portForwardStore, predictProtocol, removePortForward } from "../../port-forward";
|
||||||
import type { ForwardedPort } from "../../port-forward";
|
import type { ForwardedPort } from "../../port-forward";
|
||||||
import logger from "../../../common/logger";
|
|
||||||
import { Spinner } from "../spinner";
|
import { Spinner } from "../spinner";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -47,21 +46,15 @@ export class ServicePortComponent extends React.Component<Props> {
|
|||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
this.init();
|
this.checkExistingPortForwarding();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => [ portForwardStore.portForwards, this.props.service ], () => this.init()),
|
reaction(() => [portForwardStore.portForwards, this.props.service], () => this.checkExistingPortForwarding()),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
|
||||||
this.checkExistingPortForwarding().catch(error => {
|
|
||||||
logger.error(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async checkExistingPortForwarding() {
|
async checkExistingPortForwarding() {
|
||||||
const { service, port } = this.props;
|
const { service, port } = this.props;
|
||||||
const portForward: ForwardedPort = {
|
const portForward: ForwardedPort = {
|
||||||
@ -71,7 +64,16 @@ export class ServicePortComponent extends React.Component<Props> {
|
|||||||
port: port.port,
|
port: port.port,
|
||||||
forwardPort: this.forwardPort,
|
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.forwardPort = activePort;
|
||||||
this.isPortForwarded = activePort ? true : false;
|
this.isPortForwarded = activePort ? true : false;
|
||||||
@ -89,7 +91,6 @@ export class ServicePortComponent extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.waiting = true;
|
this.waiting = true;
|
||||||
this.isPortForwarded = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.forwardPort = await addPortForward(portForward);
|
this.forwardPort = await addPortForward(portForward);
|
||||||
@ -100,7 +101,8 @@ export class ServicePortComponent extends React.Component<Props> {
|
|||||||
this.isPortForwarded = true;
|
this.isPortForwarded = true;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(error);
|
Notifications.error("Error occurred starting port-forward, the local port may not be available");
|
||||||
|
this.checkExistingPortForwarding();
|
||||||
} finally {
|
} finally {
|
||||||
this.waiting = false;
|
this.waiting = false;
|
||||||
}
|
}
|
||||||
@ -122,7 +124,8 @@ export class ServicePortComponent extends React.Component<Props> {
|
|||||||
await removePortForward(portForward);
|
await removePortForward(portForward);
|
||||||
this.isPortForwarded = false;
|
this.isPortForwarded = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(error);
|
Notifications.error(`Error occurred stopping the port-forward from port ${portForward.forwardPort}.`);
|
||||||
|
this.checkExistingPortForwarding();
|
||||||
} finally {
|
} finally {
|
||||||
this.waiting = false;
|
this.waiting = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,6 @@ import { Notifications } from "../notifications";
|
|||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { addPortForward, getPortForward, openPortForward, PortForwardDialog, portForwardStore, predictProtocol, removePortForward } from "../../port-forward";
|
import { addPortForward, getPortForward, openPortForward, PortForwardDialog, portForwardStore, predictProtocol, removePortForward } from "../../port-forward";
|
||||||
import type { ForwardedPort } from "../../port-forward";
|
import type { ForwardedPort } from "../../port-forward";
|
||||||
import logger from "../../../common/logger";
|
|
||||||
import { Spinner } from "../spinner";
|
import { Spinner } from "../spinner";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -51,21 +50,15 @@ export class PodContainerPort extends React.Component<Props> {
|
|||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
this.init();
|
this.checkExistingPortForwarding();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
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() {
|
async checkExistingPortForwarding() {
|
||||||
const { pod, port } = this.props;
|
const { pod, port } = this.props;
|
||||||
const portForward: ForwardedPort = {
|
const portForward: ForwardedPort = {
|
||||||
@ -75,7 +68,16 @@ export class PodContainerPort extends React.Component<Props> {
|
|||||||
port: port.containerPort,
|
port: port.containerPort,
|
||||||
forwardPort: this.forwardPort,
|
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.forwardPort = activePort;
|
||||||
this.isPortForwarded = activePort ? true : false;
|
this.isPortForwarded = activePort ? true : false;
|
||||||
@ -93,7 +95,6 @@ export class PodContainerPort extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.waiting = true;
|
this.waiting = true;
|
||||||
this.isPortForwarded = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.forwardPort = await addPortForward(portForward);
|
this.forwardPort = await addPortForward(portForward);
|
||||||
@ -104,7 +105,8 @@ export class PodContainerPort extends React.Component<Props> {
|
|||||||
this.isPortForwarded = true;
|
this.isPortForwarded = true;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(error);
|
Notifications.error("Error occurred starting port-forward, the local port may not be available");
|
||||||
|
this.checkExistingPortForwarding();
|
||||||
} finally {
|
} finally {
|
||||||
this.waiting = false;
|
this.waiting = false;
|
||||||
}
|
}
|
||||||
@ -126,7 +128,8 @@ export class PodContainerPort extends React.Component<Props> {
|
|||||||
await removePortForward(portForward);
|
await removePortForward(portForward);
|
||||||
this.isPortForwarded = false;
|
this.isPortForwarded = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(error);
|
Notifications.error(`Error occurred stopping the port-forward from port ${portForward.forwardPort}.`);
|
||||||
|
this.checkExistingPortForwarding();
|
||||||
} finally {
|
} finally {
|
||||||
this.waiting = false;
|
this.waiting = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,7 +112,7 @@ export class PortForwardDialog extends Component<Props> {
|
|||||||
openPortForward(portForward);
|
openPortForward(portForward);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Notifications.error(err);
|
Notifications.error("Error occurred starting port-forward, the local port may not be available");
|
||||||
} finally {
|
} finally {
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,7 +113,8 @@ export async function addPortForward(portForward: ForwardedPort): Promise<number
|
|||||||
logger.warn(`specified ${portForward.forwardPort} got ${response.port}`);
|
logger.warn(`specified ${portForward.forwardPort} got ${response.port}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(error); // don't care, caller must check
|
logger.warn("Error adding port-forward:", error, portForward);
|
||||||
|
throw(error);
|
||||||
}
|
}
|
||||||
portForwardStore.reset();
|
portForwardStore.reset();
|
||||||
|
|
||||||
@ -134,7 +135,8 @@ export async function getPortForward(portForward: ForwardedPort): Promise<number
|
|||||||
try {
|
try {
|
||||||
response = await apiBase.get<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}?port=${portForward.port}&forwardPort=${portForward.forwardPort}${getProtocolQuery(portForward.protocol)}`);
|
response = await apiBase.get<PortForwardResult>(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}?port=${portForward.port}&forwardPort=${portForward.forwardPort}${getProtocolQuery(portForward.protocol)}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(error); // don't care, caller must check
|
logger.warn("Error getting port-forward:", error, portForward);
|
||||||
|
throw(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response?.port;
|
return response?.port;
|
||||||
@ -143,13 +145,10 @@ export async function getPortForward(portForward: ForwardedPort): Promise<number
|
|||||||
export async function modifyPortForward(portForward: ForwardedPort, desiredPort: number): Promise<number> {
|
export async function modifyPortForward(portForward: ForwardedPort, desiredPort: number): Promise<number> {
|
||||||
let port = 0;
|
let port = 0;
|
||||||
|
|
||||||
try {
|
await removePortForward(portForward);
|
||||||
await removePortForward(portForward);
|
portForward.forwardPort = desiredPort;
|
||||||
portForward.forwardPort = desiredPort;
|
port = await addPortForward(portForward);
|
||||||
port = await addPortForward(portForward);
|
|
||||||
} catch (error) {
|
|
||||||
logger.warn(error); // don't care, caller must check
|
|
||||||
}
|
|
||||||
portForwardStore.reset();
|
portForwardStore.reset();
|
||||||
|
|
||||||
return port;
|
return port;
|
||||||
@ -161,7 +160,8 @@ export async function removePortForward(portForward: ForwardedPort) {
|
|||||||
await apiBase.del(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}?port=${portForward.port}&forwardPort=${portForward.forwardPort}`);
|
await apiBase.del(`/pods/port-forward/${portForward.namespace}/${portForward.kind}/${portForward.name}?port=${portForward.port}&forwardPort=${portForward.forwardPort}`);
|
||||||
await waitUntilFree(+portForward.forwardPort, 200, 1000);
|
await waitUntilFree(+portForward.forwardPort, 200, 1000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(error); // don't care, caller must check
|
logger.warn("Error removing port-forward:", error, portForward);
|
||||||
|
throw(error);
|
||||||
}
|
}
|
||||||
portForwardStore.reset();
|
portForwardStore.reset();
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ export async function getPortForwards(): Promise<ForwardedPort[]> {
|
|||||||
|
|
||||||
return response.portForwards;
|
return response.portForwards;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(error); // don't care, caller must check
|
logger.warn("Error getting all port-forwards:", error);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user