mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Turn on strict mode in tsconfig.json, some helpful lints, and required cleanup where strictness necessitates it (#5195)
* Turn on strict mode in tsconfig.json - Add route, clusterRoute, and payloadValidatedClusterRoute helper functions to improve types with backend routes - Turn on the following new lints: - react/jsx-first-prop-new-line - react/jsx-wrap-multilines - react/jsx-one-expression-per-line - react/jsx-max-props-per-line - react/jsx-indent - react/jsx-indent-props Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix build Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace KubeObject scope strings with enum Signed-off-by: Sebastian Malton <sebastian@malton.name> * Revert package.json version changes Signed-off-by: Sebastian Malton <sebastian@malton.name> * revert move hostedCluster(Id) Signed-off-by: Sebastian Malton <sebastian@malton.name> * change some type param names to be not single letters Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove copy-extension-themes Signed-off-by: Sebastian Malton <sebastian@malton.name> * add new make clean action Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix build to not use webpack for generating types Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube-object-menu.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix select.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * revert move fileNameMigration to index Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix ref logic error Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix log-resource-selector.test.tsx tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-store.test.ts test by overriding createStorage to not touch file system Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cluster.test.ts tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube=api.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fixed hotbar-store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kubeconfig-manager.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cluster-role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix pods.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix delete-cluster-dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix daemonset.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix replicaset.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix statefulsets/dialog/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix replicasets/scale-dialog/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix deployments.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix deployments/scale/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cronjob.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix stateful-set.api.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix deployment.api.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix api-manager.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix statefulset.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix job.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix pods.store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix scroll-spy.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix hotbar-remove-command.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog-entity-registry.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix welcome.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix verify-that-all-routes-have-route-component.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix pod-tolerations.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * better fix for previous 3 fixes, plus also select.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube-object-menu.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix app-paths.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-tabs.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix isReactNode typing Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix sub-title.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix drawer.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix list-layout.tsx and header.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix error-boundary.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix upgrade-chart/store.ts and dock-tab.store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix install-chart/store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix edit-resource/store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix create-resource/store.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix namespace-select.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix namespace-select-filter.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix crd-list.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix wrong types for extensions Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix circular dependency Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix circular dependency on catalogCategoryRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix api-kube Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix type errors, most <Select /> errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * fixing more type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * some more fixing type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * convert all KubeApis to injectable with legacy global backups Signed-off-by: Sebastian Malton <sebastian@malton.name> * factor out into a common file all the exports Signed-off-by: Sebastian Malton <sebastian@malton.name> * convert all KubeObjectStores to injectable with legacy global backups Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove unused legacy KubeApi globals Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix bad previous commit Signed-off-by: Sebastian Malton <sebastian@malton.name> * more crash fixing Signed-off-by: Sebastian Malton <sebastian@malton.name> * try and fix behavioural tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix sidebar-and-tab-navigation-for-core.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix sidebar-and-tab-navigation-for-extensions.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-using-application-menu.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make ThemeStore non-singleton and fix navigation-to-terminal-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * extensions.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix catalog-entity-registry.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-using-application-menu.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix log-resource-selector.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-tabs.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix delete-cluster-dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-kubernetes-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-editor-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-proxy-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-using-application-menu.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-application-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix dock-store.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix select.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix hotbar-remove-command.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix cluster-role-bindings/__tests__/dialog.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-extension-specific-preferences.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-telemetry-preferences.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix closing-preferences.test.tsx Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-editor-preferences.test.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix navigation-to-proxy-preferences.test.ts - Fix other type errors too Signed-off-by: Sebastian Malton <sebastian@malton.name> * final tweaks Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add more tsconfig files, fix bug in <Catalog> - Make all of history, navigation injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert all of kube-details-params/ and navigate/ to injectable - This fixes a runtime error that was encountered during testing Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix runtime errors on renderer - remove all static uses of `createPageParam` (and then removed the legacy global) - Made LensRendererExtension and LensMainExtension just used dependencies and not the getLegacyDi - Fixed circular dep in extension-loader Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move registerStore calls to after injectMany Signed-off-by: Sebastian Malton <sebastian@malton.name> * replace all the rest of the legacy uses of apiManager Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix stack overflow and cycles in DI Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix NamespaceSelectFilter not opening Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix WizardStep and AddNamespaceDialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix KubeApi's not being registered Signed-off-by: Sebastian Malton <sebastian@malton.name> * cleanup WindowManager Signed-off-by: Sebastian Malton <sebastian@malton.name> * Proper fix for Wizard, fix NamespaceStore.subscribe Signed-off-by: Sebastian Malton <sebastian@malton.name> * Rewrite withTooltip to be more type correct - Fixes mobx related "too many recursive actions" error - Change all the uses of withTooltips to be functional components Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add e2e test to cover kube api registration Signed-off-by: Sebastian Malton <sebastian@malton.name> * cleanup internal-commands Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove cast in <Animate> Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix command-palette e2e test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error after rebase Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix test name Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix code to help CodeQL scanner Signed-off-by: Sebastian Malton <sebastian@malton.name> * update intree extension lock files Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix build-extensions picking wrong @types/react Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix tests from rebase Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make KubeconfigSyncManager more injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix crash in test mode for Dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * make Select snapshots deterministic Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix new type error Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix kube-object.store.test.ts typing Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix merge build issues Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix snapshots after merge Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix lint after merge Signed-off-by: Sebastian Malton <sebastian@malton.name> * reexport BaseKubeJsonApiObjectMetadata Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix typo in terminalSpawningPool Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove duplicate license header Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix typo to waitUntilDefined Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove iter use from getLegacyGlobalDiForExtensionApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove complex createStorage override Signed-off-by: Sebastian Malton <sebastian@malton.name> * override logger with mocks only when needed for tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove specialized overrideStore flags for getDiForUnitTesting Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove unnecessary | undefined types from the exactOptionalFieldTypes experiment Signed-off-by: Sebastian Malton <sebastian@malton.name> * use more descriptive name for local test mocks Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove unnecessary addition to 'make clean' target Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove oddity of KubeObjectStore.getById(undefined) being allowed Signed-off-by: Sebastian Malton <sebastian@malton.name> * rename KubeObject.getDescriptor in favour of name without fundemental JS meaning Signed-off-by: Sebastian Malton <sebastian@malton.name> * Simplify legacyRegisterApi when working in behaviour unit tests - Don't emit within main environment as there should be no auto registering there Signed-off-by: Sebastian Malton <sebastian@malton.name> * change confusing variable name in ReactiveDuration Signed-off-by: Sebastian Malton <sebastian@malton.name> * make visitor pattern more explicit for Entity contextMenuOpen Signed-off-by: Sebastian Malton <sebastian@malton.name> * toggleDetails -> toggleKubeDetailsPane is more specific Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove outdated comment Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix bug where LensExtension dependencies are not set Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests from the revert of react 18 Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix more tests from merge Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix typings with new is-compatible-extension tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * more type fixing Signed-off-by: Sebastian Malton <sebastian@malton.name> * Revert in-tree extension versions Signed-off-by: Sebastian Malton <sebastian@malton.name> * Improve name of guarding injectable for stores and apis - New name better implies that it is just a guard state and does not do anything Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add helper for <Select>.isMulti for storing in a Set<Value> Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix is-compatible-extension.test.ts types Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
381d77c633
commit
dfcb7c3330
1062 files changed
+26512
-28689
No files matched your search
@@ -10,39 +10,45 @@ import kebabCase from "lodash/kebabCase";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { DrawerItem } from "../drawer";
|
||||
import { Badge } from "../badge";
|
||||
import { Deployment, getMetricsForDeployments, type IPodMetrics } from "../../../common/k8s-api/endpoints";
|
||||
import type { PodMetricData } from "../../../common/k8s-api/endpoints";
|
||||
import { Deployment, getMetricsForDeployments } from "../../../common/k8s-api/endpoints";
|
||||
import { PodDetailsTolerations } from "../+workloads-pods/pod-details-tolerations";
|
||||
import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities";
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
||||
import { deploymentStore } from "./deployments.store";
|
||||
import type { DeploymentStore } from "./store";
|
||||
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||
import { makeObservable, observable, reaction } from "mobx";
|
||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||
import { KubeObjectMeta } from "../kube-object-meta";
|
||||
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
|
||||
import type { ReplicaSetStore } from "../+workloads-replicasets/store";
|
||||
import { DeploymentReplicaSets } from "./deployment-replicasets";
|
||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import type { Disposer } from "../../utils";
|
||||
import logger from "../../../common/logger";
|
||||
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import kubeWatchApiInjectable
|
||||
from "../../kube-watch-api/kube-watch-api.injectable";
|
||||
import type { SubscribeStores } from "../../kube-watch-api/kube-watch-api";
|
||||
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
|
||||
import type { PodStore } from "../+workloads-pods/store";
|
||||
import podStoreInjectable from "../+workloads-pods/store.injectable";
|
||||
import replicaSetStoreInjectable from "../+workloads-replicasets/store.injectable";
|
||||
import deploymentStoreInjectable from "./store.injectable";
|
||||
import type { GetActiveClusterEntity } from "../../api/catalog/entity/get-active-cluster-entity.injectable";
|
||||
import getActiveClusterEntityInjectable from "../../api/catalog/entity/get-active-cluster-entity.injectable";
|
||||
|
||||
export interface DeploymentDetailsProps extends KubeObjectDetailsProps<Deployment> {
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
subscribeStores: (stores: KubeObjectStore<KubeObject>[]) => Disposer;
|
||||
subscribeStores: SubscribeStores;
|
||||
podStore: PodStore;
|
||||
replicaSetStore: ReplicaSetStore;
|
||||
deploymentStore: DeploymentStore;
|
||||
getActiveClusterEntity: GetActiveClusterEntity;
|
||||
}
|
||||
|
||||
@observer
|
||||
class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProps & Dependencies> {
|
||||
@observable metrics: IPodMetrics = null;
|
||||
@observable metrics: PodMetricData | null = null;
|
||||
|
||||
constructor(props: DeploymentDetailsProps & Dependencies) {
|
||||
super(props);
|
||||
@@ -56,8 +62,8 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
||||
}),
|
||||
|
||||
this.props.subscribeStores([
|
||||
podsStore,
|
||||
replicaSetStore,
|
||||
this.props.podStore,
|
||||
this.props.replicaSetStore,
|
||||
]),
|
||||
]);
|
||||
}
|
||||
@@ -69,7 +75,7 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
||||
};
|
||||
|
||||
render() {
|
||||
const { object: deployment } = this.props;
|
||||
const { object: deployment, podStore, replicaSetStore, deploymentStore, getActiveClusterEntity } = this.props;
|
||||
|
||||
if (!deployment) {
|
||||
return null;
|
||||
@@ -90,45 +96,49 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
||||
|
||||
return (
|
||||
<div className="DeploymentDetails">
|
||||
{!isMetricHidden && podsStore.isLoaded && (
|
||||
{!isMetricHidden && podStore.isLoaded && (
|
||||
<ResourceMetrics
|
||||
loader={this.loadMetrics}
|
||||
tabs={podMetricTabs} object={deployment} params={{ metrics: this.metrics }}
|
||||
tabs={podMetricTabs}
|
||||
object={deployment}
|
||||
metrics={this.metrics}
|
||||
>
|
||||
<PodCharts/>
|
||||
</ResourceMetrics>
|
||||
)}
|
||||
<KubeObjectMeta object={deployment}/>
|
||||
<DrawerItem name="Replicas">
|
||||
{`${spec.replicas} desired, ${status.updatedReplicas || 0} updated`},{" "}
|
||||
{`${status.replicas || 0} total, ${status.availableReplicas || 0} available`},{" "}
|
||||
{`${status.unavailableReplicas || 0} unavailable`}
|
||||
{`${spec.replicas} desired, ${status?.updatedReplicas ?? 0} updated, `}
|
||||
{`${status?.replicas ?? 0} total, ${status?.availableReplicas ?? 0} available, `}
|
||||
{`${status?.unavailableReplicas ?? 0} unavailable`}
|
||||
</DrawerItem>
|
||||
{selectors.length > 0 &&
|
||||
<DrawerItem name="Selector" labelsOnly>
|
||||
{
|
||||
selectors.map(label => <Badge key={label} label={label}/>)
|
||||
}
|
||||
</DrawerItem>
|
||||
}
|
||||
{nodeSelector.length > 0 &&
|
||||
<DrawerItem name="Node Selector">
|
||||
{
|
||||
nodeSelector.map(label => (
|
||||
<Badge key={label} label={label}/>
|
||||
))
|
||||
}
|
||||
</DrawerItem>
|
||||
}
|
||||
{selectors.length > 0 && (
|
||||
<DrawerItem name="Selector" labelsOnly>
|
||||
{
|
||||
selectors.map(label => <Badge key={label} label={label}/>)
|
||||
}
|
||||
</DrawerItem>
|
||||
)}
|
||||
{nodeSelector.length > 0 && (
|
||||
<DrawerItem name="Node Selector">
|
||||
{
|
||||
nodeSelector.map(label => (
|
||||
<Badge key={label} label={label}/>
|
||||
))
|
||||
}
|
||||
</DrawerItem>
|
||||
)}
|
||||
<DrawerItem name="Strategy Type">
|
||||
{spec.strategy.type}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Conditions" className="conditions" labelsOnly>
|
||||
<DrawerItem
|
||||
name="Conditions"
|
||||
className="conditions"
|
||||
labelsOnly
|
||||
>
|
||||
{
|
||||
deployment.getConditions().map(condition => {
|
||||
const { type, message, lastTransitionTime, status } = condition;
|
||||
|
||||
return (
|
||||
deployment.getConditions()
|
||||
.map(({ type, message, lastTransitionTime, status }) => (
|
||||
<Badge
|
||||
key={type}
|
||||
label={type}
|
||||
@@ -137,12 +147,12 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
||||
tooltip={(
|
||||
<>
|
||||
<p>{message}</p>
|
||||
<p>Last transition time: {lastTransitionTime}</p>
|
||||
<p>
|
||||
{`Last transition time: ${lastTransitionTime}`}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
})
|
||||
)} />
|
||||
))
|
||||
}
|
||||
</DrawerItem>
|
||||
<PodDetailsTolerations workload={deployment}/>
|
||||
@@ -155,14 +165,14 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
||||
}
|
||||
}
|
||||
|
||||
export const DeploymentDetails = withInjectables<Dependencies, DeploymentDetailsProps>(
|
||||
NonInjectedDeploymentDetails,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
subscribeStores: di.inject(kubeWatchApiInjectable).subscribeStores,
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
export const DeploymentDetails = withInjectables<Dependencies, DeploymentDetailsProps>(NonInjectedDeploymentDetails, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
subscribeStores: di.inject(subscribeStoresInjectable),
|
||||
podStore: di.inject(podStoreInjectable),
|
||||
replicaSetStore: di.inject(replicaSetStoreInjectable),
|
||||
deploymentStore: di.inject(deploymentStoreInjectable),
|
||||
getActiveClusterEntity: di.inject(getActiveClusterEntityInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -4,51 +4,69 @@
|
||||
*/
|
||||
import React from "react";
|
||||
import type { KubeObjectMenuProps } from "../kube-object-menu";
|
||||
import type { Deployment } from "../../../common/k8s-api/endpoints";
|
||||
import { deploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import type { Deployment, DeploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { MenuItem } from "../menu";
|
||||
import { DeploymentScaleDialog } from "./deployment-scale-dialog";
|
||||
import { Icon } from "../icon";
|
||||
import { Notifications } from "../notifications";
|
||||
import type { OpenConfirmDialog } from "../confirm-dialog/open.injectable";
|
||||
import type { OpenDeploymentScaleDialog } from "./scale/open.injectable";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import deploymentApiInjectable from "../../../common/k8s-api/endpoints/deployment.api.injectable";
|
||||
import openDeploymentScaleDialogInjectable from "./scale/open.injectable";
|
||||
import type { OpenConfirmDialog } from "../confirm-dialog/open.injectable";
|
||||
import openConfirmDialogInjectable from "../confirm-dialog/open.injectable";
|
||||
|
||||
export interface DeploymentMenuProps extends KubeObjectMenuProps<Deployment> {}
|
||||
|
||||
interface Dependencies {
|
||||
openDeploymentScaleDialog: OpenDeploymentScaleDialog;
|
||||
deploymentApi: DeploymentApi;
|
||||
openConfirmDialog: OpenConfirmDialog;
|
||||
}
|
||||
|
||||
const NonInjectedDeploymentMenu = ({
|
||||
deploymentApi,
|
||||
object,
|
||||
openDeploymentScaleDialog,
|
||||
toolbar,
|
||||
openConfirmDialog,
|
||||
}: Dependencies & DeploymentMenuProps) => (
|
||||
<>
|
||||
<MenuItem onClick={() => DeploymentScaleDialog.open(object)}>
|
||||
<Icon material="open_with" tooltip="Scale" interactive={toolbar}/>
|
||||
<MenuItem onClick={() => openDeploymentScaleDialog(object)}>
|
||||
<Icon
|
||||
material="open_with"
|
||||
tooltip="Scale"
|
||||
interactive={toolbar}
|
||||
/>
|
||||
<span className="title">Scale</span>
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => openConfirmDialog({
|
||||
ok: async () => {
|
||||
try {
|
||||
await deploymentApi.restart({
|
||||
namespace: object.getNs(),
|
||||
name: object.getName(),
|
||||
});
|
||||
} catch (err) {
|
||||
Notifications.error(err);
|
||||
}
|
||||
},
|
||||
labelOk: `Restart`,
|
||||
message: (
|
||||
<p>
|
||||
Are you sure you want to restart deployment <b>{object.getName()}</b>?
|
||||
</p>
|
||||
),
|
||||
})}>
|
||||
<Icon material="autorenew" tooltip="Restart" interactive={toolbar}/>
|
||||
<MenuItem
|
||||
onClick={() => openConfirmDialog({
|
||||
ok: async () =>
|
||||
{
|
||||
try {
|
||||
await deploymentApi.restart({
|
||||
namespace: object.getNs(),
|
||||
name: object.getName(),
|
||||
});
|
||||
} catch (err) {
|
||||
Notifications.checkedError(err, "Unknown error occured while restarting deployment");
|
||||
}
|
||||
},
|
||||
labelOk: "Restart",
|
||||
message: (
|
||||
<p>
|
||||
{"Are you sure you want to restart deployment "}
|
||||
<b>{object.getName()}</b>
|
||||
?
|
||||
</p>
|
||||
),
|
||||
})}
|
||||
>
|
||||
<Icon
|
||||
material="autorenew"
|
||||
tooltip="Restart"
|
||||
interactive={toolbar}
|
||||
/>
|
||||
<span className="title">Restart</span>
|
||||
</MenuItem>
|
||||
</>
|
||||
@@ -57,6 +75,8 @@ const NonInjectedDeploymentMenu = ({
|
||||
export const DeploymentMenu = withInjectables<Dependencies, DeploymentMenuProps>(NonInjectedDeploymentMenu, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
deploymentApi: di.inject(deploymentApiInjectable),
|
||||
openDeploymentScaleDialog: di.inject(openDeploymentScaleDialogInjectable),
|
||||
openConfirmDialog: di.inject(openConfirmDialogInjectable),
|
||||
}),
|
||||
});
|
||||
@@ -15,7 +15,7 @@ import { prevDefault, stopPropagation } from "../../utils";
|
||||
import { DrawerTitle } from "../drawer";
|
||||
import { Table, TableCell, TableHead, TableRow } from "../table";
|
||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
|
||||
import { replicaSetStore } from "../+workloads-replicasets/legacy-store";
|
||||
import { showDetails } from "../kube-detail-params";
|
||||
import { KubeObjectAge } from "../kube-object/age";
|
||||
|
||||
@@ -33,13 +33,6 @@ export interface DeploymentReplicaSetsProps {
|
||||
|
||||
@observer
|
||||
export class DeploymentReplicaSets extends React.Component<DeploymentReplicaSetsProps> {
|
||||
private sortingCallbacks = {
|
||||
[sortBy.name]: (replicaSet: ReplicaSet) => replicaSet.getName(),
|
||||
[sortBy.namespace]: (replicaSet: ReplicaSet) => replicaSet.getNs(),
|
||||
[sortBy.age]: (replicaSet: ReplicaSet) => replicaSet.metadata.creationTimestamp,
|
||||
[sortBy.pods]: (replicaSet: ReplicaSet) => this.getPodsLength(replicaSet),
|
||||
};
|
||||
|
||||
getPodsLength(replicaSet: ReplicaSet) {
|
||||
return replicaSetStore.getChildPods(replicaSet).length;
|
||||
}
|
||||
@@ -59,7 +52,12 @@ export class DeploymentReplicaSets extends React.Component<DeploymentReplicaSets
|
||||
selectable
|
||||
tableId="deployment_replica_sets_view"
|
||||
scrollable={false}
|
||||
sortable={this.sortingCallbacks}
|
||||
sortable={{
|
||||
[sortBy.name]: (replicaSet: ReplicaSet) => replicaSet.getName(),
|
||||
[sortBy.namespace]: (replicaSet: ReplicaSet) => replicaSet.getNs(),
|
||||
[sortBy.age]: (replicaSet: ReplicaSet) => replicaSet.metadata.creationTimestamp,
|
||||
[sortBy.pods]: (replicaSet: ReplicaSet) => this.getPodsLength(replicaSet),
|
||||
}}
|
||||
sortByDefault={{ sortBy: sortBy.pods, orderBy: "desc" }}
|
||||
sortSyncWithUrl={false}
|
||||
className="box grow"
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./deployment-scale-dialog.scss";
|
||||
|
||||
import React, { Component } from "react";
|
||||
import { computed, observable, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import type { DialogProps } from "../dialog";
|
||||
import { Dialog } from "../dialog";
|
||||
import { Wizard, WizardStep } from "../wizard";
|
||||
import type { Deployment, DeploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { deploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { Icon } from "../icon";
|
||||
import { Slider } from "../slider";
|
||||
import { Notifications } from "../notifications";
|
||||
import { cssNames } from "../../utils";
|
||||
|
||||
export interface DeploymentScaleDialogProps extends Partial<DialogProps> {
|
||||
deploymentApi: DeploymentApi;
|
||||
}
|
||||
|
||||
const dialogState = observable.object({
|
||||
isOpen: false,
|
||||
data: null as Deployment,
|
||||
});
|
||||
|
||||
@observer
|
||||
export class DeploymentScaleDialog extends Component<DeploymentScaleDialogProps> {
|
||||
static defaultProps = {
|
||||
deploymentApi,
|
||||
};
|
||||
|
||||
@observable ready = false;
|
||||
@observable currentReplicas = 0;
|
||||
@observable desiredReplicas = 0;
|
||||
|
||||
constructor(props: DeploymentScaleDialogProps) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
static open(deployment: Deployment) {
|
||||
dialogState.isOpen = true;
|
||||
dialogState.data = deployment;
|
||||
}
|
||||
|
||||
static close() {
|
||||
dialogState.isOpen = false;
|
||||
}
|
||||
|
||||
get deployment() {
|
||||
return dialogState.data;
|
||||
}
|
||||
|
||||
close = () => {
|
||||
DeploymentScaleDialog.close();
|
||||
};
|
||||
|
||||
@computed get scaleMax() {
|
||||
const { currentReplicas } = this;
|
||||
const defaultMax = 50;
|
||||
|
||||
return currentReplicas <= defaultMax
|
||||
? defaultMax * 2
|
||||
: currentReplicas * 2;
|
||||
}
|
||||
|
||||
onOpen = async () => {
|
||||
const { deployment } = this;
|
||||
|
||||
this.currentReplicas = await this.props.deploymentApi.getReplicas({
|
||||
namespace: deployment.getNs(),
|
||||
name: deployment.getName(),
|
||||
});
|
||||
this.desiredReplicas = this.currentReplicas;
|
||||
this.ready = true;
|
||||
};
|
||||
|
||||
onClose = () => {
|
||||
this.ready = false;
|
||||
};
|
||||
|
||||
onChange = (evt: React.ChangeEvent, value: number) => {
|
||||
this.desiredReplicas = value;
|
||||
};
|
||||
|
||||
scale = async () => {
|
||||
const { deployment } = this;
|
||||
const { currentReplicas, desiredReplicas, close } = this;
|
||||
|
||||
try {
|
||||
if (currentReplicas !== desiredReplicas) {
|
||||
await this.props.deploymentApi.scale({
|
||||
name: deployment.getName(),
|
||||
namespace: deployment.getNs(),
|
||||
}, desiredReplicas);
|
||||
}
|
||||
close();
|
||||
} catch (err) {
|
||||
Notifications.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
private readonly scaleMin = 0;
|
||||
|
||||
desiredReplicasUp = () => {
|
||||
this.desiredReplicas = Math.min(this.scaleMax, this.desiredReplicas + 1);
|
||||
};
|
||||
|
||||
desiredReplicasDown = () => {
|
||||
this.desiredReplicas = Math.max(this.scaleMin, this.desiredReplicas - 1);
|
||||
};
|
||||
|
||||
renderContents() {
|
||||
const { currentReplicas, desiredReplicas, onChange, scaleMax } = this;
|
||||
const warning = currentReplicas < 10 && desiredReplicas > 90;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="current-scale" data-testid="current-scale">
|
||||
Current replica scale: {currentReplicas}
|
||||
</div>
|
||||
<div className="flex gaps align-center">
|
||||
<div className="desired-scale" data-testid="desired-scale">
|
||||
Desired number of replicas: {desiredReplicas}
|
||||
</div>
|
||||
<div className="slider-container flex align-center">
|
||||
<Slider value={desiredReplicas} max={scaleMax} onChange={onChange as any /** see: https://github.com/mui-org/material-ui/issues/20191 */}/>
|
||||
</div>
|
||||
<div className="plus-minus-container flex gaps">
|
||||
<Icon
|
||||
material="add_circle_outline"
|
||||
onClick={this.desiredReplicasUp}
|
||||
data-testid="desired-replicas-up"
|
||||
/>
|
||||
<Icon
|
||||
material="remove_circle_outline"
|
||||
onClick={this.desiredReplicasDown}
|
||||
data-testid="desired-replicas-down"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{warning &&
|
||||
<div className="warning" data-testid="warning">
|
||||
<Icon material="warning"/>
|
||||
High number of replicas may cause cluster performance issues
|
||||
</div>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { className, ...dialogProps } = this.props;
|
||||
const deploymentName = this.deployment ? this.deployment.getName() : "";
|
||||
const header = (
|
||||
<h5>
|
||||
Scale Deployment <span>{deploymentName}</span>
|
||||
</h5>
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
{...dialogProps}
|
||||
isOpen={dialogState.isOpen}
|
||||
className={cssNames("DeploymentScaleDialog", className)}
|
||||
onOpen={this.onOpen}
|
||||
onClose={this.onClose}
|
||||
close={this.close}
|
||||
>
|
||||
<Wizard header={header} done={this.close}>
|
||||
<WizardStep
|
||||
contentClass="flex gaps column"
|
||||
next={this.scale}
|
||||
nextLabel="Scale"
|
||||
disabledNext={!this.ready}
|
||||
>
|
||||
{this.renderContents()}
|
||||
</WizardStep>
|
||||
</Wizard>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +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 { deploymentStore } from "./deployments.store";
|
||||
|
||||
const deploymentsStoreInjectable = getInjectable({
|
||||
id: "deployments-store",
|
||||
instantiate: () => deploymentStore,
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default deploymentsStoreInjectable;
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { makeObservable } from "mobx";
|
||||
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
import type { Deployment } from "../../../common/k8s-api/endpoints";
|
||||
import { deploymentApi, PodStatus } from "../../../common/k8s-api/endpoints";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import { autoBind } from "../../utils";
|
||||
|
||||
export class DeploymentStore extends KubeObjectStore<Deployment> {
|
||||
api = deploymentApi;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
makeObservable(this);
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
protected sortItems(items: Deployment[]) {
|
||||
return super.sortItems(items, [
|
||||
item => item.getReplicas(),
|
||||
], "desc");
|
||||
}
|
||||
|
||||
getStatuses(deployments?: Deployment[]) {
|
||||
const status = { running: 0, failed: 0, pending: 0 };
|
||||
|
||||
deployments.forEach(deployment => {
|
||||
const pods = this.getChildPods(deployment);
|
||||
|
||||
if (pods.some(pod => pod.getStatus() === PodStatus.FAILED)) {
|
||||
status.failed++;
|
||||
}
|
||||
else if (pods.some(pod => pod.getStatus() === PodStatus.PENDING)) {
|
||||
status.pending++;
|
||||
}
|
||||
else {
|
||||
status.running++;
|
||||
}
|
||||
});
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
getChildPods(deployment: Deployment) {
|
||||
return podsStore
|
||||
.getByLabel(deployment.getTemplateLabels())
|
||||
.filter(pod => pod.getNs() === deployment.getNs());
|
||||
}
|
||||
}
|
||||
|
||||
export const deploymentStore = new DeploymentStore();
|
||||
apiManager.registerStore(deploymentStore);
|
||||
@@ -8,8 +8,8 @@ import "./deployments.scss";
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { Deployment } from "../../../common/k8s-api/endpoints";
|
||||
import { deploymentStore } from "./deployments.store";
|
||||
import { eventStore } from "../+events/event.store";
|
||||
import { deploymentStore } from "./legacy-store";
|
||||
import { eventStore } from "../+events/legacy-store";
|
||||
import { KubeObjectListLayout } from "../kube-object-list-layout";
|
||||
import { cssNames } from "../../utils";
|
||||
import kebabCase from "lodash/kebabCase";
|
||||
@@ -30,7 +30,7 @@ enum columnId {
|
||||
@observer
|
||||
export class Deployments extends React.Component {
|
||||
renderPods(deployment: Deployment) {
|
||||
const { replicas, availableReplicas } = deployment.status;
|
||||
const { replicas, availableReplicas } = deployment.status ?? {};
|
||||
|
||||
return `${availableReplicas || 0}/${replicas || 0}`;
|
||||
}
|
||||
@@ -39,7 +39,11 @@ export class Deployments extends React.Component {
|
||||
const conditions = orderBy(deployment.getConditions(true), "type", "asc");
|
||||
|
||||
return conditions.map(({ type, message }) => (
|
||||
<span key={type} className={cssNames("condition", kebabCase(type))} title={message}>
|
||||
<span
|
||||
key={type}
|
||||
className={cssNames("condition", kebabCase(type))}
|
||||
title={message}
|
||||
>
|
||||
{type}
|
||||
</span>
|
||||
));
|
||||
@@ -51,7 +55,8 @@ export class Deployments extends React.Component {
|
||||
<KubeObjectListLayout
|
||||
isConfigurable
|
||||
tableId="workload_deployments"
|
||||
className="Deployments" store={deploymentStore}
|
||||
className="Deployments"
|
||||
store={deploymentStore}
|
||||
dependentStores={[eventStore]} // status icon component uses event store
|
||||
sortingCallbacks={{
|
||||
[columnId.name]: deployment => deployment.getName(),
|
||||
@@ -76,7 +81,7 @@ export class Deployments extends React.Component {
|
||||
]}
|
||||
renderTableContents={deployment => [
|
||||
deployment.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={deployment}/>,
|
||||
<KubeObjectStatusIcon key="icon" object={deployment} />,
|
||||
deployment.getNs(),
|
||||
this.renderPods(deployment),
|
||||
deployment.getReplicas(),
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { asLegacyGlobalForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import deploymentStoreInjectable from "./store.injectable";
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(deploymentStoreInjectable)` instead
|
||||
*/
|
||||
export const deploymentStore = asLegacyGlobalForExtensionApi(deploymentStoreInjectable);
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 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 { observable } from "mobx";
|
||||
import type { Deployment } from "../../../../common/k8s-api/endpoints";
|
||||
|
||||
const deploymentScaleDialogStateInjectable = getInjectable({
|
||||
id: "deployment-scale-dialog-state",
|
||||
instantiate: () => observable.box<Deployment | undefined>(),
|
||||
});
|
||||
|
||||
export default deploymentScaleDialogStateInjectable;
|
||||
File renamed without changes.
+47
-59
@@ -4,13 +4,21 @@
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { render, waitFor, fireEvent } from "@testing-library/react";
|
||||
import { waitFor, fireEvent } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
|
||||
import { DeploymentScaleDialog } from "./deployment-scale-dialog";
|
||||
import { Deployment, DeploymentApi } from "../../../common/k8s-api/endpoints/deployment.api";
|
||||
import { DeploymentScaleDialog } from "./dialog";
|
||||
import type { DeploymentApi } from "../../../../common/k8s-api/endpoints/deployment.api";
|
||||
import { Deployment } from "../../../../common/k8s-api/endpoints/deployment.api";
|
||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||
import deploymentApiInjectable from "../../../../common/k8s-api/endpoints/deployment.api.injectable";
|
||||
import type { OpenDeploymentScaleDialog } from "./open.injectable";
|
||||
import openDeploymentScaleDialogInjectable from "./open.injectable";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../stores-apis-can-be-created.injectable";
|
||||
import type { DiRender } from "../../test-utils/renderFor";
|
||||
import { renderFor } from "../../test-utils/renderFor";
|
||||
|
||||
const dummyDeployment: Deployment = {
|
||||
const dummyDeployment = new Deployment({
|
||||
apiVersion: "v1",
|
||||
kind: "dummy",
|
||||
metadata: {
|
||||
@@ -18,9 +26,9 @@ const dummyDeployment: Deployment = {
|
||||
name: "dummy",
|
||||
creationTimestamp: "dummy",
|
||||
resourceVersion: "dummy",
|
||||
selfLink: "link",
|
||||
namespace: "default",
|
||||
selfLink: "/apis/apps/v1/deployments/default/dummy",
|
||||
},
|
||||
selfLink: "link",
|
||||
spec: {
|
||||
replicas: 1,
|
||||
selector: { matchLabels: { dummy: "label" }},
|
||||
@@ -66,47 +74,27 @@ const dummyDeployment: Deployment = {
|
||||
readyReplicas: 1,
|
||||
conditions: [{
|
||||
type: "dummy",
|
||||
status: "dummy",
|
||||
lastUpdateTime: "dummy",
|
||||
status: "True",
|
||||
lastTransitionTime: "dummy",
|
||||
reason: "dummy",
|
||||
message: "dummy",
|
||||
}],
|
||||
},
|
||||
getConditions: jest.fn(),
|
||||
getConditionsText: jest.fn(),
|
||||
getReplicas: jest.fn(),
|
||||
getSelectors: jest.fn(),
|
||||
getTemplateLabels: jest.fn(),
|
||||
getAffinity: jest.fn(),
|
||||
getTolerations: jest.fn(),
|
||||
getNodeSelectors: jest.fn(),
|
||||
getAffinityNumber: jest.fn(),
|
||||
getId: jest.fn(),
|
||||
getResourceVersion: jest.fn(),
|
||||
getName: jest.fn(),
|
||||
getNs: jest.fn(),
|
||||
getAge: jest.fn(),
|
||||
getCreationTimestamp: jest.fn(),
|
||||
getTimeDiffFromNow: jest.fn(),
|
||||
getFinalizers: jest.fn(),
|
||||
getLabels: jest.fn(),
|
||||
getAnnotations: jest.fn(),
|
||||
getOwnerRefs: jest.fn(),
|
||||
getSearchFields: jest.fn(),
|
||||
toPlainObject: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
patch: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe("<DeploymentScaleDialog />", () => {
|
||||
let deploymentApi: DeploymentApi;
|
||||
let openDeploymentScaleDialog: OpenDeploymentScaleDialog;
|
||||
let render: DiRender;
|
||||
|
||||
beforeEach(() => {
|
||||
deploymentApi = new DeploymentApi({
|
||||
objectConstructor: Deployment,
|
||||
});
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
|
||||
deploymentApi = di.inject(deploymentApiInjectable);
|
||||
openDeploymentScaleDialog = di.inject(openDeploymentScaleDialogInjectable);
|
||||
render = renderFor(di);
|
||||
});
|
||||
|
||||
it("renders w/o errors", () => {
|
||||
@@ -121,15 +109,15 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
const initReplicas = 3;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const { getByTestId } = render(<DeploymentScaleDialog deploymentApi={deploymentApi} />);
|
||||
const { findByTestId } = render(<DeploymentScaleDialog />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
openDeploymentScaleDialog(dummyDeployment);
|
||||
// we need to wait for the DeploymentScaleDialog to show up
|
||||
// because there is an <Animate /> in <Dialog /> which renders null at start.
|
||||
await waitFor(async () => {
|
||||
const [currentScale, desiredScale] = await Promise.all([
|
||||
getByTestId("current-scale"),
|
||||
getByTestId("desired-scale"),
|
||||
findByTestId("current-scale"),
|
||||
findByTestId("desired-scale"),
|
||||
]);
|
||||
|
||||
expect(currentScale).toHaveTextContent(`${initReplicas}`);
|
||||
@@ -142,26 +130,26 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const component = render(<DeploymentScaleDialog deploymentApi={deploymentApi} />);
|
||||
const component = render(<DeploymentScaleDialog />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
openDeploymentScaleDialog(dummyDeployment);
|
||||
await waitFor(async () => {
|
||||
expect(await component.getByTestId("desired-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas}`);
|
||||
expect(await component.findByTestId("desired-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect(await component.findByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect(component.baseElement.querySelector("input")?.value).toBe(`${initReplicas}`);
|
||||
});
|
||||
const up = await component.getByTestId("desired-replicas-up");
|
||||
const down = await component.getByTestId("desired-replicas-down");
|
||||
const up = await component.findByTestId("desired-replicas-up");
|
||||
const down = await component.findByTestId("desired-replicas-down");
|
||||
|
||||
fireEvent.click(up);
|
||||
expect(await component.getByTestId("desired-scale")).toHaveTextContent(`${initReplicas + 1}`);
|
||||
expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas + 1}`);
|
||||
expect(await component.findByTestId("desired-scale")).toHaveTextContent(`${initReplicas + 1}`);
|
||||
expect(await component.findByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect(component.baseElement.querySelector("input")?.value).toBe(`${initReplicas + 1}`);
|
||||
|
||||
fireEvent.click(down);
|
||||
expect(await component.getByTestId("desired-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect(await component.getByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect((await component.baseElement.querySelector("input").value)).toBe(`${initReplicas}`);
|
||||
expect(await component.findByTestId("desired-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect(await component.findByTestId("current-scale")).toHaveTextContent(`${initReplicas}`);
|
||||
expect(component.baseElement.querySelector("input")?.value).toBe(`${initReplicas}`);
|
||||
|
||||
// edge case, desiredScale must = 0
|
||||
let times = 10;
|
||||
@@ -169,8 +157,8 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
for (let i = 0; i < times; i++) {
|
||||
fireEvent.click(down);
|
||||
}
|
||||
expect(await component.getByTestId("desired-scale")).toHaveTextContent("0");
|
||||
expect((await component.baseElement.querySelector("input").value)).toBe("0");
|
||||
expect(await component.findByTestId("desired-scale")).toHaveTextContent("0");
|
||||
expect(component.baseElement.querySelector("input")?.value).toBe("0");
|
||||
|
||||
// edge case, desiredScale must = 100 scaleMax (100)
|
||||
times = 120;
|
||||
@@ -178,9 +166,9 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
for (let i = 0; i < times; i++) {
|
||||
fireEvent.click(up);
|
||||
}
|
||||
expect(await component.getByTestId("desired-scale")).toHaveTextContent("100");
|
||||
expect((component.baseElement.querySelector("input").value)).toBe("100");
|
||||
expect(await component.getByTestId("warning"))
|
||||
expect(await component.findByTestId("desired-scale")).toHaveTextContent("100");
|
||||
expect(component.baseElement.querySelector("input")?.value).toBe("100");
|
||||
expect(await component.findByTestId("warning"))
|
||||
.toHaveTextContent("High number of replicas may cause cluster performance issues");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./dialog.scss";
|
||||
|
||||
import React, { Component } from "react";
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { computed, observable, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import type { DialogProps } from "../../dialog";
|
||||
import { Dialog } from "../../dialog";
|
||||
import { Wizard, WizardStep } from "../../wizard";
|
||||
import type { Deployment, DeploymentApi } from "../../../../common/k8s-api/endpoints";
|
||||
import { Icon } from "../../icon";
|
||||
import { Slider } from "../../slider";
|
||||
import { Notifications } from "../../notifications";
|
||||
import { cssNames } from "../../../utils";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import deploymentApiInjectable from "../../../../common/k8s-api/endpoints/deployment.api.injectable";
|
||||
import deploymentScaleDialogStateInjectable from "./dialog-state.injectable";
|
||||
|
||||
export interface DeploymentScaleDialogProps extends Partial<DialogProps> {
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
deploymentApi: DeploymentApi;
|
||||
state: IObservableValue<Deployment | undefined>;
|
||||
}
|
||||
|
||||
@observer
|
||||
class NonInjectedDeploymentScaleDialog extends Component<DeploymentScaleDialogProps & Dependencies> {
|
||||
@observable ready = false;
|
||||
@observable currentReplicas = 0;
|
||||
@observable desiredReplicas = 0;
|
||||
|
||||
constructor(props: DeploymentScaleDialogProps & Dependencies) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
close = () => {
|
||||
this.props.state.set(undefined);
|
||||
};
|
||||
|
||||
@computed get scaleMax() {
|
||||
const { currentReplicas } = this;
|
||||
const defaultMax = 50;
|
||||
|
||||
return currentReplicas <= defaultMax
|
||||
? defaultMax * 2
|
||||
: currentReplicas * 2;
|
||||
}
|
||||
|
||||
onOpen = async (deployment: Deployment) => {
|
||||
this.currentReplicas = await this.props.deploymentApi.getReplicas({
|
||||
namespace: deployment.getNs(),
|
||||
name: deployment.getName(),
|
||||
});
|
||||
this.desiredReplicas = this.currentReplicas;
|
||||
this.ready = true;
|
||||
};
|
||||
|
||||
onClose = () => {
|
||||
this.ready = false;
|
||||
};
|
||||
|
||||
onChange = (evt: React.ChangeEvent, value: number) => {
|
||||
this.desiredReplicas = value;
|
||||
};
|
||||
|
||||
scale = async (deployment: Deployment) => {
|
||||
const { currentReplicas, desiredReplicas, close } = this;
|
||||
|
||||
try {
|
||||
if (currentReplicas !== desiredReplicas) {
|
||||
await this.props.deploymentApi.scale({
|
||||
name: deployment.getName(),
|
||||
namespace: deployment.getNs(),
|
||||
}, desiredReplicas);
|
||||
}
|
||||
close();
|
||||
} catch (err) {
|
||||
Notifications.checkedError(err, "Unknown error occured while scaling Deployment");
|
||||
}
|
||||
};
|
||||
|
||||
private readonly scaleMin = 0;
|
||||
|
||||
desiredReplicasUp = () => {
|
||||
this.desiredReplicas = Math.min(this.scaleMax, this.desiredReplicas + 1);
|
||||
};
|
||||
|
||||
desiredReplicasDown = () => {
|
||||
this.desiredReplicas = Math.max(this.scaleMin, this.desiredReplicas - 1);
|
||||
};
|
||||
|
||||
renderContents(deployment: Deployment) {
|
||||
const { currentReplicas, desiredReplicas, onChange, scaleMax } = this;
|
||||
const warning = currentReplicas < 10 && desiredReplicas > 90;
|
||||
|
||||
return (
|
||||
<Wizard
|
||||
header={(
|
||||
<h5>
|
||||
Scale Deployment
|
||||
<span>{deployment.getName()}</span>
|
||||
</h5>
|
||||
)}
|
||||
done={this.close}
|
||||
>
|
||||
<WizardStep
|
||||
contentClass="flex gaps column"
|
||||
next={() => this.scale(deployment)}
|
||||
nextLabel="Scale"
|
||||
disabledNext={!this.ready}
|
||||
>
|
||||
<div className="current-scale" data-testid="current-scale">
|
||||
Current replica scale:
|
||||
{" "}
|
||||
{currentReplicas}
|
||||
</div>
|
||||
<div className="flex gaps align-center">
|
||||
<div className="desired-scale" data-testid="desired-scale">
|
||||
Desired number of replicas:
|
||||
{" "}
|
||||
{desiredReplicas}
|
||||
</div>
|
||||
<div className="slider-container flex align-center">
|
||||
<Slider
|
||||
value={desiredReplicas}
|
||||
max={scaleMax}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="plus-minus-container flex gaps">
|
||||
<Icon
|
||||
material="add_circle_outline"
|
||||
onClick={this.desiredReplicasUp}
|
||||
data-testid="desired-replicas-up"
|
||||
/>
|
||||
<Icon
|
||||
material="remove_circle_outline"
|
||||
onClick={this.desiredReplicasDown}
|
||||
data-testid="desired-replicas-down"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{warning && (
|
||||
<div className="warning" data-testid="warning">
|
||||
<Icon material="warning"/>
|
||||
High number of replicas may cause cluster performance issues
|
||||
</div>
|
||||
)}
|
||||
</WizardStep>
|
||||
</Wizard>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { className, state, ...dialogProps } = this.props;
|
||||
const deployment = state.get();
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
{...dialogProps}
|
||||
isOpen={Boolean(deployment)}
|
||||
className={cssNames("DeploymentScaleDialog", className)}
|
||||
onOpen={deployment && (() => this.onOpen(deployment))}
|
||||
onClose={this.onClose}
|
||||
close={this.close}
|
||||
>
|
||||
{deployment && this.renderContents(deployment)}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const DeploymentScaleDialog = withInjectables<Dependencies, DeploymentScaleDialogProps>(NonInjectedDeploymentScaleDialog, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
deploymentApi: di.inject(deploymentApiInjectable),
|
||||
state: di.inject(deploymentScaleDialogStateInjectable),
|
||||
}),
|
||||
});
|
||||
@@ -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 type { Deployment } from "../../../../common/k8s-api/endpoints";
|
||||
import deploymentScaleDialogStateInjectable from "./dialog-state.injectable";
|
||||
|
||||
export type OpenDeploymentScaleDialog = (obj: Deployment) => void;
|
||||
|
||||
const openDeploymentScaleDialogInjectable = getInjectable({
|
||||
id: "open-deployment-scale-dialog",
|
||||
instantiate: (di): OpenDeploymentScaleDialog => {
|
||||
const state = di.inject(deploymentScaleDialogStateInjectable);
|
||||
|
||||
return obj => state.set(obj);
|
||||
},
|
||||
});
|
||||
|
||||
export default openDeploymentScaleDialogInjectable;
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 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 podStoreInjectable from "../+workloads-pods/store.injectable";
|
||||
import { kubeObjectStoreInjectionToken } from "../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../../../common/k8s-api/stores-apis-can-be-created.token";
|
||||
import deploymentApiInjectable from "../../../common/k8s-api/endpoints/deployment.api.injectable";
|
||||
import { DeploymentStore } from "./store";
|
||||
|
||||
const deploymentStoreInjectable = getInjectable({
|
||||
id: "deployment-store",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "deploymentStore is only available in certain environments");
|
||||
|
||||
const api = di.inject(deploymentApiInjectable);
|
||||
|
||||
return new DeploymentStore({
|
||||
podStore: di.inject(podStoreInjectable),
|
||||
}, api);
|
||||
},
|
||||
injectionToken: kubeObjectStoreInjectionToken,
|
||||
});
|
||||
|
||||
export default deploymentStoreInjectable;
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { PodStore } from "../+workloads-pods/store";
|
||||
import type { Deployment, DeploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { PodStatusPhase } from "../../../common/k8s-api/endpoints";
|
||||
import type { KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object.store";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
|
||||
// This needs to be disables because of https://github.com/microsoft/TypeScript/issues/15300
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export type DeploymentStatuses = {
|
||||
running: number;
|
||||
failed: number;
|
||||
pending: number;
|
||||
};
|
||||
|
||||
export interface DeploymentStoreDependencies {
|
||||
readonly podStore: PodStore;
|
||||
}
|
||||
|
||||
export class DeploymentStore extends KubeObjectStore<Deployment, DeploymentApi> {
|
||||
constructor(protected readonly dependencies: DeploymentStoreDependencies, api: DeploymentApi, opts?: KubeObjectStoreOptions) {
|
||||
super(api, opts);
|
||||
}
|
||||
|
||||
protected sortItems(items: Deployment[]) {
|
||||
return super.sortItems(items, [
|
||||
item => item.getReplicas(),
|
||||
], "desc");
|
||||
}
|
||||
|
||||
getStatuses(deployments: Deployment[]): DeploymentStatuses;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
getStatuses(deployments: Deployment[] | undefined): DeploymentStatuses;
|
||||
getStatuses(deployments: Deployment[] = []) {
|
||||
const status = { running: 0, failed: 0, pending: 0 };
|
||||
|
||||
deployments.forEach(deployment => {
|
||||
const statuses = new Set(this.getChildPods(deployment).map(pod => pod.getStatus()));
|
||||
|
||||
if (statuses.has(PodStatusPhase.FAILED)) {
|
||||
status.failed++;
|
||||
} else if (statuses.has(PodStatusPhase.PENDING)) {
|
||||
status.pending++;
|
||||
} else {
|
||||
status.running++;
|
||||
}
|
||||
});
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
getChildPods(deployment: Deployment) {
|
||||
return this.dependencies.podStore
|
||||
.getByLabel(deployment.getTemplateLabels())
|
||||
.filter(pod => pod.getNs() === deployment.getNs());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user