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

Display namespace defined in kubeconfig always in the namespace selector (#472)

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-06-16 17:46:37 +03:00 committed by GitHub
parent a608918dce
commit 0661954a27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -34,7 +34,7 @@ export class NamespaceSelect extends React.Component<Props> {
private unsubscribe = noop;
async componentDidMount() {
if (isAllowedResource("namespaces") && !namespaceStore.isLoaded) {
if (!namespaceStore.isLoaded) {
await namespaceStore.loadAll();
}
this.unsubscribe = namespaceStore.subscribe();

View File

@ -4,6 +4,7 @@ import { KubeObjectStore } from "../../kube-object.store";
import { Namespace, namespacesApi } from "../../api/endpoints";
import { IQueryParams, navigation, setQueryParams } from "../../navigation";
import { apiManager } from "../../api/api-manager";
import { isAllowedResource } from "../..//api/rbac";
@autobind()
export class NamespaceStore extends KubeObjectStore<Namespace> {
@ -43,6 +44,16 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
}
protected loadItems(namespaces?: string[]) {
if (!isAllowedResource("namespaces")) {
if (namespaces) {
return Promise.all(namespaces.map(name => this.getDummyNamespace(name)))
}
else {
return new Promise<Namespace[]>(() => {
return []
})
}
}
if (namespaces) {
return Promise.all(namespaces.map(name => this.api.get({ name })))
}
@ -51,6 +62,19 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
}
}
protected getDummyNamespace(name: string) {
return new Namespace({
kind: "Namespace",
apiVersion: "v1",
metadata: {
name: name,
uid: "",
resourceVersion: "",
selfLink: `/api/v1/namespaces/${name}`
}
})
}
setContext(namespaces: string[]) {
this.contextNs.replace(namespaces);
}