1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix namespaces not being shown

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-28 11:53:16 -05:00
parent 5f58196529
commit ff30f8ace7
7 changed files with 37 additions and 12 deletions

View File

@ -208,7 +208,11 @@ export abstract class KubeObjectStore<
} }
} }
return await res ?? []; const items = await res ?? [];
console.trace("loadItems", this.api, [...items]);
return items;
} }
this.loadedNamespaces.set(namespaces); this.loadedNamespaces.set(namespaces);
@ -249,6 +253,8 @@ export abstract class KubeObjectStore<
try { try {
const items = await this.loadItems({ namespaces, reqInit, onLoadFailure }); const items = await this.loadItems({ namespaces, reqInit, onLoadFailure });
console.log("loadAll", this.api, [...items]);
this.mergeItems(items, { merge, namespaces }); this.mergeItems(items, { merge, namespaces });
this.isLoaded = true; this.isLoaded = true;
@ -281,6 +287,8 @@ export abstract class KubeObjectStore<
protected mergeItems(partialItems: K[], { merge = true, updateStore = true, sort = true, filter = true, namespaces }: MergeItemsOptions): K[] { protected mergeItems(partialItems: K[], { merge = true, updateStore = true, sort = true, filter = true, namespaces }: MergeItemsOptions): K[] {
let items = partialItems; let items = partialItems;
console.log("mergeItems", this.api, [...partialItems]);
// update existing items // update existing items
if (merge && this.api.isNamespaced) { if (merge && this.api.isNamespaced) {
const ns = new Set(namespaces); const ns = new Set(namespaces);

View File

@ -0,0 +1,18 @@
/**
* 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 { computed } from "mobx";
import hostedClusterInjectable from "../cluster-frame-context/hosted-cluster.injectable";
const clusterConfiguredAccessibleNamespacesInjectable = getInjectable({
id: "cluster-configured-accessible-namespaces",
instantiate: (di) => {
const hostedCluster = di.inject(hostedClusterInjectable);
return computed(() => [...hostedCluster?.accessibleNamespaces ?? []]);
},
});
export default clusterConfiguredAccessibleNamespacesInjectable;

View File

@ -10,6 +10,7 @@ import namespaceApiInjectable from "../../../common/k8s-api/endpoints/namespace.
import assert from "assert"; import assert from "assert";
import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable"; import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable";
import clusterFrameContextForClusterScopedResourcesInjectable from "../../cluster-frame-context/for-cluster-scoped-resources.injectable"; import clusterFrameContextForClusterScopedResourcesInjectable from "../../cluster-frame-context/for-cluster-scoped-resources.injectable";
import clusterConfiguredAccessibleNamespacesInjectable from "../../cluster/accessible-namespaces.injectable";
const namespaceStoreInjectable = getInjectable({ const namespaceStoreInjectable = getInjectable({
id: "namespace-store", id: "namespace-store",
@ -23,6 +24,7 @@ const namespaceStoreInjectable = getInjectable({
return new NamespaceStore({ return new NamespaceStore({
context: di.inject(clusterFrameContextForClusterScopedResourcesInjectable), context: di.inject(clusterFrameContextForClusterScopedResourcesInjectable),
storage: createStorage<string[] | undefined>("selected_namespaces", undefined), storage: createStorage<string[] | undefined>("selected_namespaces", undefined),
clusterConfiguredAccessibleNamespaces: di.inject(clusterConfiguredAccessibleNamespacesInjectable),
}, api); }, api);
}, },
injectionToken: kubeObjectStoreInjectionToken, injectionToken: kubeObjectStoreInjectionToken,

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { IReactionDisposer } from "mobx"; import type { IComputedValue, IReactionDisposer } from "mobx";
import { action, comparer, computed, makeObservable, reaction } from "mobx"; import { action, comparer, computed, makeObservable, reaction } from "mobx";
import type { StorageLayer } from "../../utils"; import type { StorageLayer } from "../../utils";
import { autoBind, noop, toggle } from "../../utils"; import { autoBind, noop, toggle } from "../../utils";
@ -14,6 +14,7 @@ import { Namespace } from "../../../common/k8s-api/endpoints/namespace.api";
interface Dependencies extends KubeObjectStoreDependencies { interface Dependencies extends KubeObjectStoreDependencies {
readonly storage: StorageLayer<string[] | undefined>; readonly storage: StorageLayer<string[] | undefined>;
readonly clusterConfiguredAccessibleNamespaces: IComputedValue<string[]>;
} }
export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> { export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
@ -118,17 +119,13 @@ export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
} }
protected async loadItems(params: KubeObjectStoreLoadingParams): Promise<Namespace[]> { protected async loadItems(params: KubeObjectStoreLoadingParams): Promise<Namespace[]> {
const { allowedNamespaces } = this; const clusterConfiguredAccessibleNamespaces = this.dependencies.clusterConfiguredAccessibleNamespaces.get();
let namespaces = await super.loadItems(params).catch(() => []); if (clusterConfiguredAccessibleNamespaces.length > 0) {
return clusterConfiguredAccessibleNamespaces.map(getDummyNamespace);
namespaces = namespaces.filter(namespace => allowedNamespaces.includes(namespace.getName()));
if (!namespaces.length && allowedNamespaces.length > 0) {
return allowedNamespaces.map(getDummyNamespace);
} }
return namespaces; return super.loadItems(params);
} }
@action selectNamespaces = (namespace: string | string[]) => { @action selectNamespaces = (namespace: string | string[]) => {

View File

@ -76,7 +76,7 @@ class NonInjectedSearchInput extends React.Component<SearchInputProps & Dependen
} }
render() { render() {
const { className, compact, onClear, showClearIcon, bindGlobalFocusHotkey, value, ...inputProps } = this.props; const { className, compact, onClear, showClearIcon, bindGlobalFocusHotkey, value, isMac, ...inputProps } = this.props;
let rightIcon = <Icon small material="search"/>; let rightIcon = <Icon small material="search"/>;
if (showClearIcon && value) { if (showClearIcon && value) {

View File

@ -15,7 +15,7 @@ import { ClusterFrame } from "./cluster-frame";
import historyInjectable from "../../navigation/history.injectable"; import historyInjectable from "../../navigation/history.injectable";
import { computed } from "mobx"; import { computed } from "mobx";
import type { Cluster } from "../../../common/cluster/cluster"; import type { Cluster } from "../../../common/cluster/cluster";
import createClusterInjectable from "../../create-cluster/create-cluster.injectable"; import createClusterInjectable from "../../cluster/create-cluster.injectable";
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable"; import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable"; import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable";