loading k8s resources into stores per selected namespaces -- part 1

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2021-01-07 17:34:10 +02:00
1 parent 02bc210f56
commit 47bea52160
6 files changed
+50 -63

No files matched your search

@@ -1,7 +1,7 @@
import { action, comparer, observable, reaction } from "mobx";
import { autobind, createStorage } from "../../utils";
import { KubeObjectStore } from "../../kube-object.store";
import { Namespace, namespacesApi } from "../../api/endpoints";
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
import { createPageParam } from "../../navigation";
import { apiManager } from "../../api/api-manager";
import { isAllowedResource } from "../../../common/rbac";
@@ -61,18 +61,11 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
return super.subscribe(apis);
}
protected async loadItems(namespaces?: string[]) {
protected async loadItems({ isAdmin, namespaces }: KubeObjectStoreLoadingParams) {
if (!isAllowedResource("namespaces")) {
if (namespaces) return namespaces.map(this.getDummyNamespace);
return [];
}
if (namespaces) {
return Promise.all(namespaces.map(name => this.api.get({ name })));
} else {
return super.loadItems();
return namespaces.map(this.getDummyNamespace);
}
return Promise.all(namespaces.map(name => this.api.get({ name })));
}
protected getDummyNamespace(name: string) {
@@ -105,12 +98,6 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
else this.contextNs.push(namespace);
}
@action
reset() {
super.reset();
this.contextNs.clear();
}
@action
async remove(item: Namespace) {
await super.remove(item);
@@ -1,7 +1,7 @@
import difference from "lodash/difference";
import uniqBy from "lodash/uniqBy";
import { clusterRoleBindingApi, IRoleBindingSubject, RoleBinding, roleBindingApi } from "../../api/endpoints";
import { KubeObjectStore } from "../../kube-object.store";
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
import { autobind } from "../../utils";
import { apiManager } from "../../api/api-manager";
@@ -26,15 +26,12 @@ export class RoleBindingsStore extends KubeObjectStore<RoleBinding> {
return clusterRoleBindingApi.get(params);
}
protected loadItems(namespaces?: string[]) {
if (namespaces) {
return Promise.all(
namespaces.map(namespace => roleBindingApi.list({ namespace }))
).then(items => items.flat());
} else {
return Promise.all([clusterRoleBindingApi.list(), roleBindingApi.list()])
.then(items => items.flat());
}
protected async loadItems({ isAdmin, namespaces }: KubeObjectStoreLoadingParams): Promise<RoleBinding[]> {
const items = await Promise.all([
super.loadItems({ isAdmin, namespaces, api: clusterRoleBindingApi }),
super.loadItems({ isAdmin, namespaces, api: roleBindingApi }),
]);
return items.flat();
}
protected async createItem(params: { name: string; namespace?: string }, data?: Partial<RoleBinding>) {
@@ -1,6 +1,6 @@
import { clusterRoleApi, Role, roleApi } from "../../api/endpoints";
import { autobind } from "../../utils";
import { KubeObjectStore } from "../../kube-object.store";
import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store";
import { apiManager } from "../../api/api-manager";
@autobind()
@@ -24,15 +24,12 @@ export class RolesStore extends KubeObjectStore<Role> {
return clusterRoleApi.get(params);
}
protected loadItems(namespaces?: string[]): Promise<Role[]> {
if (namespaces) {
return Promise.all(
namespaces.map(namespace => roleApi.list({ namespace }))
).then(items => items.flat());
} else {
return Promise.all([clusterRoleApi.list(), roleApi.list()])
.then(items => items.flat());
}
protected async loadItems({ isAdmin, namespaces }: KubeObjectStoreLoadingParams): Promise<Role[]> {
const items = await Promise.all([
super.loadItems({ isAdmin, namespaces, api: clusterRoleApi }),
super.loadItems({ isAdmin, namespaces, api: roleApi }),
]);
return items.flat();
}
protected async createItem(params: { name: string; namespace?: string }, data?: Partial<Role>) {