mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Leases view (#6378)
* Leases view Signed-off-by: Piotr Roszatycki <piotr.roszatycki@gmail.com> * Renamed default exports Signed-off-by: Piotr Roszatycki <piotr.roszatycki@gmail.com>
This commit is contained in:
parent
f021d9d0db
commit
51af8f8aa4
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import isAllowedResourceInjectable from "../../../../../utils/is-allowed-resource.injectable";
|
||||
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
|
||||
|
||||
const leasesRouteInjectable = getInjectable({
|
||||
id: "leases",
|
||||
|
||||
instantiate: (di) => {
|
||||
const isAllowedResource = di.inject(isAllowedResourceInjectable, "leases");
|
||||
|
||||
return {
|
||||
path: "/leases",
|
||||
clusterFrame: true,
|
||||
isEnabled: isAllowedResource,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: frontEndRouteInjectionToken,
|
||||
});
|
||||
|
||||
export default leasesRouteInjectable;
|
||||
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import leasesRouteInjectable from "./leases-route.injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token";
|
||||
|
||||
const navigateToLeasesInjectable = getInjectable({
|
||||
id: "navigate-to-leases",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(leasesRouteInjectable);
|
||||
|
||||
return () => navigateToRoute(route);
|
||||
},
|
||||
});
|
||||
|
||||
export default navigateToLeasesInjectable;
|
||||
@ -19,6 +19,7 @@ export * from "./events.api";
|
||||
export * from "./horizontal-pod-autoscaler.api";
|
||||
export * from "./ingress.api";
|
||||
export * from "./job.api";
|
||||
export * from "./lease.api";
|
||||
export * from "./limit-range.api";
|
||||
export * from "./namespace.api";
|
||||
export * from "./network-policy.api";
|
||||
|
||||
22
src/common/k8s-api/endpoints/lease.api.injectable.ts
Normal file
22
src/common/k8s-api/endpoints/lease.api.injectable.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { LeaseApi } from "./lease.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
|
||||
const leaseApiInjectable = getInjectable({
|
||||
id: "lease-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "leaseApi is only available in certain environments");
|
||||
|
||||
return new LeaseApi();
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
});
|
||||
|
||||
export default leaseApiInjectable;
|
||||
56
src/common/k8s-api/endpoints/lease.api.ts
Normal file
56
src/common/k8s-api/endpoints/lease.api.ts
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
|
||||
export interface LeaseSpec {
|
||||
acquireTime?: string;
|
||||
holderIdentity: string;
|
||||
leaseDurationSeconds: number;
|
||||
leaseTransitions?: number;
|
||||
renewTime: string;
|
||||
}
|
||||
|
||||
export class Lease extends KubeObject<
|
||||
NamespaceScopedMetadata,
|
||||
void,
|
||||
LeaseSpec
|
||||
> {
|
||||
static readonly kind = "Lease";
|
||||
static readonly namespaced = true;
|
||||
static readonly apiBase = "/apis/coordination.k8s.io/v1/leases";
|
||||
|
||||
getAcquireTime(): string {
|
||||
return this.spec.acquireTime || "";
|
||||
}
|
||||
|
||||
getHolderIdentity(): string {
|
||||
return this.spec.holderIdentity;
|
||||
}
|
||||
|
||||
getLeaseDurationSeconds(): number {
|
||||
return this.spec.leaseDurationSeconds;
|
||||
}
|
||||
|
||||
getLeaseTransitions(): number | undefined {
|
||||
return this.spec.leaseTransitions;
|
||||
}
|
||||
|
||||
getRenewTime(): string {
|
||||
return this.spec.renewTime;
|
||||
}
|
||||
}
|
||||
|
||||
export class LeaseApi extends KubeApi<Lease> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
objectConstructor: Lease,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
export type KubeResource =
|
||||
"namespaces" | "nodes" | "events" | "resourcequotas" | "services" | "limitranges" |
|
||||
"namespaces" | "nodes" | "events" | "resourcequotas" | "services" | "limitranges" | "leases" |
|
||||
"secrets" | "configmaps" | "ingresses" | "networkpolicies" | "persistentvolumeclaims" | "persistentvolumes" | "storageclasses" |
|
||||
"pods" | "daemonsets" | "deployments" | "statefulsets" | "replicasets" | "jobs" | "cronjobs" |
|
||||
"endpoints" | "customresourcedefinitions" | "horizontalpodautoscalers" | "podsecuritypolicies" | "poddisruptionbudgets" |
|
||||
@ -35,6 +35,7 @@ export const apiResourceRecord: Record<KubeResource, KubeApiResourceData> = {
|
||||
"jobs": { kind: "Job", group: "batch" },
|
||||
"namespaces": { kind: "Namespace" },
|
||||
"limitranges": { kind: "LimitRange" },
|
||||
"leases": { kind: "Lease" },
|
||||
"networkpolicies": { kind: "NetworkPolicy", group: "networking.k8s.io" },
|
||||
"nodes": { kind: "Node" },
|
||||
"persistentvolumes": { kind: "PersistentVolume" },
|
||||
|
||||
7
src/renderer/components/+config-leases/index.ts
Normal file
7
src/renderer/components/+config-leases/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export * from "./leases";
|
||||
export * from "./lease-details";
|
||||
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
.LeaseDetails {}
|
||||
51
src/renderer/components/+config-leases/lease-details.tsx
Normal file
51
src/renderer/components/+config-leases/lease-details.tsx
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./lease-details.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { DrawerItem } from "../drawer";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import { KubeObjectMeta } from "../kube-object-meta";
|
||||
import type { Lease } from "../../../common/k8s-api/endpoints";
|
||||
|
||||
export interface LeaseDetailsProps extends KubeObjectDetailsProps<Lease> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class LeaseDetails extends React.Component<LeaseDetailsProps> {
|
||||
|
||||
render() {
|
||||
const { object: lease } = this.props;
|
||||
|
||||
return (
|
||||
<div className="LeaseDetails">
|
||||
<KubeObjectMeta object={lease} />
|
||||
|
||||
<DrawerItem name="Holder Identity">
|
||||
{lease.getHolderIdentity()}
|
||||
</DrawerItem>
|
||||
|
||||
<DrawerItem name="Lease Duration Seconds">
|
||||
{lease.getLeaseDurationSeconds()}
|
||||
</DrawerItem>
|
||||
|
||||
<DrawerItem name="Lease Transitions" hidden={lease.getLeaseTransitions() === undefined}>
|
||||
{lease.getLeaseTransitions()}
|
||||
</DrawerItem>
|
||||
|
||||
<DrawerItem name="Acquire Time" hidden={lease.getAcquireTime() === ""}>
|
||||
{lease.getAcquireTime()}
|
||||
</DrawerItem>
|
||||
|
||||
<DrawerItem name="Renew Time">
|
||||
{lease.getRenewTime()}
|
||||
</DrawerItem>
|
||||
|
||||
</div >
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { Leases } from "./leases";
|
||||
import leasesRouteInjectable from "../../../common/front-end-routing/routes/cluster/config/leases/leases-route.injectable";
|
||||
import { routeSpecificComponentInjectionToken } from "../../routes/route-specific-component-injection-token";
|
||||
|
||||
const leasesRouteComponentInjectable = getInjectable({
|
||||
id: "leases-route-component",
|
||||
|
||||
instantiate: (di) => ({
|
||||
route: di.inject(leasesRouteInjectable),
|
||||
Component: Leases,
|
||||
}),
|
||||
|
||||
injectionToken: routeSpecificComponentInjectionToken,
|
||||
});
|
||||
|
||||
export default leasesRouteComponentInjectable;
|
||||
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
import leasesRouteInjectable from "../../../common/front-end-routing/routes/cluster/config/leases/leases-route.injectable";
|
||||
import { configSidebarItemId } from "../+config/config-sidebar-items.injectable";
|
||||
import { sidebarItemsInjectionToken } from "../layout/sidebar-items.injectable";
|
||||
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
||||
import navigateToLeasesInjectable from "../../../common/front-end-routing/routes/cluster/config/leases/navigate-to-leases.injectable";
|
||||
|
||||
const leasesSidebarItemsInjectable = getInjectable({
|
||||
id: "leases-sidebar-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const route = di.inject(leasesRouteInjectable);
|
||||
const navigateToLeases = di.inject(navigateToLeasesInjectable);
|
||||
const routeIsActive = di.inject(routeIsActiveInjectable, route);
|
||||
|
||||
return computed(() => [
|
||||
{
|
||||
id: "leases",
|
||||
parentId: configSidebarItemId,
|
||||
title: "Leases",
|
||||
onClick: navigateToLeases,
|
||||
isActive: routeIsActive,
|
||||
isVisible: route.isEnabled,
|
||||
orderNumber: 80,
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
||||
injectionToken: sidebarItemsInjectionToken,
|
||||
});
|
||||
|
||||
export default leasesSidebarItemsInjectable;
|
||||
24
src/renderer/components/+config-leases/leases.scss
Normal file
24
src/renderer/components/+config-leases/leases.scss
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
.Leases {
|
||||
.TableCell {
|
||||
&.name {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
@include table-cell-warning;
|
||||
}
|
||||
|
||||
&.keys {
|
||||
flex: 2.5;
|
||||
}
|
||||
|
||||
&.age {
|
||||
flex: .5;
|
||||
}
|
||||
}
|
||||
}
|
||||
87
src/renderer/components/+config-leases/leases.tsx
Normal file
87
src/renderer/components/+config-leases/leases.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./leases.scss";
|
||||
|
||||
import * as React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { Lease } from "../../../common/k8s-api/endpoints/lease.api";
|
||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import { KubeObjectListLayout } from "../kube-object-list-layout";
|
||||
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
||||
import { KubeObjectAge } from "../kube-object/age";
|
||||
import { autoBind } from "../../../common/utils";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import leaseStoreInjectable from "./store.injectable";
|
||||
import type { LeaseStore } from "./store";
|
||||
|
||||
enum columnId {
|
||||
name = "name",
|
||||
namespace = "namespace",
|
||||
holder = "holder",
|
||||
age = "age",
|
||||
}
|
||||
|
||||
export interface LeaseProps extends KubeObjectDetailsProps<Lease> {
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
leaseStore: LeaseStore;
|
||||
}
|
||||
|
||||
@observer
|
||||
class NonInjectedLease extends React.Component<LeaseProps & Dependencies> {
|
||||
constructor(props: LeaseProps & Dependencies) {
|
||||
super(props);
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { leaseStore } = this.props;
|
||||
|
||||
return (
|
||||
<SiblingsInTabLayout>
|
||||
<KubeObjectListLayout
|
||||
isConfigurable
|
||||
tableId="configuration_leases"
|
||||
className="Leases"
|
||||
store={leaseStore}
|
||||
sortingCallbacks={{
|
||||
[columnId.name]: lease => lease.getName(),
|
||||
[columnId.namespace]: lease => lease.getNs(),
|
||||
[columnId.holder]: lease => lease.getHolderIdentity(),
|
||||
[columnId.age]: lease => -lease.getCreationTimestamp(),
|
||||
}}
|
||||
searchFilters={[
|
||||
lease => lease.getSearchFields(),
|
||||
]}
|
||||
renderHeaderTitle="Leases"
|
||||
renderTableHeader={[
|
||||
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
|
||||
{ className: "warning", showWithColumn: columnId.name },
|
||||
{ title: "Namespace", className: "namespace", sortBy: columnId.namespace, id: columnId.namespace },
|
||||
{ title: "Holder", className: "holder", sortBy: columnId.holder, id: columnId.holder },
|
||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
]}
|
||||
renderTableContents={lease => [
|
||||
lease.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={lease} />,
|
||||
lease.getNs(),
|
||||
lease.getHolderIdentity(),
|
||||
<KubeObjectAge key="age" object={lease} />,
|
||||
]}
|
||||
/>
|
||||
</SiblingsInTabLayout>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const Leases = withInjectables<Dependencies, LeaseProps>(NonInjectedLease, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
leaseStore: di.inject(leaseStoreInjectable),
|
||||
}),
|
||||
});
|
||||
24
src/renderer/components/+config-leases/store.injectable.ts
Normal file
24
src/renderer/components/+config-leases/store.injectable.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
import { kubeObjectStoreInjectionToken } from "../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import leaseApiInjectable from "../../../common/k8s-api/endpoints/lease.api.injectable";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable";
|
||||
import { LeaseStore } from "./store";
|
||||
|
||||
const leaseStoreInjectable = getInjectable({
|
||||
id: "lease-store",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectable), "leaseStore is only available in certain environments");
|
||||
|
||||
const api = di.inject(leaseApiInjectable);
|
||||
|
||||
return new LeaseStore(api);
|
||||
},
|
||||
injectionToken: kubeObjectStoreInjectionToken,
|
||||
});
|
||||
|
||||
export default leaseStoreInjectable;
|
||||
10
src/renderer/components/+config-leases/store.ts
Normal file
10
src/renderer/components/+config-leases/store.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import type { Lease, LeaseApi } from "../../../common/k8s-api/endpoints/lease.api";
|
||||
|
||||
export class LeaseStore extends KubeObjectStore<Lease, LeaseApi> {
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { kubeObjectDetailItemInjectionToken } from "../kube-object-detail-item-injection-token";
|
||||
import { computed } from "mobx";
|
||||
import { LeaseDetails } from "../../../+config-leases";
|
||||
import { kubeObjectMatchesToKindAndApiVersion } from "../kube-object-matches-to-kind-and-api-version";
|
||||
import currentKubeObjectInDetailsInjectable from "../../current-kube-object-in-details.injectable";
|
||||
|
||||
const leaseDetailItemInjectable = getInjectable({
|
||||
id: "lease-detail-item",
|
||||
|
||||
instantiate: (di) => {
|
||||
const kubeObject = di.inject(currentKubeObjectInDetailsInjectable);
|
||||
|
||||
return {
|
||||
Component: LeaseDetails,
|
||||
enabled: computed(() => isLease(kubeObject.get())),
|
||||
orderNumber: 10,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: kubeObjectDetailItemInjectionToken,
|
||||
});
|
||||
|
||||
const isLease = kubeObjectMatchesToKindAndApiVersion(
|
||||
"Lease",
|
||||
["coordination.k8s.io/v1"],
|
||||
);
|
||||
|
||||
export default leaseDetailItemInjectable;
|
||||
@ -10,6 +10,7 @@ export const ResourceNames: Record<KubeResource, string> = {
|
||||
"namespaces": "Namespaces",
|
||||
"nodes": "Nodes",
|
||||
"events": "Events",
|
||||
"leases": "Leases",
|
||||
"resourcequotas": "Resource Quotas",
|
||||
"services": "Services",
|
||||
"secrets": "Secrets",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user