mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add support for customreasourcedefinitions under the v1 API (#658)
* Add support for customreasourcedefinitions under the v1 API * moving store and views to use v1 Signed-off-by: Sebastian Malton <smalton@mirantis.com> Co-authored-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
parent
acfd1828eb
commit
e249769562
@ -130,9 +130,16 @@ export class CustomResourceDefinition extends KubeObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const crdApi = new KubeApi<CustomResourceDefinition>({
|
export const crdBetaApi = new KubeApi<CustomResourceDefinition>({
|
||||||
kind: CustomResourceDefinition.kind,
|
kind: CustomResourceDefinition.kind,
|
||||||
apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions",
|
apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions",
|
||||||
isNamespaced: false,
|
isNamespaced: false,
|
||||||
objectConstructor: CustomResourceDefinition,
|
objectConstructor: CustomResourceDefinition,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const crdApi = new KubeApi<CustomResourceDefinition>({
|
||||||
|
kind: CustomResourceDefinition.kind,
|
||||||
|
apiBase: "/apis/apiextensions.k8s.io/v1/customresourcedefinitions",
|
||||||
|
isNamespaced: false,
|
||||||
|
objectConstructor: CustomResourceDefinition,
|
||||||
|
});
|
||||||
|
|||||||
@ -7,6 +7,17 @@ import { KubeApi } from "../../api/kube-api";
|
|||||||
import { CRDResourceStore } from "./crd-resource.store";
|
import { CRDResourceStore } from "./crd-resource.store";
|
||||||
import { KubeObject } from "../../api/kube-object";
|
import { KubeObject } from "../../api/kube-object";
|
||||||
|
|
||||||
|
function initStore(crd: CustomResourceDefinition) {
|
||||||
|
const apiBase = crd.getResourceApiBase();
|
||||||
|
const kind = crd.getResourceKind();
|
||||||
|
const isNamespaced = crd.isNamespaced();
|
||||||
|
const api = apiManager.getApi(apiBase) || new KubeApi({ apiBase, kind, isNamespaced });
|
||||||
|
|
||||||
|
if (!apiManager.getStore(api)) {
|
||||||
|
apiManager.registerStore(api, new CRDResourceStore(api));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class CRDStore extends KubeObjectStore<CustomResourceDefinition> {
|
export class CRDStore extends KubeObjectStore<CustomResourceDefinition> {
|
||||||
api = crdApi
|
api = crdApi
|
||||||
@ -15,9 +26,7 @@ export class CRDStore extends KubeObjectStore<CustomResourceDefinition> {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
// auto-init stores for crd-s
|
// auto-init stores for crd-s
|
||||||
reaction(() => this.items.toJS(), items => {
|
reaction(() => this.items.toJS(), items => items.forEach(initStore))
|
||||||
items.forEach(this.initStore);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sortItems(items: CustomResourceDefinition[]) {
|
protected sortItems(items: CustomResourceDefinition[]) {
|
||||||
@ -27,23 +36,6 @@ export class CRDStore extends KubeObjectStore<CustomResourceDefinition> {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
protected initStore(crd: CustomResourceDefinition) {
|
|
||||||
const apiBase = crd.getResourceApiBase();
|
|
||||||
let api = apiManager.getApi(apiBase);
|
|
||||||
if (!api) {
|
|
||||||
api = new KubeApi({
|
|
||||||
apiBase: apiBase,
|
|
||||||
kind: crd.getResourceKind(),
|
|
||||||
isNamespaced: crd.isNamespaced(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
let store = apiManager.getStore(api);
|
|
||||||
if (!store) {
|
|
||||||
store = new CRDResourceStore(api);
|
|
||||||
apiManager.registerStore(api, store);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@computed get groups() {
|
@computed get groups() {
|
||||||
const groups: Record<string, CustomResourceDefinition[]> = {};
|
const groups: Record<string, CustomResourceDefinition[]> = {};
|
||||||
return this.items.reduce((groups, crd) => {
|
return this.items.reduce((groups, crd) => {
|
||||||
@ -63,9 +55,10 @@ export class CRDStore extends KubeObjectStore<CustomResourceDefinition> {
|
|||||||
getByObject(obj: KubeObject) {
|
getByObject(obj: KubeObject) {
|
||||||
if (!obj) return null
|
if (!obj) return null
|
||||||
const { kind, apiVersion } = obj;
|
const { kind, apiVersion } = obj;
|
||||||
return this.items.find(crd => {
|
|
||||||
return kind === crd.getResourceKind() && apiVersion === `${crd.getGroup()}/${crd.getVersion()}`
|
return this.items.find(crd => (
|
||||||
})
|
kind === crd.getResourceKind() && apiVersion === `${crd.getGroup()}/${crd.getVersion()}`
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user