mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
feat: New view for PriorityClasses under Config menu (#5816)
* feat: new view for PriorityClass under Config menu Signed-off-by: Piotr Roszatycki <piotr.roszatycki@gmail.com> * Added priorityClassDetailItemInjectable Signed-off-by: Piotr Roszatycki <piotr.roszatycki@gmail.com> * Removed uneccessary defensive code Signed-off-by: Piotr Roszatycki <piotr.roszatycki@gmail.com>
This commit is contained in:
1 parent
70105a6ef2
commit
f4b7fea54a
24 files changed
+470
-2
No files matched your search
@@ -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 "./priority-classes";
|
||||
export * from "./priority-classes-details";
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
.PriorityClassesDetails {}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./priority-classes.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { DrawerItem } from "../drawer";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import type { PriorityClass } from "../../../common/k8s-api/endpoints";
|
||||
import { KubeObjectMeta } from "../kube-object-meta";
|
||||
|
||||
export interface PriorityClassesDetailsProps extends KubeObjectDetailsProps<PriorityClass> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class PriorityClassesDetails extends React.Component<PriorityClassesDetailsProps> {
|
||||
|
||||
render() {
|
||||
const { object: pc } = this.props;
|
||||
|
||||
return (
|
||||
<div className="PriorityClassesDetails">
|
||||
<KubeObjectMeta object={pc} />
|
||||
|
||||
<DrawerItem name="Description">
|
||||
{pc.getDescription()}
|
||||
</DrawerItem>
|
||||
|
||||
<DrawerItem name="Value">
|
||||
{pc.getValue()}
|
||||
</DrawerItem>
|
||||
|
||||
<DrawerItem name="Global Default">
|
||||
{pc.getGlobalDefault()}
|
||||
</DrawerItem>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
+38
@@ -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 priorityClassesRouteInjectable from "../../../common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-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 navigateToPriorityClassesInjectable from "../../../common/front-end-routing/routes/cluster/config/priority-classes/navigate-to-priority-classes.injectable";
|
||||
|
||||
const priorityClassesSidebarItemsInjectable = getInjectable({
|
||||
id: "priority-classes-sidebar-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const route = di.inject(priorityClassesRouteInjectable);
|
||||
const navigateToPriorityClasses = di.inject(navigateToPriorityClassesInjectable);
|
||||
const routeIsActive = di.inject(routeIsActiveInjectable, route);
|
||||
|
||||
return computed(() => [
|
||||
{
|
||||
id: "priority-classes",
|
||||
parentId: configSidebarItemId,
|
||||
title: "Priority Classes",
|
||||
onClick: navigateToPriorityClasses,
|
||||
isActive: routeIsActive,
|
||||
isVisible: route.isEnabled,
|
||||
orderNumber: 60,
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
||||
injectionToken: sidebarItemsInjectionToken,
|
||||
});
|
||||
|
||||
export default priorityClassesSidebarItemsInjectable;
|
||||
+21
@@ -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 { PriorityClasses } from "./priority-classes";
|
||||
import priorityClassesRouteInjectable from "../../../common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable";
|
||||
import { routeSpecificComponentInjectionToken } from "../../routes/route-specific-component-injection-token";
|
||||
|
||||
const podDisruptionBudgetsRouteComponentInjectable = getInjectable({
|
||||
id: "priority-classes-route-component",
|
||||
|
||||
instantiate: (di) => ({
|
||||
route: di.inject(priorityClassesRouteInjectable),
|
||||
Component: PriorityClasses,
|
||||
}),
|
||||
|
||||
injectionToken: routeSpecificComponentInjectionToken,
|
||||
});
|
||||
|
||||
export default podDisruptionBudgetsRouteComponentInjectable;
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
.PriorityClasses {
|
||||
.TableCell {
|
||||
&.name {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
@include table-cell-warning;
|
||||
}
|
||||
|
||||
&.keys {
|
||||
flex: 2.5;
|
||||
}
|
||||
|
||||
&.age {
|
||||
flex: .5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./priority-classes.scss";
|
||||
|
||||
import * as React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { PriorityClass } from "../../../common/k8s-api/endpoints/priority-class.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 priorityClassStoreInjectable from "./store.injectable";
|
||||
import type { PriorityClassStore } from "./store";
|
||||
|
||||
enum columnId {
|
||||
name = "name",
|
||||
value = "value",
|
||||
globalDefault = "global-default",
|
||||
age = "age",
|
||||
}
|
||||
|
||||
export interface PriorityClassesProps extends KubeObjectDetailsProps<PriorityClass> {
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
priorityClassStore: PriorityClassStore;
|
||||
}
|
||||
|
||||
@observer
|
||||
class NonInjectedPriorityClasses extends React.Component<PriorityClassesProps & Dependencies> {
|
||||
constructor(props: PriorityClassesProps & Dependencies) {
|
||||
super(props);
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { priorityClassStore } = this.props;
|
||||
|
||||
return (
|
||||
<SiblingsInTabLayout>
|
||||
<KubeObjectListLayout
|
||||
isConfigurable
|
||||
tableId="configuration_priority_classes"
|
||||
className="PriorityClasses"
|
||||
store={priorityClassStore}
|
||||
sortingCallbacks={{
|
||||
[columnId.name]: pc => pc.getName(),
|
||||
[columnId.value]: pc => pc.getValue(),
|
||||
[columnId.globalDefault]: pc => pc.getGlobalDefault(),
|
||||
[columnId.age]: pc => -pc.getCreationTimestamp(),
|
||||
}}
|
||||
searchFilters={[
|
||||
pc => pc.getSearchFields(),
|
||||
]}
|
||||
renderHeaderTitle="Priority Classes"
|
||||
renderTableHeader={[
|
||||
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
|
||||
{ className: "warning", showWithColumn: columnId.name },
|
||||
{ title: "Value", className: "value", sortBy: columnId.value, id: columnId.value },
|
||||
{ title: "Global Default", className: "global-default", sortBy: columnId.globalDefault, id: columnId.globalDefault },
|
||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||
]}
|
||||
renderTableContents={pc => [
|
||||
pc.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={pc} />,
|
||||
pc.getValue(),
|
||||
pc.getGlobalDefault(),
|
||||
<KubeObjectAge key="age" object={pc} />,
|
||||
]}
|
||||
/>
|
||||
</SiblingsInTabLayout>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const PriorityClasses = withInjectables<Dependencies, PriorityClassesProps>(NonInjectedPriorityClasses, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
priorityClassStore: di.inject(priorityClassStoreInjectable),
|
||||
}),
|
||||
});
|
||||
@@ -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 priorityClassApiInjectable from "../../../common/k8s-api/endpoints/priority-class.api.injectable";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable";
|
||||
import { PriorityClassStore } from "./store";
|
||||
|
||||
const priorityClassStoreInjectable = getInjectable({
|
||||
id: "priority-class-store",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectable), "priorityClassStore is only available in certain environments");
|
||||
|
||||
const api = di.inject(priorityClassApiInjectable);
|
||||
|
||||
return new PriorityClassStore(api);
|
||||
},
|
||||
injectionToken: kubeObjectStoreInjectionToken,
|
||||
});
|
||||
|
||||
export default priorityClassStoreInjectable;
|
||||
@@ -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 { PriorityClass, PriorityClassApi } from "../../../common/k8s-api/endpoints/priority-class.api";
|
||||
|
||||
export class PriorityClassStore extends KubeObjectStore<PriorityClass, PriorityClassApi> {
|
||||
}
|
||||
+10
-1
@@ -24,13 +24,14 @@ import navigateToResourceQuotasInjectable from "../../../../common/front-end-rou
|
||||
import navigateToLimitRangesInjectable from "../../../../common/front-end-routing/routes/cluster/config/limit-ranges/navigate-to-limit-ranges.injectable";
|
||||
import navigateToHorizontalPodAutoscalersInjectable from "../../../../common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/navigate-to-horizontal-pod-autoscalers.injectable";
|
||||
import navigateToPodDisruptionBudgetsInjectable from "../../../../common/front-end-routing/routes/cluster/config/pod-disruption-budgets/navigate-to-pod-disruption-budgets.injectable";
|
||||
import navigateToPriorityClassesInjectable from "../../../../common/front-end-routing/routes/cluster/config/priority-classes/navigate-to-priority-classes.injectable";
|
||||
import navigateToServicesInjectable from "../../../../common/front-end-routing/routes/cluster/network/services/navigate-to-services.injectable";
|
||||
import navigateToEndpointsInjectable from "../../../../common/front-end-routing/routes/cluster/network/endpoints/navigate-to-endpoints.injectable";
|
||||
import navigateToIngressesInjectable from "../../../../common/front-end-routing/routes/cluster/network/ingresses/navigate-to-ingresses.injectable";
|
||||
import navigateToNetworkPoliciesInjectable from "../../../../common/front-end-routing/routes/cluster/network/network-policies/navigate-to-network-policies.injectable";
|
||||
import navigateToNodesInjectable from "../../../../common/front-end-routing/routes/cluster/nodes/navigate-to-nodes.injectable";
|
||||
import navigateToPodsInjectable from "../../../../common/front-end-routing/routes/cluster/workloads/pods/navigate-to-pods.injectable";
|
||||
import navigateToDeploymentsInjectable from "../../../../common/front-end-routing/routes/cluster/workloads/deployments/navigate-to-deployments.injectable";
|
||||
import navigateToDeploymentsInjectable from "../../../../common/front-end-routing/routes/cluster/workloads/deployments/navigate-to-deployments.injectable";
|
||||
import navigateToDaemonsetsInjectable from "../../../../common/front-end-routing/routes/cluster/workloads/daemonsets/navigate-to-daemonsets.injectable";
|
||||
import navigateToStatefulsetsInjectable from "../../../../common/front-end-routing/routes/cluster/workloads/statefulsets/navigate-to-statefulsets.injectable";
|
||||
import navigateToJobsInjectable from "../../../../common/front-end-routing/routes/cluster/workloads/jobs/navigate-to-jobs.injectable";
|
||||
@@ -57,6 +58,7 @@ interface Dependencies {
|
||||
navigateToLimitRanges: () => void;
|
||||
navigateToHorizontalPodAutoscalers: () => void;
|
||||
navigateToPodDisruptionBudgets: () => void;
|
||||
navigateToPriorityClasses: () => void;
|
||||
navigateToServices: () => void;
|
||||
navigateToEndpoints: () => void;
|
||||
navigateToIngresses: () => void;
|
||||
@@ -127,6 +129,12 @@ function getInternalCommands(dependencies: Dependencies): CommandRegistration[]
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: () => dependencies.navigateToPodDisruptionBudgets(),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewPriorityClasses",
|
||||
title: "Cluster: View PriorityClasses",
|
||||
isActive: isKubernetesClusterActive,
|
||||
action: () => dependencies.navigateToPriorityClasses(),
|
||||
},
|
||||
{
|
||||
id: "cluster.viewServices",
|
||||
title: "Cluster: View Services",
|
||||
@@ -258,6 +266,7 @@ const internalCommandsInjectable = getInjectable({
|
||||
navigateToLimitRanges: di.inject(navigateToLimitRangesInjectable),
|
||||
navigateToHorizontalPodAutoscalers: di.inject(navigateToHorizontalPodAutoscalersInjectable),
|
||||
navigateToPodDisruptionBudgets: di.inject(navigateToPodDisruptionBudgetsInjectable),
|
||||
navigateToPriorityClasses: di.inject(navigateToPriorityClassesInjectable),
|
||||
navigateToServices: di.inject(navigateToServicesInjectable),
|
||||
navigateToEndpoints: di.inject(navigateToEndpointsInjectable),
|
||||
navigateToIngresses: di.inject(navigateToIngressesInjectable),
|
||||
|
||||
+33
@@ -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 { PriorityClassesDetails } from "../../../+config-priority-classes";
|
||||
import { kubeObjectMatchesToKindAndApiVersion } from "../kube-object-matches-to-kind-and-api-version";
|
||||
import currentKubeObjectInDetailsInjectable from "../../current-kube-object-in-details.injectable";
|
||||
|
||||
const priorityClassDetailItemInjectable = getInjectable({
|
||||
id: "priority-class-detail-item",
|
||||
|
||||
instantiate: (di) => {
|
||||
const kubeObject = di.inject(currentKubeObjectInDetailsInjectable);
|
||||
|
||||
return {
|
||||
Component: PriorityClassesDetails,
|
||||
enabled: computed(() => isPriorityClass(kubeObject.get())),
|
||||
orderNumber: 10,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: kubeObjectDetailItemInjectionToken,
|
||||
});
|
||||
|
||||
const isPriorityClass = kubeObjectMatchesToKindAndApiVersion(
|
||||
"PriorityClass",
|
||||
["scheduling.k8s.io/v1"],
|
||||
);
|
||||
|
||||
export default priorityClassDetailItemInjectable;
|
||||
@@ -31,6 +31,7 @@ export const ResourceNames: Record<KubeResource, string> = {
|
||||
"horizontalpodautoscalers": "Horizontal Pod Autoscalers",
|
||||
"podsecuritypolicies": "Pod Security Policies",
|
||||
"poddisruptionbudgets": "Pod Disruption Budgets",
|
||||
"priorityclasses": "Priority Classes",
|
||||
"limitranges": "Limit Ranges",
|
||||
"roles": "Roles",
|
||||
"rolebindings": "Role Bindings",
|
||||
|
||||
Reference in new issue
Block a user