mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Does not remove subnamespace with usual method
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
9f0b4323db
commit
58546b0e65
@ -38,6 +38,8 @@ function createNamespace(name: string, labels?: Record<string, string>, annotati
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fullNamespace = createNamespace("full-namespace");
|
||||||
|
|
||||||
const singleRoot = createNamespace("single-root", {
|
const singleRoot = createNamespace("single-root", {
|
||||||
"hnc.x-k8s.io/included-namespace": "true",
|
"hnc.x-k8s.io/included-namespace": "true",
|
||||||
});
|
});
|
||||||
@ -133,6 +135,7 @@ describe("NamespaceStore", () => {
|
|||||||
namespaceStore = di.inject(namespaceStoreInjectable);
|
namespaceStore = di.inject(namespaceStoreInjectable);
|
||||||
|
|
||||||
namespaceStore.items = observable.array([
|
namespaceStore.items = observable.array([
|
||||||
|
fullNamespace,
|
||||||
acmeGroup,
|
acmeGroup,
|
||||||
orgA,
|
orgA,
|
||||||
teamA,
|
teamA,
|
||||||
@ -146,6 +149,10 @@ describe("NamespaceStore", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
})
|
||||||
|
|
||||||
it("returns tree for single node", () => {
|
it("returns tree for single node", () => {
|
||||||
const tree = namespaceStore.getNamespaceTree(service1);
|
const tree = namespaceStore.getNamespaceTree(service1);
|
||||||
|
|
||||||
@ -214,9 +221,17 @@ describe("NamespaceStore", () => {
|
|||||||
|
|
||||||
describe("when removing a full namespace", () => {
|
describe("when removing a full namespace", () => {
|
||||||
it("removes namespace", () => {
|
it("removes namespace", () => {
|
||||||
namespaceStore.remove(acmeGroup);
|
namespaceStore.remove(fullNamespace);
|
||||||
|
|
||||||
expect(deleteMock).toBeCalledWith({ name: "acme-org", namespace: undefined });
|
expect(deleteMock).toBeCalledWith({ name: "full-namespace", namespace: undefined });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when removing a subnamespace", () => {
|
||||||
|
it("does not remove namespace directly", () => {
|
||||||
|
namespaceStore.remove(service1);
|
||||||
|
|
||||||
|
expect(deleteMock).not.toBeCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-create
|
|||||||
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";
|
import clusterConfiguredAccessibleNamespacesInjectable from "../../cluster/accessible-namespaces.injectable";
|
||||||
import loggerInjectable from "../../../common/logger.injectable";
|
import loggerInjectable from "../../../common/logger.injectable";
|
||||||
|
import customResourceDefinitionStoreInjectable from "../+custom-resources/definition.store.injectable";
|
||||||
|
|
||||||
const namespaceStoreInjectable = getInjectable({
|
const namespaceStoreInjectable = getInjectable({
|
||||||
id: "namespace-store",
|
id: "namespace-store",
|
||||||
@ -27,6 +28,7 @@ const namespaceStoreInjectable = getInjectable({
|
|||||||
storage: createStorage<string[] | undefined>("selected_namespaces", undefined),
|
storage: createStorage<string[] | undefined>("selected_namespaces", undefined),
|
||||||
clusterConfiguredAccessibleNamespaces: di.inject(clusterConfiguredAccessibleNamespacesInjectable),
|
clusterConfiguredAccessibleNamespaces: di.inject(clusterConfiguredAccessibleNamespacesInjectable),
|
||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
|
crdStore: di.inject(customResourceDefinitionStoreInjectable)
|
||||||
}, api);
|
}, api);
|
||||||
},
|
},
|
||||||
injectionToken: kubeObjectStoreInjectionToken,
|
injectionToken: kubeObjectStoreInjectionToken,
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import type { KubeObjectStoreDependencies, KubeObjectStoreLoadingParams } from "
|
|||||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||||
import type { NamespaceApi } from "../../../common/k8s-api/endpoints/namespace.api";
|
import type { NamespaceApi } from "../../../common/k8s-api/endpoints/namespace.api";
|
||||||
import { Namespace } from "../../../common/k8s-api/endpoints/namespace.api";
|
import { Namespace } from "../../../common/k8s-api/endpoints/namespace.api";
|
||||||
|
import type { CustomResourceDefinitionStore } from "../+custom-resources/definition.store";
|
||||||
|
|
||||||
export interface NamespaceTree {
|
export interface NamespaceTree {
|
||||||
id: string;
|
id: string;
|
||||||
@ -21,6 +22,7 @@ export interface NamespaceTree {
|
|||||||
interface Dependencies extends KubeObjectStoreDependencies {
|
interface Dependencies extends KubeObjectStoreDependencies {
|
||||||
readonly storage: StorageLayer<string[] | undefined>;
|
readonly storage: StorageLayer<string[] | undefined>;
|
||||||
readonly clusterConfiguredAccessibleNamespaces: IComputedValue<string[]>;
|
readonly clusterConfiguredAccessibleNamespaces: IComputedValue<string[]>;
|
||||||
|
readonly crdStore: CustomResourceDefinitionStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
|
export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
|
||||||
@ -218,8 +220,26 @@ export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
async removeSubnamespace(item: Namespace) {
|
||||||
|
// Remove anchor from the parent namespace
|
||||||
|
const crd = this.dependencies.crdStore.getByName(item.getName());
|
||||||
|
|
||||||
|
if (!crd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dependencies.crdStore.remove(crd);
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async remove(item: Namespace) {
|
async remove(item: Namespace) {
|
||||||
|
if (item.isSubnamespace()) {
|
||||||
|
this.removeSubnamespace(item);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await super.remove(item);
|
await super.remove(item);
|
||||||
this.clearSelected(item.getName());
|
this.clearSelected(item.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user