mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix documentation around components examples (#4375)
This commit is contained in:
parent
0f2801552f
commit
994208b25a
@ -207,7 +207,7 @@ export default class ExampleExtension extends Renderer.LensExtension {
|
|||||||
topBarItems = [
|
topBarItems = [
|
||||||
{
|
{
|
||||||
components: {
|
components: {
|
||||||
Item: (
|
Item: () => (
|
||||||
<Icon material="favorite" onClick={() => this.navigate("/example-page" />
|
<Icon material="favorite" onClick={() => this.navigate("/example-page" />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ export default class ExampleExtension extends Renderer.LensExtension {
|
|||||||
statusBarItems = [
|
statusBarItems = [
|
||||||
{
|
{
|
||||||
components: {
|
components: {
|
||||||
Item: (
|
Item: () => (
|
||||||
<div className="flex align-center gaps hover-highlight" onClick={() => this.navigate("/example-page")} >
|
<div className="flex align-center gaps hover-highlight" onClick={() => this.navigate("/example-page")} >
|
||||||
<Icon material="favorite" />
|
<Icon material="favorite" />
|
||||||
</div>
|
</div>
|
||||||
@ -259,7 +259,7 @@ import { CustomWorkloadsOverviewItem } from "./src/custom-workloads-overview-ite
|
|||||||
export default class ExampleExtension extends Renderer.LensExtension {
|
export default class ExampleExtension extends Renderer.LensExtension {
|
||||||
kubeWorkloadsOverviewItems = [
|
kubeWorkloadsOverviewItems = [
|
||||||
{
|
{
|
||||||
components : {
|
components: {
|
||||||
Details: () => <CustomWorkloadsOverviewItem />
|
Details: () => <CustomWorkloadsOverviewItem />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -478,7 +478,7 @@ export default class HelpExtension extends Renderer.LensExtension {
|
|||||||
statusBarItems = [
|
statusBarItems = [
|
||||||
{
|
{
|
||||||
components: {
|
components: {
|
||||||
Item: (
|
Item: () => (
|
||||||
<div
|
<div
|
||||||
className="flex align-center gaps"
|
className="flex align-center gaps"
|
||||||
onClick={() => this.navigate("help")}
|
onClick={() => this.navigate("help")}
|
||||||
@ -741,7 +741,7 @@ export class PodsDetailsList extends React.Component<Props> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { pods } = this.props
|
const { pods } = this.props
|
||||||
|
|
||||||
if (!pods?.length) {
|
if (!pods?.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,8 +33,8 @@ import * as path from "path";
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
K8sApi: {
|
K8sApi: {
|
||||||
ResourceStack,
|
ResourceStack,
|
||||||
forCluster,
|
forCluster,
|
||||||
Pod,
|
Pod,
|
||||||
}
|
}
|
||||||
} = Renderer;
|
} = Renderer;
|
||||||
@ -63,7 +63,7 @@ export class ExampleClusterFeature {
|
|||||||
try {
|
try {
|
||||||
const podApi = forCluster(this.cluster, Pod);
|
const podApi = forCluster(this.cluster, Pod);
|
||||||
const examplePod = await podApi.get({name: "example-pod", namespace: "default"});
|
const examplePod = await podApi.get({name: "example-pod", namespace: "default"});
|
||||||
|
|
||||||
if (examplePod?.kind) {
|
if (examplePod?.kind) {
|
||||||
console.log("found example-pod");
|
console.log("found example-pod");
|
||||||
return true;
|
return true;
|
||||||
@ -72,7 +72,7 @@ export class ExampleClusterFeature {
|
|||||||
console.log("Error getting example-pod:", e);
|
console.log("Error getting example-pod:", e);
|
||||||
}
|
}
|
||||||
console.log("didn't find example-pod");
|
console.log("didn't find example-pod");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,11 +84,11 @@ export class ExampleClusterFeature {
|
|||||||
```
|
```
|
||||||
|
|
||||||
The `ExampleClusterFeature` class constructor takes a `Common.Catalog.KubernetesCluster` argument.
|
The `ExampleClusterFeature` class constructor takes a `Common.Catalog.KubernetesCluster` argument.
|
||||||
This is the cluster that the resource stack will be applied to, and the constructor instantiates a `Renderer.K8sApi.ResourceStack` as such.
|
This is the cluster that the resource stack will be applied to, and the constructor instantiates a `Renderer.K8sApi.ResourceStack` as such.
|
||||||
`ExampleClusterFeature` implements an `install()` method which simply invokes the `kubectlApplyFolder()` method of the `Renderer.K8sApi.ResourceStack` class.
|
`ExampleClusterFeature` implements an `install()` method which simply invokes the `kubectlApplyFolder()` method of the `Renderer.K8sApi.ResourceStack` class.
|
||||||
`kubectlApplyFolder()` applies to the cluster all kubernetes resources found in the folder passed to it, in this case `../resources`.
|
`kubectlApplyFolder()` applies to the cluster all kubernetes resources found in the folder passed to it, in this case `../resources`.
|
||||||
Similarly, `ExampleClusterFeature` implements an `uninstall()` method which simply invokes the `kubectlDeleteFolder()` method of the `Renderer.K8sApi.ResourceStack` class.
|
Similarly, `ExampleClusterFeature` implements an `uninstall()` method which simply invokes the `kubectlDeleteFolder()` method of the `Renderer.K8sApi.ResourceStack` class.
|
||||||
`kubectlDeleteFolder()` tries to delete from the cluster all kubernetes resources found in the folder passed to it, again in this case `../resources`.
|
`kubectlDeleteFolder()` tries to delete from the cluster all kubernetes resources found in the folder passed to it, again in this case `../resources`.
|
||||||
|
|
||||||
`ExampleClusterFeature` also implements an `isInstalled()` method, which demonstrates how you can utilize the kubernetes api to inspect the resource stack status.
|
`ExampleClusterFeature` also implements an `isInstalled()` method, which demonstrates how you can utilize the kubernetes api to inspect the resource stack status.
|
||||||
`isInstalled()` simply tries to find a pod named `example-pod`, as a way to determine if the pod is already installed.
|
`isInstalled()` simply tries to find a pod named `example-pod`, as a way to determine if the pod is already installed.
|
||||||
@ -102,17 +102,17 @@ To allow the end-user to control the life cycle of this cluster feature the foll
|
|||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { computed, observable, makeObservable } from "mobx";
|
import { computed, observable, makeObservable } from "mobx";
|
||||||
import { ExampleClusterFeature } from "./example-cluster-feature";
|
import { ExampleClusterFeature } from "./example-cluster-feature";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Component: {
|
Component: {
|
||||||
SubTitle, Button,
|
SubTitle, Button,
|
||||||
}
|
}
|
||||||
} = Renderer;
|
} = Renderer;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
cluster: Common.Catalog.KubernetesCluster;
|
cluster: Common.Catalog.KubernetesCluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ExampleClusterFeatureSettings extends React.Component<Props> {
|
export class ExampleClusterFeatureSettings extends React.Component<Props> {
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
@ -130,14 +130,14 @@ To allow the end-user to control the life cycle of this cluster feature the foll
|
|||||||
|
|
||||||
await this.updateFeatureState();
|
await this.updateFeatureState();
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateFeatureState() {
|
async updateFeatureState() {
|
||||||
this.installed = await this.feature.isInstalled();
|
this.installed = await this.feature.isInstalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
this.inProgress = true;
|
this.inProgress = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.installed) {
|
if (this.installed) {
|
||||||
await this.feature.uninstall();
|
await this.feature.uninstall();
|
||||||
@ -150,18 +150,18 @@ To allow the end-user to control the life cycle of this cluster feature the foll
|
|||||||
await this.updateFeatureState();
|
await this.updateFeatureState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get buttonLabel() {
|
@computed get buttonLabel() {
|
||||||
if (this.inProgress && this.installed) return "Uninstalling ...";
|
if (this.inProgress && this.installed) return "Uninstalling ...";
|
||||||
if (this.inProgress) return "Applying ...";
|
if (this.inProgress) return "Applying ...";
|
||||||
|
|
||||||
if (this.installed) {
|
if (this.installed) {
|
||||||
return "Uninstall";
|
return "Uninstall";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Apply";
|
return "Apply";
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -208,11 +208,9 @@ export default class ExampleExtension extends Renderer.LensExtension {
|
|||||||
title: "Example Cluster Feature",
|
title: "Example Cluster Feature",
|
||||||
priority: 5,
|
priority: 5,
|
||||||
components: {
|
components: {
|
||||||
View: ({ entity = null }: { entity: Common.Catalog.KubernetesCluster}) => {
|
View: ({ entity = null }: { entity: Common.Catalog.KubernetesCluster}) => (
|
||||||
return (
|
<ExampleClusterFeatureSettings cluster={entity} />
|
||||||
<ExampleClusterFeatureSettings cluster={entity} />
|
)
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@ -235,4 +233,4 @@ The final result looks like this:
|
|||||||
`ExampleClusterFeature` and `ExampleClusterFeatureSettings` demonstrate a cluster feature for a simple resource stack.
|
`ExampleClusterFeature` and `ExampleClusterFeatureSettings` demonstrate a cluster feature for a simple resource stack.
|
||||||
In practice a resource stack can include many resources, and require more sophisticated life cycle management (upgrades, partial installations, etc.)
|
In practice a resource stack can include many resources, and require more sophisticated life cycle management (upgrades, partial installations, etc.)
|
||||||
Using `Renderer.K8sApi.ResourceStack` and `entitySettings` it is possible to implement solutions for more complex cluster features.
|
Using `Renderer.K8sApi.ResourceStack` and `entitySettings` it is possible to implement solutions for more complex cluster features.
|
||||||
The **Lens Metrics** setting (on the cluster **Settings** page) is a good example of an advanced solution.
|
The **Lens Metrics** setting (on the cluster **Settings** page) is a good example of an advanced solution.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user