mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Support extending KubernetesCluster in extensions (#4702)
* Support extending KubernetesCluster in extensions Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Simplify getItemsByEntityClass Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Make apiVersion string. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Improve entity loading for extension custom types. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Improve comment. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Fix lint. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Properly handle loading custom entity in cluster-frame Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Avoid .bind with .loadOnClusterRenderer Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Fix lint. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Revert style change. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Make loadOnClusterRenderer arrow function again, revert autoInitExtensions change as unnecessary Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Remove commented code. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Document extending KubernetesCluster in extension guides. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
1 parent
74d92d09d9
commit
79c01daf6a
10 files changed
+154
-35
No files matched your search
@@ -20,6 +20,7 @@ Each guide or code sample includes the following:
|
||||
| [Main process extension](main-extension.md) | Main.LensExtension |
|
||||
| [Renderer process extension](renderer-extension.md) | Renderer.LensExtension |
|
||||
| [Resource stack (cluster feature)](resource-stack.md) | |
|
||||
| [Extending KubernetesCluster)](extending-kubernetes-cluster.md) | |
|
||||
| [Stores](stores.md) | |
|
||||
| [Components](components.md) | |
|
||||
| [KubeObjectListLayout](kube-object-list-layout.md) | |
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# Extending KubernetesCluster
|
||||
|
||||
Extension can specify it's own subclass of Common.Catalog.KubernetesCluster. Extension can also specify a new Category for it in the Catalog.
|
||||
|
||||
## Extending Common.Catalog.KubernetesCluster
|
||||
|
||||
``` typescript
|
||||
import { Common } from "@k8slens/extensions";
|
||||
|
||||
// The kind must be different from KubernetesCluster's kind
|
||||
export const kind = "ManagedDevCluster";
|
||||
|
||||
export class ManagedDevCluster extends Common.Catalog.KubernetesCluster {
|
||||
public static readonly kind = kind;
|
||||
|
||||
public readonly kind = kind;
|
||||
}
|
||||
```
|
||||
|
||||
## Extending Common.Catalog.CatalogCategory
|
||||
|
||||
These custom Catalog entities can be added a new Category in the Catalog.
|
||||
|
||||
``` typescript
|
||||
import { Common } from "@k8slens/extensions";
|
||||
import { kind, ManagedDevCluster } from "../entities/ManagedDevCluster";
|
||||
|
||||
class ManagedDevClusterCategory extends Common.Catalog.CatalogCategory {
|
||||
public readonly apiVersion = "catalog.k8slens.dev/v1alpha1";
|
||||
public readonly kind = "CatalogCategory";
|
||||
public metadata = {
|
||||
name: "Managed Dev Clusters",
|
||||
icon: ""
|
||||
};
|
||||
public spec: Common.Catalog.CatalogCategorySpec = {
|
||||
group: "entity.k8slens.dev",
|
||||
versions: [
|
||||
{
|
||||
name: "v1alpha1",
|
||||
entityClass: ManagedDevCluster as any,
|
||||
},
|
||||
],
|
||||
names: {
|
||||
kind
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export { ManagedDevClusterCategory };
|
||||
export type { ManagedDevClusterCategory as ManagedDevClusterCategoryType };
|
||||
```
|
||||
|
||||
The category needs to be registered in the `onActivate()` method both in main and renderer
|
||||
|
||||
``` typescript
|
||||
// in main's on onActivate
|
||||
Main.Catalog.catalogCategories.add(new ManagedDevClusterCategory());
|
||||
```
|
||||
|
||||
``` typescript
|
||||
// in renderer's on onActivate
|
||||
Renderer.Catalog.catalogCategories.add(new ManagedDevClusterCategory());
|
||||
```
|
||||
|
||||
You can then add the entities to the Catalog as a new source:
|
||||
|
||||
``` typescript
|
||||
this.addCatalogSource("managedDevClusters", this.managedDevClusters);
|
||||
```
|
||||
Reference in new issue
Block a user