mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Technical requirements for behavioural unit tests (#5084)
* Implement a lot of technical requirements for behavioural unit tests Note: the crux of this was to make routing env-agnostic, and not based on URLs as magic strings, but instead something type-enforced. Note: extension-based routes comply to same exact interface by "late-registering" their routes when installed. Routes are just injectables. Note: another chunk of global shared state is no more. Note: a lot of explicit side effects have been cornered to injectables. Note: a lot of stuff has become reactive as part if this. Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make a directory commonly available Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Require id for <Select /> to prevent non-deterministic renders This was caused by global state in a 3rd party lib: "react-select". Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Specify id for all <Select /> to satisfy previous commit Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Prevent explicit side effect in component by using existing dependency instead Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Extract instantiation of "conf" as injectables for causing side effects Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Introduce a legacy-helper to make gradual refactoring of inheritors of Singleton easier Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make legacy unit tests for hotbar green and more simple by using the new legacy helper Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Temporarily kludge all unit tests green with a disclaimer about allowing side-effects Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove kludge in previous commit by explicitly permitting specific side effects where old unit tests require it Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Prevent old unit test with side effects from accessing file system Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Migrate to actual typing for di.permitSideEffects Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Prevent unit tests from failing because of non-standard method of HTML-element not present in js-dom Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Adapt integration tests to recent changes Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Fix code style Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Fix artifact from bad rebase Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Add a deprecation from a review comment Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove change that is not required Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove redundant comment Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code style Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove redundant file Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix bad merge Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Improve variable name Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Tweak logger interface to be more descriptive Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make injecting legacy singleton always provide new instance Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove conditional typing when not needed Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Improve naming of variable Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove unnecessary code style changes Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove flag for causing side effects from too broad scope Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Override side-effects in unit test using injectable instead of monkey patching Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Flag some side-effects and add general overrides Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Fix unit tests in CI by removing explicit side-effect Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove explicit side-effect from getting default shell Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce abstraction for getting absolute paths Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using abstraction for getting absolute path to control explicit side effect Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce abstraction for joining paths Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using abstraction for joining paths to control explicit side effect Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix fake implementation for join paths Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix test after removing explicit side effect Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove explicit side effects from kubeconfig-syncs Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix arguments after removing explicit side effect Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make registrators not async for not being needed anymore Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make generalCatalogEntities non-observable, as there is no requirement Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Remove redundant code Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Simplify logic for registering general catalog entity sources Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add TODO Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Replace function for getting application menu items with reactive solution Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix typo in interface name Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove global shared state usages of hot bar store Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove redundant enum Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
ab2cd27a27
commit
a277cfcf02
583 files changed
+13073
-6556
No files matched your search
@@ -8,22 +8,13 @@ import "./overview-statuses.scss";
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { OverviewWorkloadStatus } from "./overview-workload-status";
|
||||
import { Link } from "react-router-dom";
|
||||
import type { KubeResource } from "../../../common/rbac";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import workloadsInjectable from "./workloads.injectable";
|
||||
import workloadsInjectable from "./workloads/workloads.injectable";
|
||||
import type { Workload } from "./workloads/workload-injection-token";
|
||||
|
||||
export interface OverviewStatusesProps {}
|
||||
|
||||
interface Workload {
|
||||
resource: KubeResource;
|
||||
amountOfItems: number;
|
||||
href: string;
|
||||
status: Record<string, number>;
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
workloads: IComputedValue<Workload[]>;
|
||||
}
|
||||
@@ -32,18 +23,17 @@ const NonInjectedOverviewStatuses = observer(
|
||||
({ workloads }: Dependencies & OverviewStatusesProps) => (
|
||||
<div className="OverviewStatuses">
|
||||
<div className="workloads">
|
||||
{workloads.get()
|
||||
.map(({ resource, title, href, status, amountOfItems }) => (
|
||||
<div className="workload" key={resource}>
|
||||
<div className="title">
|
||||
<Link to={href}>
|
||||
{title} ({amountOfItems})
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<OverviewWorkloadStatus status={status} />
|
||||
{workloads.get().map((workload) => (
|
||||
<div className="workload" key={workload.resourceName}>
|
||||
<div className="title">
|
||||
<a onClick={workload.open}>
|
||||
{workload.title} ({workload.amountOfItems.get()})
|
||||
</a>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<OverviewWorkloadStatus status={workload.status.get()} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
|
||||
@@ -7,7 +7,6 @@ import "./overview.scss";
|
||||
|
||||
import React from "react";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { eventStore } from "../+events/event.store";
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
import { deploymentStore } from "../+workloads-deployments/deployments.store";
|
||||
@@ -16,7 +15,6 @@ import { statefulSetStore } from "../+workloads-statefulsets/statefulset.store";
|
||||
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
|
||||
import { jobStore } from "../+workloads-jobs/job.store";
|
||||
import { cronJobStore } from "../+workloads-cronjobs/cronjob.store";
|
||||
import type { WorkloadsOverviewRouteParams } from "../../../common/routes";
|
||||
import { IComputedValue, makeObservable, observable, reaction } from "mobx";
|
||||
import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter";
|
||||
import { Icon } from "../icon";
|
||||
@@ -30,9 +28,7 @@ import type { Disposer } from "../../../common/utils";
|
||||
import kubeWatchApiInjectable from "../../kube-watch-api/kube-watch-api.injectable";
|
||||
import type { KubeWatchSubscribeStoreOptions } from "../../kube-watch-api/kube-watch-api";
|
||||
import detailComponentsInjectable from "./detail-components.injectable";
|
||||
|
||||
export interface WorkloadsOverviewProps extends RouteComponentProps<WorkloadsOverviewRouteParams> {
|
||||
}
|
||||
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
||||
|
||||
interface Dependencies {
|
||||
detailComponents: IComputedValue<React.ComponentType<{}>[]>;
|
||||
@@ -41,10 +37,10 @@ interface Dependencies {
|
||||
}
|
||||
|
||||
@observer
|
||||
class NonInjectedWorkloadsOverview extends React.Component<WorkloadsOverviewProps & Dependencies> {
|
||||
class NonInjectedWorkloadsOverview extends React.Component<Dependencies> {
|
||||
@observable loadErrors: string[] = [];
|
||||
|
||||
constructor(props: WorkloadsOverviewProps & Dependencies) {
|
||||
constructor(props: Dependencies) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
@@ -93,30 +89,31 @@ class NonInjectedWorkloadsOverview extends React.Component<WorkloadsOverviewProp
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="WorkloadsOverview flex column gaps">
|
||||
<div className="header flex gaps align-center">
|
||||
<h5 className="box grow">Overview</h5>
|
||||
{this.renderLoadErrors()}
|
||||
<NamespaceSelectFilter />
|
||||
</div>
|
||||
<SiblingsInTabLayout>
|
||||
<div className="WorkloadsOverview flex column gaps">
|
||||
<div className="header flex gaps align-center">
|
||||
<h5 className="box grow">Overview</h5>
|
||||
{this.renderLoadErrors()}
|
||||
<NamespaceSelectFilter id="overview-namespace-select-filter-input" />
|
||||
</div>
|
||||
|
||||
{this.props.detailComponents.get().map((Details, index) => (
|
||||
<Details key={`workload-overview-${index}`} />
|
||||
))}
|
||||
</div>
|
||||
{this.props.detailComponents.get().map((Details, index) => (
|
||||
<Details key={`workload-overview-${index}`} />
|
||||
))}
|
||||
</div>
|
||||
</SiblingsInTabLayout>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const WorkloadsOverview = withInjectables<Dependencies, WorkloadsOverviewProps>(
|
||||
export const WorkloadsOverview = withInjectables<Dependencies>(
|
||||
NonInjectedWorkloadsOverview,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
getProps: (di) => ({
|
||||
detailComponents: di.inject(detailComponentsInjectable),
|
||||
clusterFrameContext: di.inject(clusterFrameContextInjectable),
|
||||
subscribeStores: di.inject(kubeWatchApiInjectable).subscribeStores,
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
+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 { WorkloadsOverview } from "./overview";
|
||||
import workloadsOverviewRouteInjectable from "../../../common/front-end-routing/routes/cluster/workloads/overview/workloads-overview-route.injectable";
|
||||
import { routeSpecificComponentInjectionToken } from "../../routes/route-specific-component-injection-token";
|
||||
|
||||
const workloadsOverviewRouteComponentInjectable = getInjectable({
|
||||
id: "workloads-overview-route-component",
|
||||
|
||||
instantiate: (di) => ({
|
||||
route: di.inject(workloadsOverviewRouteInjectable),
|
||||
Component: WorkloadsOverview,
|
||||
}),
|
||||
|
||||
injectionToken: routeSpecificComponentInjectionToken,
|
||||
});
|
||||
|
||||
export default workloadsOverviewRouteComponentInjectable;
|
||||
+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 workloadsOverviewRouteInjectable from "../../../common/front-end-routing/routes/cluster/workloads/overview/workloads-overview-route.injectable";
|
||||
import { workloadsSidebarItemId } from "../+workloads/workloads-sidebar-items.injectable";
|
||||
import { sidebarItemsInjectionToken } from "../layout/sidebar-items.injectable";
|
||||
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
||||
import navigateToWorkloadsOverviewInjectable from "../../../common/front-end-routing/routes/cluster/workloads/overview/navigate-to-workloads-overview.injectable";
|
||||
|
||||
const workloadsOverviewSidebarItemsInjectable = getInjectable({
|
||||
id: "workloads-overview-sidebar-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const route = di.inject(workloadsOverviewRouteInjectable);
|
||||
const navigateToWorkloadsOverview = di.inject(navigateToWorkloadsOverviewInjectable);
|
||||
const routeIsActive = di.inject(routeIsActiveInjectable, route);
|
||||
|
||||
return computed(() => [
|
||||
{
|
||||
id: "overview",
|
||||
parentId: workloadsSidebarItemId,
|
||||
title: "Overview",
|
||||
onClick: navigateToWorkloadsOverview,
|
||||
isActive: routeIsActive,
|
||||
isVisible: route.isEnabled,
|
||||
orderNumber: 10,
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
||||
injectionToken: sidebarItemsInjectionToken,
|
||||
});
|
||||
|
||||
export default workloadsOverviewSidebarItemsInjectable;
|
||||
@@ -1,40 +0,0 @@
|
||||
/**
|
||||
* 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 type { KubeResource } from "../../../common/rbac";
|
||||
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
import { deploymentStore } from "../+workloads-deployments/deployments.store";
|
||||
import { daemonSetStore } from "../+workloads-daemonsets/daemonsets.store";
|
||||
import { statefulSetStore } from "../+workloads-statefulsets/statefulset.store";
|
||||
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
|
||||
import { jobStore } from "../+workloads-jobs/job.store";
|
||||
import { cronJobStore } from "../+workloads-cronjobs/cronjob.store";
|
||||
import isAllowedResourceInjectable from "../../../common/utils/is-allowed-resource.injectable";
|
||||
import namespaceStoreInjectable from "../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import { workloads } from "./workloads";
|
||||
|
||||
const workloadsInjectable = getInjectable({
|
||||
id: "workloads",
|
||||
|
||||
instantiate: (di) =>
|
||||
workloads({
|
||||
isAllowedResource: di.inject(isAllowedResourceInjectable),
|
||||
namespaceStore: di.inject(namespaceStoreInjectable),
|
||||
|
||||
workloadStores: new Map<KubeResource, KubeObjectStore<KubeObject>>([
|
||||
["pods", podsStore],
|
||||
["deployments", deploymentStore],
|
||||
["daemonsets", daemonSetStore],
|
||||
["statefulsets", statefulSetStore],
|
||||
["replicasets", replicaSetStore],
|
||||
["jobs", jobStore],
|
||||
["cronjobs", cronJobStore],
|
||||
]),
|
||||
}),
|
||||
});
|
||||
|
||||
export default workloadsInjectable;
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { computed } from "mobx";
|
||||
import type { KubeResource } from "../../../common/rbac";
|
||||
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import { workloadURL } from "../../../common/routes";
|
||||
import { ResourceNames } from "../../utils/rbac";
|
||||
import type { NamespaceStore } from "../+namespaces/namespace-store/namespace.store";
|
||||
import type { IsAllowedResource } from "../../../common/utils/is-allowed-resource.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
workloadStores: Map<KubeResource, KubeObjectStore<KubeObject>>;
|
||||
isAllowedResource: IsAllowedResource;
|
||||
namespaceStore: NamespaceStore;
|
||||
}
|
||||
|
||||
export const workloads = ({
|
||||
workloadStores,
|
||||
isAllowedResource,
|
||||
namespaceStore,
|
||||
}: Dependencies) =>
|
||||
computed(() =>
|
||||
[...workloadStores.entries()]
|
||||
.filter(([resource]) => isAllowedResource(resource))
|
||||
.map(([resource, store]) => {
|
||||
const items = store.getAllByNs(namespaceStore.contextNamespaces);
|
||||
|
||||
return {
|
||||
resource,
|
||||
href: workloadURL[resource](),
|
||||
amountOfItems: items.length,
|
||||
status: store.getStatuses(items),
|
||||
title: ResourceNames[resource],
|
||||
};
|
||||
}),
|
||||
);
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { workloadInjectionToken } from "../workload-injection-token";
|
||||
import { ResourceNames } from "../../../../utils/rbac";
|
||||
import navigateToPodsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/deployments/navigate-to-deployments.injectable";
|
||||
import namespaceStoreInjectable from "../../../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import cronJobsStoreInjectable from "../../../+workloads-cronjobs/cron-jobs-store.injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
const cronJobsWorkloadInjectable = getInjectable({
|
||||
id: "cron-jobs-workload",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigate = di.inject(navigateToPodsInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const store = di.inject(cronJobsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "cronjobs",
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.cronjobs,
|
||||
orderNumber: 70,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: workloadInjectionToken,
|
||||
});
|
||||
|
||||
export default cronJobsWorkloadInjectable;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { workloadInjectionToken } from "../workload-injection-token";
|
||||
import { ResourceNames } from "../../../../utils/rbac";
|
||||
import namespaceStoreInjectable from "../../../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import daemonsetsStoreInjectable from "../../../+workloads-daemonsets/daemonsets-store.injectable";
|
||||
import navigateToDaemonsetsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/daemonsets/navigate-to-daemonsets.injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
const daemonsetsWorkloadInjectable = getInjectable({
|
||||
id: "daemonsets-workload",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigate = di.inject(navigateToDaemonsetsInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const store = di.inject(daemonsetsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "daemonsets",
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.daemonsets,
|
||||
orderNumber: 30,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: workloadInjectionToken,
|
||||
});
|
||||
|
||||
export default daemonsetsWorkloadInjectable;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { workloadInjectionToken } from "../workload-injection-token";
|
||||
import { ResourceNames } from "../../../../utils/rbac";
|
||||
import namespaceStoreInjectable from "../../../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import deploymentsStoreInjectable from "../../../+workloads-deployments/deployments-store.injectable";
|
||||
import navigateToDeploymentsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/deployments/navigate-to-deployments.injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
const deploymentsWorkloadInjectable = getInjectable({
|
||||
id: "deployments-workload",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigate = di.inject(navigateToDeploymentsInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const store = di.inject(deploymentsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "deployments",
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.deployments,
|
||||
orderNumber: 20,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: workloadInjectionToken,
|
||||
});
|
||||
|
||||
export default deploymentsWorkloadInjectable;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { workloadInjectionToken } from "../workload-injection-token";
|
||||
import { ResourceNames } from "../../../../utils/rbac";
|
||||
import namespaceStoreInjectable from "../../../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import jobsStoreInjectable from "../../../+workloads-jobs/jobs-store.injectable";
|
||||
import navigateToJobsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/jobs/navigate-to-jobs.injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
const jobsWorkloadInjectable = getInjectable({
|
||||
id: "jobs-workload",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigate = di.inject(navigateToJobsInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const store = di.inject(jobsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "jobs",
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.jobs,
|
||||
orderNumber: 60,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: workloadInjectionToken,
|
||||
});
|
||||
|
||||
export default jobsWorkloadInjectable;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { workloadInjectionToken } from "../workload-injection-token";
|
||||
import { ResourceNames } from "../../../../utils/rbac";
|
||||
import navigateToPodsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/pods/navigate-to-pods.injectable";
|
||||
import podsStoreInjectable from "../../../+workloads-pods/pods-store.injectable";
|
||||
import namespaceStoreInjectable from "../../../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
const podsWorkloadInjectable = getInjectable({
|
||||
id: "pods-workload",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigate = di.inject(navigateToPodsInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const store = di.inject(podsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "pods",
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.pods,
|
||||
orderNumber: 10,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: workloadInjectionToken,
|
||||
});
|
||||
|
||||
export default podsWorkloadInjectable;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { workloadInjectionToken } from "../workload-injection-token";
|
||||
import { ResourceNames } from "../../../../utils/rbac";
|
||||
import navigateToPodsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/deployments/navigate-to-deployments.injectable";
|
||||
import namespaceStoreInjectable from "../../../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import replicasetsStoreInjectable from "../../../+workloads-replicasets/replicasets-store.injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
const replicasetsWorkloadInjectable = getInjectable({
|
||||
id: "replicasets-workload",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigate = di.inject(navigateToPodsInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const store = di.inject(replicasetsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "replicasets",
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.replicasets,
|
||||
orderNumber: 50,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: workloadInjectionToken,
|
||||
});
|
||||
|
||||
export default replicasetsWorkloadInjectable;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 { workloadInjectionToken } from "../workload-injection-token";
|
||||
import { ResourceNames } from "../../../../utils/rbac";
|
||||
import navigateToPodsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/deployments/navigate-to-deployments.injectable";
|
||||
import namespaceStoreInjectable from "../../../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import statefulsetsStoreInjectable from "../../../+workloads-statefulsets/statefulsets-store.injectable";
|
||||
import { computed } from "mobx";
|
||||
|
||||
const statefulsetsWorkloadInjectable = getInjectable({
|
||||
id: "statefulsets-workload",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigate = di.inject(navigateToPodsInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const store = di.inject(statefulsetsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "statefulsets",
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.statefulsets,
|
||||
orderNumber: 40,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: workloadInjectionToken,
|
||||
});
|
||||
|
||||
export default statefulsetsWorkloadInjectable;
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
export interface Workload {
|
||||
resourceName: string;
|
||||
open: () => void;
|
||||
amountOfItems: IComputedValue<number>;
|
||||
status: IComputedValue<Record<string, number>>;
|
||||
title: string;
|
||||
orderNumber: number;
|
||||
}
|
||||
|
||||
export const workloadInjectionToken = getInjectionToken<Workload>({
|
||||
id: "workload-injection-token",
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { filter, sortBy as sortByWithBadTyping } from "lodash/fp";
|
||||
import { computed } from "mobx";
|
||||
import { Workload, workloadInjectionToken } from "./workload-injection-token";
|
||||
import isAllowedResourceInjectable from "../../../../common/utils/is-allowed-resource.injectable";
|
||||
|
||||
const sortBy =
|
||||
(propertyPath: string) =>
|
||||
<Collection extends object>(collection: Collection[]) =>
|
||||
sortByWithBadTyping(propertyPath, collection);
|
||||
|
||||
const workloadsInjectable = getInjectable({
|
||||
id: "workloads",
|
||||
|
||||
instantiate: (di) => {
|
||||
const workloads = di.injectMany(workloadInjectionToken);
|
||||
|
||||
const isAllowedResource = (resourceName: string) =>
|
||||
di.inject(isAllowedResourceInjectable, resourceName);
|
||||
|
||||
return computed(() =>
|
||||
pipeline(
|
||||
workloads,
|
||||
|
||||
filter((workload: Workload) => {
|
||||
const isAllowed = isAllowedResource(workload.resourceName);
|
||||
|
||||
return isAllowed.get();
|
||||
}),
|
||||
|
||||
sortBy("orderNumber"),
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default workloadsInjectable;
|
||||
Reference in new issue
Block a user