mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor k8s api to common (#3553)
* refactor kube api to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor more utils to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor more utils to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * switch to use node-fetch on both sides Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * improve logger Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix lint errors Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix/improve tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix node-fetch require error on prod build Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * preload fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * read serverAddress from apiBase Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
476aa74101
commit
58a446bd45
250 files changed
+1244
-644
No files matched your search
@@ -26,7 +26,7 @@ import kebabCase from "lodash/kebabCase";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { DrawerItem } from "../drawer";
|
||||
import { Badge } from "../badge";
|
||||
import { Deployment, getMetricsForDeployments, IPodMetrics } from "../../api/endpoints";
|
||||
import { Deployment, getMetricsForDeployments, IPodMetrics } 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";
|
||||
|
||||
@@ -23,7 +23,7 @@ import "./deployment-replicasets.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { ReplicaSet } from "../../api/endpoints";
|
||||
import type { ReplicaSet } from "../../../common/k8s-api/endpoints";
|
||||
import { KubeObjectMenu, KubeObjectMenuProps } from "../kube-object-menu";
|
||||
import { Spinner } from "../spinner";
|
||||
import { prevDefault, stopPropagation } from "../../utils";
|
||||
|
||||
@@ -24,8 +24,7 @@ import { render, waitFor, fireEvent } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
|
||||
import { DeploymentScaleDialog } from "./deployment-scale-dialog";
|
||||
jest.mock("../../api/endpoints");
|
||||
import { Deployment, deploymentApi } from "../../api/endpoints";
|
||||
import { Deployment, DeploymentApi } from "../../../common/k8s-api/endpoints/deployment.api";
|
||||
|
||||
const dummyDeployment: Deployment = {
|
||||
apiVersion: "v1",
|
||||
@@ -116,6 +115,13 @@ const dummyDeployment: Deployment = {
|
||||
};
|
||||
|
||||
describe("<DeploymentScaleDialog />", () => {
|
||||
let deploymentApi: DeploymentApi;
|
||||
|
||||
beforeEach(() => {
|
||||
deploymentApi = new DeploymentApi({
|
||||
objectConstructor: Deployment,
|
||||
});
|
||||
});
|
||||
|
||||
it("renders w/o errors", () => {
|
||||
const { container } = render(<DeploymentScaleDialog />);
|
||||
@@ -124,12 +130,12 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
});
|
||||
|
||||
it("inits with a dummy deployment with mocked current/desired scale", async () => {
|
||||
// mock deploymentApi.getReplicas() which will be called
|
||||
// mock deploymentApi.getReplicas() which will be called
|
||||
// when <DeploymentScaleDialog /> rendered.
|
||||
const initReplicas = 3;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const { getByTestId } = render(<DeploymentScaleDialog />);
|
||||
const { getByTestId } = render(<DeploymentScaleDialog deploymentApi={deploymentApi} />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
// we need to wait for the DeploymentScaleDialog to show up
|
||||
@@ -143,14 +149,14 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
expect(currentScale).toHaveTextContent(`${initReplicas}`);
|
||||
expect(desiredScale).toHaveTextContent(`${initReplicas}`);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
it("changes the desired scale when clicking the icon buttons +/-", async () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const component = render(<DeploymentScaleDialog />);
|
||||
const component = render(<DeploymentScaleDialog deploymentApi={deploymentApi} />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
await waitFor(async () => {
|
||||
|
||||
@@ -26,13 +26,14 @@ import { computed, observable, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { Dialog, DialogProps } from "../dialog";
|
||||
import { Wizard, WizardStep } from "../wizard";
|
||||
import { Deployment, deploymentApi } from "../../api/endpoints";
|
||||
import { Deployment, DeploymentApi, deploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import { Icon } from "../icon";
|
||||
import { Slider } from "../slider";
|
||||
import { Notifications } from "../notifications";
|
||||
import { cssNames } from "../../utils";
|
||||
|
||||
interface Props extends Partial<DialogProps> {
|
||||
deploymentApi: DeploymentApi
|
||||
}
|
||||
|
||||
const dialogState = observable.object({
|
||||
@@ -42,6 +43,10 @@ const dialogState = observable.object({
|
||||
|
||||
@observer
|
||||
export class DeploymentScaleDialog extends Component<Props> {
|
||||
static defaultProps = {
|
||||
deploymentApi
|
||||
};
|
||||
|
||||
@observable ready = false;
|
||||
@observable currentReplicas = 0;
|
||||
@observable desiredReplicas = 0;
|
||||
@@ -80,7 +85,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
onOpen = async () => {
|
||||
const { deployment } = this;
|
||||
|
||||
this.currentReplicas = await deploymentApi.getReplicas({
|
||||
this.currentReplicas = await this.props.deploymentApi.getReplicas({
|
||||
namespace: deployment.getNs(),
|
||||
name: deployment.getName(),
|
||||
});
|
||||
@@ -102,7 +107,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
|
||||
try {
|
||||
if (currentReplicas !== desiredReplicas) {
|
||||
await deploymentApi.scale({
|
||||
await this.props.deploymentApi.scale({
|
||||
name: deployment.getName(),
|
||||
namespace: deployment.getNs(),
|
||||
}, desiredReplicas);
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
import { makeObservable } from "mobx";
|
||||
|
||||
import { podsStore } from "../+workloads-pods/pods.store";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { Deployment, deploymentApi, PodStatus } from "../../api/endpoints";
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
import { Deployment, 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> {
|
||||
|
||||
@@ -24,7 +24,7 @@ import "./deployments.scss";
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { Deployment, deploymentApi } from "../../api/endpoints";
|
||||
import { Deployment, deploymentApi } from "../../../common/k8s-api/endpoints";
|
||||
import type { KubeObjectMenuProps } from "../kube-object-menu";
|
||||
import { MenuItem } from "../menu";
|
||||
import { Icon } from "../icon";
|
||||
|
||||
Reference in new issue
Block a user