Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor kube detail components and add KubeEvents automatically to all custom resources #6468

Merged
merged 34 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7188342
Support Events on CustomResourece details panel
Nokel81 Oct 24, 2022
e9ea1fc
Remove unnecessary check
Nokel81 Oct 24, 2022
5b15d12
Remove legacy KubeObjectMeta use from non-metrics details
Nokel81 Oct 24, 2022
fc3ed25
Change orderNumber of default KubeMetaDetails
Nokel81 Oct 24, 2022
1a594b9
Remove last use of legacy global getActiveClusterEntity
Nokel81 Oct 24, 2022
660dd47
Refactor ResourceMetrics to use IAsyncComputed
Nokel81 Oct 24, 2022
f269ba8
Introduce metrics details item for Ingress
Nokel81 Oct 24, 2022
382d8b9
Remove legacyStore for nodes
Nokel81 Oct 24, 2022
7c5aa6a
Remove legacyStore for ingresses
Nokel81 Oct 24, 2022
a1c9b9a
Replace NodeMetrics in details with injectable
Nokel81 Oct 24, 2022
84dbb5f
Change namespace metrics details to use more injectables
Nokel81 Oct 24, 2022
4328f03
Change ingress metrics details to use more injectables
Nokel81 Oct 24, 2022
3518c44
Change PersistentVolumeClaim metrics to be injectable
Nokel81 Oct 24, 2022
6f73c4d
Change DaemonSet metrics to be injectable
Nokel81 Oct 24, 2022
8c032ce
Change Deployment metrics to be injectable
Nokel81 Oct 24, 2022
4264ba0
Change Job metrics to be injectable
Nokel81 Oct 24, 2022
836783f
Convert Pod metrics to be injectable
Nokel81 Oct 25, 2022
c060a6b
Make ReplicaSet metrics details injectable
Nokel81 Oct 25, 2022
d734276
Make StatefulSet metrics component injectable
Nokel81 Oct 25, 2022
01f66c4
Remove dead code
Nokel81 Oct 25, 2022
026053d
Introduce fix for metrics components visible on all details
Nokel81 Oct 25, 2022
4a39e4b
Use the new and correct enabled check
Nokel81 Oct 25, 2022
a92c53e
Remove legacy global for daemonSetStore
Nokel81 Oct 25, 2022
1f78c66
Switch components to be static to help with React performance
Nokel81 Oct 25, 2022
72f199f
Remove legacy store of CronJobs
Nokel81 Oct 25, 2022
d359747
Make DeploymentReplicaSets injectable to fix build error
Nokel81 Oct 25, 2022
8e67ba2
Fix up remove dead code
Nokel81 Oct 25, 2022
1444c73
Allow use of ResourceMetrics without IAsyncComputed
Nokel81 Oct 25, 2022
fb95ca8
Fix metrics not updating correctly
Nokel81 Oct 25, 2022
974a31e
Update snapshots because moving KubeObjectMeta out of CustomResourceD…
Nokel81 Oct 25, 2022
13ccae9
Fix tests
Nokel81 Oct 25, 2022
e76e529
Update more snapshots
Nokel81 Oct 25, 2022
1eaf253
Fix test failures due to newer dep versions
Nokel81 Nov 14, 2022
03322e6
Fix type errors from new asyncComputed
Nokel81 Nov 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const requestPodMetricsForJobsInjectable = getInjectable({
instantiate: (di): RequestPodMetricsForJobs => {
const requestMetrics = di.inject(requestMetricsInjectable);

return (jobs, namespace, selector) => {
return (jobs, namespace, selector = "") => {
const podSelector = jobs.map(job => `${job.getName()}-[[:alnum:]]{5}`).join("|");
const opts = { category: "pods", pods: podSelector, namespace, selector };

Expand Down
16 changes: 16 additions & 0 deletions src/common/utils/sort-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/

/**
* Get an ordering function based on the function getter
*/
export function byValue<T>(getOrderValue: (src: T) => number): (left: T, right: T) => number {
return (left, right) => {
const leftValue = getOrderValue(left);
const rightValue = getOrderValue(right);

return leftValue - rightValue;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,63 @@ exports[`disable kube object detail items when cluster is not relevant given ext
<div
class="drawer-content flex column box grow"
>
<div
class="DrawerItem"
>
<span
class="name"
>
Created
</span>
<span
class="value"
>
&lt;unknown&gt;
ago
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Name
</span>
<span
class="value"
>
some-name
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Namespace
</span>
<span
class="value"
>
some-namespace
</span>
</div>
<div
data-testid="some-kube-object-detail-item"
>
Some detail
</div>
<div>
<div
class="DrawerTitle flex gaps align-center title"
>
<span>
Events
</span>
</div>
</div>
</div>
</div>
<div
Expand Down Expand Up @@ -792,6 +844,15 @@ exports[`disable kube object detail items when cluster is not relevant given ext
some-namespace
</span>
</div>
<div>
<div
class="DrawerTitle flex gaps align-center title"
>
<span>
Events
</span>
</div>
</div>
</div>
</div>
<div
Expand Down Expand Up @@ -1277,6 +1338,15 @@ exports[`disable kube object detail items when cluster is not relevant given not
some-namespace
</span>
</div>
<div>
<div
class="DrawerTitle flex gaps align-center title"
>
<span>
Events
</span>
</div>
</div>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import extensionShouldBeEnabledForClusterFrameInjectable from "../../../../rende
import apiManagerInjectable from "../../../../common/k8s-api/api-manager/manager.injectable";
import { KubeObjectDetails } from "../../../../renderer/components/kube-object-details";
import type { ApiManager } from "../../../../common/k8s-api/api-manager";
import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";

describe("disable kube object detail items when cluster is not relevant", () => {
let builder: ApplicationBuilder;
Expand All @@ -32,16 +33,11 @@ describe("disable kube object detail items when cluster is not relevant", () =>
builder.setEnvironmentToClusterFrame();

builder.beforeWindowStart((windowDi) => {
windowDi.override(
apiManagerInjectable,
() =>
({
getStore: () => ({
getByPath: () =>
getKubeObjectStub("some-kind", "some-api-version"),
}),
} as unknown as ApiManager),
);
windowDi.override(apiManagerInjectable, () => ({
getStore: () => ({
loadFromPath: async () => getKubeObjectStub("some-kind", "some-api-version"),
}) as Partial<KubeObjectStore> as KubeObjectStore,
}) as Partial<ApiManager> as ApiManager);

windowDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { KubeObject } from "../../../../common/k8s-api/kube-object";
import apiManagerInjectable from "../../../../common/k8s-api/api-manager/manager.injectable";
import { KubeObjectDetails } from "../../../../renderer/components/kube-object-details";
import type { ApiManager } from "../../../../common/k8s-api/api-manager";
import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store";

describe("reactively hide kube object detail item", () => {
let builder: ApplicationBuilder;
Expand All @@ -28,16 +29,11 @@ describe("reactively hide kube object detail item", () => {
builder.setEnvironmentToClusterFrame();

builder.beforeWindowStart((windowDi) => {
windowDi.override(
apiManagerInjectable,
() =>
({
getStore: () => ({
getByPath: () =>
getKubeObjectStub("some-kind", "some-api-version"),
}),
} as unknown as ApiManager),
);
windowDi.override(apiManagerInjectable, () => ({
getStore: () => ({
loadFromPath: async () => getKubeObjectStub("some-kind", "some-api-version"),
}) as Partial<KubeObjectStore> as KubeObjectStore,
}) as Partial<ApiManager> as ApiManager);

runInAction(() => {
windowDi.register(testRouteInjectable, testRouteComponentInjectable);
Expand Down
12 changes: 0 additions & 12 deletions src/renderer/api/catalog/entity/legacy-globals.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { computed } from "mobx";
import type { ClusterMetricsResourceType } from "../../../../common/cluster-types";
import currentKubeObjectInDetailsInjectable from "../../../components/kube-object-details/current-kube-object-in-details.injectable";
import enabledMetricsInjectable from "./metrics-enabled.injectable";

const metricsDetailsComponentEnabledInjectable = getInjectable({
id: "metrics-details-component-enabled",
instantiate: (di, kind) => {
const metricsEnabled = di.inject(enabledMetricsInjectable, kind);
const currentKubeObjectInDetails = di.inject(currentKubeObjectInDetailsInjectable);

return computed(() => {
const current = currentKubeObjectInDetails.value.get();

if (!current?.object) {
return false;
}

return current.object.kind == kind && metricsEnabled.get();
});
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, kind: ClusterMetricsResourceType) => kind,
}),
});

export default metricsDetailsComponentEnabledInjectable;
22 changes: 22 additions & 0 deletions src/renderer/api/catalog/entity/metrics-enabled.injectable.ts
Original file line number Diff line number Diff line change
@@ -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, lifecycleEnum } from "@ogre-tools/injectable";
import { computed } from "mobx";
import type { ClusterMetricsResourceType } from "../../../../common/cluster-types";
import getActiveClusterEntityInjectable from "./get-active-cluster-entity.injectable";

const enabledMetricsInjectable = getInjectable({
id: "enabled-metrics",
instantiate: (di, kind) => {
const getActiveClusterEntity = di.inject(getActiveClusterEntityInjectable);

return computed(() => !getActiveClusterEntity()?.isMetricHidden(kind));
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, kind: ClusterMetricsResourceType) => kind,
}),
});

export default enabledMetricsInjectable;
3 changes: 0 additions & 3 deletions src/renderer/components/+config-autoscalers/hpa-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type { HorizontalPodAutoscalerMetricSpec, HorizontalPodAutoscalerMetricTa
import { HorizontalPodAutoscaler, HpaMetricType } from "../../../common/k8s-api/endpoints/horizontal-pod-autoscaler.api";
import { Table, TableCell, TableHead, TableRow } from "../table";
import type { ApiManager } from "../../../common/k8s-api/api-manager";
import { KubeObjectMeta } from "../kube-object-meta";
import logger from "../../../common/logger";
import type { GetDetailsUrl } from "../kube-detail-params/get-details-url.injectable";
import { withInjectables } from "@ogre-tools/injectable-react";
Expand Down Expand Up @@ -121,8 +120,6 @@ class NonInjectedHpaDetails extends React.Component<HpaDetailsProps & Dependenci

return (
<div className="HpaDetails">
<KubeObjectMeta object={hpa}/>

<DrawerItem name="Reference">
{scaleTargetRef && (
<Link to={getDetailsUrl(apiManager.lookupApiLink(scaleTargetRef, hpa))}>
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/components/+config-leases/lease-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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> {
Expand All @@ -23,8 +22,6 @@ export class LeaseDetails extends React.Component<LeaseDetailsProps> {

return (
<div className="LeaseDetails">
<KubeObjectMeta object={lease} />

<DrawerItem name="Holder Identity">
{lease.getHolderIdentity()}
</DrawerItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { observer } from "mobx-react";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import type { LimitRangeItem } from "../../../common/k8s-api/endpoints/limit-range.api";
import { LimitPart, LimitRange, Resource } from "../../../common/k8s-api/endpoints/limit-range.api";
import { KubeObjectMeta } from "../kube-object-meta";
import { DrawerItem } from "../drawer/drawer-item";
import { Badge } from "../badge";
import logger from "../../../common/logger";
Expand Down Expand Up @@ -73,8 +72,6 @@ export class LimitRangeDetails extends React.Component<LimitRangeDetailsProps> {

return (
<div className="LimitRangeDetails">
<KubeObjectMeta object={limitRange}/>

{containerLimits.length > 0 && (
<DrawerItem name="Container Limits" labelsOnly>
{
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/components/+config-maps/config-map-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { Input } from "../input";
import { Button } from "../button";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { ConfigMap } from "../../../common/k8s-api/endpoints";
import { KubeObjectMeta } from "../kube-object-meta";
import type { Logger } from "../../../common/logger";
import type { ConfigMapStore } from "./store";
import { withInjectables } from "@ogre-tools/injectable-react";
Expand Down Expand Up @@ -95,7 +94,6 @@ class NonInjectedConfigMapDetails extends React.Component<ConfigMapDetailsProps

return (
<div className="ConfigMapDetails">
<KubeObjectMeta object={configMap}/>
{
data.length > 0 && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { DrawerItem } from "../drawer";
import { Badge } from "../badge";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { PodDisruptionBudget } from "../../../common/k8s-api/endpoints";
import { KubeObjectMeta } from "../kube-object-meta";
import logger from "../../../common/logger";

export interface PodDisruptionBudgetDetailsProps extends KubeObjectDetailsProps<PodDisruptionBudget> {
Expand All @@ -37,8 +36,6 @@ export class PodDisruptionBudgetDetails extends React.Component<PodDisruptionBud

return (
<div className="PdbDetails">
<KubeObjectMeta object={pdb}/>

{selectors.length > 0 && (
<DrawerItem name="Selector" labelsOnly>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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> {
}
Expand All @@ -23,8 +22,6 @@ export class PriorityClassesDetails extends React.Component<PriorityClassesDetai

return (
<div className="PriorityClassesDetails">
<KubeObjectMeta object={pc} />

<DrawerItem name="Description">
{pc.getDescription()}
</DrawerItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type { KubeObjectDetailsProps } from "../kube-object-details";
import { ResourceQuota } from "../../../common/k8s-api/endpoints/resource-quota.api";
import { LineProgress } from "../line-progress";
import { Table, TableCell, TableHead, TableRow } from "../table";
import { KubeObjectMeta } from "../kube-object-meta";
import logger from "../../../common/logger";

export interface ResourceQuotaDetailsProps extends KubeObjectDetailsProps<ResourceQuota> {
Expand Down Expand Up @@ -93,8 +92,6 @@ export class ResourceQuotaDetails extends React.Component<ResourceQuotaDetailsPr

return (
<div className="ResourceQuotaDetails">
<KubeObjectMeta object={quota}/>

<DrawerItem name="Quotas" className="quota-list">
{renderQuotas(quota)}
</DrawerItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { observer } from "mobx-react";
import { DrawerItem } from "../drawer";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import type { RuntimeClass } from "../../../common/k8s-api/endpoints";
import { KubeObjectMeta } from "../kube-object-meta";
import { Badge } from "../badge";
import { RuntimeClassDetailsTolerations } from "./runtime-classes-details-tolerations";

Expand All @@ -26,8 +25,6 @@ export class RuntimeClassesDetails extends React.Component<RuntimeClassesDetails

return (
<div className="RuntimeClassesDetails">
<KubeObjectMeta object={rc} />

<DrawerItem name="Handler">
{rc.getHandler()}
</DrawerItem>
Expand Down
Loading