mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move cluster related types and function into seperate files (#3530)
This commit is contained in:
1 parent
2893ad956d
commit
a6e91fc34a
49 files changed
+435
-258
No files matched your search
@@ -30,12 +30,11 @@ import path from "path";
|
||||
import React from "react";
|
||||
|
||||
import { catalogURL } from "../../../common/routes";
|
||||
import { ClusterStore } from "../../../common/cluster-store";
|
||||
import { appEventBus } from "../../../common/event-bus";
|
||||
import { loadConfigFromString, splitConfig } from "../../../common/kube-helpers";
|
||||
import { docsUrl } from "../../../common/vars";
|
||||
import { navigate } from "../../navigation";
|
||||
import { iter } from "../../utils";
|
||||
import { getCustomKubeConfigPath, iter } from "../../utils";
|
||||
import { AceEditor } from "../ace-editor";
|
||||
import { Button } from "../button";
|
||||
import { Notifications } from "../notifications";
|
||||
@@ -93,7 +92,7 @@ export class AddCluster extends React.Component {
|
||||
appEventBus.emit({ name: "cluster-add", action: "click" });
|
||||
|
||||
try {
|
||||
const absPath = ClusterStore.getCustomKubeConfigPath();
|
||||
const absPath = getCustomKubeConfigPath();
|
||||
|
||||
await fse.ensureDir(path.dirname(absPath));
|
||||
await fse.writeFile(absPath, this.customConfig.trim(), { encoding: "utf-8", mode: 0o600 });
|
||||
|
||||
@@ -26,8 +26,7 @@ import { reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { nodesStore } from "../+nodes/nodes.store";
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
import { getHostedCluster } from "../../../common/cluster-store";
|
||||
import { interval } from "../../utils";
|
||||
import { getHostedClusterId, interval } from "../../utils";
|
||||
import { TabLayout } from "../layout/tab-layout";
|
||||
import { Spinner } from "../spinner";
|
||||
import { ClusterIssues } from "./cluster-issues";
|
||||
@@ -35,14 +34,19 @@ import { ClusterMetrics } from "./cluster-metrics";
|
||||
import { clusterOverviewStore } from "./cluster-overview.store";
|
||||
import { ClusterPieCharts } from "./cluster-pie-charts";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { ClusterStore } from "../../../common/cluster-store";
|
||||
|
||||
@observer
|
||||
export class ClusterOverview extends React.Component {
|
||||
private metricPoller = interval(60, () => this.loadMetrics());
|
||||
|
||||
loadMetrics() {
|
||||
getHostedCluster().available && clusterOverviewStore.loadMetrics();
|
||||
const cluster = ClusterStore.getInstance().getById(getHostedClusterId());
|
||||
|
||||
if (cluster.available) {
|
||||
clusterOverviewStore.loadMetrics();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
@@ -35,7 +35,7 @@ import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { limitRangeStore } from "../+config-limit-ranges/limit-ranges.store";
|
||||
import { ResourceMetrics } from "../resource-metrics";
|
||||
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<Namespace> {
|
||||
|
||||
@@ -33,7 +33,7 @@ import { IngressCharts } from "./ingress-charts";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { getBackendServiceNamePort, getMetricsForIngress, IIngressMetrics } from "../../api/endpoints/ingress.api";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<Ingress> {
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import { makeObservable, observable, reaction } from "mobx";
|
||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { NodeDetailsResources } from "./node-details-resources";
|
||||
import { DrawerTitle } from "../drawer/drawer-title";
|
||||
import { boundMethod } from "../../utils";
|
||||
|
||||
@@ -33,7 +33,7 @@ import { VolumeClaimDiskChart } from "./volume-claim-disk-chart";
|
||||
import { getDetailsUrl, KubeObjectDetailsProps, KubeObjectMeta } from "../kube-object";
|
||||
import { getMetricsForPvc, IPvcMetrics, PersistentVolumeClaim } from "../../api/endpoints";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<PersistentVolumeClaim> {
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import { makeObservable, observable, reaction } from "mobx";
|
||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { boundMethod } from "../../utils";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<DaemonSet> {
|
||||
|
||||
@@ -40,7 +40,7 @@ import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
|
||||
import { DeploymentReplicaSets } from "./deployment-replicasets";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { boundMethod } from "../../utils";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<Deployment> {
|
||||
|
||||
@@ -39,7 +39,7 @@ import { lookupApiLink } from "../../api/kube-api";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { makeObservable, observable } from "mobx";
|
||||
import { podMetricTabs, PodCharts } from "../+workloads-pods/pod-charts";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ResourceMetrics } from "../resource-metrics";
|
||||
import { boundMethod } from "autobind-decorator";
|
||||
|
||||
@@ -34,7 +34,7 @@ import type { IMetrics } from "../../api/endpoints/metrics.api";
|
||||
import { ContainerCharts } from "./container-charts";
|
||||
import { LocaleDate } from "../locale-date";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
|
||||
interface Props {
|
||||
pod: Pod;
|
||||
|
||||
@@ -41,7 +41,7 @@ import { getItemMetrics } from "../../api/endpoints/metrics.api";
|
||||
import { PodCharts, podMetricTabs } from "./pod-charts";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<Pod> {
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { boundMethod } from "../../utils";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<ReplicaSet> {
|
||||
|
||||
@@ -38,7 +38,7 @@ import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../main/cluster";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import { boundMethod } from "../../utils";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<StatefulSet> {
|
||||
|
||||
@@ -32,7 +32,6 @@ import { DeploymentScaleDialog } from "./+workloads-deployments/deployment-scale
|
||||
import { CronJobTriggerDialog } from "./+workloads-cronjobs/cronjob-trigger-dialog";
|
||||
import { CustomResources } from "./+custom-resources/custom-resources";
|
||||
import { isAllowedResource } from "../../common/rbac";
|
||||
import { getHostedCluster, getHostedClusterId } from "../../common/cluster-store";
|
||||
import logger from "../../main/logger";
|
||||
import { webFrame } from "electron";
|
||||
import { ClusterPageRegistry, getExtensionPageUrl } from "../../extensions/registries/page-registry";
|
||||
@@ -70,9 +69,14 @@ import { Workloads } from "./+workloads";
|
||||
import { Config } from "./+config";
|
||||
import { Storage } from "./+storage";
|
||||
import { catalogEntityRegistry } from "../api/catalog-entity-registry";
|
||||
import { getHostedClusterId } from "../utils";
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import type { ClusterId } from "../../common/cluster-types";
|
||||
|
||||
@observer
|
||||
export class App extends React.Component {
|
||||
static clusterId: ClusterId;
|
||||
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
@@ -81,15 +85,18 @@ export class App extends React.Component {
|
||||
static async init() {
|
||||
catalogEntityRegistry.init();
|
||||
const frameId = webFrame.routingId;
|
||||
const clusterId = getHostedClusterId();
|
||||
|
||||
logger.info(`[APP]: Init dashboard, clusterId=${clusterId}, frameId=${frameId}`);
|
||||
App.clusterId = getHostedClusterId();
|
||||
|
||||
logger.info(`[APP]: Init dashboard, clusterId=${App.clusterId}, frameId=${frameId}`);
|
||||
await Terminal.preloadFonts();
|
||||
await requestMain(clusterSetFrameIdHandler, App.clusterId);
|
||||
|
||||
await requestMain(clusterSetFrameIdHandler, clusterId);
|
||||
await getHostedCluster().whenReady; // cluster.activate() is done at this point
|
||||
const cluster = ClusterStore.getInstance().getById(App.clusterId);
|
||||
|
||||
const activeEntityDisposer = reaction(() => catalogEntityRegistry.getById(clusterId), (entity) => {
|
||||
await cluster.whenReady; // cluster.activate() is done at this point
|
||||
|
||||
const activeEntityDisposer = reaction(() => catalogEntityRegistry.getById(App.clusterId), (entity) => {
|
||||
if (!entity) {
|
||||
return;
|
||||
}
|
||||
@@ -103,7 +110,7 @@ export class App extends React.Component {
|
||||
name: "cluster",
|
||||
action: "open",
|
||||
params: {
|
||||
clusterId
|
||||
clusterId: App.clusterId
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -212,7 +219,7 @@ export class App extends React.Component {
|
||||
<StatefulSetScaleDialog/>
|
||||
<ReplicaSetScaleDialog/>
|
||||
<CronJobTriggerDialog/>
|
||||
<CommandContainer clusterId={getHostedCluster()?.id}/>
|
||||
<CommandContainer clusterId={App.clusterId}/>
|
||||
</ErrorBoundary>
|
||||
</Router>
|
||||
);
|
||||
|
||||
@@ -26,7 +26,7 @@ import { computed, observable, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import { clusterActivateHandler } from "../../../common/cluster-ipc";
|
||||
import { ClusterId, ClusterStore } from "../../../common/cluster-store";
|
||||
import { ClusterStore } from "../../../common/cluster-store";
|
||||
import { ipcRendererOn, requestMain } from "../../../common/ipc";
|
||||
import type { Cluster } from "../../../main/cluster";
|
||||
import { cssNames, IClassName } from "../../utils";
|
||||
@@ -36,6 +36,7 @@ import { Spinner } from "../spinner";
|
||||
import type { KubeAuthProxyLog } from "../../../main/kube-auth-proxy";
|
||||
import { navigate } from "../../navigation";
|
||||
import { entitySettingsURL } from "../../../common/routes";
|
||||
import type { ClusterId } from "../../../common/cluster-types";
|
||||
|
||||
interface Props {
|
||||
className?: IClassName;
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
*/
|
||||
|
||||
import { observable, when } from "mobx";
|
||||
import { ClusterId, ClusterStore, getClusterFrameUrl } from "../../../common/cluster-store";
|
||||
import logger from "../../../main/logger";
|
||||
import { requestMain } from "../../../common/ipc";
|
||||
import { clusterVisibilityHandler } from "../../../common/cluster-ipc";
|
||||
import { ClusterStore } from "../../../common/cluster-store";
|
||||
import type { ClusterId } from "../../../common/cluster-types";
|
||||
import { getClusterFrameUrl } from "../../utils";
|
||||
|
||||
export interface LensView {
|
||||
isLoaded?: boolean
|
||||
|
||||
@@ -25,8 +25,9 @@ import { Select, SelectOption } from "../../select/select";
|
||||
import { Icon } from "../../icon/icon";
|
||||
import { Button } from "../../button/button";
|
||||
import { SubTitle } from "../../layout/sub-title";
|
||||
import { Cluster, ClusterMetricsResourceType } from "../../../../main/cluster";
|
||||
import type { Cluster } from "../../../../main/cluster";
|
||||
import { observable, reaction, makeObservable } from "mobx";
|
||||
import { ClusterMetricsResourceType } from "../../../../common/cluster-types";
|
||||
|
||||
interface Props {
|
||||
cluster: Cluster;
|
||||
|
||||
@@ -26,7 +26,7 @@ import React from "react";
|
||||
import { Input } from "../../input/input";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { Icon } from "../../icon/icon";
|
||||
import { initialNodeShellImage } from "../../../../common/cluster-store";
|
||||
import { initialNodeShellImage } from "../../../../common/cluster-types";
|
||||
|
||||
interface Props {
|
||||
cluster: Cluster;
|
||||
|
||||
@@ -28,7 +28,7 @@ import { Dialog } from "../dialog";
|
||||
import { EventEmitter } from "../../../common/event-emitter";
|
||||
import { ipcRendererOn } from "../../../common/ipc";
|
||||
import { CommandDialog } from "./command-dialog";
|
||||
import type { ClusterId } from "../../../common/cluster-store";
|
||||
import type { ClusterId } from "../../../common/cluster-types";
|
||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||
import { CommandRegistration, CommandRegistry } from "../../../extensions/registries/command-registry";
|
||||
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import type { Cluster } from "../../main/cluster";
|
||||
import { getHostedCluster } from "../../common/cluster-store";
|
||||
import { getHostedClusterId } from "../utils";
|
||||
import { namespaceStore } from "./+namespaces/namespace.store";
|
||||
|
||||
export interface ClusterContext {
|
||||
@@ -31,7 +32,7 @@ export interface ClusterContext {
|
||||
|
||||
export const clusterContext: ClusterContext = {
|
||||
get cluster(): Cluster | null {
|
||||
return getHostedCluster();
|
||||
return ClusterStore.getInstance().getById(getHostedClusterId());
|
||||
},
|
||||
|
||||
get allNamespaces(): string[] {
|
||||
|
||||
@@ -26,8 +26,9 @@ import { app, remote } from "electron";
|
||||
import { comparer, observable, reaction, toJS, when } from "mobx";
|
||||
import fse from "fs-extra";
|
||||
import { StorageHelper } from "./storageHelper";
|
||||
import { ClusterStore, getHostedClusterId } from "../../common/cluster-store";
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import logger from "../../main/logger";
|
||||
import { getHostedClusterId } from "../../common/utils";
|
||||
|
||||
const storage = observable({
|
||||
initialized: false,
|
||||
|
||||
Reference in new issue
Block a user