mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
KubeObjectStore & KubeWatchApi fixes and optimizations (#2063)
* Detach NamespaceStore from KubeWatchApi, proper KubeObjectStore.loadAll (rebase of #2033) Signed-off-by: Roman <ixrock@gmail.com> * Watch-api requests optimization (#2066) * subscribe for watching resources in single request when has admin-like access rights Signed-off-by: Roman <ixrock@gmail.com> * responding to comments Signed-off-by: Roman <ixrock@gmail.com> * fix unit-tests Signed-off-by: Roman <ixrock@gmail.com> * fix: reloading stores when preloading enabled and waitUntilLoaded=false Signed-off-by: Roman <ixrock@gmail.com> * mark Cluster.canUseWatchApi() and Cluster.refreshAccessibility() as private Signed-off-by: Roman <ixrock@gmail.com> * fix unit test: make public Cluster.canUseWatchApi() Signed-off-by: Roman <ixrock@gmail.com> * responding to comments in #2066 Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
f56969a64b
commit
5287e7e528
21 files changed
+155
-101
No files matched your search
@@ -58,11 +58,11 @@ export class ReleaseStore extends ItemStore<HelmRelease> {
|
||||
}
|
||||
|
||||
@action
|
||||
async loadAll() {
|
||||
async loadAll(namespaces = namespaceStore.allowedNamespaces) {
|
||||
this.isLoading = true;
|
||||
|
||||
try {
|
||||
const items = await this.loadItems(namespaceStore.getContextNamespaces());
|
||||
const items = await this.loadItems(namespaces);
|
||||
|
||||
this.items.replace(this.sortItems(items));
|
||||
this.isLoaded = true;
|
||||
@@ -73,6 +73,10 @@ export class ReleaseStore extends ItemStore<HelmRelease> {
|
||||
}
|
||||
}
|
||||
|
||||
async loadSelectedNamespaces(): Promise<void> {
|
||||
return this.loadAll(namespaceStore.getContextNamespaces());
|
||||
}
|
||||
|
||||
async loadItems(namespaces: string[]) {
|
||||
return Promise
|
||||
.all(namespaces.map(namespace => helmReleasesApi.list(namespace)))
|
||||
@@ -82,7 +86,7 @@ export class ReleaseStore extends ItemStore<HelmRelease> {
|
||||
async create(payload: IReleaseCreatePayload) {
|
||||
const response = await helmReleasesApi.create(payload);
|
||||
|
||||
if (this.isLoaded) this.loadAll();
|
||||
if (this.isLoaded) this.loadSelectedNamespaces();
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -90,7 +94,7 @@ export class ReleaseStore extends ItemStore<HelmRelease> {
|
||||
async update(name: string, namespace: string, payload: IReleaseUpdatePayload) {
|
||||
const response = await helmReleasesApi.update(name, namespace, payload);
|
||||
|
||||
if (this.isLoaded) this.loadAll();
|
||||
if (this.isLoaded) this.loadSelectedNamespaces();
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -98,7 +102,7 @@ export class ReleaseStore extends ItemStore<HelmRelease> {
|
||||
async rollback(name: string, namespace: string, revision: number) {
|
||||
const response = await helmReleasesApi.rollback(name, namespace, revision);
|
||||
|
||||
if (this.isLoaded) this.loadAll();
|
||||
if (this.isLoaded) this.loadSelectedNamespaces();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export class CrdResources extends React.Component<Props> {
|
||||
const { store } = this;
|
||||
|
||||
if (store && !store.isLoading && !store.isLoaded) {
|
||||
store.loadAll();
|
||||
store.loadSelectedNamespaces();
|
||||
}
|
||||
})
|
||||
]);
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface KubeEventDetailsProps {
|
||||
@observer
|
||||
export class KubeEventDetails extends React.Component<KubeEventDetailsProps> {
|
||||
async componentDidMount() {
|
||||
eventStore.loadAll();
|
||||
eventStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -32,8 +32,8 @@ export class NamespaceDetails extends React.Component<Props> {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
resourceQuotaStore.loadAll();
|
||||
limitRangeStore.loadAll();
|
||||
resourceQuotaStore.loadSelectedNamespaces();
|
||||
limitRangeStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -73,7 +73,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
||||
}
|
||||
|
||||
private autoLoadAllowedNamespaces(): IReactionDisposer {
|
||||
return reaction(() => this.allowedNamespaces, () => this.loadAll(), {
|
||||
return reaction(() => this.allowedNamespaces, namespaces => this.loadAll(namespaces), {
|
||||
fireImmediately: true,
|
||||
equals: comparer.shallow,
|
||||
});
|
||||
|
||||
@@ -29,9 +29,7 @@ export class NodeDetails extends React.Component<Props> {
|
||||
});
|
||||
|
||||
async componentDidMount() {
|
||||
if (!podsStore.isLoaded) {
|
||||
podsStore.loadAll();
|
||||
}
|
||||
podsStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
@@ -80,7 +80,7 @@ export class AddRoleBindingDialog extends React.Component<Props> {
|
||||
];
|
||||
|
||||
this.isLoading = true;
|
||||
await Promise.all(stores.map(store => store.loadAll()));
|
||||
await Promise.all(stores.map(store => store.loadSelectedNamespaces()));
|
||||
this.isLoading = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ interface Props extends KubeObjectDetailsProps<CronJob> {
|
||||
@observer
|
||||
export class CronJobDetails extends React.Component<Props> {
|
||||
async componentDidMount() {
|
||||
if (!jobStore.isLoaded) {
|
||||
jobStore.loadAll();
|
||||
}
|
||||
jobStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -30,9 +30,7 @@ export class DaemonSetDetails extends React.Component<Props> {
|
||||
});
|
||||
|
||||
componentDidMount() {
|
||||
if (!podsStore.isLoaded) {
|
||||
podsStore.loadAll();
|
||||
}
|
||||
podsStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
@@ -31,9 +31,7 @@ export class DeploymentDetails extends React.Component<Props> {
|
||||
});
|
||||
|
||||
componentDidMount() {
|
||||
if (!podsStore.isLoaded) {
|
||||
podsStore.loadAll();
|
||||
}
|
||||
podsStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
@@ -25,9 +25,7 @@ interface Props extends KubeObjectDetailsProps<Job> {
|
||||
@observer
|
||||
export class JobDetails extends React.Component<Props> {
|
||||
async componentDidMount() {
|
||||
if (!podsStore.isLoaded) {
|
||||
podsStore.loadAll();
|
||||
}
|
||||
podsStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -29,9 +29,7 @@ export class ReplicaSetDetails extends React.Component<Props> {
|
||||
});
|
||||
|
||||
async componentDidMount() {
|
||||
if (!podsStore.isLoaded) {
|
||||
podsStore.loadAll();
|
||||
}
|
||||
podsStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
@@ -30,9 +30,7 @@ export class StatefulSetDetails extends React.Component<Props> {
|
||||
});
|
||||
|
||||
componentDidMount() {
|
||||
if (!podsStore.isLoaded) {
|
||||
podsStore.loadAll();
|
||||
}
|
||||
podsStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { computed, observable, reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { Redirect, Route, Router, Switch } from "react-router";
|
||||
import { history } from "../navigation";
|
||||
@@ -42,7 +43,7 @@ import { ClusterPageMenuRegistration, clusterPageMenuRegistry } from "../../exte
|
||||
import { TabLayout, TabLayoutRoute } from "./layout/tab-layout";
|
||||
import { StatefulSetScaleDialog } from "./+workloads-statefulsets/statefulset-scale-dialog";
|
||||
import { eventStore } from "./+events/event.store";
|
||||
import { computed, reaction, observable } from "mobx";
|
||||
import { namespaceStore } from "./+namespaces/namespace.store";
|
||||
import { nodesStore } from "./+nodes/nodes.store";
|
||||
import { podsStore } from "./+workloads-pods/pods.store";
|
||||
import { kubeWatchApi } from "../api/kube-watch-api";
|
||||
@@ -74,6 +75,12 @@ export class App extends React.Component {
|
||||
window.location.reload();
|
||||
});
|
||||
whatInput.ask(); // Start to monitor user input device
|
||||
|
||||
await namespaceStore.whenReady;
|
||||
await kubeWatchApi.init({
|
||||
getCluster: getHostedCluster,
|
||||
getNamespaces: namespaceStore.getContextNamespaces,
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
@@ -80,7 +80,7 @@ export class UpgradeChartStore extends DockTabStore<IChartUpgradeData> {
|
||||
const values = this.values.getData(tabId);
|
||||
|
||||
await Promise.all([
|
||||
!releaseStore.isLoaded && releaseStore.loadAll(),
|
||||
!releaseStore.isLoaded && releaseStore.loadSelectedNamespaces(),
|
||||
!values && this.loadValues(tabId)
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
const { store, dependentStores } = this.props;
|
||||
const stores = Array.from(new Set([store, ...dependentStores]));
|
||||
|
||||
stores.forEach(store => store.loadAll());
|
||||
stores.forEach(store => store.loadAll(namespaceStore.getContextNamespaces()));
|
||||
}
|
||||
|
||||
private filterCallbacks: { [type: string]: ItemsFilter } = {
|
||||
|
||||
@@ -40,9 +40,7 @@ interface Props {
|
||||
@observer
|
||||
export class Sidebar extends React.Component<Props> {
|
||||
async componentDidMount() {
|
||||
if (!crdStore.isLoaded && isAllowedResource("customresourcedefinitions")) {
|
||||
crdStore.loadAll();
|
||||
}
|
||||
crdStore.loadSelectedNamespaces();
|
||||
}
|
||||
|
||||
renderCustomResources() {
|
||||
|
||||
Reference in new issue
Block a user