mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove a lot of usages of legacy globals (#6825)
* Remove all usages of legacy global logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global secretApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global resourceQuotaApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeClaimApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global nodeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global networkPolicyApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix formatting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global configMapApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global jobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global cronJobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove exports of NonInjected components - To improve auto-complete Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogEntityRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add lint against using legacy global works Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeObject file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogCategoryRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigation Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigate Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unneeded index file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global customResourceDefinitionStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global eventStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podSecurityPolicyStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move files around Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceAccountStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove final uses of asLegacyGlobalForExtensionApi in application code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint rule and start fixing lint errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make listHelmReleases injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make installHelmChart injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make deleteHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseValues injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseHistory injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make rollbackHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides from getDiForUnitTesting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for history Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup typing around getting injectables within jest Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move some more overrides to global if needed Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for forcusWindow Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in catalog/index.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global getDetailsUrl Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global showDetails Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add functions back to extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove all uses of legacy global Notification functions Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer existing export Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix injecting side effects by using more injectables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role binding dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix create service account dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix history override Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make KubeApi consume its dependencies while not breaking the extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix CephFs tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix user store tests by using override of config Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add direct devDep of memfs Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in cluster store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in router tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in kube auth proxy tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in log resource selector tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar remove command tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the select component tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove mock-fs as a dependency Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer necessary mocks Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix namespace select filter tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the extension loader tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixing edit-namespace-from-new-tab test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix app paths tests by making the tests run in "production" mode Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last vestiges of isTestEnv and the is* globals Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix delete-cluster-dialog tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix install-helm-chart-from-previously-opened-tab tests - Split out storage initialization to a runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary override of non side effect injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix disable-kube-object-detail-items-when-cluster-is-not-relevant tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix reactively-hide-kube-object-detail-item tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix sidebar-and-tab-navigation-for-core tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove need to override lensLocalStoragePath in tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace more overrides with global ones Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix typings Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer needed technical test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
900a8bbda3
commit
2b33d5eed6
530 files changed
+11320
-5399
No files matched your search
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { aboutPortForwarding } from "./port-forward-notify";
|
||||
import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
import hostedClusterIdInjectable from "../cluster-frame-context/hosted-cluster-id.injectable";
|
||||
import assert from "assert";
|
||||
import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable";
|
||||
|
||||
const aboutPortForwardingInjectable = getInjectable({
|
||||
id: "about-port-forwarding",
|
||||
|
||||
instantiate: (di) => {
|
||||
const hostedClusterId = di.inject(hostedClusterIdInjectable);
|
||||
const notificationsStore = di.inject(notificationsStoreInjectable);
|
||||
const navigateToPortForwards = di.inject(navigateToPortForwardsInjectable);
|
||||
|
||||
assert(hostedClusterId, "Only allowed to notify about port forward errors within a cluster frame");
|
||||
|
||||
return aboutPortForwarding({
|
||||
navigateToPortForwards,
|
||||
hostedClusterId,
|
||||
notificationsStore,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default aboutPortForwardingInjectable;
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import React from "react";
|
||||
import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
import { Button } from "../components/button";
|
||||
import showSuccessNotificationInjectable from "../components/notifications/show-success-notification.injectable";
|
||||
|
||||
const aboutPortForwardingInjectable = getInjectable({
|
||||
id: "about-port-forwarding",
|
||||
|
||||
instantiate: (di) => {
|
||||
const showSuccessNotification = di.inject(showSuccessNotificationInjectable);
|
||||
const navigateToPortForwards = di.inject(navigateToPortForwardsInjectable);
|
||||
|
||||
return () => {
|
||||
const removeNotification = showSuccessNotification(
|
||||
(
|
||||
<div className="flex column gaps">
|
||||
<b>Port Forwarding</b>
|
||||
<p>
|
||||
You can manage your port forwards on the Port Forwarding Page.
|
||||
</p>
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="Go to Port Forwarding"
|
||||
onClick={() => {
|
||||
navigateToPortForwards();
|
||||
removeNotification();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
id: "port-forward-notification",
|
||||
timeout: 10_000,
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default aboutPortForwardingInjectable;
|
||||
@@ -6,5 +6,4 @@
|
||||
export * from "./port-forward-store/port-forward-store";
|
||||
export * from "./port-forward-item";
|
||||
export * from "./port-forward-dialog";
|
||||
export * from "./port-forward-notify";
|
||||
export * from "./port-forward-utils";
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { notifyErrorPortForwarding } from "./port-forward-notify";
|
||||
import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
import hostedClusterIdInjectable from "../cluster-frame-context/hosted-cluster-id.injectable";
|
||||
import assert from "assert";
|
||||
import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable";
|
||||
|
||||
const notifyErrorPortForwardingInjectable = getInjectable({
|
||||
id: "notify-error-port-forwarding",
|
||||
|
||||
instantiate: (di) => {
|
||||
const hostedClusterId = di.inject(hostedClusterIdInjectable);
|
||||
const notificationsStore = di.inject(notificationsStoreInjectable);
|
||||
const navigateToPortForwards = di.inject(navigateToPortForwardsInjectable);
|
||||
|
||||
assert(hostedClusterId, "Only allowed to notify about port forward errors within a cluster frame");
|
||||
|
||||
return notifyErrorPortForwarding({
|
||||
navigateToPortForwards,
|
||||
hostedClusterId,
|
||||
notificationsStore,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default notifyErrorPortForwardingInjectable;
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
||||
import React from "react";
|
||||
import { Button } from "../components/button";
|
||||
|
||||
const notifyErrorPortForwardingInjectable = getInjectable({
|
||||
id: "notify-error-port-forwarding",
|
||||
|
||||
instantiate: (di) => {
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
const navigateToPortForwards = di.inject(navigateToPortForwardsInjectable);
|
||||
|
||||
return (msg: string) => {
|
||||
const removeNotification = showErrorNotification(
|
||||
(
|
||||
<div className="flex column gaps">
|
||||
<b>Port Forwarding</b>
|
||||
<p>
|
||||
{msg}
|
||||
</p>
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="Check Port Forwarding"
|
||||
onClick={() => {
|
||||
navigateToPortForwards();
|
||||
removeNotification();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
timeout: 10_000,
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default notifyErrorPortForwardingInjectable;
|
||||
-2
@@ -17,8 +17,6 @@ const portForwardDialogClusterFrameChildComponentInjectable = getInjectable({
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default portForwardDialogClusterFrameChildComponentInjectable;
|
||||
@@ -18,18 +18,20 @@ import { Checkbox } from "../components/checkbox";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { PortForwardDialogData, PortForwardDialogModel } from "./port-forward-dialog-model/port-forward-dialog-model";
|
||||
import portForwardDialogModelInjectable from "./port-forward-dialog-model/port-forward-dialog-model.injectable";
|
||||
import logger from "../../common/logger";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import portForwardStoreInjectable from "./port-forward-store/port-forward-store.injectable";
|
||||
import aboutPortForwardingInjectable from "./about-port-forwarding.injectable";
|
||||
import notifyErrorPortForwardingInjectable from "./notify-error-port-forwarding.injectable";
|
||||
import type { OpenPortForward } from "./open-port-forward.injectable";
|
||||
import openPortForwardInjectable from "./open-port-forward.injectable";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
|
||||
export interface PortForwardDialogProps extends Partial<DialogProps> {}
|
||||
|
||||
interface Dependencies {
|
||||
portForwardStore: PortForwardStore;
|
||||
model: PortForwardDialogModel;
|
||||
logger: Logger;
|
||||
aboutPortForwarding: () => void;
|
||||
notifyErrorPortForwarding: (message: string) => void;
|
||||
openPortForward: OpenPortForward;
|
||||
@@ -94,7 +96,7 @@ class NonInjectedPortForwardDialog extends Component<PortForwardDialogProps & De
|
||||
this.props.openPortForward(portForward);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`[PORT-FORWARD-DIALOG]: ${error}`, portForward);
|
||||
this.props.logger.error(`[PORT-FORWARD-DIALOG]: ${error}`, portForward);
|
||||
} finally {
|
||||
this.props.model.close();
|
||||
}
|
||||
@@ -170,17 +172,14 @@ class NonInjectedPortForwardDialog extends Component<PortForwardDialogProps & De
|
||||
}
|
||||
}
|
||||
|
||||
export const PortForwardDialog = withInjectables<Dependencies, PortForwardDialogProps>(
|
||||
NonInjectedPortForwardDialog,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
portForwardStore: di.inject(portForwardStoreInjectable),
|
||||
model: di.inject(portForwardDialogModelInjectable),
|
||||
aboutPortForwarding: di.inject(aboutPortForwardingInjectable),
|
||||
notifyErrorPortForwarding: di.inject(notifyErrorPortForwardingInjectable),
|
||||
openPortForward: di.inject(openPortForwardInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
export const PortForwardDialog = withInjectables<Dependencies, PortForwardDialogProps>(NonInjectedPortForwardDialog, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
portForwardStore: di.inject(portForwardStoreInjectable),
|
||||
model: di.inject(portForwardDialogModelInjectable),
|
||||
aboutPortForwarding: di.inject(aboutPortForwardingInjectable),
|
||||
notifyErrorPortForwarding: di.inject(notifyErrorPortForwardingInjectable),
|
||||
openPortForward: di.inject(openPortForwardInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
}),
|
||||
});
|
||||
@@ -1,92 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { Button } from "../components/button";
|
||||
import { Notifications } from "../components/notifications";
|
||||
import type { NavigateToPortForwards } from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
|
||||
import type { NotificationsStore } from "../components/notifications/notifications.store";
|
||||
|
||||
interface AboutPortForwardingDependencies {
|
||||
navigateToPortForwards: NavigateToPortForwards;
|
||||
hostedClusterId: string;
|
||||
notificationsStore: NotificationsStore;
|
||||
}
|
||||
|
||||
export const aboutPortForwarding = ({
|
||||
navigateToPortForwards,
|
||||
hostedClusterId,
|
||||
notificationsStore,
|
||||
}: AboutPortForwardingDependencies) => () => {
|
||||
const notificationId = `port-forward-notification-${hostedClusterId}`;
|
||||
|
||||
Notifications.info(
|
||||
(
|
||||
<div className="flex column gaps">
|
||||
<b>Port Forwarding</b>
|
||||
<p>
|
||||
You can manage your port forwards on the Port Forwarding Page.
|
||||
</p>
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="Go to Port Forwarding"
|
||||
onClick={() => {
|
||||
navigateToPortForwards();
|
||||
notificationsStore.remove(notificationId);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
id: notificationId,
|
||||
timeout: 10_000,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
interface NotifyErrorPortForwardingDependencies {
|
||||
navigateToPortForwards: NavigateToPortForwards;
|
||||
hostedClusterId: string;
|
||||
notificationsStore: NotificationsStore;
|
||||
}
|
||||
|
||||
|
||||
export const notifyErrorPortForwarding = ({
|
||||
navigateToPortForwards,
|
||||
hostedClusterId,
|
||||
notificationsStore,
|
||||
}: NotifyErrorPortForwardingDependencies) => (msg: string) => {
|
||||
const notificationId = `port-forward-error-notification-${hostedClusterId}`;
|
||||
|
||||
Notifications.error(
|
||||
(
|
||||
<div className="flex column gaps">
|
||||
<b>Port Forwarding</b>
|
||||
<p>
|
||||
{msg}
|
||||
</p>
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="Check Port Forwarding"
|
||||
onClick={() => {
|
||||
navigateToPortForwards();
|
||||
notificationsStore.remove(notificationId);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
id: notificationId,
|
||||
timeout: 10_000,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ import createStorageInjectable from "../../utils/create-storage/create-storage.i
|
||||
import notifyErrorPortForwardingInjectable from "../notify-error-port-forwarding.injectable";
|
||||
import requestActivePortForwardInjectable from "./request-active-port-forward.injectable";
|
||||
import apiBaseInjectable from "../../../common/k8s-api/api-base.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
|
||||
const portForwardStoreInjectable = getInjectable({
|
||||
id: "port-forward-store",
|
||||
@@ -24,6 +25,7 @@ const portForwardStoreInjectable = getInjectable({
|
||||
notifyErrorPortForwarding: di.inject(notifyErrorPortForwardingInjectable),
|
||||
apiBase: di.inject(apiBaseInjectable),
|
||||
requestActivePortForward: di.inject(requestActivePortForwardInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,14 +10,15 @@ import { autoBind, disposer } from "../../utils";
|
||||
import type { ForwardedPort } from "../port-forward-item";
|
||||
import { PortForwardItem } from "../port-forward-item";
|
||||
import { waitUntilFree } from "tcp-port-used";
|
||||
import logger from "../../../common/logger";
|
||||
import type { Logger } from "../../../common/logger";
|
||||
import type { JsonApi } from "../../../common/k8s-api/json-api";
|
||||
import type { RequestActivePortForward } from "./request-active-port-forward.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
readonly storage: StorageLayer<ForwardedPort[] | undefined>;
|
||||
notifyErrorPortForwarding: (message: string) => void;
|
||||
readonly apiBase: JsonApi; // TODO: replace with individual dependencies
|
||||
readonly logger: Logger;
|
||||
notifyErrorPortForwarding: (message: string) => void;
|
||||
requestActivePortForward: RequestActivePortForward;
|
||||
}
|
||||
|
||||
@@ -33,12 +34,10 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
}
|
||||
|
||||
private async init() {
|
||||
await this.dependencies.storage.whenReady;
|
||||
|
||||
const savedPortForwards = this.dependencies.storage.get(); // undefined on first load
|
||||
|
||||
if (Array.isArray(savedPortForwards) && savedPortForwards.length > 0) {
|
||||
logger.info("[PORT-FORWARD-STORE] starting saved port-forwards");
|
||||
this.dependencies.logger.info("[PORT-FORWARD-STORE] starting saved port-forwards");
|
||||
|
||||
// add the disabled ones
|
||||
await Promise.all(savedPortForwards.filter(pf => pf.status === "Disabled").map(this.add));
|
||||
@@ -169,7 +168,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
if (!pf) {
|
||||
const error = new Error("port-forward not found");
|
||||
|
||||
logger.warn(
|
||||
this.dependencies.logger.warn(
|
||||
`[PORT-FORWARD-STORE] Error getting port-forward: ${error}`,
|
||||
portForward,
|
||||
);
|
||||
@@ -181,7 +180,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
await this.stop(portForward);
|
||||
} catch (error) {
|
||||
if (pf.status === "Active") {
|
||||
logger.warn(
|
||||
this.dependencies.logger.warn(
|
||||
`[PORT-FORWARD-STORE] Error removing port-forward: ${error}`,
|
||||
portForward,
|
||||
);
|
||||
@@ -214,7 +213,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
const pf = this.findPortForward(portForward);
|
||||
|
||||
if (!pf) {
|
||||
logger.warn(
|
||||
this.dependencies.logger.warn(
|
||||
"[PORT-FORWARD-STORE] Error getting port-forward: port-forward not found",
|
||||
portForward,
|
||||
);
|
||||
@@ -231,7 +230,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
);
|
||||
await waitUntilFree(+forwardPort, 200, 1000);
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
this.dependencies.logger.warn(
|
||||
`[PORT-FORWARD-STORE] Error stopping active port-forward: ${error}`,
|
||||
portForward,
|
||||
);
|
||||
@@ -289,7 +288,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
response?.port &&
|
||||
response.port != +pf.forwardPort
|
||||
) {
|
||||
logger.warn(
|
||||
this.dependencies.logger.warn(
|
||||
`[PORT-FORWARD-STORE] specified ${pf.forwardPort}, got ${response.port}`,
|
||||
);
|
||||
}
|
||||
@@ -297,7 +296,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
pf.forwardPort = response.port;
|
||||
pf.status = "Active";
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
this.dependencies.logger.warn(
|
||||
`[PORT-FORWARD-STORE] Error starting port-forward: ${error}`,
|
||||
pf,
|
||||
);
|
||||
@@ -328,7 +327,7 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
|
||||
const pf = await this.dependencies.requestActivePortForward(portForward);
|
||||
|
||||
if (pf?.forwardPort && pf.forwardPort !== portForward.forwardPort) {
|
||||
logger.warn(
|
||||
this.dependencies.logger.warn(
|
||||
`[PORT-FORWARD-STORE] local port, expected ${pf.forwardPort}, got ${portForward.forwardPort}`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user