From 58a446bd45f9ef21fe633e5cda1c695113d5b5c4 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Tue, 10 Aug 2021 13:26:14 +0300 Subject: [PATCH] Refactor k8s api to common (#3553) * refactor kube api to common Signed-off-by: Jari Kolehmainen * refactor more utils to common Signed-off-by: Jari Kolehmainen * refactor more utils to common Signed-off-by: Jari Kolehmainen * fix tests Signed-off-by: Jari Kolehmainen * switch to use node-fetch on both sides Signed-off-by: Jari Kolehmainen * cleanup Signed-off-by: Jari Kolehmainen * improve logger Signed-off-by: Jari Kolehmainen * fix lint errors Signed-off-by: Jari Kolehmainen * fix/improve tests Signed-off-by: Jari Kolehmainen * fix tests Signed-off-by: Jari Kolehmainen * fix node-fetch require error on prod build Signed-off-by: Jari Kolehmainen * preload fix Signed-off-by: Jari Kolehmainen * fixes Signed-off-by: Jari Kolehmainen * read serverAddress from apiBase Signed-off-by: Jari Kolehmainen * cleanup Signed-off-by: Jari Kolehmainen --- package.json | 3 + src/{renderer => common}/item.store.ts | 0 .../k8s-api}/__tests__/api-manager.test.ts | 2 +- .../k8s-api}/__tests__/crd.test.ts | 0 .../k8s-api}/__tests__/endpoint.api.test.ts | 0 .../k8s-api}/__tests__/kube-api-parse.test.ts | 0 .../k8s-api}/__tests__/kube-api.test.ts | 20 +++- .../k8s-api}/__tests__/kube-object.test.ts | 0 .../k8s-api}/__tests__/pods.api.test.ts | 0 .../k8s-api}/__tests__/pods.test.ts | 0 .../api => common/k8s-api}/api-manager.ts | 8 +- src/common/k8s-api/cluster-context.ts | 28 ++++++ .../endpoints/cluster-role-binding.api.ts | 18 +++- .../k8s-api}/endpoints/cluster-role.api.ts | 18 +++- .../k8s-api}/endpoints/cluster.api.ts | 18 +++- .../endpoints/component-status.api.ts | 0 .../k8s-api}/endpoints/configmap.api.ts | 20 +++- .../k8s-api}/endpoints/crd.api.ts | 22 ++++- .../k8s-api}/endpoints/cron-job.api.ts | 18 +++- .../k8s-api}/endpoints/daemon-set.api.ts | 18 +++- .../k8s-api}/endpoints/deployment.api.ts | 15 ++- .../k8s-api}/endpoints/endpoint.api.ts | 15 ++- .../k8s-api}/endpoints/events.api.ts | 15 ++- .../k8s-api}/endpoints/helm-charts.api.ts | 1 + .../k8s-api}/endpoints/helm-releases.api.ts | 4 +- .../k8s-api}/endpoints/hpa.api.ts | 15 ++- .../api => common/k8s-api}/endpoints/index.ts | 0 .../k8s-api}/endpoints/ingress.api.ts | 22 +++-- .../k8s-api}/endpoints/job.api.ts | 15 ++- .../k8s-api}/endpoints/limit-range.api.ts | 15 ++- .../k8s-api}/endpoints/metrics.api.ts | 0 .../k8s-api}/endpoints/namespaces.api.ts | 17 +++- .../k8s-api}/endpoints/network-policy.api.ts | 15 ++- .../k8s-api}/endpoints/nodes.api.ts | 17 +++- .../endpoints/persistent-volume-claims.api.ts | 15 ++- .../endpoints/persistent-volume.api.ts | 18 +++- .../k8s-api}/endpoints/pod-metrics.api.ts | 15 ++- .../endpoints/poddisruptionbudget.api.ts | 15 ++- .../k8s-api}/endpoints/pods.api.ts | 15 ++- .../endpoints/podsecuritypolicy.api.ts | 15 ++- .../k8s-api}/endpoints/replica-set.api.ts | 17 +++- .../endpoints/resource-applier.api.ts | 0 .../k8s-api}/endpoints/resource-quota.api.ts | 15 ++- .../k8s-api}/endpoints/role-binding.api.ts | 15 ++- .../k8s-api}/endpoints/role.api.ts | 15 ++- .../k8s-api}/endpoints/secret.api.ts | 15 ++- .../endpoints/selfsubjectrulesreviews.api.ts | 16 +++- .../endpoints/service-accounts.api.ts | 15 ++- .../k8s-api}/endpoints/service.api.ts | 17 +++- .../k8s-api}/endpoints/stateful-set.api.ts | 15 ++- .../k8s-api}/endpoints/storage-class.api.ts | 15 ++- src/common/k8s-api/index.ts | 67 +++++++++++++ .../api => common/k8s-api}/json-api.ts | 28 +++--- .../api => common/k8s-api}/kube-api-parse.ts | 6 +- .../api => common/k8s-api}/kube-api.ts | 30 ++---- .../api => common/k8s-api}/kube-json-api.ts | 2 + .../k8s-api}/kube-object.store.ts | 26 +++--- .../api => common/k8s-api}/kube-object.ts | 0 .../api => common/k8s-api}/kube-watch-api.ts | 6 +- .../k8s-api}/workload-kube-object.ts | 0 src/common/logger.ts | 81 ++++++++++++++++ .../utils/__tests__/formatDuration.test.ts | 0 src/common/utils/cluster-id-url-parsing.ts | 9 ++ src/{renderer => common}/utils/convertCpu.ts | 0 .../utils/convertMemory.ts | 0 .../utils/formatDuration.ts | 0 src/common/utils/index.ts | 3 + .../utils/readableStream.ts | 0 src/common/vars.ts | 1 + src/extensions/main-api/index.ts | 2 + src/extensions/main-api/k8s-api.ts | 60 ++++++++++++ src/extensions/renderer-api/k8s-api.ts | 72 +++++++------- src/main/helm/helm-chart-manager.ts | 2 +- src/main/helm/helm-service.ts | 2 +- src/main/k8s-request.ts | 2 +- src/main/lens-proxy.ts | 1 + src/main/logger.ts | 93 +------------------ src/main/window-manager.ts | 2 + src/preload.ts | 26 ++++++ src/renderer/api/index.ts | 19 ++-- .../+apps-helm-charts/helm-chart-details.tsx | 2 +- .../+apps-helm-charts/helm-chart.store.ts | 4 +- .../+apps-helm-charts/helm-charts.tsx | 2 +- .../+apps-releases/release-details.tsx | 6 +- .../+apps-releases/release-menu.tsx | 2 +- .../release-rollback-dialog.tsx | 2 +- .../+apps-releases/release.store.ts | 6 +- .../components/+apps-releases/releases.tsx | 2 +- .../+catalog/catalog-entity.store.tsx | 4 +- .../components/+cluster/cluster-issues.tsx | 6 +- .../components/+cluster/cluster-metrics.tsx | 2 +- .../+cluster/cluster-overview.store.ts | 8 +- .../+cluster/cluster-pie-charts.tsx | 2 +- .../+config-autoscalers/hpa-details.tsx | 4 +- .../+config-autoscalers/hpa.store.ts | 6 +- .../components/+config-autoscalers/hpa.tsx | 2 +- .../limit-range-details.tsx | 2 +- .../limit-ranges.store.ts | 6 +- .../+config-maps/config-map-details.tsx | 2 +- .../+config-maps/config-maps.store.ts | 6 +- .../pod-disruption-budgets-details.tsx | 2 +- .../pod-disruption-budgets.store.ts | 6 +- .../pod-disruption-budgets.tsx | 2 +- .../add-quota-dialog.tsx | 2 +- .../resource-quota-details.tsx | 2 +- .../resource-quotas.store.ts | 6 +- .../+config-secrets/add-secret-dialog.tsx | 4 +- .../+config-secrets/secret-details.tsx | 2 +- .../+config-secrets/secrets.store.ts | 6 +- .../+custom-resources/crd-details.tsx | 2 +- .../components/+custom-resources/crd-list.tsx | 2 +- .../crd-resource-details.tsx | 4 +- .../+custom-resources/crd-resource.store.ts | 6 +- .../+custom-resources/crd-resources.tsx | 4 +- .../components/+custom-resources/crd.store.ts | 10 +- .../components/+events/event-details.tsx | 4 +- .../components/+events/event.store.ts | 10 +- src/renderer/components/+events/events.tsx | 4 +- .../components/+events/kube-event-details.tsx | 2 +- .../components/+events/kube-event-icon.tsx | 4 +- .../+namespaces/add-namespace-dialog.tsx | 2 +- .../+namespaces/namespace-details.tsx | 2 +- .../+namespaces/namespace-select.tsx | 2 +- .../components/+namespaces/namespace.store.ts | 6 +- .../components/+namespaces/namespaces.tsx | 2 +- .../+network-endpoints/endpoint-details.tsx | 2 +- .../endpoint-subset-list.tsx | 4 +- .../+network-endpoints/endpoints.store.ts | 6 +- .../+network-ingresses/ingress-charts.tsx | 4 +- .../+network-ingresses/ingress-details.tsx | 4 +- .../+network-ingresses/ingress.store.ts | 6 +- .../network-policy-details.tsx | 2 +- .../+network-policies/network-policy.store.ts | 6 +- .../service-details-endpoint.tsx | 2 +- .../+network-services/service-details.tsx | 4 +- .../service-port-component.tsx | 2 +- .../+network-services/services.store.ts | 6 +- .../components/+nodes/node-charts.tsx | 6 +- .../+nodes/node-details-resources.tsx | 2 +- .../components/+nodes/node-details.tsx | 2 +- src/renderer/components/+nodes/nodes.store.ts | 6 +- src/renderer/components/+nodes/nodes.tsx | 6 +- .../pod-security-policies.store.ts | 6 +- .../pod-security-policy-details.tsx | 2 +- .../storage-class-details.tsx | 2 +- .../+storage-classes/storage-class.store.ts | 6 +- .../volume-claim-details.tsx | 2 +- .../volume-claim-disk-chart.tsx | 4 +- .../volume-claim.store.ts | 6 +- .../+storage-volume-claims/volume-claims.tsx | 4 +- .../+storage-volumes/volume-details-list.tsx | 2 +- .../+storage-volumes/volume-details.tsx | 2 +- .../+storage-volumes/volumes.store.ts | 8 +- .../components/+storage-volumes/volumes.tsx | 2 +- .../+cluster-role-bindings/details.tsx | 2 +- .../+cluster-role-bindings/dialog.tsx | 2 +- .../+cluster-role-bindings/hashers.ts | 2 +- .../+cluster-role-bindings/store.ts | 6 +- .../+cluster-roles/details.tsx | 2 +- .../+user-management/+cluster-roles/store.ts | 6 +- .../+role-bindings/details.tsx | 2 +- .../+role-bindings/dialog.tsx | 2 +- .../+role-bindings/hashers.ts | 2 +- .../+user-management/+role-bindings/store.ts | 6 +- .../+user-management/+roles/details.tsx | 2 +- .../+user-management/+roles/store.ts | 6 +- .../+service-accounts/details.tsx | 2 +- .../+service-accounts/secret.tsx | 2 +- .../+service-accounts/store.ts | 6 +- .../+service-accounts/view.tsx | 2 +- .../+user-management/select-options.tsx | 4 +- .../+workloads-cronjobs/cronjob-details.tsx | 4 +- .../cronjob-trigger-dialog.tsx | 4 +- .../+workloads-cronjobs/cronjob.store.ts | 6 +- .../+workloads-cronjobs/cronjobs.tsx | 2 +- .../daemonset-details.tsx | 2 +- .../+workloads-daemonsets/daemonsets.store.ts | 6 +- .../+workloads-daemonsets/daemonsets.tsx | 2 +- .../deployment-details.tsx | 2 +- .../deployment-replicasets.tsx | 2 +- .../deployment-scale-dialog.test.tsx | 18 ++-- .../deployment-scale-dialog.tsx | 11 ++- .../deployments.store.ts | 6 +- .../+workloads-deployments/deployments.tsx | 2 +- .../+workloads-jobs/job-details.tsx | 4 +- .../components/+workloads-jobs/job.store.ts | 8 +- .../+workloads-overview/overview.tsx | 2 +- .../__tests__/pod-tolerations.test.tsx | 2 +- .../+workloads-pods/container-charts.tsx | 4 +- .../components/+workloads-pods/pod-charts.tsx | 6 +- .../+workloads-pods/pod-container-env.tsx | 2 +- .../+workloads-pods/pod-container-port.tsx | 2 +- .../pod-details-affinities.tsx | 2 +- .../+workloads-pods/pod-details-container.tsx | 4 +- .../+workloads-pods/pod-details-list.tsx | 4 +- .../+workloads-pods/pod-details-secrets.tsx | 2 +- .../+workloads-pods/pod-details-statuses.tsx | 2 +- .../pod-details-tolerations.tsx | 2 +- .../+workloads-pods/pod-details.tsx | 4 +- .../+workloads-pods/pod-tolerations.tsx | 2 +- .../components/+workloads-pods/pods.store.ts | 8 +- .../components/+workloads-pods/pods.tsx | 4 +- .../replicaset-details.tsx | 2 +- .../replicaset-scale-dialog.test.tsx | 17 +++- .../replicaset-scale-dialog.tsx | 11 ++- .../replicasets.store.ts | 8 +- .../+workloads-replicasets/replicasets.tsx | 2 +- .../statefulset-details.tsx | 2 +- .../statefulset-scale-dialog.test.tsx | 17 +++- .../statefulset-scale-dialog.tsx | 10 +- .../statefulset.store.ts | 6 +- .../+workloads-statefulsets/statefulsets.tsx | 2 +- .../components/+workloads/workloads.stores.ts | 4 +- .../__tests__/cronjob.store.test.ts | 2 +- .../__tests__/daemonset.store.test.ts | 2 +- .../__tests__/deployments.store.test.ts | 2 +- .../components/__tests__/job.store.test.ts | 2 +- .../components/__tests__/pods.store.test.ts | 2 +- .../__tests__/replicaset.store.test.ts | 2 +- .../__tests__/statefulset.store.test.ts | 2 +- src/renderer/components/app.tsx | 4 +- .../components/cluster-prometheus-setting.tsx | 2 +- src/renderer/components/context.ts | 7 +- .../__test__/log-resource-selector.test.tsx | 2 +- .../dock/__test__/log-tab.store.test.ts | 2 +- .../components/dock/create-resource.tsx | 4 +- .../components/dock/edit-resource.store.ts | 6 +- .../components/dock/edit-resource.tsx | 2 +- .../components/dock/install-chart.store.ts | 4 +- src/renderer/components/dock/log-controls.tsx | 2 +- .../components/dock/log-resource-selector.tsx | 2 +- src/renderer/components/dock/log-tab.store.ts | 4 +- src/renderer/components/dock/log.store.ts | 2 +- .../components/dock/upgrade-chart.store.ts | 2 +- .../components/dock/upgrade-chart.tsx | 2 +- .../item-object-list/item-list-layout.tsx | 2 +- .../kube-object-details.tsx | 4 +- .../kube-object-list-layout.tsx | 8 +- .../kube-object-menu/kube-object-menu.tsx | 4 +- .../kube-object-meta/kube-object-meta.tsx | 4 +- .../kubeconfig-dialog/kubeconfig-dialog.tsx | 2 +- .../notifications/notifications.store.tsx | 2 +- .../notifications/notifications.tsx | 2 +- .../resource-metrics-text.tsx | 4 +- .../resource-metrics/resource-metrics.tsx | 2 +- src/renderer/components/table/table-row.tsx | 2 +- .../components/virtual-list/virtual-list.tsx | 2 +- src/renderer/utils/index.ts | 5 +- webpack.main.ts | 47 +++++++++- yarn.lock | 32 ++++++- 250 files changed, 1244 insertions(+), 644 deletions(-) rename src/{renderer => common}/item.store.ts (100%) rename src/{renderer/api => common/k8s-api}/__tests__/api-manager.test.ts (96%) rename src/{renderer/api => common/k8s-api}/__tests__/crd.test.ts (100%) rename src/{renderer/api => common/k8s-api}/__tests__/endpoint.api.test.ts (100%) rename src/{renderer/api => common/k8s-api}/__tests__/kube-api-parse.test.ts (100%) rename src/{renderer/api => common/k8s-api}/__tests__/kube-api.test.ts (84%) rename src/{renderer/api => common/k8s-api}/__tests__/kube-object.test.ts (100%) rename src/{renderer/api => common/k8s-api}/__tests__/pods.api.test.ts (100%) rename src/{renderer/api => common/k8s-api}/__tests__/pods.test.ts (100%) rename src/{renderer/api => common/k8s-api}/api-manager.ts (95%) create mode 100644 src/common/k8s-api/cluster-context.ts rename src/{renderer/api => common/k8s-api}/endpoints/cluster-role-binding.api.ts (84%) rename src/{renderer/api => common/k8s-api}/endpoints/cluster-role.api.ts (80%) rename src/{renderer/api => common/k8s-api}/endpoints/cluster.api.ts (90%) rename src/{renderer/api => common/k8s-api}/endpoints/component-status.api.ts (100%) rename src/{renderer/api => common/k8s-api}/endpoints/configmap.api.ts (82%) rename src/{renderer/api => common/k8s-api}/endpoints/crd.api.ts (91%) rename src/{renderer/api => common/k8s-api}/endpoints/cron-job.api.ts (93%) rename src/{renderer/api => common/k8s-api}/endpoints/daemon-set.api.ts (92%) rename src/{renderer/api => common/k8s-api}/endpoints/deployment.api.ts (96%) rename src/{renderer/api => common/k8s-api}/endpoints/endpoint.api.ts (93%) rename src/{renderer/api => common/k8s-api}/endpoints/events.api.ts (90%) rename src/{renderer/api => common/k8s-api}/endpoints/helm-charts.api.ts (98%) rename src/{renderer/api => common/k8s-api}/endpoints/helm-releases.api.ts (97%) rename src/{renderer/api => common/k8s-api}/endpoints/hpa.api.ts (94%) rename src/{renderer/api => common/k8s-api}/endpoints/index.ts (100%) rename src/{renderer/api => common/k8s-api}/endpoints/ingress.api.ts (93%) rename src/{renderer/api => common/k8s-api}/endpoints/job.api.ts (95%) rename src/{renderer/api => common/k8s-api}/endpoints/limit-range.api.ts (90%) rename src/{renderer/api => common/k8s-api}/endpoints/metrics.api.ts (100%) rename src/{renderer/api => common/k8s-api}/endpoints/namespaces.api.ts (88%) rename src/{renderer/api => common/k8s-api}/endpoints/network-policy.api.ts (90%) rename src/{renderer/api => common/k8s-api}/endpoints/nodes.api.ts (96%) rename src/{renderer/api => common/k8s-api}/endpoints/persistent-volume-claims.api.ts (93%) rename src/{renderer/api => common/k8s-api}/endpoints/persistent-volume.api.ts (89%) rename src/{renderer/api => common/k8s-api}/endpoints/pod-metrics.api.ts (85%) rename src/{renderer/api => common/k8s-api}/endpoints/poddisruptionbudget.api.ts (90%) rename src/{renderer/api => common/k8s-api}/endpoints/pods.api.ts (98%) rename src/{renderer/api => common/k8s-api}/endpoints/podsecuritypolicy.api.ts (93%) rename src/{renderer/api => common/k8s-api}/endpoints/replica-set.api.ts (92%) rename src/{renderer/api => common/k8s-api}/endpoints/resource-applier.api.ts (100%) rename src/{renderer/api => common/k8s-api}/endpoints/resource-quota.api.ts (90%) rename src/{renderer/api => common/k8s-api}/endpoints/role-binding.api.ts (89%) rename src/{renderer/api => common/k8s-api}/endpoints/role.api.ts (87%) rename src/{renderer/api => common/k8s-api}/endpoints/secret.api.ts (90%) rename src/{renderer/api => common/k8s-api}/endpoints/selfsubjectrulesreviews.api.ts (89%) rename src/{renderer/api => common/k8s-api}/endpoints/service-accounts.api.ts (86%) rename src/{renderer/api => common/k8s-api}/endpoints/service.api.ts (92%) rename src/{renderer/api => common/k8s-api}/endpoints/stateful-set.api.ts (94%) rename src/{renderer/api => common/k8s-api}/endpoints/storage-class.api.ts (89%) create mode 100644 src/common/k8s-api/index.ts rename src/{renderer/api => common/k8s-api}/json-api.ts (85%) rename src/{renderer/api => common/k8s-api}/kube-api-parse.ts (96%) rename src/{renderer/api => common/k8s-api}/kube-api.ts (95%) rename src/{renderer/api => common/k8s-api}/kube-json-api.ts (98%) rename src/{renderer => common/k8s-api}/kube-object.store.ts (94%) rename src/{renderer/api => common/k8s-api}/kube-object.ts (100%) rename src/{renderer/api => common/k8s-api}/kube-watch-api.ts (96%) rename src/{renderer/api => common/k8s-api}/workload-kube-object.ts (100%) create mode 100644 src/common/logger.ts rename src/{renderer => common}/utils/__tests__/formatDuration.test.ts (100%) rename src/{renderer => common}/utils/convertCpu.ts (100%) rename src/{renderer => common}/utils/convertMemory.ts (100%) rename src/{renderer => common}/utils/formatDuration.ts (100%) rename src/{renderer => common}/utils/readableStream.ts (100%) create mode 100644 src/extensions/main-api/k8s-api.ts create mode 100644 src/preload.ts diff --git a/package.json b/package.json index 2dd48e4e54..b6c81ba3b5 100644 --- a/package.json +++ b/package.json @@ -221,6 +221,7 @@ "mock-fs": "^4.14.0", "moment": "^2.29.1", "moment-timezone": "^0.5.33", + "node-fetch": "^2.6.1", "node-pty": "^0.10.1", "npm": "^6.14.8", "openid-client": "^3.15.2", @@ -245,6 +246,7 @@ "uuid": "^8.3.2", "win-ca": "^3.2.0", "winston": "^3.3.3", + "winston-console-format": "^1.0.8", "winston-transport-browserconsole": "^1.0.5", "ws": "^7.4.6" }, @@ -283,6 +285,7 @@ "@types/mock-fs": "^4.13.1", "@types/module-alias": "^2.0.0", "@types/node": "12.20", + "@types/node-fetch": "^2.5.12", "@types/npm": "^2.0.31", "@types/progress-bar-webpack-plugin": "^2.1.2", "@types/proper-lockfile": "^4.1.1", diff --git a/src/renderer/item.store.ts b/src/common/item.store.ts similarity index 100% rename from src/renderer/item.store.ts rename to src/common/item.store.ts diff --git a/src/renderer/api/__tests__/api-manager.test.ts b/src/common/k8s-api/__tests__/api-manager.test.ts similarity index 96% rename from src/renderer/api/__tests__/api-manager.test.ts rename to src/common/k8s-api/__tests__/api-manager.test.ts index 83034d20b6..27c2575341 100644 --- a/src/renderer/api/__tests__/api-manager.test.ts +++ b/src/common/k8s-api/__tests__/api-manager.test.ts @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { ingressStore } from "../../components/+network-ingresses/ingress.store"; +import { ingressStore } from "../../../renderer/components/+network-ingresses/ingress.store"; import { apiManager } from "../api-manager"; import { KubeApi } from "../kube-api"; import { KubeObject } from "../kube-object"; diff --git a/src/renderer/api/__tests__/crd.test.ts b/src/common/k8s-api/__tests__/crd.test.ts similarity index 100% rename from src/renderer/api/__tests__/crd.test.ts rename to src/common/k8s-api/__tests__/crd.test.ts diff --git a/src/renderer/api/__tests__/endpoint.api.test.ts b/src/common/k8s-api/__tests__/endpoint.api.test.ts similarity index 100% rename from src/renderer/api/__tests__/endpoint.api.test.ts rename to src/common/k8s-api/__tests__/endpoint.api.test.ts diff --git a/src/renderer/api/__tests__/kube-api-parse.test.ts b/src/common/k8s-api/__tests__/kube-api-parse.test.ts similarity index 100% rename from src/renderer/api/__tests__/kube-api-parse.test.ts rename to src/common/k8s-api/__tests__/kube-api-parse.test.ts diff --git a/src/renderer/api/__tests__/kube-api.test.ts b/src/common/k8s-api/__tests__/kube-api.test.ts similarity index 84% rename from src/renderer/api/__tests__/kube-api.test.ts rename to src/common/k8s-api/__tests__/kube-api.test.ts index 1eb0199f89..1e1bac05fe 100644 --- a/src/renderer/api/__tests__/kube-api.test.ts +++ b/src/common/k8s-api/__tests__/kube-api.test.ts @@ -20,12 +20,22 @@ */ import { KubeApi } from "../kube-api"; +import { KubeJsonApi } from "../kube-json-api"; import { KubeObject } from "../kube-object"; describe("KubeApi", () => { + let request: KubeJsonApi; + + beforeEach(() => { + request = new KubeJsonApi({ + serverAddress: `http://127.0.0.1:9999`, + apiBase: "/api-kube" + }); + }); + it("uses url from apiBase if apiBase contains the resource", async () => { (fetch as any).mockResponse(async (request: any) => { - if (request.url === "/api-kube/apis/networking.k8s.io/v1") { + if (request.url === "http://127.0.0.1:9999/api-kube/apis/networking.k8s.io/v1") { return { body: JSON.stringify({ resources: [{ @@ -33,7 +43,7 @@ describe("KubeApi", () => { }] as any[] }) }; - } else if (request.url === "/api-kube/apis/extensions/v1beta1") { + } else if (request.url === "http://127.0.0.1:9999/api-kube/apis/extensions/v1beta1") { // Even if the old API contains ingresses, KubeApi should prefer the apiBase url return { body: JSON.stringify({ @@ -54,6 +64,7 @@ describe("KubeApi", () => { const apiBase = "/apis/networking.k8s.io/v1/ingresses"; const fallbackApiBase = "/apis/extensions/v1beta1/ingresses"; const kubeApi = new KubeApi({ + request, objectConstructor: KubeObject, apiBase, fallbackApiBases: [fallbackApiBase], @@ -67,13 +78,13 @@ describe("KubeApi", () => { it("uses url from fallbackApiBases if apiBase lacks the resource", async () => { (fetch as any).mockResponse(async (request: any) => { - if (request.url === "/api-kube/apis/networking.k8s.io/v1") { + if (request.url === "http://127.0.0.1:9999/api-kube/apis/networking.k8s.io/v1") { return { body: JSON.stringify({ resources: [] as any[] }) }; - } else if (request.url === "/api-kube/apis/extensions/v1beta1") { + } else if (request.url === "http://127.0.0.1:9999/api-kube/apis/extensions/v1beta1") { return { body: JSON.stringify({ resources: [{ @@ -93,6 +104,7 @@ describe("KubeApi", () => { const apiBase = "apis/networking.k8s.io/v1/ingresses"; const fallbackApiBase = "/apis/extensions/v1beta1/ingresses"; const kubeApi = new KubeApi({ + request, objectConstructor: KubeObject, apiBase, fallbackApiBases: [fallbackApiBase], diff --git a/src/renderer/api/__tests__/kube-object.test.ts b/src/common/k8s-api/__tests__/kube-object.test.ts similarity index 100% rename from src/renderer/api/__tests__/kube-object.test.ts rename to src/common/k8s-api/__tests__/kube-object.test.ts diff --git a/src/renderer/api/__tests__/pods.api.test.ts b/src/common/k8s-api/__tests__/pods.api.test.ts similarity index 100% rename from src/renderer/api/__tests__/pods.api.test.ts rename to src/common/k8s-api/__tests__/pods.api.test.ts diff --git a/src/renderer/api/__tests__/pods.test.ts b/src/common/k8s-api/__tests__/pods.test.ts similarity index 100% rename from src/renderer/api/__tests__/pods.test.ts rename to src/common/k8s-api/__tests__/pods.test.ts diff --git a/src/renderer/api/api-manager.ts b/src/common/k8s-api/api-manager.ts similarity index 95% rename from src/renderer/api/api-manager.ts rename to src/common/k8s-api/api-manager.ts index e11fd9a07b..3070f932be 100644 --- a/src/renderer/api/api-manager.ts +++ b/src/common/k8s-api/api-manager.ts @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { KubeObjectStore } from "../kube-object.store"; +import type { KubeObjectStore } from "./kube-object.store"; import { action, observable, makeObservable } from "mobx"; import { autoBind, iter } from "../utils"; @@ -49,6 +49,8 @@ export class ApiManager { } registerApi(apiBase: string, api: KubeApi) { + if (!api.apiBase) return; + if (!this.apis.has(apiBase)) { this.stores.forEach((store) => { if (store.api === api) { @@ -84,8 +86,8 @@ export class ApiManager { @action registerStore(store: KubeObjectStore, apis: KubeApi[] = [store.api]) { - apis.forEach(api => { - this.stores.set(api.apiBase, store); + apis.filter(Boolean).forEach(api => { + if (api.apiBase) this.stores.set(api.apiBase, store); }); } diff --git a/src/common/k8s-api/cluster-context.ts b/src/common/k8s-api/cluster-context.ts new file mode 100644 index 0000000000..596e658bde --- /dev/null +++ b/src/common/k8s-api/cluster-context.ts @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import type { Cluster } from "../../main/cluster"; + +export interface ClusterContext { + cluster?: Cluster; + allNamespaces: string[]; // available / allowed namespaces from cluster.ts + contextNamespaces: string[]; // selected by user (see: namespace-select.tsx) +} diff --git a/src/renderer/api/endpoints/cluster-role-binding.api.ts b/src/common/k8s-api/endpoints/cluster-role-binding.api.ts similarity index 84% rename from src/renderer/api/endpoints/cluster-role-binding.api.ts rename to src/common/k8s-api/endpoints/cluster-role-binding.api.ts index 868f00261a..1508e3716f 100644 --- a/src/renderer/api/endpoints/cluster-role-binding.api.ts +++ b/src/common/k8s-api/endpoints/cluster-role-binding.api.ts @@ -18,6 +18,7 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { KubeApi } from "../kube-api"; import { KubeObject } from "../kube-object"; @@ -53,6 +54,17 @@ export class ClusterRoleBinding extends KubeObject { } } -export const clusterRoleBindingApi = new KubeApi({ - objectConstructor: ClusterRoleBinding, -}); +/** + * Only available within kubernetes cluster pages + */ +let clusterRoleBindingApi: KubeApi; + +if (isClusterPageContext()) { + clusterRoleBindingApi = new KubeApi({ + objectConstructor: ClusterRoleBinding, + }); +} + +export { + clusterRoleBindingApi +}; diff --git a/src/renderer/api/endpoints/cluster-role.api.ts b/src/common/k8s-api/endpoints/cluster-role.api.ts similarity index 80% rename from src/renderer/api/endpoints/cluster-role.api.ts rename to src/common/k8s-api/endpoints/cluster-role.api.ts index 55a2f5283d..1478e7dcd1 100644 --- a/src/renderer/api/endpoints/cluster-role.api.ts +++ b/src/common/k8s-api/endpoints/cluster-role.api.ts @@ -19,6 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; import { KubeApi } from "../kube-api"; import { KubeObject } from "../kube-object"; @@ -41,6 +42,17 @@ export class ClusterRole extends KubeObject { } } -export const clusterRoleApi = new KubeApi({ - objectConstructor: ClusterRole, -}); +/** + * Only available within kubernetes cluster pages + */ +let clusterRoleApi: KubeApi; + +if (isClusterPageContext()) { // initialize automatically only when within a cluster iframe/context + clusterRoleApi = new KubeApi({ + objectConstructor: ClusterRole, + }); +} + +export { + clusterRoleApi +}; diff --git a/src/renderer/api/endpoints/cluster.api.ts b/src/common/k8s-api/endpoints/cluster.api.ts similarity index 90% rename from src/renderer/api/endpoints/cluster.api.ts rename to src/common/k8s-api/endpoints/cluster.api.ts index f0879fa501..66fc1a8c5f 100644 --- a/src/renderer/api/endpoints/cluster.api.ts +++ b/src/common/k8s-api/endpoints/cluster.api.ts @@ -22,6 +22,7 @@ import { IMetrics, IMetricsReqParams, metricsApi } from "./metrics.api"; import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class ClusterApi extends KubeApi { static kind = "Cluster"; @@ -122,6 +123,17 @@ export class Cluster extends KubeObject { } } -export const clusterApi = new ClusterApi({ - objectConstructor: Cluster, -}); +/** + * Only available within kubernetes cluster pages + */ +let clusterApi: ClusterApi; + +if (isClusterPageContext()) { // initialize automatically only when within a cluster iframe/context + clusterApi = new ClusterApi({ + objectConstructor: Cluster, + }); +} + +export { + clusterApi +}; diff --git a/src/renderer/api/endpoints/component-status.api.ts b/src/common/k8s-api/endpoints/component-status.api.ts similarity index 100% rename from src/renderer/api/endpoints/component-status.api.ts rename to src/common/k8s-api/endpoints/component-status.api.ts diff --git a/src/renderer/api/endpoints/configmap.api.ts b/src/common/k8s-api/endpoints/configmap.api.ts similarity index 82% rename from src/renderer/api/endpoints/configmap.api.ts rename to src/common/k8s-api/endpoints/configmap.api.ts index 5087f352ca..153e1a3169 100644 --- a/src/renderer/api/endpoints/configmap.api.ts +++ b/src/common/k8s-api/endpoints/configmap.api.ts @@ -22,7 +22,8 @@ import { KubeObject } from "../kube-object"; import type { KubeJsonApiData } from "../kube-json-api"; import { KubeApi } from "../kube-api"; -import { autoBind } from "../../../common/utils"; +import { autoBind } from "../../utils"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface ConfigMap { data: { @@ -47,6 +48,17 @@ export class ConfigMap extends KubeObject { } } -export const configMapApi = new KubeApi({ - objectConstructor: ConfigMap, -}); +/** + * Only available within kubernetes cluster pages + */ +let configMapApi: KubeApi; + +if (isClusterPageContext()) { + configMapApi = new KubeApi({ + objectConstructor: ConfigMap, + }); +} + +export { + configMapApi +}; diff --git a/src/renderer/api/endpoints/crd.api.ts b/src/common/k8s-api/endpoints/crd.api.ts similarity index 91% rename from src/renderer/api/endpoints/crd.api.ts rename to src/common/k8s-api/endpoints/crd.api.ts index 35f85b8832..b1ab179cc4 100644 --- a/src/renderer/api/endpoints/crd.api.ts +++ b/src/common/k8s-api/endpoints/crd.api.ts @@ -21,7 +21,8 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; -import { crdResourcesURL } from "../../../common/routes"; +import { crdResourcesURL } from "../../routes"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; type AdditionalPrinterColumnsCommon = { name: string; @@ -174,7 +175,18 @@ export class CustomResourceDefinition extends KubeObject { } } -export const crdApi = new KubeApi({ - objectConstructor: CustomResourceDefinition, - checkPreferredVersion: true, -}); +/** + * Only available within kubernetes cluster pages + */ +let crdApi: KubeApi; + +if (isClusterPageContext()) { + crdApi = new KubeApi({ + objectConstructor: CustomResourceDefinition, + checkPreferredVersion: true, + }); +} + +export { + crdApi +}; diff --git a/src/renderer/api/endpoints/cron-job.api.ts b/src/common/k8s-api/endpoints/cron-job.api.ts similarity index 93% rename from src/renderer/api/endpoints/cron-job.api.ts rename to src/common/k8s-api/endpoints/cron-job.api.ts index 43743b2bb4..85936e4d32 100644 --- a/src/renderer/api/endpoints/cron-job.api.ts +++ b/src/common/k8s-api/endpoints/cron-job.api.ts @@ -26,6 +26,7 @@ import { formatDuration } from "../../utils/formatDuration"; import { autoBind } from "../../utils"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class CronJobApi extends KubeApi { suspend(params: { namespace: string; name: string }) { @@ -140,6 +141,17 @@ export class CronJob extends KubeObject { } } -export const cronJobApi = new CronJobApi({ - objectConstructor: CronJob, -}); +/** + * Only available within kubernetes cluster pages + */ +let cronJobApi: CronJobApi; + +if (isClusterPageContext()) { + cronJobApi = new CronJobApi({ + objectConstructor: CronJob, + }); +} + +export { + cronJobApi +}; diff --git a/src/renderer/api/endpoints/daemon-set.api.ts b/src/common/k8s-api/endpoints/daemon-set.api.ts similarity index 92% rename from src/renderer/api/endpoints/daemon-set.api.ts rename to src/common/k8s-api/endpoints/daemon-set.api.ts index cb584806d4..4cd3eff4f4 100644 --- a/src/renderer/api/endpoints/daemon-set.api.ts +++ b/src/common/k8s-api/endpoints/daemon-set.api.ts @@ -26,6 +26,7 @@ import { KubeApi } from "../kube-api"; import { metricsApi } from "./metrics.api"; import type { KubeJsonApiData } from "../kube-json-api"; import type { IPodContainer, IPodMetrics } from "./pods.api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class DaemonSet extends WorkloadKubeObject { static kind = "DaemonSet"; @@ -116,6 +117,17 @@ export function getMetricsForDaemonSets(daemonsets: DaemonSet[], namespace: stri }); } -export const daemonSetApi = new DaemonSetApi({ - objectConstructor: DaemonSet, -}); +/** + * Only available within kubernetes cluster pages + */ +let daemonSetApi: DaemonSetApi; + +if (isClusterPageContext()) { + daemonSetApi = new DaemonSetApi({ + objectConstructor: DaemonSet, + }); +} + +export { + daemonSetApi +}; diff --git a/src/renderer/api/endpoints/deployment.api.ts b/src/common/k8s-api/endpoints/deployment.api.ts similarity index 96% rename from src/renderer/api/endpoints/deployment.api.ts rename to src/common/k8s-api/endpoints/deployment.api.ts index 0d5bef48dd..dd364ab6c2 100644 --- a/src/renderer/api/endpoints/deployment.api.ts +++ b/src/common/k8s-api/endpoints/deployment.api.ts @@ -27,6 +27,7 @@ import { KubeApi } from "../kube-api"; import { metricsApi } from "./metrics.api"; import type { IPodMetrics } from "./pods.api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class DeploymentApi extends KubeApi { protected getScaleApiUrl(params: { namespace: string; name: string }) { @@ -232,6 +233,14 @@ export class Deployment extends WorkloadKubeObject { } } -export const deploymentApi = new DeploymentApi({ - objectConstructor: Deployment, -}); +let deploymentApi: DeploymentApi; + +if (isClusterPageContext()) { + deploymentApi = new DeploymentApi({ + objectConstructor: Deployment, + }); +} + +export { + deploymentApi +}; diff --git a/src/renderer/api/endpoints/endpoint.api.ts b/src/common/k8s-api/endpoints/endpoint.api.ts similarity index 93% rename from src/renderer/api/endpoints/endpoint.api.ts rename to src/common/k8s-api/endpoints/endpoint.api.ts index 14bc399062..e6dceb2b8f 100644 --- a/src/renderer/api/endpoints/endpoint.api.ts +++ b/src/common/k8s-api/endpoints/endpoint.api.ts @@ -24,6 +24,7 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; import { get } from "lodash"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface IEndpointPort { name?: string; @@ -149,6 +150,14 @@ export class Endpoint extends KubeObject { } -export const endpointApi = new KubeApi({ - objectConstructor: Endpoint, -}); +let endpointApi: KubeApi; + +if (isClusterPageContext()) { + endpointApi = new KubeApi({ + objectConstructor: Endpoint, + }); +} + +export { + endpointApi +}; diff --git a/src/renderer/api/endpoints/events.api.ts b/src/common/k8s-api/endpoints/events.api.ts similarity index 90% rename from src/renderer/api/endpoints/events.api.ts rename to src/common/k8s-api/endpoints/events.api.ts index ad194a532a..f6b954be6b 100644 --- a/src/renderer/api/endpoints/events.api.ts +++ b/src/common/k8s-api/endpoints/events.api.ts @@ -23,6 +23,7 @@ import moment from "moment"; import { KubeObject } from "../kube-object"; import { formatDuration } from "../../utils/formatDuration"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface KubeEvent { involvedObject: { @@ -77,6 +78,14 @@ export class KubeEvent extends KubeObject { } } -export const eventApi = new KubeApi({ - objectConstructor: KubeEvent, -}); +let eventApi: KubeApi; + +if (isClusterPageContext()) { + eventApi = new KubeApi({ + objectConstructor: KubeEvent, + }); +} + +export { + eventApi +}; diff --git a/src/renderer/api/endpoints/helm-charts.api.ts b/src/common/k8s-api/endpoints/helm-charts.api.ts similarity index 98% rename from src/renderer/api/endpoints/helm-charts.api.ts rename to src/common/k8s-api/endpoints/helm-charts.api.ts index 2244bca1f2..c7bc662b75 100644 --- a/src/renderer/api/endpoints/helm-charts.api.ts +++ b/src/common/k8s-api/endpoints/helm-charts.api.ts @@ -23,6 +23,7 @@ import { compile } from "path-to-regexp"; import { apiBase } from "../index"; import { stringify } from "querystring"; import { autoBind } from "../../utils"; +import type { RequestInit } from "node-fetch"; export type RepoHelmChartList = Record; export type HelmChartList = Record; diff --git a/src/renderer/api/endpoints/helm-releases.api.ts b/src/common/k8s-api/endpoints/helm-releases.api.ts similarity index 97% rename from src/renderer/api/endpoints/helm-releases.api.ts rename to src/common/k8s-api/endpoints/helm-releases.api.ts index 9a4a05875c..301e077e4e 100644 --- a/src/renderer/api/endpoints/helm-releases.api.ts +++ b/src/common/k8s-api/endpoints/helm-releases.api.ts @@ -23,11 +23,11 @@ import jsYaml from "js-yaml"; import { autoBind, formatDuration } from "../../utils"; import capitalize from "lodash/capitalize"; import { apiBase } from "../index"; -import { helmChartStore } from "../../components/+apps-helm-charts/helm-chart.store"; +import { helmChartStore } from "../../../renderer/components/+apps-helm-charts/helm-chart.store"; import type { ItemObject } from "../../item.store"; import { KubeObject } from "../kube-object"; import type { JsonApiData } from "../json-api"; -import { buildURLPositional } from "../../../common/utils/buildUrl"; +import { buildURLPositional } from "../../utils/buildUrl"; import type { KubeJsonApiData } from "../kube-json-api"; interface IReleasePayload { diff --git a/src/renderer/api/endpoints/hpa.api.ts b/src/common/k8s-api/endpoints/hpa.api.ts similarity index 94% rename from src/renderer/api/endpoints/hpa.api.ts rename to src/common/k8s-api/endpoints/hpa.api.ts index dba89d4111..4a217d23f1 100644 --- a/src/renderer/api/endpoints/hpa.api.ts +++ b/src/common/k8s-api/endpoints/hpa.api.ts @@ -21,6 +21,7 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export enum HpaMetricType { Resource = "Resource", @@ -163,6 +164,14 @@ export class HorizontalPodAutoscaler extends KubeObject { } } -export const hpaApi = new KubeApi({ - objectConstructor: HorizontalPodAutoscaler, -}); +let hpaApi: KubeApi; + +if (isClusterPageContext()) { + hpaApi = new KubeApi({ + objectConstructor: HorizontalPodAutoscaler, + }); +} + +export { + hpaApi +}; diff --git a/src/renderer/api/endpoints/index.ts b/src/common/k8s-api/endpoints/index.ts similarity index 100% rename from src/renderer/api/endpoints/index.ts rename to src/common/k8s-api/endpoints/index.ts diff --git a/src/renderer/api/endpoints/ingress.api.ts b/src/common/k8s-api/endpoints/ingress.api.ts similarity index 93% rename from src/renderer/api/endpoints/ingress.api.ts rename to src/common/k8s-api/endpoints/ingress.api.ts index 31745f30c4..5a1a404f20 100644 --- a/src/renderer/api/endpoints/ingress.api.ts +++ b/src/common/k8s-api/endpoints/ingress.api.ts @@ -24,6 +24,7 @@ import { autoBind } from "../../utils"; import { IMetrics, metricsApi } from "./metrics.api"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class IngressApi extends KubeApi { } @@ -203,10 +204,17 @@ export class Ingress extends KubeObject { } } -export const ingressApi = new IngressApi({ - objectConstructor: Ingress, - // Add fallback for Kubernetes <1.19 - checkPreferredVersion: true, - fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"], - logStuff: true -} as any); +let ingressApi: IngressApi; + +if (isClusterPageContext()) { + ingressApi = new IngressApi({ + objectConstructor: Ingress, + // Add fallback for Kubernetes <1.19 + checkPreferredVersion: true, + fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"], + }); +} + +export { + ingressApi +}; diff --git a/src/renderer/api/endpoints/job.api.ts b/src/common/k8s-api/endpoints/job.api.ts similarity index 95% rename from src/renderer/api/endpoints/job.api.ts rename to src/common/k8s-api/endpoints/job.api.ts index 823a04bef9..539e3dc902 100644 --- a/src/renderer/api/endpoints/job.api.ts +++ b/src/common/k8s-api/endpoints/job.api.ts @@ -27,6 +27,7 @@ import { metricsApi } from "./metrics.api"; import type { JsonApiParams } from "../json-api"; import type { KubeJsonApiData } from "../kube-json-api"; import type { IPodContainer, IPodMetrics } from "./pods.api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class Job extends WorkloadKubeObject { static kind = "Job"; @@ -148,6 +149,14 @@ export function getMetricsForJobs(jobs: Job[], namespace: string, selector = "") }); } -export const jobApi = new JobApi({ - objectConstructor: Job, -}); +let jobApi: JobApi; + +if (isClusterPageContext()) { + jobApi = new JobApi({ + objectConstructor: Job, + }); +} + +export { + jobApi +}; diff --git a/src/renderer/api/endpoints/limit-range.api.ts b/src/common/k8s-api/endpoints/limit-range.api.ts similarity index 90% rename from src/renderer/api/endpoints/limit-range.api.ts rename to src/common/k8s-api/endpoints/limit-range.api.ts index 82b02cfa70..3c41aca1a1 100644 --- a/src/renderer/api/endpoints/limit-range.api.ts +++ b/src/common/k8s-api/endpoints/limit-range.api.ts @@ -23,6 +23,7 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import { autoBind } from "../../utils"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export enum LimitType { CONTAINER = "Container", @@ -80,6 +81,14 @@ export class LimitRange extends KubeObject { } } -export const limitRangeApi = new KubeApi({ - objectConstructor: LimitRange, -}); +let limitRangeApi: KubeApi; + +if (isClusterPageContext()) { + limitRangeApi = new KubeApi({ + objectConstructor: LimitRange, + }); +} + +export { + limitRangeApi +}; diff --git a/src/renderer/api/endpoints/metrics.api.ts b/src/common/k8s-api/endpoints/metrics.api.ts similarity index 100% rename from src/renderer/api/endpoints/metrics.api.ts rename to src/common/k8s-api/endpoints/metrics.api.ts diff --git a/src/renderer/api/endpoints/namespaces.api.ts b/src/common/k8s-api/endpoints/namespaces.api.ts similarity index 88% rename from src/renderer/api/endpoints/namespaces.api.ts rename to src/common/k8s-api/endpoints/namespaces.api.ts index 208edb023f..f973ceb1b6 100644 --- a/src/renderer/api/endpoints/namespaces.api.ts +++ b/src/common/k8s-api/endpoints/namespaces.api.ts @@ -21,10 +21,11 @@ import { KubeApi } from "../kube-api"; import { KubeObject } from "../kube-object"; -import { autoBind } from "../../utils"; +import { autoBind } from "../../../renderer/utils"; import { metricsApi } from "./metrics.api"; import type { IPodMetrics } from "./pods.api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export enum NamespaceStatus { ACTIVE = "Active", @@ -69,6 +70,14 @@ export function getMetricsForNamespace(namespace: string, selector = ""): Promis }); } -export const namespacesApi = new NamespaceApi({ - objectConstructor: Namespace, -}); +let namespacesApi: NamespaceApi; + +if (isClusterPageContext()) { + namespacesApi = new NamespaceApi({ + objectConstructor: Namespace, + }); +} + +export { + namespacesApi +}; diff --git a/src/renderer/api/endpoints/network-policy.api.ts b/src/common/k8s-api/endpoints/network-policy.api.ts similarity index 90% rename from src/renderer/api/endpoints/network-policy.api.ts rename to src/common/k8s-api/endpoints/network-policy.api.ts index 03a06b7c42..026aa0b047 100644 --- a/src/renderer/api/endpoints/network-policy.api.ts +++ b/src/common/k8s-api/endpoints/network-policy.api.ts @@ -23,6 +23,7 @@ import { KubeObject } from "../kube-object"; import { autoBind } from "../../utils"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface IPolicyIpBlock { cidr: string; @@ -96,6 +97,14 @@ export class NetworkPolicy extends KubeObject { } } -export const networkPolicyApi = new KubeApi({ - objectConstructor: NetworkPolicy, -}); +let networkPolicyApi: KubeApi; + +if (isClusterPageContext()) { + networkPolicyApi = new KubeApi({ + objectConstructor: NetworkPolicy, + }); +} + +export { + networkPolicyApi +}; diff --git a/src/renderer/api/endpoints/nodes.api.ts b/src/common/k8s-api/endpoints/nodes.api.ts similarity index 96% rename from src/renderer/api/endpoints/nodes.api.ts rename to src/common/k8s-api/endpoints/nodes.api.ts index 21f7776c58..2705eeb1dd 100644 --- a/src/renderer/api/endpoints/nodes.api.ts +++ b/src/common/k8s-api/endpoints/nodes.api.ts @@ -20,10 +20,11 @@ */ import { KubeObject } from "../kube-object"; -import { autoBind, cpuUnitsToNumber, unitsToBytes } from "../../utils"; +import { autoBind, cpuUnitsToNumber, unitsToBytes } from "../../../renderer/utils"; import { IMetrics, metricsApi } from "./metrics.api"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class NodesApi extends KubeApi { } @@ -225,6 +226,14 @@ export class Node extends KubeObject { } } -export const nodesApi = new NodesApi({ - objectConstructor: Node, -}); +let nodesApi: NodesApi; + +if (isClusterPageContext()) { + nodesApi = new NodesApi({ + objectConstructor: Node, + }); +} + +export { + nodesApi +}; diff --git a/src/renderer/api/endpoints/persistent-volume-claims.api.ts b/src/common/k8s-api/endpoints/persistent-volume-claims.api.ts similarity index 93% rename from src/renderer/api/endpoints/persistent-volume-claims.api.ts rename to src/common/k8s-api/endpoints/persistent-volume-claims.api.ts index 356122569a..1ac5d8df9a 100644 --- a/src/renderer/api/endpoints/persistent-volume-claims.api.ts +++ b/src/common/k8s-api/endpoints/persistent-volume-claims.api.ts @@ -25,6 +25,7 @@ import { IMetrics, metricsApi } from "./metrics.api"; import type { Pod } from "./pods.api"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class PersistentVolumeClaimsApi extends KubeApi { } @@ -116,6 +117,14 @@ export class PersistentVolumeClaim extends KubeObject { } } -export const pvcApi = new PersistentVolumeClaimsApi({ - objectConstructor: PersistentVolumeClaim, -}); +let pvcApi: PersistentVolumeClaimsApi; + +if (isClusterPageContext()) { + pvcApi = new PersistentVolumeClaimsApi({ + objectConstructor: PersistentVolumeClaim, + }); +} + +export { + pvcApi +}; diff --git a/src/renderer/api/endpoints/persistent-volume.api.ts b/src/common/k8s-api/endpoints/persistent-volume.api.ts similarity index 89% rename from src/renderer/api/endpoints/persistent-volume.api.ts rename to src/common/k8s-api/endpoints/persistent-volume.api.ts index e71c355977..3a7a10ea6c 100644 --- a/src/renderer/api/endpoints/persistent-volume.api.ts +++ b/src/common/k8s-api/endpoints/persistent-volume.api.ts @@ -20,10 +20,10 @@ */ import { KubeObject } from "../kube-object"; -import { unitsToBytes } from "../../utils/convertMemory"; -import { autoBind } from "../../utils"; +import { autoBind, unitsToBytes } from "../../utils"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface PersistentVolume { spec: { @@ -102,6 +102,14 @@ export class PersistentVolume extends KubeObject { } } -export const persistentVolumeApi = new KubeApi({ - objectConstructor: PersistentVolume, -}); +let persistentVolumeApi: KubeApi; + +if (isClusterPageContext()) { + persistentVolumeApi = new KubeApi({ + objectConstructor: PersistentVolume, + }); +} + +export { + persistentVolumeApi +}; diff --git a/src/renderer/api/endpoints/pod-metrics.api.ts b/src/common/k8s-api/endpoints/pod-metrics.api.ts similarity index 85% rename from src/renderer/api/endpoints/pod-metrics.api.ts rename to src/common/k8s-api/endpoints/pod-metrics.api.ts index 191a128267..8d89f306b1 100644 --- a/src/renderer/api/endpoints/pod-metrics.api.ts +++ b/src/common/k8s-api/endpoints/pod-metrics.api.ts @@ -21,6 +21,7 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface PodMetrics { timestamp: string; @@ -40,6 +41,14 @@ export class PodMetrics extends KubeObject { static apiBase = "/apis/metrics.k8s.io/v1beta1/pods"; } -export const podMetricsApi = new KubeApi({ - objectConstructor: PodMetrics, -}); +let podMetricsApi: KubeApi; + +if (isClusterPageContext()) { + podMetricsApi = new KubeApi({ + objectConstructor: PodMetrics, + }); +} + +export { + podMetricsApi +}; diff --git a/src/renderer/api/endpoints/poddisruptionbudget.api.ts b/src/common/k8s-api/endpoints/poddisruptionbudget.api.ts similarity index 90% rename from src/renderer/api/endpoints/poddisruptionbudget.api.ts rename to src/common/k8s-api/endpoints/poddisruptionbudget.api.ts index daa16933da..1e57c1a3ec 100644 --- a/src/renderer/api/endpoints/poddisruptionbudget.api.ts +++ b/src/common/k8s-api/endpoints/poddisruptionbudget.api.ts @@ -23,6 +23,7 @@ import { autoBind } from "../../utils"; import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface PodDisruptionBudget { spec: { @@ -72,6 +73,14 @@ export class PodDisruptionBudget extends KubeObject { } -export const pdbApi = new KubeApi({ - objectConstructor: PodDisruptionBudget, -}); +let pdbApi: KubeApi; + +if (isClusterPageContext()) { + pdbApi = new KubeApi({ + objectConstructor: PodDisruptionBudget, + }); +} + +export { + pdbApi +}; diff --git a/src/renderer/api/endpoints/pods.api.ts b/src/common/k8s-api/endpoints/pods.api.ts similarity index 98% rename from src/renderer/api/endpoints/pods.api.ts rename to src/common/k8s-api/endpoints/pods.api.ts index e4d33c75bc..f002260de4 100644 --- a/src/renderer/api/endpoints/pods.api.ts +++ b/src/common/k8s-api/endpoints/pods.api.ts @@ -24,6 +24,7 @@ import { autoBind } from "../../utils"; import { IMetrics, metricsApi } from "./metrics.api"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class PodsApi extends KubeApi { async getLogs(params: { namespace: string; name: string }, query?: IPodLogsQuery): Promise { @@ -502,6 +503,14 @@ export class Pod extends WorkloadKubeObject { } } -export const podsApi = new PodsApi({ - objectConstructor: Pod, -}); +let podsApi: PodsApi; + +if (isClusterPageContext()) { + podsApi = new PodsApi({ + objectConstructor: Pod, + }); +} + +export { + podsApi +}; diff --git a/src/renderer/api/endpoints/podsecuritypolicy.api.ts b/src/common/k8s-api/endpoints/podsecuritypolicy.api.ts similarity index 93% rename from src/renderer/api/endpoints/podsecuritypolicy.api.ts rename to src/common/k8s-api/endpoints/podsecuritypolicy.api.ts index eac827ffcc..c1b29f3c6e 100644 --- a/src/renderer/api/endpoints/podsecuritypolicy.api.ts +++ b/src/common/k8s-api/endpoints/podsecuritypolicy.api.ts @@ -23,6 +23,7 @@ import { autoBind } from "../../utils"; import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface PodSecurityPolicy { spec: { @@ -117,6 +118,14 @@ export class PodSecurityPolicy extends KubeObject { } } -export const pspApi = new KubeApi({ - objectConstructor: PodSecurityPolicy, -}); +let pspApi: KubeApi; + +if (isClusterPageContext()) { + pspApi = new KubeApi({ + objectConstructor: PodSecurityPolicy, + }); +} + +export { + pspApi +}; diff --git a/src/renderer/api/endpoints/replica-set.api.ts b/src/common/k8s-api/endpoints/replica-set.api.ts similarity index 92% rename from src/renderer/api/endpoints/replica-set.api.ts rename to src/common/k8s-api/endpoints/replica-set.api.ts index 4632e1bfad..eeaf361557 100644 --- a/src/renderer/api/endpoints/replica-set.api.ts +++ b/src/common/k8s-api/endpoints/replica-set.api.ts @@ -20,12 +20,13 @@ */ import get from "lodash/get"; -import { autoBind } from "../../utils"; +import { autoBind } from "../../../renderer/utils"; import { WorkloadKubeObject } from "../workload-kube-object"; import { KubeApi } from "../kube-api"; import { metricsApi } from "./metrics.api"; import type { IPodContainer, IPodMetrics, Pod } from "./pods.api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class ReplicaSetApi extends KubeApi { protected getScaleApiUrl(params: { namespace: string; name: string }) { @@ -123,6 +124,14 @@ export class ReplicaSet extends WorkloadKubeObject { } } -export const replicaSetApi = new ReplicaSetApi({ - objectConstructor: ReplicaSet, -}); +let replicaSetApi: ReplicaSetApi; + +if (isClusterPageContext()) { + replicaSetApi = new ReplicaSetApi({ + objectConstructor: ReplicaSet, + }); +} + +export { + replicaSetApi +}; diff --git a/src/renderer/api/endpoints/resource-applier.api.ts b/src/common/k8s-api/endpoints/resource-applier.api.ts similarity index 100% rename from src/renderer/api/endpoints/resource-applier.api.ts rename to src/common/k8s-api/endpoints/resource-applier.api.ts diff --git a/src/renderer/api/endpoints/resource-quota.api.ts b/src/common/k8s-api/endpoints/resource-quota.api.ts similarity index 90% rename from src/renderer/api/endpoints/resource-quota.api.ts rename to src/common/k8s-api/endpoints/resource-quota.api.ts index 762c6682e1..3f6493aa01 100644 --- a/src/renderer/api/endpoints/resource-quota.api.ts +++ b/src/common/k8s-api/endpoints/resource-quota.api.ts @@ -21,6 +21,7 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface IResourceQuotaValues { [quota: string]: string; @@ -80,6 +81,14 @@ export class ResourceQuota extends KubeObject { } } -export const resourceQuotaApi = new KubeApi({ - objectConstructor: ResourceQuota, -}); +let resourceQuotaApi: KubeApi; + +if (isClusterPageContext()) { + resourceQuotaApi = new KubeApi({ + objectConstructor: ResourceQuota, + }); +} + +export { + resourceQuotaApi +}; diff --git a/src/renderer/api/endpoints/role-binding.api.ts b/src/common/k8s-api/endpoints/role-binding.api.ts similarity index 89% rename from src/renderer/api/endpoints/role-binding.api.ts rename to src/common/k8s-api/endpoints/role-binding.api.ts index c8c83d3151..df6b0c7bc5 100644 --- a/src/renderer/api/endpoints/role-binding.api.ts +++ b/src/common/k8s-api/endpoints/role-binding.api.ts @@ -23,6 +23,7 @@ import { autoBind } from "../../utils"; import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export type RoleBindingSubjectKind = "Group" | "ServiceAccount" | "User"; @@ -61,6 +62,14 @@ export class RoleBinding extends KubeObject { } } -export const roleBindingApi = new KubeApi({ - objectConstructor: RoleBinding, -}); +let roleBindingApi: KubeApi; + +if (isClusterPageContext()) { + roleBindingApi = new KubeApi({ + objectConstructor: RoleBinding, + }); +} + +export { + roleBindingApi +}; diff --git a/src/renderer/api/endpoints/role.api.ts b/src/common/k8s-api/endpoints/role.api.ts similarity index 87% rename from src/renderer/api/endpoints/role.api.ts rename to src/common/k8s-api/endpoints/role.api.ts index b504c7fc8b..f9c0be19fb 100644 --- a/src/renderer/api/endpoints/role.api.ts +++ b/src/common/k8s-api/endpoints/role.api.ts @@ -21,6 +21,7 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface Role { rules: { @@ -41,6 +42,14 @@ export class Role extends KubeObject { } } -export const roleApi = new KubeApi({ - objectConstructor: Role, -}); +let roleApi: KubeApi; + +if (isClusterPageContext()) { + roleApi = new KubeApi({ + objectConstructor: Role, + }); +} + +export{ + roleApi +}; diff --git a/src/renderer/api/endpoints/secret.api.ts b/src/common/k8s-api/endpoints/secret.api.ts similarity index 90% rename from src/renderer/api/endpoints/secret.api.ts rename to src/common/k8s-api/endpoints/secret.api.ts index 5ddd0e1db3..99200933ff 100644 --- a/src/renderer/api/endpoints/secret.api.ts +++ b/src/common/k8s-api/endpoints/secret.api.ts @@ -23,6 +23,7 @@ import { KubeObject } from "../kube-object"; import type { KubeJsonApiData } from "../kube-json-api"; import { autoBind } from "../../utils"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export enum SecretType { Opaque = "Opaque", @@ -69,6 +70,14 @@ export class Secret extends KubeObject { } } -export const secretsApi = new KubeApi({ - objectConstructor: Secret, -}); +let secretsApi: KubeApi; + +if (isClusterPageContext()) { + secretsApi = new KubeApi({ + objectConstructor: Secret, + }); +} + +export { + secretsApi +}; diff --git a/src/renderer/api/endpoints/selfsubjectrulesreviews.api.ts b/src/common/k8s-api/endpoints/selfsubjectrulesreviews.api.ts similarity index 89% rename from src/renderer/api/endpoints/selfsubjectrulesreviews.api.ts rename to src/common/k8s-api/endpoints/selfsubjectrulesreviews.api.ts index 84c27f21cb..799abec798 100644 --- a/src/renderer/api/endpoints/selfsubjectrulesreviews.api.ts +++ b/src/common/k8s-api/endpoints/selfsubjectrulesreviews.api.ts @@ -21,6 +21,7 @@ import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class SelfSubjectRulesReviewApi extends KubeApi { create({ namespace = "default" }): Promise { @@ -86,6 +87,15 @@ export class SelfSubjectRulesReview extends KubeObject { } } -export const selfSubjectRulesReviewApi = new SelfSubjectRulesReviewApi({ - objectConstructor: SelfSubjectRulesReview, -}); +let selfSubjectRulesReviewApi: SelfSubjectRulesReviewApi; + +if (isClusterPageContext()) { + selfSubjectRulesReviewApi = new SelfSubjectRulesReviewApi({ + objectConstructor: SelfSubjectRulesReview, + }); +} + +export { + selfSubjectRulesReviewApi +}; + diff --git a/src/renderer/api/endpoints/service-accounts.api.ts b/src/common/k8s-api/endpoints/service-accounts.api.ts similarity index 86% rename from src/renderer/api/endpoints/service-accounts.api.ts rename to src/common/k8s-api/endpoints/service-accounts.api.ts index 6cc9d292ba..678541afe4 100644 --- a/src/renderer/api/endpoints/service-accounts.api.ts +++ b/src/common/k8s-api/endpoints/service-accounts.api.ts @@ -23,6 +23,7 @@ import { autoBind } from "../../utils"; import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface ServiceAccount { secrets?: { @@ -52,6 +53,14 @@ export class ServiceAccount extends KubeObject { } } -export const serviceAccountsApi = new KubeApi({ - objectConstructor: ServiceAccount, -}); +let serviceAccountsApi: KubeApi; + +if (isClusterPageContext()) { + serviceAccountsApi = new KubeApi({ + objectConstructor: ServiceAccount, + }); +} + +export { + serviceAccountsApi +}; diff --git a/src/renderer/api/endpoints/service.api.ts b/src/common/k8s-api/endpoints/service.api.ts similarity index 92% rename from src/renderer/api/endpoints/service.api.ts rename to src/common/k8s-api/endpoints/service.api.ts index e9a6b9b40f..e5af9de828 100644 --- a/src/renderer/api/endpoints/service.api.ts +++ b/src/common/k8s-api/endpoints/service.api.ts @@ -19,10 +19,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { autoBind } from "../../utils"; +import { autoBind } from "../../../renderer/utils"; import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface ServicePort { name?: string; @@ -143,6 +144,14 @@ export class Service extends KubeObject { } } -export const serviceApi = new KubeApi({ - objectConstructor: Service, -}); +let serviceApi: KubeApi; + +if (isClusterPageContext()) { + serviceApi = new KubeApi({ + objectConstructor: Service, + }); +} + +export { + serviceApi +}; diff --git a/src/renderer/api/endpoints/stateful-set.api.ts b/src/common/k8s-api/endpoints/stateful-set.api.ts similarity index 94% rename from src/renderer/api/endpoints/stateful-set.api.ts rename to src/common/k8s-api/endpoints/stateful-set.api.ts index 21f4c6e02e..ee47fa6a24 100644 --- a/src/renderer/api/endpoints/stateful-set.api.ts +++ b/src/common/k8s-api/endpoints/stateful-set.api.ts @@ -26,6 +26,7 @@ import { KubeApi } from "../kube-api"; import { metricsApi } from "./metrics.api"; import type { IPodContainer, IPodMetrics } from "./pods.api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export class StatefulSetApi extends KubeApi { protected getScaleApiUrl(params: { namespace: string; name: string }) { @@ -149,6 +150,14 @@ export class StatefulSet extends WorkloadKubeObject { } } -export const statefulSetApi = new StatefulSetApi({ - objectConstructor: StatefulSet, -}); +let statefulSetApi: StatefulSetApi; + +if (isClusterPageContext()) { + statefulSetApi = new StatefulSetApi({ + objectConstructor: StatefulSet, + }); +} + +export { + statefulSetApi +}; diff --git a/src/renderer/api/endpoints/storage-class.api.ts b/src/common/k8s-api/endpoints/storage-class.api.ts similarity index 89% rename from src/renderer/api/endpoints/storage-class.api.ts rename to src/common/k8s-api/endpoints/storage-class.api.ts index 226e3ab477..3b44a2e124 100644 --- a/src/renderer/api/endpoints/storage-class.api.ts +++ b/src/common/k8s-api/endpoints/storage-class.api.ts @@ -23,6 +23,7 @@ import { autoBind } from "../../utils"; import { KubeObject } from "../kube-object"; import { KubeApi } from "../kube-api"; import type { KubeJsonApiData } from "../kube-json-api"; +import { isClusterPageContext } from "../../utils/cluster-id-url-parsing"; export interface StorageClass { provisioner: string; // e.g. "storage.k8s.io/v1" @@ -62,6 +63,14 @@ export class StorageClass extends KubeObject { } } -export const storageClassApi = new KubeApi({ - objectConstructor: StorageClass, -}); +let storageClassApi: KubeApi; + +if (isClusterPageContext()) { + storageClassApi = new KubeApi({ + objectConstructor: StorageClass, + }); +} + +export { + storageClassApi +}; diff --git a/src/common/k8s-api/index.ts b/src/common/k8s-api/index.ts new file mode 100644 index 0000000000..791ee09285 --- /dev/null +++ b/src/common/k8s-api/index.ts @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import { JsonApi } from "./json-api"; +import { KubeJsonApi } from "./kube-json-api"; +import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars"; +import { isClusterPageContext } from "../utils/cluster-id-url-parsing"; + +let apiBase: JsonApi; +let apiKube: KubeJsonApi; + +if (typeof window === "undefined") { + apiBase = new JsonApi({ + serverAddress: `http://127.0.0.1:${process.env.LENS_PROXY_PORT}`, + apiBase: apiPrefix, + debug: isDevelopment || isDebugging, + }, { + headers: { + "Host": `localhost:${process.env.LENS_PROXY_PORT}` + } + }); +} else { + apiBase = new JsonApi({ + serverAddress: `http://127.0.0.1:${window.location.port}`, + apiBase: apiPrefix, + debug: isDevelopment || isDebugging, + }, { + headers: { + "Host": window.location.host + } + }); +} + +if (isClusterPageContext()) { + apiKube = new KubeJsonApi({ + serverAddress: `http://127.0.0.1:${window.location.port}`, + apiBase: apiKubePrefix, + debug: isDevelopment + }, { + headers: { + "Host": window.location.host + } + }); +} + +export { + apiBase, + apiKube +}; diff --git a/src/renderer/api/json-api.ts b/src/common/k8s-api/json-api.ts similarity index 85% rename from src/renderer/api/json-api.ts rename to src/common/k8s-api/json-api.ts index 0060259c76..5ebd30650d 100644 --- a/src/renderer/api/json-api.ts +++ b/src/common/k8s-api/json-api.ts @@ -21,9 +21,11 @@ // Base http-service / json-api class +import { merge } from "lodash"; +import fetch, { Response, RequestInit } from "node-fetch"; import { stringify } from "querystring"; import { EventEmitter } from "../../common/event-emitter"; -import { randomBytes } from "crypto"; +import logger from "../../common/logger"; export interface JsonApiData { } @@ -49,9 +51,9 @@ export interface JsonApiLog { export interface JsonApiConfig { apiBase: string; + serverAddress: string; debug?: boolean; } - export class JsonApi { static reqInitDefault: RequestInit = { headers: { @@ -63,9 +65,9 @@ export class JsonApi { debug: false }; - constructor(protected config: JsonApiConfig, protected reqInit?: RequestInit) { + constructor(public readonly config: JsonApiConfig, protected reqInit?: RequestInit) { this.config = Object.assign({}, JsonApi.configDefault, config); - this.reqInit = Object.assign({}, JsonApi.reqInitDefault, reqInit); + this.reqInit = merge({}, JsonApi.reqInitDefault, reqInit); this.parseResponse = this.parseResponse.bind(this); } @@ -77,10 +79,8 @@ export class JsonApi { } getResponse(path: string, params?: P, init: RequestInit = {}): Promise { - const reqPath = `${this.config.apiBase}${path}`; - const subdomain = randomBytes(2).toString("hex"); - let reqUrl = `http://${subdomain}.${window.location.host}${reqPath}`; // hack around browser connection limits (chromium allows 6 per domain) - const reqInit: RequestInit = { ...init }; + let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`; + const reqInit: RequestInit = merge({}, this.reqInit, init); const { query } = params || {} as P; if (!reqInit.method) { @@ -95,7 +95,7 @@ export class JsonApi { this.writeLog({ method: reqInit.method.toUpperCase(), - reqUrl: reqPath, + reqUrl, reqInit, }); @@ -119,8 +119,8 @@ export class JsonApi { } protected async request(path: string, params?: P, init: RequestInit = {}) { - let reqUrl = this.config.apiBase + path; - const reqInit: RequestInit = { ...this.reqInit, ...init }; + let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`; + const reqInit: RequestInit = merge({}, this.reqInit, init); const { data, query } = params || {} as P; if (data && !reqInit.body) { @@ -192,13 +192,9 @@ export class JsonApi { } protected writeLog(log: JsonApiLog) { - if (!this.config.debug) return; const { method, reqUrl, ...params } = log; - let textStyle = "font-weight: bold;"; - if (params.data) textStyle += "background: green; color: white;"; - if (params.error) textStyle += "background: red; color: white;"; - console.log(`%c${method} ${reqUrl}`, textStyle, params); + logger.info(`[JSON-API] request ${method} ${reqUrl}`, params); } } diff --git a/src/renderer/api/kube-api-parse.ts b/src/common/k8s-api/kube-api-parse.ts similarity index 96% rename from src/renderer/api/kube-api-parse.ts rename to src/common/k8s-api/kube-api-parse.ts index 53d731203d..57c835ed6b 100644 --- a/src/renderer/api/kube-api-parse.ts +++ b/src/common/k8s-api/kube-api-parse.ts @@ -21,8 +21,8 @@ // Parse kube-api path and get api-version, group, etc. -import { splitArray } from "../../common/utils"; -import { isDebugging } from "../../common/vars"; +import { splitArray } from "../utils"; +import { isDebugging } from "../vars"; import logger from "../../main/logger"; import { inspect } from "util"; @@ -66,7 +66,7 @@ export function parseKubeApi(path: string): IKubeApiParsed { } function _parseKubeApi(path: string): IKubeApiParsed { - const apiPath = new URL(path, location.origin).pathname; + const apiPath = new URL(path, "http://localhost").pathname; const [, prefix, ...parts] = apiPath.split("/"); const apiPrefix = `/${prefix}`; const [left, right, namespaced] = splitArray(parts, "namespaces"); diff --git a/src/renderer/api/kube-api.ts b/src/common/k8s-api/kube-api.ts similarity index 95% rename from src/renderer/api/kube-api.ts rename to src/common/k8s-api/kube-api.ts index 5fe65a2357..1131119a3b 100644 --- a/src/renderer/api/kube-api.ts +++ b/src/common/k8s-api/kube-api.ts @@ -23,17 +23,18 @@ import merge from "lodash/merge"; import { stringify } from "querystring"; -import { apiKubePrefix, isDevelopment, isTestEnv } from "../../common/vars"; +import { apiKubePrefix, isDevelopment } from "../../common/vars"; import logger from "../../main/logger"; import { apiManager } from "./api-manager"; -import { apiKube } from "./index"; +import { apiBase, apiKube } from "./index"; import { createKubeApiURL, parseKubeApi } from "./kube-api-parse"; import { KubeObjectConstructor, KubeObject, KubeStatus } from "./kube-object"; import byline from "byline"; import type { IKubeWatchEvent } from "./kube-watch-api"; -import { ReadableWebToNodeStream } from "../utils/readableStream"; import { KubeJsonApi, KubeJsonApiData } from "./kube-json-api"; import { noop } from "../utils"; +import type { RequestInit } from "node-fetch"; +import AbortController from "abort-controller"; export interface IKubeApiOptions { /** @@ -96,11 +97,12 @@ export interface IKubeApiCluster { export function forCluster(cluster: IKubeApiCluster, kubeClass: KubeObjectConstructor): KubeApi { const request = new KubeJsonApi({ + serverAddress: apiBase.config.serverAddress, apiBase: apiKubePrefix, debug: isDevelopment, }, { headers: { - "X-Cluster-ID": cluster.metadata.uid + "Host": apiBase.config.serverAddress } }); @@ -168,7 +170,6 @@ export class KubeApi { this.request = request; this.objectConstructor = objectConstructor; - this.checkPreferredVersion(); this.parseResponse = this.parseResponse.bind(this); apiManager.registerApi(apiBase, this); } @@ -201,18 +202,9 @@ export class KubeApi { } } catch (error) { // Exception is ignored as we can try the next url - console.error(error); } } - // Avoid throwing in tests - if (isTestEnv) { - return { - apiPrefix: this.apiPrefix, - apiGroup: this.apiGroup - }; - } - throw new Error(`Can't find working API for the Kubernetes resource ${this.apiResource}`); } @@ -435,7 +427,7 @@ export class KubeApi { }); const watchUrl = this.getWatchUrl(namespace); - const responsePromise = this.request.getResponse(watchUrl, null, { signal }); + const responsePromise = this.request.getResponse(watchUrl, null, { signal, timeout: 600_000 }); responsePromise .then(response => { @@ -443,10 +435,8 @@ export class KubeApi { return callback(null, response); } - const nodeStream = new ReadableWebToNodeStream(response.body); - ["end", "close", "error"].forEach((eventName) => { - nodeStream.on(eventName, () => { + response.body.on(eventName, () => { if (errorReceived) return; // kubernetes errors should be handled in a callback clearTimeout(timedRetry); @@ -456,7 +446,7 @@ export class KubeApi { }); }); - byline(nodeStream).on("data", (line) => { + byline(response.body).on("data", (line) => { try { const event: IKubeWatchEvent = JSON.parse(line); @@ -474,7 +464,7 @@ export class KubeApi { }); }) .catch(error => { - if (error instanceof DOMException) return; // AbortController rejects, we can ignore it + if (error?.type === "aborted") return; // AbortController rejects, we can ignore it callback(null, error); }); diff --git a/src/renderer/api/kube-json-api.ts b/src/common/k8s-api/kube-json-api.ts similarity index 98% rename from src/renderer/api/kube-json-api.ts rename to src/common/k8s-api/kube-json-api.ts index ebb01b696c..2e6e892b21 100644 --- a/src/renderer/api/kube-json-api.ts +++ b/src/common/k8s-api/kube-json-api.ts @@ -20,6 +20,7 @@ */ import { JsonApi, JsonApiData, JsonApiError } from "./json-api"; +import type { Response } from "node-fetch"; export interface KubeJsonApiListMetadata { resourceVersion: string; @@ -79,3 +80,4 @@ export class KubeJsonApi extends JsonApi { return super.parseError(error, res); } } + diff --git a/src/renderer/kube-object.store.ts b/src/common/k8s-api/kube-object.store.ts similarity index 94% rename from src/renderer/kube-object.store.ts rename to src/common/k8s-api/kube-object.store.ts index fd53345655..3215306d93 100644 --- a/src/renderer/kube-object.store.ts +++ b/src/common/k8s-api/kube-object.store.ts @@ -19,18 +19,19 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { ClusterContext } from "./components/context"; +import type { ClusterContext } from "./cluster-context"; import { action, computed, makeObservable, observable, reaction, when } from "mobx"; -import { autoBind, noop, rejectPromiseBy } from "./utils"; -import { KubeObject, KubeStatus } from "./api/kube-object"; -import type { IKubeWatchEvent } from "./api/kube-watch-api"; -import { ItemStore } from "./item.store"; -import { apiManager } from "./api/api-manager"; -import { ensureObjectSelfLink, IKubeApiQueryParams, KubeApi } from "./api/kube-api"; -import { parseKubeApi } from "./api/kube-api-parse"; -import type { KubeJsonApiData } from "./api/kube-json-api"; -import { Notifications } from "./components/notifications"; +import { autoBind, noop, rejectPromiseBy } from "../utils"; +import { KubeObject, KubeStatus } from "./kube-object"; +import type { IKubeWatchEvent } from "./kube-watch-api"; +import { ItemStore } from "../item.store"; +import { apiManager } from "./api-manager"; +import { ensureObjectSelfLink, IKubeApiQueryParams, KubeApi } from "./kube-api"; +import { parseKubeApi } from "./kube-api-parse"; +import type { KubeJsonApiData } from "./kube-json-api"; +import type { RequestInit } from "node-fetch"; +import AbortController from "abort-controller"; export interface KubeObjectStoreLoadingParams { namespaces: string[]; @@ -193,9 +194,6 @@ export abstract class KubeObjectStore extends ItemStore return items; } catch (error) { - if (error.message) { - Notifications.error(error.message); - } console.warn("[KubeObjectStore] loadAll failed", this.api.apiBase, error); this.resetOnError(error); this.failedLoading = true; @@ -348,7 +346,7 @@ export abstract class KubeObjectStore extends ItemStore const { signal } = abortController; const callback = (data: IKubeWatchEvent, error: any) => { - if (!this.isLoaded || error instanceof DOMException) return; + if (!this.isLoaded || error?.type === "aborted") return; if (error instanceof Response) { if (error.status === 404 || error.status === 401) { diff --git a/src/renderer/api/kube-object.ts b/src/common/k8s-api/kube-object.ts similarity index 100% rename from src/renderer/api/kube-object.ts rename to src/common/k8s-api/kube-object.ts diff --git a/src/renderer/api/kube-watch-api.ts b/src/common/k8s-api/kube-watch-api.ts similarity index 96% rename from src/renderer/api/kube-watch-api.ts rename to src/common/k8s-api/kube-watch-api.ts index 4d316b5caa..5ce16dcfbd 100644 --- a/src/renderer/api/kube-watch-api.ts +++ b/src/common/k8s-api/kube-watch-api.ts @@ -22,15 +22,15 @@ // Kubernetes watch-api client // API: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams -import type { KubeObjectStore } from "../kube-object.store"; -import type { ClusterContext } from "../components/context"; +import type { KubeObjectStore } from "./kube-object.store"; +import type { ClusterContext } from "./cluster-context"; import plimit from "p-limit"; import { comparer, observable, reaction, makeObservable } from "mobx"; import { autoBind, Disposer, noop } from "../utils"; import type { KubeApi } from "./kube-api"; import type { KubeJsonApiData } from "./kube-json-api"; -import { isDebugging, isProduction } from "../../common/vars"; +import { isDebugging, isProduction } from "../vars"; import type { KubeObject } from "./kube-object"; export interface IKubeWatchEvent { diff --git a/src/renderer/api/workload-kube-object.ts b/src/common/k8s-api/workload-kube-object.ts similarity index 100% rename from src/renderer/api/workload-kube-object.ts rename to src/common/k8s-api/workload-kube-object.ts diff --git a/src/common/logger.ts b/src/common/logger.ts new file mode 100644 index 0000000000..57f12ce4e9 --- /dev/null +++ b/src/common/logger.ts @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import { app, ipcMain, remote } from "electron"; +import winston from "winston"; +import { consoleFormat } from "winston-console-format"; +import { isDebugging, isTestEnv } from "./vars"; +import BrowserConsole from "winston-transport-browserconsole"; + + +const logLevel = process.env.LOG_LEVEL ? process.env.LOG_LEVEL : isDebugging ? "debug" : "info"; +let consoleOptions: winston.transports.ConsoleTransportOptions; + +if (ipcMain) { + consoleOptions = { + handleExceptions: false, + level: logLevel, + format: winston.format.combine( + winston.format.colorize({ level: true, message: false}), + winston.format.padLevels(), + winston.format.ms(), + consoleFormat({ + showMeta: true, + inspectOptions: { + depth: 4, + colors: true, + maxArrayLength: 10, + breakLength: 120, + compact: Infinity, + }, + }) + ) + }; +} else { + consoleOptions = { + handleExceptions: false, + level: logLevel, + format: winston.format.combine( + winston.format.colorize({ level: true, message: false}), + ) + }; +} + +const fileOptions: winston.transports.FileTransportOptions = { + handleExceptions: false, + level: logLevel, + filename: "lens.log", + dirname: (app ?? remote?.app)?.getPath("logs"), + maxsize: 16 * 1024, + maxFiles: 16, + tailable: true, +}; +const logger = winston.createLogger({ + format: winston.format.combine( + winston.format.simple() + ), + transports: [ + ipcMain ? new winston.transports.Console(consoleOptions) : new BrowserConsole(), + ...(isTestEnv ? [] : [new winston.transports.File(fileOptions)]), + ], +}); + +export default logger; diff --git a/src/renderer/utils/__tests__/formatDuration.test.ts b/src/common/utils/__tests__/formatDuration.test.ts similarity index 100% rename from src/renderer/utils/__tests__/formatDuration.test.ts rename to src/common/utils/__tests__/formatDuration.test.ts diff --git a/src/common/utils/cluster-id-url-parsing.ts b/src/common/utils/cluster-id-url-parsing.ts index e9517dce1d..e692bc4595 100644 --- a/src/common/utils/cluster-id-url-parsing.ts +++ b/src/common/utils/cluster-id-url-parsing.ts @@ -48,3 +48,12 @@ export function getClusterFrameUrl(clusterId: ClusterId) { export function getHostedClusterId(): ClusterId | undefined { return getClusterIdFromHost(location.host); } + +/** + * Returns true only if code is running within a cluster iframe context + */ +export function isClusterPageContext(): boolean { + if (typeof window === "undefined") return false; + + return !!getClusterIdFromHost(window.location.host); +} diff --git a/src/renderer/utils/convertCpu.ts b/src/common/utils/convertCpu.ts similarity index 100% rename from src/renderer/utils/convertCpu.ts rename to src/common/utils/convertCpu.ts diff --git a/src/renderer/utils/convertMemory.ts b/src/common/utils/convertMemory.ts similarity index 100% rename from src/renderer/utils/convertMemory.ts rename to src/common/utils/convertMemory.ts diff --git a/src/renderer/utils/formatDuration.ts b/src/common/utils/formatDuration.ts similarity index 100% rename from src/renderer/utils/formatDuration.ts rename to src/common/utils/formatDuration.ts diff --git a/src/common/utils/index.ts b/src/common/utils/index.ts index 140ceaea2c..3d7f4f9838 100644 --- a/src/common/utils/index.ts +++ b/src/common/utils/index.ts @@ -37,6 +37,7 @@ export * from "./defineGlobal"; export * from "./delay"; export * from "./disposer"; export * from "./downloadFile"; +export * from "./formatDuration"; export * from "./escapeRegExp"; export * from "./extended-map"; export * from "./getRandId"; @@ -54,6 +55,8 @@ export * from "./toggle-set"; export * from "./toJS"; export * from "./type-narrowing"; export * from "./types"; +export * from "./convertMemory"; +export * from "./convertCpu"; import * as iter from "./iter"; diff --git a/src/renderer/utils/readableStream.ts b/src/common/utils/readableStream.ts similarity index 100% rename from src/renderer/utils/readableStream.ts rename to src/common/utils/readableStream.ts diff --git a/src/common/vars.ts b/src/common/vars.ts index 0dea82cab6..dec81f313e 100644 --- a/src/common/vars.ts +++ b/src/common/vars.ts @@ -42,6 +42,7 @@ export const publicPath = "/build/" as string; // Webpack build paths export const contextDir = process.cwd(); export const buildDir = path.join(contextDir, "static", publicPath); +export const preloadEntrypoint = path.join(contextDir, "src/preload.ts"); export const mainDir = path.join(contextDir, "src/main"); export const rendererDir = path.join(contextDir, "src/renderer"); export const htmlTemplate = path.resolve(rendererDir, "template.html"); diff --git a/src/extensions/main-api/index.ts b/src/extensions/main-api/index.ts index a596e8169e..012ff0ebde 100644 --- a/src/extensions/main-api/index.ts +++ b/src/extensions/main-api/index.ts @@ -21,12 +21,14 @@ import * as Catalog from "./catalog"; import * as Navigation from "./navigation"; +import * as K8sApi from "./k8s-api"; import { IpcMain as Ipc } from "../ipc/ipc-main"; import { LensMainExtension as LensExtension } from "../lens-main-extension"; export { Catalog, Navigation, + K8sApi, Ipc, LensExtension, }; diff --git a/src/extensions/main-api/k8s-api.ts b/src/extensions/main-api/k8s-api.ts new file mode 100644 index 0000000000..991415cc56 --- /dev/null +++ b/src/extensions/main-api/k8s-api.ts @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +export { isAllowedResource } from "../../common/utils/allowed-resource"; +export { ResourceStack } from "../../common/k8s/resource-stack"; +export { apiManager } from "../../common/k8s-api/api-manager"; +export { KubeApi, forCluster } from "../../common/k8s-api/kube-api"; +export { KubeObject } from "../../common/k8s-api/kube-object"; +export { Pod, podsApi, PodsApi } from "../../common/k8s-api/endpoints/pods.api"; +export { Node, nodesApi, NodesApi } from "../../common/k8s-api/endpoints/nodes.api"; +export { Deployment, deploymentApi, DeploymentApi } from "../../common/k8s-api/endpoints/deployment.api"; +export { DaemonSet, daemonSetApi } from "../../common/k8s-api/endpoints/daemon-set.api"; +export { StatefulSet, statefulSetApi } from "../../common/k8s-api/endpoints/stateful-set.api"; +export { Job, jobApi } from "../../common/k8s-api/endpoints/job.api"; +export { CronJob, cronJobApi } from "../../common/k8s-api/endpoints/cron-job.api"; +export { ConfigMap, configMapApi } from "../../common/k8s-api/endpoints/configmap.api"; +export { Secret, secretsApi } from "../../common/k8s-api/endpoints/secret.api"; +export { ReplicaSet, replicaSetApi } from "../../common/k8s-api/endpoints/replica-set.api"; +export { ResourceQuota, resourceQuotaApi } from "../../common/k8s-api/endpoints/resource-quota.api"; +export { LimitRange, limitRangeApi } from "../../common/k8s-api/endpoints/limit-range.api"; +export { HorizontalPodAutoscaler, hpaApi } from "../../common/k8s-api/endpoints/hpa.api"; +export { PodDisruptionBudget, pdbApi } from "../../common/k8s-api/endpoints/poddisruptionbudget.api"; +export { Service, serviceApi } from "../../common/k8s-api/endpoints/service.api"; +export { Endpoint, endpointApi } from "../../common/k8s-api/endpoints/endpoint.api"; +export { Ingress, ingressApi, IngressApi } from "../../common/k8s-api/endpoints/ingress.api"; +export { NetworkPolicy, networkPolicyApi } from "../../common/k8s-api/endpoints/network-policy.api"; +export { PersistentVolume, persistentVolumeApi } from "../../common/k8s-api/endpoints/persistent-volume.api"; +export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints/persistent-volume-claims.api"; +export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints/storage-class.api"; +export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints/namespaces.api"; +export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints/events.api"; +export { ServiceAccount, serviceAccountsApi } from "../../common/k8s-api/endpoints/service-accounts.api"; +export { Role, roleApi } from "../../common/k8s-api/endpoints/role.api"; +export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints/role-binding.api"; +export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints/cluster-role.api"; +export { ClusterRoleBinding, clusterRoleBindingApi } from "../../common/k8s-api/endpoints/cluster-role-binding.api"; +export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints/crd.api"; + +// types +export type { IKubeApiCluster } from "../../common/k8s-api/kube-api"; +export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints/pods.api"; +export type { ISecretRef } from "../../common/k8s-api/endpoints/secret.api"; diff --git a/src/extensions/renderer-api/k8s-api.ts b/src/extensions/renderer-api/k8s-api.ts index 2c31a4036f..1622dd6f3d 100644 --- a/src/extensions/renderer-api/k8s-api.ts +++ b/src/extensions/renderer-api/k8s-api.ts @@ -21,45 +21,45 @@ export { isAllowedResource } from "../../common/utils/allowed-resource"; export { ResourceStack } from "../../common/k8s/resource-stack"; -export { apiManager } from "../../renderer/api/api-manager"; -export { KubeObjectStore } from "../../renderer/kube-object.store"; -export { KubeApi, forCluster } from "../../renderer/api/kube-api"; -export { KubeObject } from "../../renderer/api/kube-object"; -export { Pod, podsApi, PodsApi } from "../../renderer/api/endpoints"; -export { Node, nodesApi, NodesApi } from "../../renderer/api/endpoints"; -export { Deployment, deploymentApi, DeploymentApi } from "../../renderer/api/endpoints"; -export { DaemonSet, daemonSetApi } from "../../renderer/api/endpoints"; -export { StatefulSet, statefulSetApi } from "../../renderer/api/endpoints"; -export { Job, jobApi } from "../../renderer/api/endpoints"; -export { CronJob, cronJobApi } from "../../renderer/api/endpoints"; -export { ConfigMap, configMapApi } from "../../renderer/api/endpoints"; -export { Secret, secretsApi } from "../../renderer/api/endpoints"; -export { ReplicaSet, replicaSetApi } from "../../renderer/api/endpoints"; -export { ResourceQuota, resourceQuotaApi } from "../../renderer/api/endpoints"; -export { LimitRange, limitRangeApi } from "../../renderer/api/endpoints"; -export { HorizontalPodAutoscaler, hpaApi } from "../../renderer/api/endpoints"; -export { PodDisruptionBudget, pdbApi } from "../../renderer/api/endpoints"; -export { Service, serviceApi } from "../../renderer/api/endpoints"; -export { Endpoint, endpointApi } from "../../renderer/api/endpoints"; -export { Ingress, ingressApi, IngressApi } from "../../renderer/api/endpoints"; -export { NetworkPolicy, networkPolicyApi } from "../../renderer/api/endpoints"; -export { PersistentVolume, persistentVolumeApi } from "../../renderer/api/endpoints"; -export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../renderer/api/endpoints"; -export { StorageClass, storageClassApi } from "../../renderer/api/endpoints"; -export { Namespace, namespacesApi } from "../../renderer/api/endpoints"; -export { KubeEvent, eventApi } from "../../renderer/api/endpoints"; -export { ServiceAccount, serviceAccountsApi } from "../../renderer/api/endpoints"; -export { Role, roleApi } from "../../renderer/api/endpoints"; -export { RoleBinding, roleBindingApi } from "../../renderer/api/endpoints"; -export { ClusterRole, clusterRoleApi } from "../../renderer/api/endpoints"; -export { ClusterRoleBinding, clusterRoleBindingApi } from "../../renderer/api/endpoints"; -export { CustomResourceDefinition, crdApi } from "../../renderer/api/endpoints"; +export { apiManager } from "../../common/k8s-api/api-manager"; +export { KubeObjectStore } from "../../common/k8s-api/kube-object.store"; +export { KubeApi, forCluster } from "../../common/k8s-api/kube-api"; +export { KubeObject } from "../../common/k8s-api/kube-object"; +export { Pod, podsApi, PodsApi } from "../../common/k8s-api/endpoints"; +export { Node, nodesApi, NodesApi } from "../../common/k8s-api/endpoints"; +export { Deployment, deploymentApi, DeploymentApi } from "../../common/k8s-api/endpoints"; +export { DaemonSet, daemonSetApi } from "../../common/k8s-api/endpoints"; +export { StatefulSet, statefulSetApi } from "../../common/k8s-api/endpoints"; +export { Job, jobApi } from "../../common/k8s-api/endpoints"; +export { CronJob, cronJobApi } from "../../common/k8s-api/endpoints"; +export { ConfigMap, configMapApi } from "../../common/k8s-api/endpoints"; +export { Secret, secretsApi } from "../../common/k8s-api/endpoints"; +export { ReplicaSet, replicaSetApi } from "../../common/k8s-api/endpoints"; +export { ResourceQuota, resourceQuotaApi } from "../../common/k8s-api/endpoints"; +export { LimitRange, limitRangeApi } from "../../common/k8s-api/endpoints"; +export { HorizontalPodAutoscaler, hpaApi } from "../../common/k8s-api/endpoints"; +export { PodDisruptionBudget, pdbApi } from "../../common/k8s-api/endpoints"; +export { Service, serviceApi } from "../../common/k8s-api/endpoints"; +export { Endpoint, endpointApi } from "../../common/k8s-api/endpoints"; +export { Ingress, ingressApi, IngressApi } from "../../common/k8s-api/endpoints"; +export { NetworkPolicy, networkPolicyApi } from "../../common/k8s-api/endpoints"; +export { PersistentVolume, persistentVolumeApi } from "../../common/k8s-api/endpoints"; +export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints"; +export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints"; +export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints"; +export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints"; +export { ServiceAccount, serviceAccountsApi } from "../../common/k8s-api/endpoints"; +export { Role, roleApi } from "../../common/k8s-api/endpoints"; +export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints"; +export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints"; +export { ClusterRoleBinding, clusterRoleBindingApi } from "../../common/k8s-api/endpoints"; +export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints"; export { KubeObjectStatusLevel } from "./kube-object-status"; // types -export type { IKubeApiCluster } from "../../renderer/api/kube-api"; -export type { IPodContainer, IPodContainerStatus } from "../../renderer/api/endpoints"; -export type { ISecretRef } from "../../renderer/api/endpoints"; +export type { IKubeApiCluster } from "../../common/k8s-api/kube-api"; +export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints"; +export type { ISecretRef } from "../../common/k8s-api/endpoints"; export type { KubeObjectStatus } from "./kube-object-status"; // stores diff --git a/src/main/helm/helm-chart-manager.ts b/src/main/helm/helm-chart-manager.ts index 7ab6c8f9db..5523e0f050 100644 --- a/src/main/helm/helm-chart-manager.ts +++ b/src/main/helm/helm-chart-manager.ts @@ -25,7 +25,7 @@ import { HelmRepo, HelmRepoManager } from "./helm-repo-manager"; import logger from "../logger"; import { promiseExec } from "../promise-exec"; import { helmCli } from "./helm-cli"; -import type { RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api"; +import type { RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api"; type CachedYaml = { entries: RepoHelmChartList diff --git a/src/main/helm/helm-service.ts b/src/main/helm/helm-service.ts index 3cf56ccb13..2fe531c215 100644 --- a/src/main/helm/helm-service.ts +++ b/src/main/helm/helm-service.ts @@ -24,7 +24,7 @@ import type { Cluster } from "../cluster"; import logger from "../logger"; import { HelmRepoManager } from "./helm-repo-manager"; import { HelmChartManager } from "./helm-chart-manager"; -import type { HelmChart, HelmChartList, RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api"; +import type { HelmChart, HelmChartList, RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api"; import { deleteRelease, getHistory, getRelease, getValues, installChart, listReleases, rollback, upgradeRelease } from "./helm-release-manager"; import { iter, sortCompareChartVersions } from "../../common/utils"; diff --git a/src/main/k8s-request.ts b/src/main/k8s-request.ts index 513860fbd9..923ec81609 100644 --- a/src/main/k8s-request.ts +++ b/src/main/k8s-request.ts @@ -21,7 +21,7 @@ import request, { RequestPromiseOptions } from "request-promise-native"; import { apiKubePrefix } from "../common/vars"; -import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api"; +import type { IMetricsReqParams } from "../common/k8s-api/endpoints/metrics.api"; import { LensProxy } from "./lens-proxy"; import type { Cluster } from "./cluster"; diff --git a/src/main/lens-proxy.ts b/src/main/lens-proxy.ts index fef1183f32..353ed935e7 100644 --- a/src/main/lens-proxy.ts +++ b/src/main/lens-proxy.ts @@ -97,6 +97,7 @@ export class LensProxy extends Singleton { }); this.port = port; + process.env.LENS_PROXY_PORT = port.toString(); resolve(); }) .once("error", (error) => { diff --git a/src/main/logger.ts b/src/main/logger.ts index ffa695ac2e..b6d7e7ebb9 100644 --- a/src/main/logger.ts +++ b/src/main/logger.ts @@ -19,95 +19,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { app, remote } from "electron"; -import winston from "winston"; -import Transport from "winston-transport"; -import { isDebugging, isTestEnv } from "../common/vars"; -import { LEVEL } from "triple-beam"; -import { Severity } from "@sentry/browser"; -import * as Sentry from "@sentry/electron"; +import logger from "../common/logger"; -const SENTRY_LEVELS_MAP = { - silly: Severity.Debug, - verbose: Severity.Debug, - debug: Severity.Debug, - info: Severity.Info, - warn: Severity.Warning, - error: Severity.Error, -}; -const WINSTON_CMP: Record> = { - silly: new Set(["silly", "verbose", "debug", "info", "warn", "error"]), - verbose: new Set(["verbose", "debug", "info", "warn", "error"]), - debug: new Set(["debug", "info", "warn", "error"]), - info: new Set(["info", "warn", "error"]), - warn: new Set(["warn", "error"]), - error: new Set(["error"]), -}; - -type WinstonLevel = keyof typeof SENTRY_LEVELS_MAP; - -class SentryTransport extends Transport { - logLevels: Set; - - constructor(minWinstonLevel: WinstonLevel) { - super(); - - this.logLevels = WINSTON_CMP[minWinstonLevel]; - } - - log(info: any, next: () => void) { - setImmediate(() => { - this.emit("logged", info); - }); - - const { message, level: _, tags, user, ...extra } = info; - const winstonLevel: WinstonLevel = info[LEVEL]; - const level = SENTRY_LEVELS_MAP[winstonLevel]; - - try { - if (this.logLevels.has(winstonLevel)) { - Sentry.captureMessage(message, { - level, - tags, - extra, - }); - } - } finally { - next(); - } - } -} - -interface CreateLoggerOpts extends winston.LoggerOptions { - transports?: Transport[]; -} - -const logLevel = process.env.LOG_LEVEL || (isDebugging ? "debug" : "info"); - -const loggerOpts: CreateLoggerOpts = { - format: winston.format.combine( - winston.format.colorize(), - winston.format.simple(), - ), - transports: [ - new SentryTransport("error"), - new winston.transports.Console({ - handleExceptions: false, - level: logLevel, - }), - ], -}; - -if (!isTestEnv) { - loggerOpts.transports.push(new winston.transports.File({ - handleExceptions: false, - level: logLevel, - filename: "lens.log", - dirname: (app ?? remote?.app)?.getPath("logs"), - maxsize: 16 * 1024, - maxFiles: 16, - tailable: true, - })); -} - -export default winston.createLogger(loggerOpts); +export default logger; diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 13045bc496..88d7dff0af 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -31,6 +31,7 @@ import { IpcRendererNavigationEvents } from "../renderer/navigation/events"; import logger from "./logger"; import { productName } from "../common/vars"; import { LensProxy } from "./lens-proxy"; +import * as path from "path"; function isHideable(window: BrowserWindow | null): boolean { return Boolean(window && !window.isDestroyed()); @@ -84,6 +85,7 @@ export class WindowManager extends Singleton { titleBarStyle: "hidden", backgroundColor: "#1e2124", webPreferences: { + preload: path.join(__static, "build", "preload.js"), nodeIntegration: true, nodeIntegrationInSubFrames: true, enableRemoteModule: true, diff --git a/src/preload.ts b/src/preload.ts new file mode 100644 index 0000000000..71c601c2fa --- /dev/null +++ b/src/preload.ts @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import fetch from "node-fetch"; + +export { + fetch +}; diff --git a/src/renderer/api/index.ts b/src/renderer/api/index.ts index e46898d3b7..054dac794f 100644 --- a/src/renderer/api/index.ts +++ b/src/renderer/api/index.ts @@ -19,19 +19,12 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { JsonApi, JsonApiErrorParsed } from "./json-api"; -import { KubeJsonApi } from "./kube-json-api"; +import type { JsonApiErrorParsed } from "../../common/k8s-api/json-api"; +import type { Response } from "node-fetch"; import { Notifications } from "../components/notifications"; -import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars"; +import { apiBase, apiKube } from "../../common/k8s-api"; +export { apiBase, apiKube } from "../../common/k8s-api"; -export const apiBase = new JsonApi({ - apiBase: apiPrefix, - debug: isDevelopment || isDebugging, -}); -export const apiKube = new KubeJsonApi({ - apiBase: apiKubePrefix, - debug: isDevelopment, -}); // Common handler for HTTP api errors export function onApiError(error: JsonApiErrorParsed, res: Response) { @@ -43,5 +36,5 @@ export function onApiError(error: JsonApiErrorParsed, res: Response) { } } -apiBase.onError.addListener(onApiError); -apiKube.onError.addListener(onApiError); +if (apiBase) apiBase.onError.addListener(onApiError); +if (apiKube) apiKube.onError.addListener(onApiError); diff --git a/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx b/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx index 963df018af..d1a152808a 100644 --- a/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx +++ b/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx @@ -22,7 +22,7 @@ import "./helm-chart-details.scss"; import React, { Component } from "react"; -import { getChartDetails, HelmChart } from "../../api/endpoints/helm-charts.api"; +import { getChartDetails, HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api"; import { observable, autorun, makeObservable } from "mobx"; import { observer } from "mobx-react"; import { Drawer, DrawerItem } from "../drawer"; diff --git a/src/renderer/components/+apps-helm-charts/helm-chart.store.ts b/src/renderer/components/+apps-helm-charts/helm-chart.store.ts index 71a5072068..e97e9fc276 100644 --- a/src/renderer/components/+apps-helm-charts/helm-chart.store.ts +++ b/src/renderer/components/+apps-helm-charts/helm-chart.store.ts @@ -22,8 +22,8 @@ import semver from "semver"; import { observable, makeObservable } from "mobx"; import { autoBind, sortCompareChartVersions } from "../../utils"; -import { getChartDetails, HelmChart, listCharts } from "../../api/endpoints/helm-charts.api"; -import { ItemStore } from "../../item.store"; +import { getChartDetails, HelmChart, listCharts } from "../../../common/k8s-api/endpoints/helm-charts.api"; +import { ItemStore } from "../../../common/item.store"; import flatten from "lodash/flatten"; export interface IChartVersion { diff --git a/src/renderer/components/+apps-helm-charts/helm-charts.tsx b/src/renderer/components/+apps-helm-charts/helm-charts.tsx index 1fc1dbf7b0..169b2c258d 100644 --- a/src/renderer/components/+apps-helm-charts/helm-charts.tsx +++ b/src/renderer/components/+apps-helm-charts/helm-charts.tsx @@ -25,7 +25,7 @@ import React, { Component } from "react"; import type { RouteComponentProps } from "react-router"; import { observer } from "mobx-react"; import { helmChartStore } from "./helm-chart.store"; -import type { HelmChart } from "../../api/endpoints/helm-charts.api"; +import type { HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api"; import { HelmChartDetails } from "./helm-chart-details"; import { navigation } from "../../navigation"; import { ItemListLayout } from "../item-object-list/item-list-layout"; diff --git a/src/renderer/components/+apps-releases/release-details.tsx b/src/renderer/components/+apps-releases/release-details.tsx index bf3850f462..e3e68ffb53 100644 --- a/src/renderer/components/+apps-releases/release-details.tsx +++ b/src/renderer/components/+apps-releases/release-details.tsx @@ -27,7 +27,7 @@ import isEqual from "lodash/isEqual"; import { observable, reaction, makeObservable } from "mobx"; import { Link } from "react-router-dom"; import kebabCase from "lodash/kebabCase"; -import { getRelease, getReleaseValues, HelmRelease, IReleaseDetails } from "../../api/endpoints/helm-releases.api"; +import { getRelease, getReleaseValues, HelmRelease, IReleaseDetails } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { HelmReleaseMenu } from "./release-menu"; import { Drawer, DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; @@ -41,10 +41,10 @@ import { releaseStore } from "./release.store"; import { Notifications } from "../notifications"; import { createUpgradeChartTab } from "../dock/upgrade-chart.store"; import { ThemeStore } from "../../theme.store"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { SubTitle } from "../layout/sub-title"; import { secretsStore } from "../+config-secrets/secrets.store"; -import { Secret } from "../../api/endpoints"; +import { Secret } from "../../../common/k8s-api/endpoints"; import { getDetailsUrl } from "../kube-detail-params"; import { Checkbox } from "../checkbox"; diff --git a/src/renderer/components/+apps-releases/release-menu.tsx b/src/renderer/components/+apps-releases/release-menu.tsx index d74ffcc6eb..0b8d4b8c91 100644 --- a/src/renderer/components/+apps-releases/release-menu.tsx +++ b/src/renderer/components/+apps-releases/release-menu.tsx @@ -20,7 +20,7 @@ */ import React from "react"; -import type { HelmRelease } from "../../api/endpoints/helm-releases.api"; +import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { boundMethod, cssNames } from "../../utils"; import { releaseStore } from "./release.store"; import { MenuActions, MenuActionsProps } from "../menu/menu-actions"; diff --git a/src/renderer/components/+apps-releases/release-rollback-dialog.tsx b/src/renderer/components/+apps-releases/release-rollback-dialog.tsx index e42813f1f9..07de38232f 100644 --- a/src/renderer/components/+apps-releases/release-rollback-dialog.tsx +++ b/src/renderer/components/+apps-releases/release-rollback-dialog.tsx @@ -26,7 +26,7 @@ import { observable, makeObservable } from "mobx"; import { observer } from "mobx-react"; import { Dialog, DialogProps } from "../dialog"; import { Wizard, WizardStep } from "../wizard"; -import { getReleaseHistory, HelmRelease, IReleaseRevision } from "../../api/endpoints/helm-releases.api"; +import { getReleaseHistory, HelmRelease, IReleaseRevision } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { releaseStore } from "./release.store"; import { Select, SelectOption } from "../select"; import { Notifications } from "../notifications"; diff --git a/src/renderer/components/+apps-releases/release.store.ts b/src/renderer/components/+apps-releases/release.store.ts index 9d704566e7..93b5cf5eef 100644 --- a/src/renderer/components/+apps-releases/release.store.ts +++ b/src/renderer/components/+apps-releases/release.store.ts @@ -22,9 +22,9 @@ import isEqual from "lodash/isEqual"; import { action, observable, reaction, when, makeObservable } from "mobx"; import { autoBind } from "../../utils"; -import { createRelease, deleteRelease, HelmRelease, IReleaseCreatePayload, IReleaseUpdatePayload, listReleases, rollbackRelease, updateRelease } from "../../api/endpoints/helm-releases.api"; -import { ItemStore } from "../../item.store"; -import type { Secret } from "../../api/endpoints"; +import { createRelease, deleteRelease, HelmRelease, IReleaseCreatePayload, IReleaseUpdatePayload, listReleases, rollbackRelease, updateRelease } from "../../../common/k8s-api/endpoints/helm-releases.api"; +import { ItemStore } from "../../../common/item.store"; +import type { Secret } from "../../../common/k8s-api/endpoints"; import { secretsStore } from "../+config-secrets/secrets.store"; import { namespaceStore } from "../+namespaces/namespace.store"; import { Notifications } from "../notifications"; diff --git a/src/renderer/components/+apps-releases/releases.tsx b/src/renderer/components/+apps-releases/releases.tsx index cf464710c5..d43174cc10 100644 --- a/src/renderer/components/+apps-releases/releases.tsx +++ b/src/renderer/components/+apps-releases/releases.tsx @@ -26,7 +26,7 @@ import kebabCase from "lodash/kebabCase"; import { disposeOnUnmount, observer } from "mobx-react"; import type { RouteComponentProps } from "react-router"; import { releaseStore } from "./release.store"; -import type { HelmRelease } from "../../api/endpoints/helm-releases.api"; +import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { ReleaseDetails } from "./release-details"; import { ReleaseRollbackDialog } from "./release-rollback-dialog"; import { navigation } from "../../navigation"; diff --git a/src/renderer/components/+catalog/catalog-entity.store.tsx b/src/renderer/components/+catalog/catalog-entity.store.tsx index b606d54c1a..c5bb96e5f2 100644 --- a/src/renderer/components/+catalog/catalog-entity.store.tsx +++ b/src/renderer/components/+catalog/catalog-entity.store.tsx @@ -25,14 +25,14 @@ import React from "react"; import { action, computed, IReactionDisposer, makeObservable, observable, reaction } from "mobx"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import type { CatalogEntity, CatalogEntityActionContext } from "../../api/catalog-entity"; -import { ItemObject, ItemStore } from "../../item.store"; +import { ItemObject, ItemStore } from "../../../common/item.store"; import { CatalogCategory, catalogCategoryRegistry } from "../../../common/catalog"; import { autoBind } from "../../../common/utils"; import { Badge } from "../badge"; import { navigation } from "../../navigation"; import { searchUrlParam } from "../input"; import { makeCss } from "../../../common/utils/makeCss"; -import { KubeObject } from "../../api/kube-object"; +import { KubeObject } from "../../../common/k8s-api/kube-object"; const css = makeCss(styles); diff --git a/src/renderer/components/+cluster/cluster-issues.tsx b/src/renderer/components/+cluster/cluster-issues.tsx index a68950bc0e..9b5f73b9a6 100644 --- a/src/renderer/components/+cluster/cluster-issues.tsx +++ b/src/renderer/components/+cluster/cluster-issues.tsx @@ -30,12 +30,12 @@ import { Table, TableCell, TableHead, TableRow } from "../table"; import { nodesStore } from "../+nodes/nodes.store"; import { eventStore } from "../+events/event.store"; import { boundMethod, cssNames, prevDefault } from "../../utils"; -import type { ItemObject } from "../../item.store"; +import type { ItemObject } from "../../../common/item.store"; import { Spinner } from "../spinner"; import { ThemeStore } from "../../theme.store"; -import { apiManager } from "../../api/api-manager"; import { kubeSelectedUrlParam, showDetails } from "../kube-detail-params"; -import { kubeWatchApi } from "../../api/kube-watch-api"; +import { kubeWatchApi } from "../../../common/k8s-api/kube-watch-api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; interface Props { className?: string; diff --git a/src/renderer/components/+cluster/cluster-metrics.tsx b/src/renderer/components/+cluster/cluster-metrics.tsx index 0c4910e7e5..43e540dca2 100644 --- a/src/renderer/components/+cluster/cluster-metrics.tsx +++ b/src/renderer/components/+cluster/cluster-metrics.tsx @@ -31,7 +31,7 @@ import { Spinner } from "../spinner"; import { ZebraStripes } from "../chart/zebra-stripes.plugin"; import { ClusterNoMetrics } from "./cluster-no-metrics"; import { ClusterMetricSwitchers } from "./cluster-metric-switchers"; -import { getMetricLastPoints } from "../../api/endpoints/metrics.api"; +import { getMetricLastPoints } from "../../../common/k8s-api/endpoints/metrics.api"; export const ClusterMetrics = observer(() => { const { metricType, metricNodeRole, getMetricsValues, metricsLoaded, metrics } = clusterOverviewStore; diff --git a/src/renderer/components/+cluster/cluster-overview.store.ts b/src/renderer/components/+cluster/cluster-overview.store.ts index 547eb6832f..17cc100109 100644 --- a/src/renderer/components/+cluster/cluster-overview.store.ts +++ b/src/renderer/components/+cluster/cluster-overview.store.ts @@ -20,12 +20,12 @@ */ import { action, observable, reaction, when, makeObservable } from "mobx"; -import { KubeObjectStore } from "../../kube-object.store"; -import { Cluster, clusterApi, getMetricsByNodeNames, IClusterMetrics } from "../../api/endpoints"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { Cluster, clusterApi, getMetricsByNodeNames, IClusterMetrics } from "../../../common/k8s-api/endpoints"; import { autoBind, createStorage } from "../../utils"; -import { IMetricsReqParams, normalizeMetrics } from "../../api/endpoints/metrics.api"; +import { IMetricsReqParams, normalizeMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { nodesStore } from "../+nodes/nodes.store"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export enum MetricType { MEMORY = "memory", diff --git a/src/renderer/components/+cluster/cluster-pie-charts.tsx b/src/renderer/components/+cluster/cluster-pie-charts.tsx index 979a91f0bb..76bb6967f6 100644 --- a/src/renderer/components/+cluster/cluster-pie-charts.tsx +++ b/src/renderer/components/+cluster/cluster-pie-charts.tsx @@ -31,7 +31,7 @@ import { ChartData, PieChart } from "../chart"; import { ClusterNoMetrics } from "./cluster-no-metrics"; import { bytesToUnits } from "../../utils"; import { ThemeStore } from "../../theme.store"; -import { getMetricLastPoints } from "../../api/endpoints/metrics.api"; +import { getMetricLastPoints } from "../../../common/k8s-api/endpoints/metrics.api"; function createLabels(rawLabelData: [string, number | undefined][]): string[] { return rawLabelData.map(([key, value]) => `${key}: ${value?.toFixed(2) || "N/A"}`); diff --git a/src/renderer/components/+config-autoscalers/hpa-details.tsx b/src/renderer/components/+config-autoscalers/hpa-details.tsx index 4849c69fe0..4dd544e5b1 100644 --- a/src/renderer/components/+config-autoscalers/hpa-details.tsx +++ b/src/renderer/components/+config-autoscalers/hpa-details.tsx @@ -28,9 +28,9 @@ import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { cssNames } from "../../utils"; -import { HorizontalPodAutoscaler, HpaMetricType, IHpaMetric } from "../../api/endpoints/hpa.api"; +import { HorizontalPodAutoscaler, HpaMetricType, IHpaMetric } from "../../../common/k8s-api/endpoints/hpa.api"; import { Table, TableCell, TableHead, TableRow } from "../table"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { KubeObjectMeta } from "../kube-object-meta"; import { getDetailsUrl } from "../kube-detail-params"; diff --git a/src/renderer/components/+config-autoscalers/hpa.store.ts b/src/renderer/components/+config-autoscalers/hpa.store.ts index d92ffd3a6f..c129b32acd 100644 --- a/src/renderer/components/+config-autoscalers/hpa.store.ts +++ b/src/renderer/components/+config-autoscalers/hpa.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { HorizontalPodAutoscaler, hpaApi } from "../../api/endpoints/hpa.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { HorizontalPodAutoscaler, hpaApi } from "../../../common/k8s-api/endpoints/hpa.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class HPAStore extends KubeObjectStore { api = hpaApi; diff --git a/src/renderer/components/+config-autoscalers/hpa.tsx b/src/renderer/components/+config-autoscalers/hpa.tsx index 855b5c3cec..c620e6c629 100644 --- a/src/renderer/components/+config-autoscalers/hpa.tsx +++ b/src/renderer/components/+config-autoscalers/hpa.tsx @@ -25,7 +25,7 @@ import React from "react"; import { observer } from "mobx-react"; import type { RouteComponentProps } from "react-router"; import { KubeObjectListLayout } from "../kube-object-list-layout"; -import type { HorizontalPodAutoscaler } from "../../api/endpoints/hpa.api"; +import type { HorizontalPodAutoscaler } from "../../../common/k8s-api/endpoints/hpa.api"; import { hpaStore } from "./hpa.store"; import { Badge } from "../badge"; import { cssNames } from "../../utils"; diff --git a/src/renderer/components/+config-limit-ranges/limit-range-details.tsx b/src/renderer/components/+config-limit-ranges/limit-range-details.tsx index 0d235252f2..e9acbd0a22 100644 --- a/src/renderer/components/+config-limit-ranges/limit-range-details.tsx +++ b/src/renderer/components/+config-limit-ranges/limit-range-details.tsx @@ -24,7 +24,7 @@ import "./limit-range-details.scss"; import React from "react"; import { observer } from "mobx-react"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { LimitPart, LimitRange, LimitRangeItem, Resource } from "../../api/endpoints/limit-range.api"; +import { LimitPart, LimitRange, LimitRangeItem, Resource } from "../../../common/k8s-api/endpoints/limit-range.api"; import { KubeObjectMeta } from "../kube-object-meta"; import { DrawerItem } from "../drawer/drawer-item"; import { Badge } from "../badge"; diff --git a/src/renderer/components/+config-limit-ranges/limit-ranges.store.ts b/src/renderer/components/+config-limit-ranges/limit-ranges.store.ts index af7ebe6b41..4f4bd52ced 100644 --- a/src/renderer/components/+config-limit-ranges/limit-ranges.store.ts +++ b/src/renderer/components/+config-limit-ranges/limit-ranges.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { apiManager } from "../../api/api-manager"; -import { LimitRange, limitRangeApi } from "../../api/endpoints/limit-range.api"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { LimitRange, limitRangeApi } from "../../../common/k8s-api/endpoints/limit-range.api"; export class LimitRangesStore extends KubeObjectStore { api = limitRangeApi; diff --git a/src/renderer/components/+config-maps/config-map-details.tsx b/src/renderer/components/+config-maps/config-map-details.tsx index b34ca83ab2..abbd31c97a 100644 --- a/src/renderer/components/+config-maps/config-map-details.tsx +++ b/src/renderer/components/+config-maps/config-map-details.tsx @@ -30,7 +30,7 @@ import { Input } from "../input"; import { Button } from "../button"; import { configMapsStore } from "./config-maps.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { ConfigMap } from "../../api/endpoints"; +import type { ConfigMap } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; interface Props extends KubeObjectDetailsProps { diff --git a/src/renderer/components/+config-maps/config-maps.store.ts b/src/renderer/components/+config-maps/config-maps.store.ts index e45c9b3b27..164b9fa604 100644 --- a/src/renderer/components/+config-maps/config-maps.store.ts +++ b/src/renderer/components/+config-maps/config-maps.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { ConfigMap, configMapApi } from "../../api/endpoints/configmap.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { ConfigMap, configMapApi } from "../../../common/k8s-api/endpoints/configmap.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class ConfigMapsStore extends KubeObjectStore { api = configMapApi; diff --git a/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets-details.tsx b/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets-details.tsx index 4f8aaab465..15c17ae639 100644 --- a/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets-details.tsx +++ b/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets-details.tsx @@ -26,7 +26,7 @@ import { observer } from "mobx-react"; import { DrawerItem } from "../drawer"; import { Badge } from "../badge"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { PodDisruptionBudget } from "../../api/endpoints"; +import type { PodDisruptionBudget } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; interface Props extends KubeObjectDetailsProps { diff --git a/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.store.ts b/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.store.ts index b4a48fbef7..3011e20065 100644 --- a/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.store.ts +++ b/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { pdbApi, PodDisruptionBudget } from "../../api/endpoints/poddisruptionbudget.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { pdbApi, PodDisruptionBudget } from "../../../common/k8s-api/endpoints/poddisruptionbudget.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class PodDisruptionBudgetsStore extends KubeObjectStore { api = pdbApi; diff --git a/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.tsx b/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.tsx index 1b1420931e..1278f96f59 100644 --- a/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.tsx +++ b/src/renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.tsx @@ -24,7 +24,7 @@ import "./pod-disruption-budgets.scss"; import * as React from "react"; import { observer } from "mobx-react"; import { podDisruptionBudgetsStore } from "./pod-disruption-budgets.store"; -import type { PodDisruptionBudget } from "../../api/endpoints/poddisruptionbudget.api"; +import type { PodDisruptionBudget } from "../../../common/k8s-api/endpoints/poddisruptionbudget.api"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectListLayout } from "../kube-object-list-layout"; diff --git a/src/renderer/components/+config-resource-quotas/add-quota-dialog.tsx b/src/renderer/components/+config-resource-quotas/add-quota-dialog.tsx index b341d2c86a..0fc2149e45 100644 --- a/src/renderer/components/+config-resource-quotas/add-quota-dialog.tsx +++ b/src/renderer/components/+config-resource-quotas/add-quota-dialog.tsx @@ -28,7 +28,7 @@ import { Dialog, DialogProps } from "../dialog"; import { Wizard, WizardStep } from "../wizard"; import { Input } from "../input"; import { systemName } from "../input/input_validators"; -import { IResourceQuotaValues, resourceQuotaApi } from "../../api/endpoints/resource-quota.api"; +import { IResourceQuotaValues, resourceQuotaApi } from "../../../common/k8s-api/endpoints/resource-quota.api"; import { Select } from "../select"; import { Icon } from "../icon"; import { Button } from "../button"; diff --git a/src/renderer/components/+config-resource-quotas/resource-quota-details.tsx b/src/renderer/components/+config-resource-quotas/resource-quota-details.tsx index 06a154db61..3b07bc9a7a 100644 --- a/src/renderer/components/+config-resource-quotas/resource-quota-details.tsx +++ b/src/renderer/components/+config-resource-quotas/resource-quota-details.tsx @@ -26,7 +26,7 @@ import { observer } from "mobx-react"; import { DrawerItem, DrawerTitle } from "../drawer"; import { cpuUnitsToNumber, cssNames, unitsToBytes, metricUnitsToNumber } from "../../utils"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { ResourceQuota } from "../../api/endpoints/resource-quota.api"; +import type { ResourceQuota } from "../../../common/k8s-api/endpoints/resource-quota.api"; import { LineProgress } from "../line-progress"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { KubeObjectMeta } from "../kube-object-meta"; diff --git a/src/renderer/components/+config-resource-quotas/resource-quotas.store.ts b/src/renderer/components/+config-resource-quotas/resource-quotas.store.ts index 5e7494b33a..9ec218f346 100644 --- a/src/renderer/components/+config-resource-quotas/resource-quotas.store.ts +++ b/src/renderer/components/+config-resource-quotas/resource-quotas.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { ResourceQuota, resourceQuotaApi } from "../../api/endpoints/resource-quota.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { ResourceQuota, resourceQuotaApi } from "../../../common/k8s-api/endpoints/resource-quota.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class ResourceQuotasStore extends KubeObjectStore { api = resourceQuotaApi; diff --git a/src/renderer/components/+config-secrets/add-secret-dialog.tsx b/src/renderer/components/+config-secrets/add-secret-dialog.tsx index d93b19d405..d74a523dc5 100644 --- a/src/renderer/components/+config-secrets/add-secret-dialog.tsx +++ b/src/renderer/components/+config-secrets/add-secret-dialog.tsx @@ -28,12 +28,12 @@ import { Dialog, DialogProps } from "../dialog"; import { Wizard, WizardStep } from "../wizard"; import { Input } from "../input"; import { systemName } from "../input/input_validators"; -import { Secret, secretsApi, SecretType } from "../../api/endpoints"; +import { Secret, secretsApi, SecretType } from "../../../common/k8s-api/endpoints"; import { SubTitle } from "../layout/sub-title"; import { NamespaceSelect } from "../+namespaces/namespace-select"; import { Select, SelectOption } from "../select"; import { Icon } from "../icon"; -import type { KubeObjectMetadata } from "../../api/kube-object"; +import type { KubeObjectMetadata } from "../../../common/k8s-api/kube-object"; import { base64 } from "../../utils"; import { Notifications } from "../notifications"; import upperFirst from "lodash/upperFirst"; diff --git a/src/renderer/components/+config-secrets/secret-details.tsx b/src/renderer/components/+config-secrets/secret-details.tsx index 370c28b9d2..bfd6e9d257 100644 --- a/src/renderer/components/+config-secrets/secret-details.tsx +++ b/src/renderer/components/+config-secrets/secret-details.tsx @@ -33,7 +33,7 @@ import { base64 } from "../../utils"; import { Icon } from "../icon"; import { secretsStore } from "./secrets.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { Secret } from "../../api/endpoints"; +import type { Secret } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; interface Props extends KubeObjectDetailsProps { diff --git a/src/renderer/components/+config-secrets/secrets.store.ts b/src/renderer/components/+config-secrets/secrets.store.ts index f338232371..4bf99bceda 100644 --- a/src/renderer/components/+config-secrets/secrets.store.ts +++ b/src/renderer/components/+config-secrets/secrets.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { Secret, secretsApi } from "../../api/endpoints"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { Secret, secretsApi } from "../../../common/k8s-api/endpoints"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class SecretsStore extends KubeObjectStore { api = secretsApi; diff --git a/src/renderer/components/+custom-resources/crd-details.tsx b/src/renderer/components/+custom-resources/crd-details.tsx index 79d5a31e65..d8de38d671 100644 --- a/src/renderer/components/+custom-resources/crd-details.tsx +++ b/src/renderer/components/+custom-resources/crd-details.tsx @@ -24,7 +24,7 @@ import "./crd-details.scss"; import React from "react"; import { Link } from "react-router-dom"; import { observer } from "mobx-react"; -import type { CustomResourceDefinition } from "../../api/endpoints/crd.api"; +import type { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/crd.api"; import { AceEditor } from "../ace-editor"; import { Badge } from "../badge"; import { DrawerItem, DrawerTitle } from "../drawer"; diff --git a/src/renderer/components/+custom-resources/crd-list.tsx b/src/renderer/components/+custom-resources/crd-list.tsx index fb0735d223..e257289008 100644 --- a/src/renderer/components/+custom-resources/crd-list.tsx +++ b/src/renderer/components/+custom-resources/crd-list.tsx @@ -28,7 +28,7 @@ import { Link } from "react-router-dom"; import { stopPropagation } from "../../utils"; import { KubeObjectListLayout } from "../kube-object-list-layout"; import { crdStore } from "./crd.store"; -import type { CustomResourceDefinition } from "../../api/endpoints/crd.api"; +import type { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/crd.api"; import { Select, SelectOption } from "../select"; import { createPageParam } from "../../navigation"; import { Icon } from "../icon"; diff --git a/src/renderer/components/+custom-resources/crd-resource-details.tsx b/src/renderer/components/+custom-resources/crd-resource-details.tsx index 9acaa93e86..b20ad7d885 100644 --- a/src/renderer/components/+custom-resources/crd-resource-details.tsx +++ b/src/renderer/components/+custom-resources/crd-resource-details.tsx @@ -30,9 +30,9 @@ import { DrawerItem } from "../drawer"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectMeta } from "../kube-object-meta"; import { Input } from "../input"; -import type { AdditionalPrinterColumnsV1, CustomResourceDefinition } from "../../api/endpoints/crd.api"; +import type { AdditionalPrinterColumnsV1, CustomResourceDefinition } from "../../../common/k8s-api/endpoints/crd.api"; import { parseJsonPath } from "../../utils/jsonPath"; -import type { KubeObject, KubeObjectMetadata, KubeObjectStatus } from "../../api/kube-object"; +import type { KubeObject, KubeObjectMetadata, KubeObjectStatus } from "../../../common/k8s-api/kube-object"; interface Props extends KubeObjectDetailsProps { crd: CustomResourceDefinition; diff --git a/src/renderer/components/+custom-resources/crd-resource.store.ts b/src/renderer/components/+custom-resources/crd-resource.store.ts index 335a015aa7..f71f8e6400 100644 --- a/src/renderer/components/+custom-resources/crd-resource.store.ts +++ b/src/renderer/components/+custom-resources/crd-resource.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { KubeApi } from "../../api/kube-api"; -import { KubeObjectStore } from "../../kube-object.store"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeApi } from "../../../common/k8s-api/kube-api"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; export class CRDResourceStore extends KubeObjectStore { api: KubeApi; diff --git a/src/renderer/components/+custom-resources/crd-resources.tsx b/src/renderer/components/+custom-resources/crd-resources.tsx index d64dd4e5f0..7c0e36639a 100644 --- a/src/renderer/components/+custom-resources/crd-resources.tsx +++ b/src/renderer/components/+custom-resources/crd-resources.tsx @@ -26,11 +26,11 @@ import jsonPath from "jsonpath"; import { observer } from "mobx-react"; import type { RouteComponentProps } from "react-router"; import { KubeObjectListLayout } from "../kube-object-list-layout"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { computed, makeObservable } from "mobx"; import { crdStore } from "./crd.store"; import type { TableSortCallbacks } from "../table"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { parseJsonPath } from "../../utils/jsonPath"; import type { CRDRouteParams } from "../../../common/routes"; diff --git a/src/renderer/components/+custom-resources/crd.store.ts b/src/renderer/components/+custom-resources/crd.store.ts index 25415e5ab3..83c8b5cdb6 100644 --- a/src/renderer/components/+custom-resources/crd.store.ts +++ b/src/renderer/components/+custom-resources/crd.store.ts @@ -20,13 +20,13 @@ */ import { computed, reaction, makeObservable } from "mobx"; -import { KubeObjectStore } from "../../kube-object.store"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; -import { crdApi, CustomResourceDefinition } from "../../api/endpoints/crd.api"; -import { apiManager } from "../../api/api-manager"; -import { KubeApi } from "../../api/kube-api"; +import { crdApi, CustomResourceDefinition } from "../../../common/k8s-api/endpoints/crd.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { KubeApi } from "../../../common/k8s-api/kube-api"; import { CRDResourceStore } from "./crd-resource.store"; -import { KubeObject } from "../../api/kube-object"; +import { KubeObject } from "../../../common/k8s-api/kube-object"; function initStore(crd: CustomResourceDefinition) { const apiBase = crd.getResourceApiBase(); diff --git a/src/renderer/components/+events/event-details.tsx b/src/renderer/components/+events/event-details.tsx index 496e249df3..010928a6d5 100644 --- a/src/renderer/components/+events/event-details.tsx +++ b/src/renderer/components/+events/event-details.tsx @@ -27,12 +27,12 @@ import { DrawerItem, DrawerTitle } from "../drawer"; import { Link } from "react-router-dom"; import { observer } from "mobx-react"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { KubeEvent } from "../../api/endpoints/events.api"; +import type { KubeEvent } from "../../../common/k8s-api/endpoints/events.api"; import { KubeObjectMeta } from "../kube-object-meta"; import { Table, TableCell, TableHead, TableRow } from "../table"; -import { apiManager } from "../../api/api-manager"; import { LocaleDate } from "../locale-date"; import { getDetailsUrl } from "../kube-detail-params"; +import { apiManager } from "../../../common/k8s-api/api-manager"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+events/event.store.ts b/src/renderer/components/+events/event.store.ts index c2f90475d0..b655e7f611 100644 --- a/src/renderer/components/+events/event.store.ts +++ b/src/renderer/components/+events/event.store.ts @@ -21,13 +21,13 @@ import groupBy from "lodash/groupBy"; import compact from "lodash/compact"; -import { KubeObjectStore } from "../../kube-object.store"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; -import { eventApi, KubeEvent } from "../../api/endpoints/events.api"; -import type { KubeObject } from "../../api/kube-object"; -import { Pod } from "../../api/endpoints/pods.api"; +import { eventApi, KubeEvent } from "../../../common/k8s-api/endpoints/events.api"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; +import { Pod } from "../../../common/k8s-api/endpoints/pods.api"; import { podsStore } from "../+workloads-pods/pods.store"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class EventStore extends KubeObjectStore { api = eventApi; diff --git a/src/renderer/components/+events/events.tsx b/src/renderer/components/+events/events.tsx index ae9d71415d..456de9e2aa 100644 --- a/src/renderer/components/+events/events.tsx +++ b/src/renderer/components/+events/events.tsx @@ -28,16 +28,16 @@ import { orderBy } from "lodash"; import { TabLayout } from "../layout/tab-layout"; import { EventStore, eventStore } from "./event.store"; import { KubeObjectListLayout, KubeObjectListLayoutProps } from "../kube-object-list-layout"; -import type { KubeEvent } from "../../api/endpoints/events.api"; +import type { KubeEvent } from "../../../common/k8s-api/endpoints/events.api"; import type { TableSortCallbacks, TableSortParams } from "../table"; import type { HeaderCustomizer } from "../item-object-list"; import { Tooltip } from "../tooltip"; import { Link } from "react-router-dom"; import { cssNames, IClassName, stopPropagation } from "../../utils"; import { Icon } from "../icon"; -import { apiManager } from "../../api/api-manager"; import { eventsURL } from "../../../common/routes"; import { getDetailsUrl } from "../kube-detail-params"; +import { apiManager } from "../../../common/k8s-api/api-manager"; enum columnId { message = "message", diff --git a/src/renderer/components/+events/kube-event-details.tsx b/src/renderer/components/+events/kube-event-details.tsx index 4ac3e63a84..7f00fd6a15 100644 --- a/src/renderer/components/+events/kube-event-details.tsx +++ b/src/renderer/components/+events/kube-event-details.tsx @@ -23,7 +23,7 @@ import "./kube-event-details.scss"; import React from "react"; import { observer } from "mobx-react"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { DrawerItem, DrawerTitle } from "../drawer"; import { cssNames } from "../../utils"; import { eventStore } from "./event.store"; diff --git a/src/renderer/components/+events/kube-event-icon.tsx b/src/renderer/components/+events/kube-event-icon.tsx index 03bfa92a07..8fe83d2940 100644 --- a/src/renderer/components/+events/kube-event-icon.tsx +++ b/src/renderer/components/+events/kube-event-icon.tsx @@ -23,10 +23,10 @@ import "./kube-event-icon.scss"; import React from "react"; import { Icon } from "../icon"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { eventStore } from "./event.store"; import { cssNames } from "../../utils"; -import type { KubeEvent } from "../../api/endpoints/events.api"; +import type { KubeEvent } from "../../../common/k8s-api/endpoints/events.api"; interface Props { object: KubeObject; diff --git a/src/renderer/components/+namespaces/add-namespace-dialog.tsx b/src/renderer/components/+namespaces/add-namespace-dialog.tsx index 2427c9fd9b..e01381efe9 100644 --- a/src/renderer/components/+namespaces/add-namespace-dialog.tsx +++ b/src/renderer/components/+namespaces/add-namespace-dialog.tsx @@ -27,7 +27,7 @@ import { observer } from "mobx-react"; import { Dialog, DialogProps } from "../dialog"; import { Wizard, WizardStep } from "../wizard"; import { namespaceStore } from "./namespace.store"; -import type { Namespace } from "../../api/endpoints"; +import type { Namespace } from "../../../common/k8s-api/endpoints"; import { Input } from "../input"; import { systemName } from "../input/input_validators"; import { Notifications } from "../notifications"; diff --git a/src/renderer/components/+namespaces/namespace-details.tsx b/src/renderer/components/+namespaces/namespace-details.tsx index 784cdef3c8..08493e7a6b 100644 --- a/src/renderer/components/+namespaces/namespace-details.tsx +++ b/src/renderer/components/+namespaces/namespace-details.tsx @@ -26,7 +26,7 @@ import { computed, makeObservable, observable, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { DrawerItem } from "../drawer"; import { boundMethod, cssNames } from "../../utils"; -import { getMetricsForNamespace, IPodMetrics, Namespace } from "../../api/endpoints"; +import { getMetricsForNamespace, IPodMetrics, Namespace } from "../../../common/k8s-api/endpoints"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { Link } from "react-router-dom"; import { Spinner } from "../spinner"; diff --git a/src/renderer/components/+namespaces/namespace-select.tsx b/src/renderer/components/+namespaces/namespace-select.tsx index 3a662ef66c..0cefdb2905 100644 --- a/src/renderer/components/+namespaces/namespace-select.tsx +++ b/src/renderer/components/+namespaces/namespace-select.tsx @@ -28,7 +28,7 @@ import { Select, SelectOption, SelectProps } from "../select"; import { cssNames } from "../../utils"; import { Icon } from "../icon"; import { namespaceStore } from "./namespace.store"; -import { kubeWatchApi } from "../../api/kube-watch-api"; +import { kubeWatchApi } from "../../../common/k8s-api/kube-watch-api"; interface Props extends SelectProps { showIcons?: boolean; diff --git a/src/renderer/components/+namespaces/namespace.store.ts b/src/renderer/components/+namespaces/namespace.store.ts index cc4a8b98ce..54f98702fc 100644 --- a/src/renderer/components/+namespaces/namespace.store.ts +++ b/src/renderer/components/+namespaces/namespace.store.ts @@ -21,9 +21,9 @@ import { action, comparer, computed, IReactionDisposer, IReactionOptions, makeObservable, reaction, } from "mobx"; import { autoBind, createStorage, noop } from "../../utils"; -import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../kube-object.store"; -import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore, KubeObjectStoreLoadingParams } from "../../../common/k8s-api/kube-object.store"; +import { Namespace, namespacesApi } from "../../../common/k8s-api/endpoints/namespaces.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class NamespaceStore extends KubeObjectStore { api = namespacesApi; diff --git a/src/renderer/components/+namespaces/namespaces.tsx b/src/renderer/components/+namespaces/namespaces.tsx index cd90d44f9d..f0d3164e23 100644 --- a/src/renderer/components/+namespaces/namespaces.tsx +++ b/src/renderer/components/+namespaces/namespaces.tsx @@ -22,7 +22,7 @@ import "./namespaces.scss"; import React from "react"; -import { NamespaceStatus } from "../../api/endpoints"; +import { NamespaceStatus } from "../../../common/k8s-api/endpoints"; import { AddNamespaceDialog } from "./add-namespace-dialog"; import { TabLayout } from "../layout/tab-layout"; import { Badge } from "../badge"; diff --git a/src/renderer/components/+network-endpoints/endpoint-details.tsx b/src/renderer/components/+network-endpoints/endpoint-details.tsx index 70677cc51e..7805cd8d70 100644 --- a/src/renderer/components/+network-endpoints/endpoint-details.tsx +++ b/src/renderer/components/+network-endpoints/endpoint-details.tsx @@ -25,7 +25,7 @@ import React from "react"; import { observer } from "mobx-react"; import { DrawerTitle } from "../drawer"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { Endpoint } from "../../api/endpoints"; +import type { Endpoint } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; import { EndpointSubsetList } from "./endpoint-subset-list"; diff --git a/src/renderer/components/+network-endpoints/endpoint-subset-list.tsx b/src/renderer/components/+network-endpoints/endpoint-subset-list.tsx index 917d03e320..7dcb1fc99b 100644 --- a/src/renderer/components/+network-endpoints/endpoint-subset-list.tsx +++ b/src/renderer/components/+network-endpoints/endpoint-subset-list.tsx @@ -23,10 +23,10 @@ import "./endpoint-subset-list.scss"; import React from "react"; import { observer } from "mobx-react"; -import { EndpointSubset, Endpoint, EndpointAddress} from "../../api/endpoints"; +import { EndpointSubset, Endpoint, EndpointAddress} from "../../../common/k8s-api/endpoints"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { boundMethod } from "../../utils"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { Link } from "react-router-dom"; import { getDetailsUrl } from "../kube-detail-params"; diff --git a/src/renderer/components/+network-endpoints/endpoints.store.ts b/src/renderer/components/+network-endpoints/endpoints.store.ts index f51e8a072a..e19f868dea 100644 --- a/src/renderer/components/+network-endpoints/endpoints.store.ts +++ b/src/renderer/components/+network-endpoints/endpoints.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { Endpoint, endpointApi } from "../../api/endpoints/endpoint.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { Endpoint, endpointApi } from "../../../common/k8s-api/endpoints/endpoint.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class EndpointStore extends KubeObjectStore { api = endpointApi; diff --git a/src/renderer/components/+network-ingresses/ingress-charts.tsx b/src/renderer/components/+network-ingresses/ingress-charts.tsx index 178d61652c..0811209450 100644 --- a/src/renderer/components/+network-ingresses/ingress-charts.tsx +++ b/src/renderer/components/+network-ingresses/ingress-charts.tsx @@ -22,9 +22,9 @@ import React, { useContext } from "react"; import { observer } from "mobx-react"; import type { ChartOptions, ChartPoint } from "chart.js"; -import type { IIngressMetrics, Ingress } from "../../api/endpoints"; +import type { IIngressMetrics, Ingress } from "../../../common/k8s-api/endpoints"; import { BarChart, memoryOptions } from "../chart"; -import { normalizeMetrics, isMetricsEmpty } from "../../api/endpoints/metrics.api"; +import { normalizeMetrics, isMetricsEmpty } from "../../../common/k8s-api/endpoints/metrics.api"; import { NoMetrics } from "../resource-metrics/no-metrics"; import { ResourceMetricsContext, IResourceMetricsValue } from "../resource-metrics"; diff --git a/src/renderer/components/+network-ingresses/ingress-details.tsx b/src/renderer/components/+network-ingresses/ingress-details.tsx index bad75d717b..7fe7665041 100644 --- a/src/renderer/components/+network-ingresses/ingress-details.tsx +++ b/src/renderer/components/+network-ingresses/ingress-details.tsx @@ -25,13 +25,13 @@ import React from "react"; import { disposeOnUnmount, observer } from "mobx-react"; import { observable, reaction } from "mobx"; import { DrawerItem, DrawerTitle } from "../drawer"; -import type { ILoadBalancerIngress, Ingress } from "../../api/endpoints"; +import type { ILoadBalancerIngress, Ingress } from "../../../common/k8s-api/endpoints"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { ResourceMetrics } from "../resource-metrics"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { IngressCharts } from "./ingress-charts"; import { KubeObjectMeta } from "../kube-object-meta"; -import { getBackendServiceNamePort, getMetricsForIngress, IIngressMetrics } from "../../api/endpoints/ingress.api"; +import { getBackendServiceNamePort, getMetricsForIngress, IIngressMetrics } from "../../../common/k8s-api/endpoints/ingress.api"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; diff --git a/src/renderer/components/+network-ingresses/ingress.store.ts b/src/renderer/components/+network-ingresses/ingress.store.ts index 72190a5103..ecf25ffa6a 100644 --- a/src/renderer/components/+network-ingresses/ingress.store.ts +++ b/src/renderer/components/+network-ingresses/ingress.store.ts @@ -18,9 +18,9 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { apiManager } from "../../api/api-manager"; -import { Ingress, ingressApi } from "../../api/endpoints"; -import { KubeObjectStore } from "../../kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { Ingress, ingressApi } from "../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class IngressStore extends KubeObjectStore { api = ingressApi; diff --git a/src/renderer/components/+network-policies/network-policy-details.tsx b/src/renderer/components/+network-policies/network-policy-details.tsx index a81afc211b..e08b891c41 100644 --- a/src/renderer/components/+network-policies/network-policy-details.tsx +++ b/src/renderer/components/+network-policies/network-policy-details.tsx @@ -24,7 +24,7 @@ import "./network-policy-details.scss"; import get from "lodash/get"; import React, { Fragment } from "react"; import { DrawerItem, DrawerTitle } from "../drawer"; -import type { IPolicyEgress, IPolicyIngress, IPolicyIpBlock, IPolicySelector, NetworkPolicy } from "../../api/endpoints/network-policy.api"; +import type { IPolicyEgress, IPolicyIngress, IPolicyIpBlock, IPolicySelector, NetworkPolicy } from "../../../common/k8s-api/endpoints/network-policy.api"; import { Badge } from "../badge"; import { SubTitle } from "../layout/sub-title"; import { observer } from "mobx-react"; diff --git a/src/renderer/components/+network-policies/network-policy.store.ts b/src/renderer/components/+network-policies/network-policy.store.ts index f5186e4cfd..4dc547a82e 100644 --- a/src/renderer/components/+network-policies/network-policy.store.ts +++ b/src/renderer/components/+network-policies/network-policy.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { NetworkPolicy, networkPolicyApi } from "../../api/endpoints/network-policy.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { NetworkPolicy, networkPolicyApi } from "../../../common/k8s-api/endpoints/network-policy.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class NetworkPolicyStore extends KubeObjectStore { api = networkPolicyApi; diff --git a/src/renderer/components/+network-services/service-details-endpoint.tsx b/src/renderer/components/+network-services/service-details-endpoint.tsx index 1d41ccf9e5..a36425afb6 100644 --- a/src/renderer/components/+network-services/service-details-endpoint.tsx +++ b/src/renderer/components/+network-services/service-details-endpoint.tsx @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { observer } from "mobx-react"; import React from "react"; import { Table, TableHead, TableCell, TableRow } from "../table"; diff --git a/src/renderer/components/+network-services/service-details.tsx b/src/renderer/components/+network-services/service-details.tsx index 6b6067f077..66a09672a1 100644 --- a/src/renderer/components/+network-services/service-details.tsx +++ b/src/renderer/components/+network-services/service-details.tsx @@ -26,12 +26,12 @@ import { disposeOnUnmount, observer } from "mobx-react"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { Service } from "../../api/endpoints"; +import type { Service } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; import { ServicePortComponent } from "./service-port-component"; import { endpointStore } from "../+network-endpoints/endpoints.store"; import { ServiceDetailsEndpoint } from "./service-details-endpoint"; -import { kubeWatchApi } from "../../api/kube-watch-api"; +import { kubeWatchApi } from "../../../common/k8s-api/kube-watch-api"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+network-services/service-port-component.tsx b/src/renderer/components/+network-services/service-port-component.tsx index a0c4c32f49..96bb7385cb 100644 --- a/src/renderer/components/+network-services/service-port-component.tsx +++ b/src/renderer/components/+network-services/service-port-component.tsx @@ -23,7 +23,7 @@ import "./service-port-component.scss"; import React from "react"; import { observer } from "mobx-react"; -import type { Service, ServicePort } from "../../api/endpoints"; +import type { Service, ServicePort } from "../../../common/k8s-api/endpoints"; import { apiBase } from "../../api"; import { observable, makeObservable } from "mobx"; import { cssNames } from "../../utils"; diff --git a/src/renderer/components/+network-services/services.store.ts b/src/renderer/components/+network-services/services.store.ts index 608d311617..3da75d70a3 100644 --- a/src/renderer/components/+network-services/services.store.ts +++ b/src/renderer/components/+network-services/services.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; -import { Service, serviceApi } from "../../api/endpoints/service.api"; -import { apiManager } from "../../api/api-manager"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { Service, serviceApi } from "../../../common/k8s-api/endpoints/service.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class ServiceStore extends KubeObjectStore { api = serviceApi; diff --git a/src/renderer/components/+nodes/node-charts.tsx b/src/renderer/components/+nodes/node-charts.tsx index 60d6e08842..6f9495fce5 100644 --- a/src/renderer/components/+nodes/node-charts.tsx +++ b/src/renderer/components/+nodes/node-charts.tsx @@ -20,9 +20,9 @@ */ import React, { useContext } from "react"; -import type { IClusterMetrics, Node } from "../../api/endpoints"; +import type { IClusterMetrics, Node } from "../../../common/k8s-api/endpoints"; import { BarChart, cpuOptions, memoryOptions } from "../chart"; -import { isMetricsEmpty, normalizeMetrics } from "../../api/endpoints/metrics.api"; +import { isMetricsEmpty, normalizeMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { NoMetrics } from "../resource-metrics/no-metrics"; import { IResourceMetricsValue, ResourceMetricsContext } from "../resource-metrics"; import { observer } from "mobx-react"; @@ -172,7 +172,7 @@ export const NodeCharts = observer(() => { yAxes: [{ ticks: { callback: value => value - } + } }] }, tooltips: { diff --git a/src/renderer/components/+nodes/node-details-resources.tsx b/src/renderer/components/+nodes/node-details-resources.tsx index 636a3f55f0..c53018d62f 100644 --- a/src/renderer/components/+nodes/node-details-resources.tsx +++ b/src/renderer/components/+nodes/node-details-resources.tsx @@ -25,7 +25,7 @@ import { Table } from "../table/table"; import { TableHead } from "../table/table-head"; import { TableRow } from "../table/table-row"; import React from "react"; -import type { Node } from "../../api/endpoints"; +import type { Node } from "../../../common/k8s-api/endpoints"; import { TableCell } from "../table/table-cell"; interface Props { diff --git a/src/renderer/components/+nodes/node-details.tsx b/src/renderer/components/+nodes/node-details.tsx index 24a998ae32..9e86939260 100644 --- a/src/renderer/components/+nodes/node-details.tsx +++ b/src/renderer/components/+nodes/node-details.tsx @@ -30,7 +30,7 @@ import { Badge } from "../badge"; import { ResourceMetrics } from "../resource-metrics"; import { podsStore } from "../+workloads-pods/pods.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { getMetricsByNodeNames, IClusterMetrics, Node } from "../../api/endpoints"; +import { getMetricsByNodeNames, IClusterMetrics, Node } from "../../../common/k8s-api/endpoints"; import { NodeCharts } from "./node-charts"; import { makeObservable, observable, reaction } from "mobx"; import { PodDetailsList } from "../+workloads-pods/pod-details-list"; diff --git a/src/renderer/components/+nodes/nodes.store.ts b/src/renderer/components/+nodes/nodes.store.ts index 43b5e32cca..e398c2896d 100644 --- a/src/renderer/components/+nodes/nodes.store.ts +++ b/src/renderer/components/+nodes/nodes.store.ts @@ -21,9 +21,9 @@ import { sum } from "lodash"; import { computed, makeObservable } from "mobx"; -import { apiManager } from "../../api/api-manager"; -import { Node, nodesApi } from "../../api/endpoints"; -import { KubeObjectStore } from "../../kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { Node, nodesApi } from "../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; export class NodesStore extends KubeObjectStore { diff --git a/src/renderer/components/+nodes/nodes.tsx b/src/renderer/components/+nodes/nodes.tsx index 5a464f1221..4df10dcadf 100644 --- a/src/renderer/components/+nodes/nodes.tsx +++ b/src/renderer/components/+nodes/nodes.tsx @@ -28,15 +28,15 @@ import { TabLayout } from "../layout/tab-layout"; import { nodesStore } from "./nodes.store"; import { podsStore } from "../+workloads-pods/pods.store"; import { KubeObjectListLayout } from "../kube-object-list-layout"; -import { getMetricsForAllNodes, INodeMetrics, Node } from "../../api/endpoints/nodes.api"; +import { getMetricsForAllNodes, INodeMetrics, Node } from "../../../common/k8s-api/endpoints/nodes.api"; import { LineProgress } from "../line-progress"; -import { bytesToUnits } from "../../utils/convertMemory"; +import { bytesToUnits } from "../../../common/utils/convertMemory"; import { Tooltip, TooltipPosition } from "../tooltip"; import kebabCase from "lodash/kebabCase"; import upperFirst from "lodash/upperFirst"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { Badge } from "../badge/badge"; -import { kubeWatchApi } from "../../api/kube-watch-api"; +import { kubeWatchApi } from "../../../common/k8s-api/kube-watch-api"; import { eventStore } from "../+events/event.store"; import type { NodesRouteParams } from "../../../common/routes"; import { observable } from "mobx"; diff --git a/src/renderer/components/+pod-security-policies/pod-security-policies.store.ts b/src/renderer/components/+pod-security-policies/pod-security-policies.store.ts index ea51c2acb6..afb655b426 100644 --- a/src/renderer/components/+pod-security-policies/pod-security-policies.store.ts +++ b/src/renderer/components/+pod-security-policies/pod-security-policies.store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { PodSecurityPolicy, pspApi } from "../../api/endpoints"; -import { KubeObjectStore } from "../../kube-object.store"; -import { apiManager } from "../../api/api-manager"; +import { PodSecurityPolicy, pspApi } from "../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class PodSecurityPoliciesStore extends KubeObjectStore { api = pspApi; diff --git a/src/renderer/components/+pod-security-policies/pod-security-policy-details.tsx b/src/renderer/components/+pod-security-policies/pod-security-policy-details.tsx index 7da0218a7a..0c1c73567a 100644 --- a/src/renderer/components/+pod-security-policies/pod-security-policy-details.tsx +++ b/src/renderer/components/+pod-security-policies/pod-security-policy-details.tsx @@ -25,7 +25,7 @@ import React from "react"; import { observer } from "mobx-react"; import { DrawerItem, DrawerTitle } from "../drawer"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { PodSecurityPolicy } from "../../api/endpoints"; +import type { PodSecurityPolicy } from "../../../common/k8s-api/endpoints"; import { Badge } from "../badge"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { KubeObjectMeta } from "../kube-object-meta"; diff --git a/src/renderer/components/+storage-classes/storage-class-details.tsx b/src/renderer/components/+storage-classes/storage-class-details.tsx index 302a94b3f4..2e8eae63bb 100644 --- a/src/renderer/components/+storage-classes/storage-class-details.tsx +++ b/src/renderer/components/+storage-classes/storage-class-details.tsx @@ -27,7 +27,7 @@ import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { observer } from "mobx-react"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { StorageClass } from "../../api/endpoints"; +import type { StorageClass } from "../../../common/k8s-api/endpoints"; import { KubeObjectMeta } from "../kube-object-meta"; import { storageClassStore } from "./storage-class.store"; import { VolumeDetailsList } from "../+storage-volumes/volume-details-list"; diff --git a/src/renderer/components/+storage-classes/storage-class.store.ts b/src/renderer/components/+storage-classes/storage-class.store.ts index f2f7056377..67c7d33f6b 100644 --- a/src/renderer/components/+storage-classes/storage-class.store.ts +++ b/src/renderer/components/+storage-classes/storage-class.store.ts @@ -19,10 +19,10 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; -import { StorageClass, storageClassApi } from "../../api/endpoints/storage-class.api"; -import { apiManager } from "../../api/api-manager"; +import { StorageClass, storageClassApi } from "../../../common/k8s-api/endpoints/storage-class.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { volumesStore } from "../+storage-volumes/volumes.store"; export class StorageClassStore extends KubeObjectStore { diff --git a/src/renderer/components/+storage-volume-claims/volume-claim-details.tsx b/src/renderer/components/+storage-volume-claims/volume-claim-details.tsx index 5911b202cb..2836d33f91 100644 --- a/src/renderer/components/+storage-volume-claims/volume-claim-details.tsx +++ b/src/renderer/components/+storage-volume-claims/volume-claim-details.tsx @@ -31,7 +31,7 @@ import { Link } from "react-router-dom"; import { ResourceMetrics } from "../resource-metrics"; import { VolumeClaimDiskChart } from "./volume-claim-disk-chart"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { getMetricsForPvc, IPvcMetrics, PersistentVolumeClaim } from "../../api/endpoints"; +import { getMetricsForPvc, IPvcMetrics, PersistentVolumeClaim } from "../../../common/k8s-api/endpoints"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { KubeObjectMeta } from "../kube-object-meta"; diff --git a/src/renderer/components/+storage-volume-claims/volume-claim-disk-chart.tsx b/src/renderer/components/+storage-volume-claims/volume-claim-disk-chart.tsx index cd1c6f7024..04e888e4f1 100644 --- a/src/renderer/components/+storage-volume-claims/volume-claim-disk-chart.tsx +++ b/src/renderer/components/+storage-volume-claims/volume-claim-disk-chart.tsx @@ -21,9 +21,9 @@ import React, { useContext } from "react"; import { observer } from "mobx-react"; -import type { IPvcMetrics, PersistentVolumeClaim } from "../../api/endpoints"; +import type { IPvcMetrics, PersistentVolumeClaim } from "../../../common/k8s-api/endpoints"; import { BarChart, ChartDataSets, memoryOptions } from "../chart"; -import { isMetricsEmpty, normalizeMetrics } from "../../api/endpoints/metrics.api"; +import { isMetricsEmpty, normalizeMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { NoMetrics } from "../resource-metrics/no-metrics"; import { IResourceMetricsValue, ResourceMetricsContext } from "../resource-metrics"; import { ThemeStore } from "../../theme.store"; diff --git a/src/renderer/components/+storage-volume-claims/volume-claim.store.ts b/src/renderer/components/+storage-volume-claims/volume-claim.store.ts index 4beca645a5..808592083a 100644 --- a/src/renderer/components/+storage-volume-claims/volume-claim.store.ts +++ b/src/renderer/components/+storage-volume-claims/volume-claim.store.ts @@ -18,9 +18,9 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { apiManager } from "../../api/api-manager"; -import { PersistentVolumeClaim, pvcApi } from "../../api/endpoints"; -import { KubeObjectStore } from "../../kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { PersistentVolumeClaim, pvcApi } from "../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class VolumeClaimStore extends KubeObjectStore { api = pvcApi; diff --git a/src/renderer/components/+storage-volume-claims/volume-claims.tsx b/src/renderer/components/+storage-volume-claims/volume-claims.tsx index e1f8e38527..798cce0e53 100644 --- a/src/renderer/components/+storage-volume-claims/volume-claims.tsx +++ b/src/renderer/components/+storage-volume-claims/volume-claims.tsx @@ -27,9 +27,9 @@ import { Link, RouteComponentProps } from "react-router-dom"; import { volumeClaimStore } from "./volume-claim.store"; import { podsStore } from "../+workloads-pods/pods.store"; import { KubeObjectListLayout } from "../kube-object-list-layout"; -import { unitsToBytes } from "../../utils/convertMemory"; +import { unitsToBytes } from "../../../common/utils/convertMemory"; import { stopPropagation } from "../../utils"; -import { storageClassApi } from "../../api/endpoints"; +import { storageClassApi } from "../../../common/k8s-api/endpoints"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import type { VolumeClaimsRouteParams } from "../../../common/routes"; import { getDetailsUrl } from "../kube-detail-params"; diff --git a/src/renderer/components/+storage-volumes/volume-details-list.tsx b/src/renderer/components/+storage-volumes/volume-details-list.tsx index 1bd3e5d6d3..b9e2f9af0d 100644 --- a/src/renderer/components/+storage-volumes/volume-details-list.tsx +++ b/src/renderer/components/+storage-volumes/volume-details-list.tsx @@ -23,7 +23,7 @@ import "./volume-details-list.scss"; import React from "react"; import { observer } from "mobx-react"; -import type { PersistentVolume } from "../../api/endpoints/persistent-volume.api"; +import type { PersistentVolume } from "../../../common/k8s-api/endpoints/persistent-volume.api"; import { boundMethod } from "../../../common/utils/autobind"; import { TableRow } from "../table/table-row"; import { cssNames, prevDefault } from "../../utils"; diff --git a/src/renderer/components/+storage-volumes/volume-details.tsx b/src/renderer/components/+storage-volumes/volume-details.tsx index 0509e8e183..781df4b5b4 100644 --- a/src/renderer/components/+storage-volumes/volume-details.tsx +++ b/src/renderer/components/+storage-volumes/volume-details.tsx @@ -27,7 +27,7 @@ import { Link } from "react-router-dom"; import { observer } from "mobx-react"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; -import { PersistentVolume, pvcApi } from "../../api/endpoints"; +import { PersistentVolume, pvcApi } from "../../../common/k8s-api/endpoints"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectMeta } from "../kube-object-meta"; import { getDetailsUrl } from "../kube-detail-params"; diff --git a/src/renderer/components/+storage-volumes/volumes.store.ts b/src/renderer/components/+storage-volumes/volumes.store.ts index 726792884b..f0567db82c 100644 --- a/src/renderer/components/+storage-volumes/volumes.store.ts +++ b/src/renderer/components/+storage-volumes/volumes.store.ts @@ -19,11 +19,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; -import { PersistentVolume, persistentVolumeApi } from "../../api/endpoints/persistent-volume.api"; -import { apiManager } from "../../api/api-manager"; -import type { StorageClass } from "../../api/endpoints/storage-class.api"; +import { PersistentVolume, persistentVolumeApi } from "../../../common/k8s-api/endpoints/persistent-volume.api"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import type { StorageClass } from "../../../common/k8s-api/endpoints/storage-class.api"; export class PersistentVolumesStore extends KubeObjectStore { api = persistentVolumeApi; diff --git a/src/renderer/components/+storage-volumes/volumes.tsx b/src/renderer/components/+storage-volumes/volumes.tsx index 0d7cafd1b2..c98ff6f8fb 100644 --- a/src/renderer/components/+storage-volumes/volumes.tsx +++ b/src/renderer/components/+storage-volumes/volumes.tsx @@ -28,7 +28,7 @@ import { KubeObjectListLayout } from "../kube-object-list-layout"; import { getDetailsUrl } from "../kube-detail-params"; import { stopPropagation } from "../../utils"; import { volumesStore } from "./volumes.store"; -import { pvcApi, storageClassApi } from "../../api/endpoints"; +import { pvcApi, storageClassApi } from "../../../common/k8s-api/endpoints"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import type { VolumesRouteParams } from "../../../common/routes"; diff --git a/src/renderer/components/+user-management/+cluster-role-bindings/details.tsx b/src/renderer/components/+user-management/+cluster-role-bindings/details.tsx index b6a6afba83..2be9588fa7 100644 --- a/src/renderer/components/+user-management/+cluster-role-bindings/details.tsx +++ b/src/renderer/components/+user-management/+cluster-role-bindings/details.tsx @@ -25,7 +25,7 @@ import { reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import React from "react"; -import type { ClusterRoleBinding, ClusterRoleBindingSubject } from "../../../api/endpoints"; +import type { ClusterRoleBinding, ClusterRoleBindingSubject } from "../../../../common/k8s-api/endpoints"; import { autoBind, ObservableHashSet, prevDefault } from "../../../utils"; import { AddRemoveButtons } from "../../add-remove-buttons"; import { ConfirmDialog } from "../../confirm-dialog"; diff --git a/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx b/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx index 6755edfa74..b575068804 100644 --- a/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx +++ b/src/renderer/components/+user-management/+cluster-role-bindings/dialog.tsx @@ -26,7 +26,7 @@ import { disposeOnUnmount, observer } from "mobx-react"; import React from "react"; import { serviceAccountsStore } from "../+service-accounts/store"; -import { ClusterRole, ClusterRoleBinding, ClusterRoleBindingSubject, ServiceAccount } from "../../../api/endpoints"; +import { ClusterRole, ClusterRoleBinding, ClusterRoleBindingSubject, ServiceAccount } from "../../../../common/k8s-api/endpoints"; import { Dialog, DialogProps } from "../../dialog"; import { EditableList } from "../../editable-list"; import { Icon } from "../../icon"; diff --git a/src/renderer/components/+user-management/+cluster-role-bindings/hashers.ts b/src/renderer/components/+user-management/+cluster-role-bindings/hashers.ts index 9bb85576ca..23c7f86f5c 100644 --- a/src/renderer/components/+user-management/+cluster-role-bindings/hashers.ts +++ b/src/renderer/components/+user-management/+cluster-role-bindings/hashers.ts @@ -20,7 +20,7 @@ */ import { MD5 } from "crypto-js"; -import type { ClusterRoleBindingSubject } from "../../../api/endpoints"; +import type { ClusterRoleBindingSubject } from "../../../../common/k8s-api/endpoints"; export function hashClusterRoleBindingSubject(subject: ClusterRoleBindingSubject): string { return MD5(JSON.stringify([ diff --git a/src/renderer/components/+user-management/+cluster-role-bindings/store.ts b/src/renderer/components/+user-management/+cluster-role-bindings/store.ts index 56fce615e0..e9d09f2b3f 100644 --- a/src/renderer/components/+user-management/+cluster-role-bindings/store.ts +++ b/src/renderer/components/+user-management/+cluster-role-bindings/store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { apiManager } from "../../../api/api-manager"; -import { ClusterRoleBinding, clusterRoleBindingApi, ClusterRoleBindingSubject } from "../../../api/endpoints"; -import { KubeObjectStore } from "../../../kube-object.store"; +import { apiManager } from "../../../../common/k8s-api/api-manager"; +import { ClusterRoleBinding, clusterRoleBindingApi, ClusterRoleBindingSubject } from "../../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import { autoBind, HashSet } from "../../../utils"; import { hashClusterRoleBindingSubject } from "./hashers"; diff --git a/src/renderer/components/+user-management/+cluster-roles/details.tsx b/src/renderer/components/+user-management/+cluster-roles/details.tsx index 7eec29db12..063d424d75 100644 --- a/src/renderer/components/+user-management/+cluster-roles/details.tsx +++ b/src/renderer/components/+user-management/+cluster-roles/details.tsx @@ -27,7 +27,7 @@ import React from "react"; import { DrawerTitle } from "../../drawer"; import type { KubeObjectDetailsProps } from "../../kube-object-details"; import { KubeObjectMeta } from "../../kube-object-meta"; -import type { ClusterRole } from "../../../api/endpoints"; +import type { ClusterRole } from "../../../../common/k8s-api/endpoints"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+user-management/+cluster-roles/store.ts b/src/renderer/components/+user-management/+cluster-roles/store.ts index 6fe25a2c42..d3d5da561b 100644 --- a/src/renderer/components/+user-management/+cluster-roles/store.ts +++ b/src/renderer/components/+user-management/+cluster-roles/store.ts @@ -18,9 +18,9 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { apiManager } from "../../../api/api-manager"; -import { ClusterRole, clusterRoleApi } from "../../../api/endpoints"; -import { KubeObjectStore } from "../../../kube-object.store"; +import { apiManager } from "../../../../common/k8s-api/api-manager"; +import { ClusterRole, clusterRoleApi } from "../../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../../utils"; export class ClusterRolesStore extends KubeObjectStore { diff --git a/src/renderer/components/+user-management/+role-bindings/details.tsx b/src/renderer/components/+user-management/+role-bindings/details.tsx index 71f062aa22..b04690dcf7 100644 --- a/src/renderer/components/+user-management/+role-bindings/details.tsx +++ b/src/renderer/components/+user-management/+role-bindings/details.tsx @@ -24,7 +24,7 @@ import "./details.scss"; import { reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import React from "react"; -import type { RoleBinding, RoleBindingSubject } from "../../../api/endpoints"; +import type { RoleBinding, RoleBindingSubject } from "../../../../common/k8s-api/endpoints"; import { prevDefault, boundMethod } from "../../../utils"; import { AddRemoveButtons } from "../../add-remove-buttons"; import { ConfirmDialog } from "../../confirm-dialog"; diff --git a/src/renderer/components/+user-management/+role-bindings/dialog.tsx b/src/renderer/components/+user-management/+role-bindings/dialog.tsx index 6353145cc9..0f331ee698 100644 --- a/src/renderer/components/+user-management/+role-bindings/dialog.tsx +++ b/src/renderer/components/+user-management/+role-bindings/dialog.tsx @@ -28,7 +28,7 @@ import React from "react"; import { rolesStore } from "../+roles/store"; import { serviceAccountsStore } from "../+service-accounts/store"; import { NamespaceSelect } from "../../+namespaces/namespace-select"; -import { ClusterRole, Role, roleApi, RoleBinding, RoleBindingSubject, ServiceAccount } from "../../../api/endpoints"; +import { ClusterRole, Role, roleApi, RoleBinding, RoleBindingSubject, ServiceAccount } from "../../../../common/k8s-api/endpoints"; import { Dialog, DialogProps } from "../../dialog"; import { EditableList } from "../../editable-list"; import { Icon } from "../../icon"; diff --git a/src/renderer/components/+user-management/+role-bindings/hashers.ts b/src/renderer/components/+user-management/+role-bindings/hashers.ts index 2d8771bb18..2ab149738b 100644 --- a/src/renderer/components/+user-management/+role-bindings/hashers.ts +++ b/src/renderer/components/+user-management/+role-bindings/hashers.ts @@ -20,7 +20,7 @@ */ import { MD5 } from "crypto-js"; -import type { RoleBindingSubject } from "../../../api/endpoints"; +import type { RoleBindingSubject } from "../../../../common/k8s-api/endpoints"; export function hashRoleBindingSubject(subject: RoleBindingSubject): string { return MD5(JSON.stringify([ diff --git a/src/renderer/components/+user-management/+role-bindings/store.ts b/src/renderer/components/+user-management/+role-bindings/store.ts index d59db292e6..c55126b1a4 100644 --- a/src/renderer/components/+user-management/+role-bindings/store.ts +++ b/src/renderer/components/+user-management/+role-bindings/store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { apiManager } from "../../../api/api-manager"; -import { RoleBinding, roleBindingApi, RoleBindingSubject } from "../../../api/endpoints"; -import { KubeObjectStore } from "../../../kube-object.store"; +import { apiManager } from "../../../../common/k8s-api/api-manager"; +import { RoleBinding, roleBindingApi, RoleBindingSubject } from "../../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import { HashSet } from "../../../utils"; import { hashRoleBindingSubject } from "./hashers"; diff --git a/src/renderer/components/+user-management/+roles/details.tsx b/src/renderer/components/+user-management/+roles/details.tsx index e90ac46e6b..02aa46f560 100644 --- a/src/renderer/components/+user-management/+roles/details.tsx +++ b/src/renderer/components/+user-management/+roles/details.tsx @@ -24,7 +24,7 @@ import "./details.scss"; import { observer } from "mobx-react"; import React from "react"; -import type { Role } from "../../../api/endpoints"; +import type { Role } from "../../../../common/k8s-api/endpoints"; import { DrawerTitle } from "../../drawer"; import type { KubeObjectDetailsProps } from "../../kube-object-details"; import { KubeObjectMeta } from "../../kube-object-meta"; diff --git a/src/renderer/components/+user-management/+roles/store.ts b/src/renderer/components/+user-management/+roles/store.ts index 43774e8b09..e0033af6e7 100644 --- a/src/renderer/components/+user-management/+roles/store.ts +++ b/src/renderer/components/+user-management/+roles/store.ts @@ -18,9 +18,9 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { apiManager } from "../../../api/api-manager"; -import { Role, roleApi } from "../../../api/endpoints"; -import { KubeObjectStore } from "../../../kube-object.store"; +import { apiManager } from "../../../../common/k8s-api/api-manager"; +import { Role, roleApi } from "../../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../../utils"; export class RolesStore extends KubeObjectStore { diff --git a/src/renderer/components/+user-management/+service-accounts/details.tsx b/src/renderer/components/+user-management/+service-accounts/details.tsx index a121b072bb..3cc12dd24d 100644 --- a/src/renderer/components/+user-management/+service-accounts/details.tsx +++ b/src/renderer/components/+user-management/+service-accounts/details.tsx @@ -27,7 +27,7 @@ import React from "react"; import { Link } from "react-router-dom"; import { secretsStore } from "../../+config-secrets/secrets.store"; -import { Secret, ServiceAccount } from "../../../api/endpoints"; +import { Secret, ServiceAccount } from "../../../../common/k8s-api/endpoints"; import { DrawerItem, DrawerTitle } from "../../drawer"; import { Icon } from "../../icon"; import type { KubeObjectDetailsProps } from "../../kube-object-details"; diff --git a/src/renderer/components/+user-management/+service-accounts/secret.tsx b/src/renderer/components/+user-management/+service-accounts/secret.tsx index 4eff2b30dd..3acd53f0dc 100644 --- a/src/renderer/components/+user-management/+service-accounts/secret.tsx +++ b/src/renderer/components/+user-management/+service-accounts/secret.tsx @@ -24,7 +24,7 @@ import "./secret.scss"; import moment from "moment"; import React from "react"; -import type { Secret } from "../../../api/endpoints/secret.api"; +import type { Secret } from "../../../../common/k8s-api/endpoints/secret.api"; import { prevDefault } from "../../../utils"; import { Icon } from "../../icon"; diff --git a/src/renderer/components/+user-management/+service-accounts/store.ts b/src/renderer/components/+user-management/+service-accounts/store.ts index 51bbabca34..3e3abd4d4a 100644 --- a/src/renderer/components/+user-management/+service-accounts/store.ts +++ b/src/renderer/components/+user-management/+service-accounts/store.ts @@ -19,9 +19,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { apiManager } from "../../../api/api-manager"; -import { ServiceAccount, serviceAccountsApi } from "../../../api/endpoints"; -import { KubeObjectStore } from "../../../kube-object.store"; +import { apiManager } from "../../../../common/k8s-api/api-manager"; +import { ServiceAccount, serviceAccountsApi } from "../../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../../utils"; export class ServiceAccountsStore extends KubeObjectStore { diff --git a/src/renderer/components/+user-management/+service-accounts/view.tsx b/src/renderer/components/+user-management/+service-accounts/view.tsx index af2090018c..a538384b95 100644 --- a/src/renderer/components/+user-management/+service-accounts/view.tsx +++ b/src/renderer/components/+user-management/+service-accounts/view.tsx @@ -24,7 +24,7 @@ import "./view.scss"; import { observer } from "mobx-react"; import React from "react"; import type { RouteComponentProps } from "react-router"; -import type { ServiceAccount } from "../../../api/endpoints/service-accounts.api"; +import type { ServiceAccount } from "../../../../common/k8s-api/endpoints/service-accounts.api"; import { Icon } from "../../icon"; import { KubeObjectListLayout } from "../../kube-object-list-layout"; import { KubeObjectStatusIcon } from "../../kube-object-status-icon"; diff --git a/src/renderer/components/+user-management/select-options.tsx b/src/renderer/components/+user-management/select-options.tsx index 65bfeeec9e..a51824f388 100644 --- a/src/renderer/components/+user-management/select-options.tsx +++ b/src/renderer/components/+user-management/select-options.tsx @@ -20,8 +20,8 @@ */ import React from "react"; -import type { ServiceAccount } from "../../api/endpoints"; -import type { KubeObject } from "../../api/kube-object"; +import type { ServiceAccount } from "../../../common/k8s-api/endpoints"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { Icon } from "../icon"; import type { SelectOption } from "../select"; import { TooltipPosition } from "../tooltip"; diff --git a/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx b/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx index c0e827d40b..108ec47012 100644 --- a/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx +++ b/src/renderer/components/+workloads-cronjobs/cronjob-details.tsx @@ -30,9 +30,9 @@ import { jobStore } from "../+workloads-jobs/job.store"; import { Link } from "react-router-dom"; import { cronJobStore } from "./cronjob.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { CronJob, Job } from "../../api/endpoints"; -import { KubeObjectMeta } from "../kube-object-meta"; import { getDetailsUrl } from "../kube-detail-params"; +import type { CronJob, Job } from "../../../common/k8s-api/endpoints"; +import { KubeObjectMeta } from "../kube-object-meta"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+workloads-cronjobs/cronjob-trigger-dialog.tsx b/src/renderer/components/+workloads-cronjobs/cronjob-trigger-dialog.tsx index 6938185479..aa0d401cae 100644 --- a/src/renderer/components/+workloads-cronjobs/cronjob-trigger-dialog.tsx +++ b/src/renderer/components/+workloads-cronjobs/cronjob-trigger-dialog.tsx @@ -26,12 +26,12 @@ import { observable, makeObservable } from "mobx"; import { observer } from "mobx-react"; import { Dialog, DialogProps } from "../dialog"; import { Wizard, WizardStep } from "../wizard"; -import { CronJob, cronJobApi, jobApi } from "../../api/endpoints"; +import { CronJob, cronJobApi, jobApi } from "../../../common/k8s-api/endpoints"; import { Notifications } from "../notifications"; import { cssNames } from "../../utils"; import { Input } from "../input"; import { systemName, maxLength } from "../input/input_validators"; -import type { KubeObjectMetadata } from "../../api/kube-object"; +import type { KubeObjectMetadata } from "../../../common/k8s-api/kube-object"; interface Props extends Partial { } diff --git a/src/renderer/components/+workloads-cronjobs/cronjob.store.ts b/src/renderer/components/+workloads-cronjobs/cronjob.store.ts index 90ea0e0c2c..4f46eaf60a 100644 --- a/src/renderer/components/+workloads-cronjobs/cronjob.store.ts +++ b/src/renderer/components/+workloads-cronjobs/cronjob.store.ts @@ -19,11 +19,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; -import { CronJob, cronJobApi } from "../../api/endpoints/cron-job.api"; +import { CronJob, cronJobApi } from "../../../common/k8s-api/endpoints/cron-job.api"; import { jobStore } from "../+workloads-jobs/job.store"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class CronJobStore extends KubeObjectStore { api = cronJobApi; diff --git a/src/renderer/components/+workloads-cronjobs/cronjobs.tsx b/src/renderer/components/+workloads-cronjobs/cronjobs.tsx index f17d8ed5f1..40dcb481ba 100644 --- a/src/renderer/components/+workloads-cronjobs/cronjobs.tsx +++ b/src/renderer/components/+workloads-cronjobs/cronjobs.tsx @@ -24,7 +24,7 @@ import "./cronjobs.scss"; import React from "react"; import { observer } from "mobx-react"; import type { RouteComponentProps } from "react-router"; -import { CronJob, cronJobApi } from "../../api/endpoints/cron-job.api"; +import { CronJob, cronJobApi } from "../../../common/k8s-api/endpoints/cron-job.api"; import { MenuItem } from "../menu"; import { Icon } from "../icon"; import { cronJobStore } from "./cronjob.store"; diff --git a/src/renderer/components/+workloads-daemonsets/daemonset-details.tsx b/src/renderer/components/+workloads-daemonsets/daemonset-details.tsx index 7a2fdc62e9..92615e54ef 100644 --- a/src/renderer/components/+workloads-daemonsets/daemonset-details.tsx +++ b/src/renderer/components/+workloads-daemonsets/daemonset-details.tsx @@ -31,7 +31,7 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities" import { daemonSetStore } from "./daemonsets.store"; import { podsStore } from "../+workloads-pods/pods.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { DaemonSet, getMetricsForDaemonSets, IPodMetrics } from "../../api/endpoints"; +import { DaemonSet, getMetricsForDaemonSets, IPodMetrics } from "../../../common/k8s-api/endpoints"; import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics"; import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts"; import { makeObservable, observable, reaction } from "mobx"; diff --git a/src/renderer/components/+workloads-daemonsets/daemonsets.store.ts b/src/renderer/components/+workloads-daemonsets/daemonsets.store.ts index e8f729fde1..605aa65c93 100644 --- a/src/renderer/components/+workloads-daemonsets/daemonsets.store.ts +++ b/src/renderer/components/+workloads-daemonsets/daemonsets.store.ts @@ -21,9 +21,9 @@ import { makeObservable } from "mobx"; import { podsStore } from "../+workloads-pods/pods.store"; -import { apiManager } from "../../api/api-manager"; -import { DaemonSet, daemonSetApi, Pod, PodStatus } from "../../api/endpoints"; -import { KubeObjectStore } from "../../kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { DaemonSet, daemonSetApi, Pod, PodStatus } from "../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; export class DaemonSetStore extends KubeObjectStore { diff --git a/src/renderer/components/+workloads-daemonsets/daemonsets.tsx b/src/renderer/components/+workloads-daemonsets/daemonsets.tsx index b8dcb51568..e9c4442b15 100644 --- a/src/renderer/components/+workloads-daemonsets/daemonsets.tsx +++ b/src/renderer/components/+workloads-daemonsets/daemonsets.tsx @@ -24,7 +24,7 @@ import "./daemonsets.scss"; import React from "react"; import { observer } from "mobx-react"; import type { RouteComponentProps } from "react-router"; -import type { DaemonSet } from "../../api/endpoints"; +import type { DaemonSet } from "../../../common/k8s-api/endpoints"; import { eventStore } from "../+events/event.store"; import { daemonSetStore } from "./daemonsets.store"; import { podsStore } from "../+workloads-pods/pods.store"; diff --git a/src/renderer/components/+workloads-deployments/deployment-details.tsx b/src/renderer/components/+workloads-deployments/deployment-details.tsx index 28b450b71c..8f4a45a580 100644 --- a/src/renderer/components/+workloads-deployments/deployment-details.tsx +++ b/src/renderer/components/+workloads-deployments/deployment-details.tsx @@ -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"; diff --git a/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx b/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx index 5a8e7edd5b..e332b19fe8 100644 --- a/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx +++ b/src/renderer/components/+workloads-deployments/deployment-replicasets.tsx @@ -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"; diff --git a/src/renderer/components/+workloads-deployments/deployment-scale-dialog.test.tsx b/src/renderer/components/+workloads-deployments/deployment-scale-dialog.test.tsx index 2df89e90df..22c90dda2c 100644 --- a/src/renderer/components/+workloads-deployments/deployment-scale-dialog.test.tsx +++ b/src/renderer/components/+workloads-deployments/deployment-scale-dialog.test.tsx @@ -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("", () => { + let deploymentApi: DeploymentApi; + + beforeEach(() => { + deploymentApi = new DeploymentApi({ + objectConstructor: Deployment, + }); + }); it("renders w/o errors", () => { const { container } = render(); @@ -124,12 +130,12 @@ describe("", () => { }); 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 rendered. const initReplicas = 3; deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); - const { getByTestId } = render(); + const { getByTestId } = render(); DeploymentScaleDialog.open(dummyDeployment); // we need to wait for the DeploymentScaleDialog to show up @@ -143,14 +149,14 @@ describe("", () => { 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(); + const component = render(); DeploymentScaleDialog.open(dummyDeployment); await waitFor(async () => { diff --git a/src/renderer/components/+workloads-deployments/deployment-scale-dialog.tsx b/src/renderer/components/+workloads-deployments/deployment-scale-dialog.tsx index 0e7ae52f3d..f4dec0a9b9 100644 --- a/src/renderer/components/+workloads-deployments/deployment-scale-dialog.tsx +++ b/src/renderer/components/+workloads-deployments/deployment-scale-dialog.tsx @@ -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 { + deploymentApi: DeploymentApi } const dialogState = observable.object({ @@ -42,6 +43,10 @@ const dialogState = observable.object({ @observer export class DeploymentScaleDialog extends Component { + static defaultProps = { + deploymentApi + }; + @observable ready = false; @observable currentReplicas = 0; @observable desiredReplicas = 0; @@ -80,7 +85,7 @@ export class DeploymentScaleDialog extends Component { 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 { try { if (currentReplicas !== desiredReplicas) { - await deploymentApi.scale({ + await this.props.deploymentApi.scale({ name: deployment.getName(), namespace: deployment.getNs(), }, desiredReplicas); diff --git a/src/renderer/components/+workloads-deployments/deployments.store.ts b/src/renderer/components/+workloads-deployments/deployments.store.ts index 34b6e295ad..64f349491e 100644 --- a/src/renderer/components/+workloads-deployments/deployments.store.ts +++ b/src/renderer/components/+workloads-deployments/deployments.store.ts @@ -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 { diff --git a/src/renderer/components/+workloads-deployments/deployments.tsx b/src/renderer/components/+workloads-deployments/deployments.tsx index 6531114fa9..28705fd53d 100644 --- a/src/renderer/components/+workloads-deployments/deployments.tsx +++ b/src/renderer/components/+workloads-deployments/deployments.tsx @@ -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"; diff --git a/src/renderer/components/+workloads-jobs/job-details.tsx b/src/renderer/components/+workloads-jobs/job-details.tsx index 9cf5a2e75d..6c4d9d3525 100644 --- a/src/renderer/components/+workloads-jobs/job-details.tsx +++ b/src/renderer/components/+workloads-jobs/job-details.tsx @@ -33,9 +33,8 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities" import { podsStore } from "../+workloads-pods/pods.store"; import { jobStore } from "./job.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { getMetricsForJobs, IPodMetrics, Job } from "../../api/endpoints"; +import { getMetricsForJobs, IPodMetrics, Job } from "../../../common/k8s-api/endpoints"; import { PodDetailsList } from "../+workloads-pods/pod-details-list"; -import { apiManager } from "../../api/api-manager"; import { KubeObjectMeta } from "../kube-object-meta"; import { makeObservable, observable } from "mobx"; import { podMetricTabs, PodCharts } from "../+workloads-pods/pod-charts"; @@ -44,6 +43,7 @@ import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { ResourceMetrics } from "../resource-metrics"; import { boundMethod } from "autobind-decorator"; import { getDetailsUrl } from "../kube-detail-params"; +import { apiManager } from "../../../common/k8s-api/api-manager"; interface Props extends KubeObjectDetailsProps { } diff --git a/src/renderer/components/+workloads-jobs/job.store.ts b/src/renderer/components/+workloads-jobs/job.store.ts index 643f29385a..71f854c6c3 100644 --- a/src/renderer/components/+workloads-jobs/job.store.ts +++ b/src/renderer/components/+workloads-jobs/job.store.ts @@ -19,12 +19,12 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { KubeObjectStore } from "../../kube-object.store"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; -import { Job, jobApi } from "../../api/endpoints/job.api"; -import { CronJob, Pod, PodStatus } from "../../api/endpoints"; +import { Job, jobApi } from "../../../common/k8s-api/endpoints/job.api"; +import { CronJob, Pod, PodStatus } from "../../../common/k8s-api/endpoints"; import { podsStore } from "../+workloads-pods/pods.store"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; export class JobStore extends KubeObjectStore { api = jobApi; diff --git a/src/renderer/components/+workloads-overview/overview.tsx b/src/renderer/components/+workloads-overview/overview.tsx index ec025f0d80..695e3edf95 100644 --- a/src/renderer/components/+workloads-overview/overview.tsx +++ b/src/renderer/components/+workloads-overview/overview.tsx @@ -32,7 +32,7 @@ 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 { kubeWatchApi } from "../../api/kube-watch-api"; +import { kubeWatchApi } from "../../../common/k8s-api/kube-watch-api"; import { clusterContext } from "../context"; import { WorkloadsOverviewDetailRegistry } from "../../../extensions/registries"; import type { WorkloadsOverviewRouteParams } from "../../../common/routes"; diff --git a/src/renderer/components/+workloads-pods/__tests__/pod-tolerations.test.tsx b/src/renderer/components/+workloads-pods/__tests__/pod-tolerations.test.tsx index 30ef2e98e9..72d12af5a9 100644 --- a/src/renderer/components/+workloads-pods/__tests__/pod-tolerations.test.tsx +++ b/src/renderer/components/+workloads-pods/__tests__/pod-tolerations.test.tsx @@ -22,7 +22,7 @@ import React from "react"; import "@testing-library/jest-dom/extend-expect"; import { fireEvent, render } from "@testing-library/react"; -import type { IToleration } from "../../../api/workload-kube-object"; +import type { IToleration } from "../../../../common/k8s-api/workload-kube-object"; import { PodTolerations } from "../pod-tolerations"; jest.mock("electron", () => ({ diff --git a/src/renderer/components/+workloads-pods/container-charts.tsx b/src/renderer/components/+workloads-pods/container-charts.tsx index 0c810b47de..9586d7bf7c 100644 --- a/src/renderer/components/+workloads-pods/container-charts.tsx +++ b/src/renderer/components/+workloads-pods/container-charts.tsx @@ -21,9 +21,9 @@ import React, { useContext } from "react"; import { observer } from "mobx-react"; -import type { IPodMetrics } from "../../api/endpoints"; +import type { IPodMetrics } from "../../../common/k8s-api/endpoints"; import { BarChart, cpuOptions, memoryOptions } from "../chart"; -import { isMetricsEmpty, normalizeMetrics } from "../../api/endpoints/metrics.api"; +import { isMetricsEmpty, normalizeMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { NoMetrics } from "../resource-metrics/no-metrics"; import { IResourceMetricsValue, ResourceMetricsContext } from "../resource-metrics"; import { ThemeStore } from "../../theme.store"; diff --git a/src/renderer/components/+workloads-pods/pod-charts.tsx b/src/renderer/components/+workloads-pods/pod-charts.tsx index cc05aeec55..4caf12fbbd 100644 --- a/src/renderer/components/+workloads-pods/pod-charts.tsx +++ b/src/renderer/components/+workloads-pods/pod-charts.tsx @@ -22,13 +22,13 @@ import { mapValues } from "lodash"; import { observer } from "mobx-react"; import React, { useContext } from "react"; -import { isMetricsEmpty, normalizeMetrics } from "../../api/endpoints/metrics.api"; +import { isMetricsEmpty, normalizeMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { BarChart, cpuOptions, memoryOptions } from "../chart"; import { IResourceMetricsValue, ResourceMetricsContext } from "../resource-metrics"; import { NoMetrics } from "../resource-metrics/no-metrics"; -import type { WorkloadKubeObject } from "../../api/workload-kube-object"; -import type { IPodMetrics } from "../../api/endpoints"; +import type { WorkloadKubeObject } from "../../../common/k8s-api/workload-kube-object"; +import type { IPodMetrics } from "../../../common/k8s-api/endpoints"; export const podMetricTabs = [ "CPU", diff --git a/src/renderer/components/+workloads-pods/pod-container-env.tsx b/src/renderer/components/+workloads-pods/pod-container-env.tsx index 3d3eb33474..4c847e68bb 100644 --- a/src/renderer/components/+workloads-pods/pod-container-env.tsx +++ b/src/renderer/components/+workloads-pods/pod-container-env.tsx @@ -23,7 +23,7 @@ import "./pod-container-env.scss"; import React, { useEffect, useState } from "react"; import { observer } from "mobx-react"; -import type { IPodContainer, Secret } from "../../api/endpoints"; +import type { IPodContainer, Secret } from "../../../common/k8s-api/endpoints"; import { DrawerItem } from "../drawer"; import { autorun } from "mobx"; import { secretsStore } from "../+config-secrets/secrets.store"; diff --git a/src/renderer/components/+workloads-pods/pod-container-port.tsx b/src/renderer/components/+workloads-pods/pod-container-port.tsx index 9e035c1fd9..c8bb435b55 100644 --- a/src/renderer/components/+workloads-pods/pod-container-port.tsx +++ b/src/renderer/components/+workloads-pods/pod-container-port.tsx @@ -23,7 +23,7 @@ import "./pod-container-port.scss"; import React from "react"; import { observer } from "mobx-react"; -import type { Pod } from "../../api/endpoints"; +import type { Pod } from "../../../common/k8s-api/endpoints"; import { apiBase } from "../../api"; import { observable, makeObservable } from "mobx"; import { cssNames } from "../../utils"; diff --git a/src/renderer/components/+workloads-pods/pod-details-affinities.tsx b/src/renderer/components/+workloads-pods/pod-details-affinities.tsx index 7be1722286..f20a3b7a65 100644 --- a/src/renderer/components/+workloads-pods/pod-details-affinities.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-affinities.tsx @@ -24,7 +24,7 @@ import React from "react"; import jsYaml from "js-yaml"; import { AceEditor } from "../ace-editor"; import { DrawerParamToggler, DrawerItem } from "../drawer"; -import type { Pod, Deployment, DaemonSet, StatefulSet, ReplicaSet, Job } from "../../api/endpoints"; +import type { Pod, Deployment, DaemonSet, StatefulSet, ReplicaSet, Job } from "../../../common/k8s-api/endpoints"; interface Props { workload: Pod | Deployment | DaemonSet | StatefulSet | ReplicaSet | Job; diff --git a/src/renderer/components/+workloads-pods/pod-details-container.tsx b/src/renderer/components/+workloads-pods/pod-details-container.tsx index 5ae7625fb0..c39ed80751 100644 --- a/src/renderer/components/+workloads-pods/pod-details-container.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-container.tsx @@ -22,7 +22,7 @@ import "./pod-details-container.scss"; import React from "react"; -import type { IPodContainer, IPodContainerStatus, Pod } from "../../api/endpoints"; +import type { IPodContainer, IPodContainerStatus, Pod } from "../../../common/k8s-api/endpoints"; import { DrawerItem } from "../drawer"; import { cssNames } from "../../utils"; import { StatusBrick } from "../status-brick"; @@ -30,7 +30,7 @@ import { Badge } from "../badge"; import { ContainerEnvironment } from "./pod-container-env"; import { PodContainerPort } from "./pod-container-port"; import { ResourceMetrics } from "../resource-metrics"; -import type { IMetrics } from "../../api/endpoints/metrics.api"; +import type { IMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { ContainerCharts } from "./container-charts"; import { LocaleDate } from "../locale-date"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; diff --git a/src/renderer/components/+workloads-pods/pod-details-list.tsx b/src/renderer/components/+workloads-pods/pod-details-list.tsx index 2ea299f5d0..b3dbe80fe7 100644 --- a/src/renderer/components/+workloads-pods/pod-details-list.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-list.tsx @@ -26,10 +26,10 @@ import kebabCase from "lodash/kebabCase"; import { reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { podsStore } from "./pods.store"; -import type { Pod } from "../../api/endpoints"; +import type { Pod } from "../../../common/k8s-api/endpoints"; import { boundMethod, bytesToUnits, cssNames, interval, prevDefault } from "../../utils"; import { LineProgress } from "../line-progress"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { Table, TableCell, TableHead, TableRow } from "../table"; import { Spinner } from "../spinner"; import { DrawerTitle } from "../drawer"; diff --git a/src/renderer/components/+workloads-pods/pod-details-secrets.tsx b/src/renderer/components/+workloads-pods/pod-details-secrets.tsx index 93457cb360..706da34668 100644 --- a/src/renderer/components/+workloads-pods/pod-details-secrets.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-secrets.tsx @@ -25,7 +25,7 @@ import React, { Component } from "react"; import { Link } from "react-router-dom"; import { autorun, observable, makeObservable } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; -import { Pod, Secret, secretsApi } from "../../api/endpoints"; +import { Pod, Secret, secretsApi } from "../../../common/k8s-api/endpoints"; import { getDetailsUrl } from "../kube-detail-params"; interface Props { diff --git a/src/renderer/components/+workloads-pods/pod-details-statuses.tsx b/src/renderer/components/+workloads-pods/pod-details-statuses.tsx index 90c59ef778..36e6a26fb4 100644 --- a/src/renderer/components/+workloads-pods/pod-details-statuses.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-statuses.tsx @@ -23,7 +23,7 @@ import "./pod-details-statuses.scss"; import React from "react"; import countBy from "lodash/countBy"; import kebabCase from "lodash/kebabCase"; -import type { Pod } from "../../api/endpoints"; +import type { Pod } from "../../../common/k8s-api/endpoints"; interface Props { pods: Pod[]; diff --git a/src/renderer/components/+workloads-pods/pod-details-tolerations.tsx b/src/renderer/components/+workloads-pods/pod-details-tolerations.tsx index 124192d549..70b1d36e7e 100644 --- a/src/renderer/components/+workloads-pods/pod-details-tolerations.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-tolerations.tsx @@ -22,7 +22,7 @@ import "./pod-details-tolerations.scss"; import React from "react"; import { DrawerParamToggler, DrawerItem } from "../drawer"; -import type { WorkloadKubeObject } from "../../api/workload-kube-object"; +import type { WorkloadKubeObject } from "../../../common/k8s-api/workload-kube-object"; import { PodTolerations } from "./pod-tolerations"; interface Props { diff --git a/src/renderer/components/+workloads-pods/pod-details.tsx b/src/renderer/components/+workloads-pods/pod-details.tsx index 986d979cf2..9f95c5289f 100644 --- a/src/renderer/components/+workloads-pods/pod-details.tsx +++ b/src/renderer/components/+workloads-pods/pod-details.tsx @@ -26,7 +26,7 @@ import kebabCase from "lodash/kebabCase"; import { disposeOnUnmount, observer } from "mobx-react"; import { Link } from "react-router-dom"; import { observable, reaction, makeObservable } from "mobx"; -import { IPodMetrics, nodesApi, Pod, pvcApi, configMapApi, getMetricsForPods } from "../../api/endpoints"; +import { IPodMetrics, nodesApi, Pod, pvcApi, configMapApi, getMetricsForPods } from "../../../common/k8s-api/endpoints"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { boundMethod, cssNames, toJS } from "../../utils"; @@ -37,7 +37,7 @@ import { Icon } from "../icon"; import { PodDetailsSecrets } from "./pod-details-secrets"; import { ResourceMetrics } from "../resource-metrics"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { getItemMetrics } from "../../api/endpoints/metrics.api"; +import { getItemMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { PodCharts, podMetricTabs } from "./pod-charts"; import { KubeObjectMeta } from "../kube-object-meta"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; diff --git a/src/renderer/components/+workloads-pods/pod-tolerations.tsx b/src/renderer/components/+workloads-pods/pod-tolerations.tsx index 28793e0ea5..e2be706b7b 100644 --- a/src/renderer/components/+workloads-pods/pod-tolerations.tsx +++ b/src/renderer/components/+workloads-pods/pod-tolerations.tsx @@ -23,7 +23,7 @@ import "./pod-tolerations.scss"; import React from "react"; import uniqueId from "lodash/uniqueId"; -import type { IToleration } from "../../api/workload-kube-object"; +import type { IToleration } from "../../../common/k8s-api/workload-kube-object"; import { Table, TableCell, TableHead, TableRow } from "../table"; interface Props { diff --git a/src/renderer/components/+workloads-pods/pods.store.ts b/src/renderer/components/+workloads-pods/pods.store.ts index 9c2b925400..8941fc6c05 100644 --- a/src/renderer/components/+workloads-pods/pods.store.ts +++ b/src/renderer/components/+workloads-pods/pods.store.ts @@ -21,11 +21,11 @@ import countBy from "lodash/countBy"; import { observable, makeObservable } from "mobx"; -import { KubeObjectStore } from "../../kube-object.store"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind, cpuUnitsToNumber, unitsToBytes } from "../../utils"; -import { Pod, PodMetrics, podMetricsApi, podsApi } from "../../api/endpoints"; -import { apiManager } from "../../api/api-manager"; -import type { WorkloadKubeObject } from "../../api/workload-kube-object"; +import { Pod, PodMetrics, podMetricsApi, podsApi } from "../../../common/k8s-api/endpoints"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import type { WorkloadKubeObject } from "../../../common/k8s-api/workload-kube-object"; export class PodsStore extends KubeObjectStore { api = podsApi; diff --git a/src/renderer/components/+workloads-pods/pods.tsx b/src/renderer/components/+workloads-pods/pods.tsx index 46fce21e16..448bfa75c8 100644 --- a/src/renderer/components/+workloads-pods/pods.tsx +++ b/src/renderer/components/+workloads-pods/pods.tsx @@ -29,13 +29,13 @@ import type { RouteComponentProps } from "react-router"; import { volumeClaimStore } from "../+storage-volume-claims/volume-claim.store"; import { eventStore } from "../+events/event.store"; import { KubeObjectListLayout } from "../kube-object-list-layout"; -import { nodesApi, Pod } from "../../api/endpoints"; +import { nodesApi, Pod } from "../../../common/k8s-api/endpoints"; import { StatusBrick } from "../status-brick"; import { cssNames, stopPropagation } from "../../utils"; import toPairs from "lodash/toPairs"; import startCase from "lodash/startCase"; import kebabCase from "lodash/kebabCase"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { Badge } from "../badge"; import type { PodsRouteParams } from "../../../common/routes"; diff --git a/src/renderer/components/+workloads-replicasets/replicaset-details.tsx b/src/renderer/components/+workloads-replicasets/replicaset-details.tsx index 59921432c1..7da1e22361 100644 --- a/src/renderer/components/+workloads-replicasets/replicaset-details.tsx +++ b/src/renderer/components/+workloads-replicasets/replicaset-details.tsx @@ -31,7 +31,7 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities" import { disposeOnUnmount, observer } from "mobx-react"; import { podsStore } from "../+workloads-pods/pods.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { getMetricsForReplicaSets, IPodMetrics, ReplicaSet } from "../../api/endpoints"; +import { getMetricsForReplicaSets, IPodMetrics, ReplicaSet } from "../../../common/k8s-api/endpoints"; import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics"; import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts"; import { PodDetailsList } from "../+workloads-pods/pod-details-list"; diff --git a/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.test.tsx b/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.test.tsx index 6107d43643..7f8c31e99c 100755 --- a/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.test.tsx +++ b/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.test.tsx @@ -21,11 +21,10 @@ import "@testing-library/jest-dom/extend-expect"; -jest.mock("../../api/endpoints"); import { ReplicaSetScaleDialog } from "./replicaset-scale-dialog"; import { render, waitFor, fireEvent } from "@testing-library/react"; import React from "react"; -import { ReplicaSet, replicaSetApi } from "../../api/endpoints/replica-set.api"; +import { ReplicaSet, ReplicaSetApi } from "../../../common/k8s-api/endpoints/replica-set.api"; const dummyReplicaSet: ReplicaSet = { apiVersion: "v1", @@ -111,8 +110,16 @@ const dummyReplicaSet: ReplicaSet = { }; describe("", () => { + let replicaSetApi: ReplicaSetApi; + + beforeEach(() => { + replicaSetApi = new ReplicaSetApi({ + objectConstructor: ReplicaSet + }); + }); + it("renders w/o errors", () => { - const { container } = render(); + const { container } = render(); expect(container).toBeInstanceOf(HTMLElement); }); @@ -123,7 +130,7 @@ describe("", () => { const initReplicas = 1; replicaSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); - const { getByTestId } = render(); + const { getByTestId } = render(); ReplicaSetScaleDialog.open(dummyReplicaSet); // we need to wait for the replicaSetScaleDialog to show up @@ -143,7 +150,7 @@ describe("", () => { const initReplicas = 1; replicaSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); - const component = render(); + const component = render(); ReplicaSetScaleDialog.open(dummyReplicaSet); await waitFor(async () => { diff --git a/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.tsx b/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.tsx index 0e98dde43a..3fda576d0e 100644 --- a/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.tsx +++ b/src/renderer/components/+workloads-replicasets/replicaset-scale-dialog.tsx @@ -30,9 +30,10 @@ import { Icon } from "../icon"; import { Slider } from "../slider"; import { Notifications } from "../notifications"; import { cssNames } from "../../utils"; -import { ReplicaSet, replicaSetApi } from "../../api/endpoints/replica-set.api"; +import { ReplicaSet, ReplicaSetApi, replicaSetApi } from "../../../common/k8s-api/endpoints/replica-set.api"; interface Props extends Partial { + replicaSetApi: ReplicaSetApi } const dialogState = observable.object({ @@ -42,6 +43,10 @@ const dialogState = observable.object({ @observer export class ReplicaSetScaleDialog extends Component { + static defaultProps = { + replicaSetApi + }; + @observable ready = false; @observable currentReplicas = 0; @observable desiredReplicas = 0; @@ -71,7 +76,7 @@ export class ReplicaSetScaleDialog extends Component { onOpen = async () => { const { replicaSet } = this; - this.currentReplicas = await replicaSetApi.getReplicas({ + this.currentReplicas = await this.props.replicaSetApi.getReplicas({ namespace: replicaSet.getNs(), name: replicaSet.getName(), }); @@ -102,7 +107,7 @@ export class ReplicaSetScaleDialog extends Component { try { if (currentReplicas !== desiredReplicas) { - await replicaSetApi.scale({ + await this.props.replicaSetApi.scale({ name: replicaSet.getName(), namespace: replicaSet.getNs(), }, desiredReplicas); diff --git a/src/renderer/components/+workloads-replicasets/replicasets.store.ts b/src/renderer/components/+workloads-replicasets/replicasets.store.ts index 5daa57e45d..15c25c1e4e 100644 --- a/src/renderer/components/+workloads-replicasets/replicasets.store.ts +++ b/src/renderer/components/+workloads-replicasets/replicasets.store.ts @@ -21,10 +21,10 @@ import { makeObservable } from "mobx"; import { podsStore } from "../+workloads-pods/pods.store"; -import { apiManager } from "../../api/api-manager"; -import { Deployment, ReplicaSet, replicaSetApi } from "../../api/endpoints"; -import { PodStatus } from "../../api/endpoints/pods.api"; -import { KubeObjectStore } from "../../kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { Deployment, ReplicaSet, replicaSetApi } from "../../../common/k8s-api/endpoints"; +import { PodStatus } from "../../../common/k8s-api/endpoints/pods.api"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; export class ReplicaSetStore extends KubeObjectStore { diff --git a/src/renderer/components/+workloads-replicasets/replicasets.tsx b/src/renderer/components/+workloads-replicasets/replicasets.tsx index 156d3e0a13..8eaaa8f7cb 100644 --- a/src/renderer/components/+workloads-replicasets/replicasets.tsx +++ b/src/renderer/components/+workloads-replicasets/replicasets.tsx @@ -23,7 +23,7 @@ import "./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 type { KubeObjectMenuProps } from "../kube-object-menu"; import { replicaSetStore } from "./replicasets.store"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; diff --git a/src/renderer/components/+workloads-statefulsets/statefulset-details.tsx b/src/renderer/components/+workloads-statefulsets/statefulset-details.tsx index e6a3cda340..ff116105c9 100644 --- a/src/renderer/components/+workloads-statefulsets/statefulset-details.tsx +++ b/src/renderer/components/+workloads-statefulsets/statefulset-details.tsx @@ -32,7 +32,7 @@ import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities" import { podsStore } from "../+workloads-pods/pods.store"; import { statefulSetStore } from "./statefulset.store"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import { getMetricsForStatefulSets, IPodMetrics, StatefulSet } from "../../api/endpoints"; +import { getMetricsForStatefulSets, IPodMetrics, StatefulSet } from "../../../common/k8s-api/endpoints"; import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics"; import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts"; import { PodDetailsList } from "../+workloads-pods/pod-details-list"; diff --git a/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.test.tsx b/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.test.tsx index 5c12040022..b27d8b0892 100755 --- a/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.test.tsx +++ b/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.test.tsx @@ -21,8 +21,7 @@ import "@testing-library/jest-dom/extend-expect"; -jest.mock("../../api/endpoints"); -import { StatefulSet, statefulSetApi } from "../../api/endpoints"; +import { StatefulSet, StatefulSetApi } from "../../../common/k8s-api/endpoints"; import { StatefulSetScaleDialog } from "./statefulset-scale-dialog"; import { render, waitFor, fireEvent } from "@testing-library/react"; import React from "react"; @@ -121,8 +120,16 @@ const dummyStatefulSet: StatefulSet = { }; describe("", () => { + let statefulSetApi: StatefulSetApi; + + beforeEach(() => { + statefulSetApi = new StatefulSetApi({ + objectConstructor: StatefulSet + }); + }); + it("renders w/o errors", () => { - const { container } = render(); + const { container } = render(); expect(container).toBeInstanceOf(HTMLElement); }); @@ -133,7 +140,7 @@ describe("", () => { const initReplicas = 1; statefulSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); - const { getByTestId } = render(); + const { getByTestId } = render(); StatefulSetScaleDialog.open(dummyStatefulSet); // we need to wait for the StatefulSetScaleDialog to show up @@ -153,7 +160,7 @@ describe("", () => { const initReplicas = 1; statefulSetApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas); - const component = render(); + const component = render(); StatefulSetScaleDialog.open(dummyStatefulSet); await waitFor(async () => { diff --git a/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.tsx b/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.tsx index cce00287a9..7fb49fabbe 100644 --- a/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.tsx +++ b/src/renderer/components/+workloads-statefulsets/statefulset-scale-dialog.tsx @@ -21,7 +21,7 @@ import "./statefulset-scale-dialog.scss"; -import { StatefulSet, statefulSetApi } from "../../api/endpoints"; +import { StatefulSet, StatefulSetApi, statefulSetApi } from "../../../common/k8s-api/endpoints"; import React, { Component } from "react"; import { computed, makeObservable, observable } from "mobx"; import { observer } from "mobx-react"; @@ -33,6 +33,7 @@ import { Notifications } from "../notifications"; import { cssNames } from "../../utils"; interface Props extends Partial { + statefulSetApi: StatefulSetApi } const dialogState = observable.object({ @@ -42,6 +43,9 @@ const dialogState = observable.object({ @observer export class StatefulSetScaleDialog extends Component { + static defaultProps = { + statefulSetApi + }; @observable ready = false; @observable currentReplicas = 0; @observable desiredReplicas = 0; @@ -71,7 +75,7 @@ export class StatefulSetScaleDialog extends Component { onOpen = async () => { const { statefulSet } = this; - this.currentReplicas = await statefulSetApi.getReplicas({ + this.currentReplicas = await this.props.statefulSetApi.getReplicas({ namespace: statefulSet.getNs(), name: statefulSet.getName(), }); @@ -102,7 +106,7 @@ export class StatefulSetScaleDialog extends Component { try { if (currentReplicas !== desiredReplicas) { - await statefulSetApi.scale({ + await this.props.statefulSetApi.scale({ name: statefulSet.getName(), namespace: statefulSet.getNs(), }, desiredReplicas); diff --git a/src/renderer/components/+workloads-statefulsets/statefulset.store.ts b/src/renderer/components/+workloads-statefulsets/statefulset.store.ts index 73c03a1b60..cf5b8ea36d 100644 --- a/src/renderer/components/+workloads-statefulsets/statefulset.store.ts +++ b/src/renderer/components/+workloads-statefulsets/statefulset.store.ts @@ -21,9 +21,9 @@ import { makeObservable } from "mobx"; import { podsStore } from "../+workloads-pods/pods.store"; -import { apiManager } from "../../api/api-manager"; -import { PodStatus, StatefulSet, statefulSetApi } from "../../api/endpoints"; -import { KubeObjectStore } from "../../kube-object.store"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import { PodStatus, StatefulSet, statefulSetApi } from "../../../common/k8s-api/endpoints"; +import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { autoBind } from "../../utils"; export class StatefulSetStore extends KubeObjectStore { diff --git a/src/renderer/components/+workloads-statefulsets/statefulsets.tsx b/src/renderer/components/+workloads-statefulsets/statefulsets.tsx index 88997e19c7..c3b5b0e023 100644 --- a/src/renderer/components/+workloads-statefulsets/statefulsets.tsx +++ b/src/renderer/components/+workloads-statefulsets/statefulsets.tsx @@ -24,7 +24,7 @@ import "./statefulsets.scss"; import React from "react"; import { observer } from "mobx-react"; import type { RouteComponentProps } from "react-router"; -import type { StatefulSet } from "../../api/endpoints"; +import type { StatefulSet } from "../../../common/k8s-api/endpoints"; import { podsStore } from "../+workloads-pods/pods.store"; import { statefulSetStore } from "./statefulset.store"; import { nodesStore } from "../+nodes/nodes.store"; diff --git a/src/renderer/components/+workloads/workloads.stores.ts b/src/renderer/components/+workloads/workloads.stores.ts index e53ea7cb03..d3d69c2a17 100644 --- a/src/renderer/components/+workloads/workloads.stores.ts +++ b/src/renderer/components/+workloads/workloads.stores.ts @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { KubeObjectStore } from "../../kube-object.store"; +import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { podsStore } from "../+workloads-pods/pods.store"; import { deploymentStore } from "../+workloads-deployments/deployments.store"; import { daemonSetStore } from "../+workloads-daemonsets/daemonsets.store"; @@ -28,7 +28,7 @@ import { jobStore } from "../+workloads-jobs/job.store"; import { cronJobStore } from "../+workloads-cronjobs/cronjob.store"; import type { KubeResource } from "../../../common/rbac"; import { replicaSetStore } from "../+workloads-replicasets/replicasets.store"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; export const workloadStores = new Map>([ ["pods", podsStore], diff --git a/src/renderer/components/__tests__/cronjob.store.test.ts b/src/renderer/components/__tests__/cronjob.store.test.ts index fcd8f93023..35531b2ec2 100644 --- a/src/renderer/components/__tests__/cronjob.store.test.ts +++ b/src/renderer/components/__tests__/cronjob.store.test.ts @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import { cronJobStore } from "../+workloads-cronjobs/cronjob.store"; -import { CronJob } from "../../api/endpoints"; +import { CronJob } from "../../../common/k8s-api/endpoints"; const spec = { schedule: "test", diff --git a/src/renderer/components/__tests__/daemonset.store.test.ts b/src/renderer/components/__tests__/daemonset.store.test.ts index 00dcce5468..65ea991d9b 100644 --- a/src/renderer/components/__tests__/daemonset.store.test.ts +++ b/src/renderer/components/__tests__/daemonset.store.test.ts @@ -22,7 +22,7 @@ import { observable } from "mobx"; import { daemonSetStore } from "../+workloads-daemonsets/daemonsets.store"; import { podsStore } from "../+workloads-pods/pods.store"; -import { DaemonSet, Pod } from "../../api/endpoints"; +import { DaemonSet, Pod } from "../../../common/k8s-api/endpoints"; const runningDaemonSet = new DaemonSet({ apiVersion: "foo", diff --git a/src/renderer/components/__tests__/deployments.store.test.ts b/src/renderer/components/__tests__/deployments.store.test.ts index 6d7552dd6b..7742b55313 100644 --- a/src/renderer/components/__tests__/deployments.store.test.ts +++ b/src/renderer/components/__tests__/deployments.store.test.ts @@ -22,7 +22,7 @@ import { observable } from "mobx"; import { deploymentStore } from "../+workloads-deployments/deployments.store"; import { podsStore } from "../+workloads-pods/pods.store"; -import { Deployment, Pod } from "../../api/endpoints"; +import { Deployment, Pod } from "../../../common/k8s-api/endpoints"; const spec = { containers: [{ diff --git a/src/renderer/components/__tests__/job.store.test.ts b/src/renderer/components/__tests__/job.store.test.ts index 9f3a81ba91..f3d850e3dc 100644 --- a/src/renderer/components/__tests__/job.store.test.ts +++ b/src/renderer/components/__tests__/job.store.test.ts @@ -22,7 +22,7 @@ import { observable } from "mobx"; import { jobStore } from "../+workloads-jobs/job.store"; import { podsStore } from "../+workloads-pods/pods.store"; -import { Job, Pod } from "../../api/endpoints"; +import { Job, Pod } from "../../../common/k8s-api/endpoints"; const runningJob = new Job({ apiVersion: "foo", diff --git a/src/renderer/components/__tests__/pods.store.test.ts b/src/renderer/components/__tests__/pods.store.test.ts index 69d4f49840..74fe9de9f6 100644 --- a/src/renderer/components/__tests__/pods.store.test.ts +++ b/src/renderer/components/__tests__/pods.store.test.ts @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { Pod } from "../../api/endpoints"; +import { Pod } from "../../../common/k8s-api/endpoints"; import { podsStore } from "../+workloads-pods/pods.store"; const runningPod = new Pod({ diff --git a/src/renderer/components/__tests__/replicaset.store.test.ts b/src/renderer/components/__tests__/replicaset.store.test.ts index 74404e9004..3114290bc7 100644 --- a/src/renderer/components/__tests__/replicaset.store.test.ts +++ b/src/renderer/components/__tests__/replicaset.store.test.ts @@ -22,7 +22,7 @@ import { observable } from "mobx"; import { podsStore } from "../+workloads-pods/pods.store"; import { replicaSetStore } from "../+workloads-replicasets/replicasets.store"; -import { ReplicaSet, Pod } from "../../api/endpoints"; +import { ReplicaSet, Pod } from "../../../common/k8s-api/endpoints"; const runningReplicaSet = new ReplicaSet({ apiVersion: "foo", diff --git a/src/renderer/components/__tests__/statefulset.store.test.ts b/src/renderer/components/__tests__/statefulset.store.test.ts index 162684f092..4121be6c58 100644 --- a/src/renderer/components/__tests__/statefulset.store.test.ts +++ b/src/renderer/components/__tests__/statefulset.store.test.ts @@ -22,7 +22,7 @@ import { observable } from "mobx"; import { podsStore } from "../+workloads-pods/pods.store"; import { statefulSetStore } from "../+workloads-statefulsets/statefulset.store"; -import { StatefulSet, Pod } from "../../api/endpoints"; +import { StatefulSet, Pod } from "../../../common/k8s-api/endpoints"; const runningStatefulSet = new StatefulSet({ apiVersion: "foo", diff --git a/src/renderer/components/app.tsx b/src/renderer/components/app.tsx index b881bb74bb..46e285969a 100755 --- a/src/renderer/components/app.tsx +++ b/src/renderer/components/app.tsx @@ -45,10 +45,10 @@ import { StatefulSetScaleDialog } from "./+workloads-statefulsets/statefulset-sc import { eventStore } from "./+events/event.store"; import { nodesStore } from "./+nodes/nodes.store"; import { podsStore } from "./+workloads-pods/pods.store"; -import { kubeWatchApi } from "../api/kube-watch-api"; +import { kubeWatchApi } from "../../common/k8s-api/kube-watch-api"; import { ReplicaSetScaleDialog } from "./+workloads-replicasets/replicaset-scale-dialog"; import { CommandContainer } from "./command-palette/command-container"; -import { KubeObjectStore } from "../kube-object.store"; +import { KubeObjectStore } from "../../common/k8s-api/kube-object.store"; import { clusterContext } from "./context"; import * as routes from "../../common/routes"; import { TabLayout, TabLayoutRoute } from "./layout/tab-layout"; diff --git a/src/renderer/components/cluster-settings/components/cluster-prometheus-setting.tsx b/src/renderer/components/cluster-settings/components/cluster-prometheus-setting.tsx index a74606b1ec..26469a87ad 100644 --- a/src/renderer/components/cluster-settings/components/cluster-prometheus-setting.tsx +++ b/src/renderer/components/cluster-settings/components/cluster-prometheus-setting.tsx @@ -27,7 +27,7 @@ import { Select, SelectOption } from "../../select"; import { Input } from "../../input"; import { observable, computed, autorun, makeObservable } from "mobx"; import { productName } from "../../../../common/vars"; -import { MetricProviderInfo, metricsApi } from "../../../api/endpoints/metrics.api"; +import { MetricProviderInfo, metricsApi } from "../../../../common/k8s-api/endpoints/metrics.api"; import { Spinner } from "../../spinner"; interface Props { diff --git a/src/renderer/components/context.ts b/src/renderer/components/context.ts index 758e3dd20d..6e37aabdce 100755 --- a/src/renderer/components/context.ts +++ b/src/renderer/components/context.ts @@ -23,12 +23,7 @@ import { ClusterStore } from "../../common/cluster-store"; import type { Cluster } from "../../main/cluster"; import { getHostedClusterId } from "../utils"; import { namespaceStore } from "./+namespaces/namespace.store"; - -export interface ClusterContext { - cluster?: Cluster; - allNamespaces: string[]; // available / allowed namespaces from cluster.ts - contextNamespaces: string[]; // selected by user (see: namespace-select.tsx) -} +import type { ClusterContext } from "../../common/k8s-api/cluster-context"; export const clusterContext: ClusterContext = { get cluster(): Cluster | null { diff --git a/src/renderer/components/dock/__test__/log-resource-selector.test.tsx b/src/renderer/components/dock/__test__/log-resource-selector.test.tsx index 17ebb92d09..45e8a858f1 100644 --- a/src/renderer/components/dock/__test__/log-resource-selector.test.tsx +++ b/src/renderer/components/dock/__test__/log-resource-selector.test.tsx @@ -24,7 +24,7 @@ import "@testing-library/jest-dom/extend-expect"; import { render } from "@testing-library/react"; import selectEvent from "react-select-event"; -import { Pod } from "../../../api/endpoints"; +import { Pod } from "../../../../common/k8s-api/endpoints"; import { LogResourceSelector } from "../log-resource-selector"; import type { LogTabData } from "../log-tab.store"; import { dockerPod, deploymentPod1 } from "./pod.mock"; diff --git a/src/renderer/components/dock/__test__/log-tab.store.test.ts b/src/renderer/components/dock/__test__/log-tab.store.test.ts index da7d0b1052..7048be780a 100644 --- a/src/renderer/components/dock/__test__/log-tab.store.test.ts +++ b/src/renderer/components/dock/__test__/log-tab.store.test.ts @@ -21,7 +21,7 @@ import { podsStore } from "../../+workloads-pods/pods.store"; import { UserStore } from "../../../../common/user-store"; -import { Pod } from "../../../api/endpoints"; +import { Pod } from "../../../../common/k8s-api/endpoints"; import { ThemeStore } from "../../../theme.store"; import { dockStore } from "../dock.store"; import { logTabStore } from "../log-tab.store"; diff --git a/src/renderer/components/dock/create-resource.tsx b/src/renderer/components/dock/create-resource.tsx index c290e3f8bf..f826b772aa 100644 --- a/src/renderer/components/dock/create-resource.tsx +++ b/src/renderer/components/dock/create-resource.tsx @@ -33,8 +33,8 @@ import { createResourceStore } from "./create-resource.store"; import type { DockTab } from "./dock.store"; import { EditorPanel } from "./editor-panel"; import { InfoPanel } from "./info-panel"; -import { resourceApplierApi } from "../../api/endpoints/resource-applier.api"; -import type { JsonApiErrorParsed } from "../../api/json-api"; +import { resourceApplierApi } from "../../../common/k8s-api/endpoints/resource-applier.api"; +import type { JsonApiErrorParsed } from "../../../common/k8s-api/json-api"; import { Notifications } from "../notifications"; interface Props { diff --git a/src/renderer/components/dock/edit-resource.store.ts b/src/renderer/components/dock/edit-resource.store.ts index c0467b330b..2c8d26bbb9 100644 --- a/src/renderer/components/dock/edit-resource.store.ts +++ b/src/renderer/components/dock/edit-resource.store.ts @@ -23,9 +23,9 @@ import { autoBind, noop } from "../../utils"; import { DockTabStore } from "./dock-tab.store"; import { autorun, IReactionDisposer } from "mobx"; import { dockStore, DockTab, DockTabCreateSpecific, TabId, TabKind } from "./dock.store"; -import type { KubeObject } from "../../api/kube-object"; -import { apiManager } from "../../api/api-manager"; -import type { KubeObjectStore } from "../../kube-object.store"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; +import { apiManager } from "../../../common/k8s-api/api-manager"; +import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export interface EditingResource { resource: string; // resource path, e.g. /api/v1/namespaces/default diff --git a/src/renderer/components/dock/edit-resource.tsx b/src/renderer/components/dock/edit-resource.tsx index 0496ef3104..19a238ab30 100644 --- a/src/renderer/components/dock/edit-resource.tsx +++ b/src/renderer/components/dock/edit-resource.tsx @@ -32,7 +32,7 @@ import { InfoPanel } from "./info-panel"; import { Badge } from "../badge"; import { EditorPanel } from "./editor-panel"; import { Spinner } from "../spinner"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; interface Props { className?: string; diff --git a/src/renderer/components/dock/install-chart.store.ts b/src/renderer/components/dock/install-chart.store.ts index f7ae6930e6..fb185ffb52 100644 --- a/src/renderer/components/dock/install-chart.store.ts +++ b/src/renderer/components/dock/install-chart.store.ts @@ -22,8 +22,8 @@ import { action, autorun, makeObservable } from "mobx"; import { dockStore, DockTabCreateSpecific, TabId, TabKind } from "./dock.store"; import { DockTabStore } from "./dock-tab.store"; -import { getChartDetails, getChartValues, HelmChart } from "../../api/endpoints/helm-charts.api"; -import type { IReleaseUpdateDetails } from "../../api/endpoints/helm-releases.api"; +import { getChartDetails, getChartValues, HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api"; +import type { IReleaseUpdateDetails } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { Notifications } from "../notifications"; export interface IChartInstallData { diff --git a/src/renderer/components/dock/log-controls.tsx b/src/renderer/components/dock/log-controls.tsx index b12350d8f8..b7ac1c5fb4 100644 --- a/src/renderer/components/dock/log-controls.tsx +++ b/src/renderer/components/dock/log-controls.tsx @@ -24,7 +24,7 @@ import "./log-controls.scss"; import React from "react"; import { observer } from "mobx-react"; -import { Pod } from "../../api/endpoints"; +import { Pod } from "../../../common/k8s-api/endpoints"; import { cssNames, saveFileDialog } from "../../utils"; import { logStore } from "./log.store"; import { Checkbox } from "../checkbox"; diff --git a/src/renderer/components/dock/log-resource-selector.tsx b/src/renderer/components/dock/log-resource-selector.tsx index 068ad44d89..ab7a7560ed 100644 --- a/src/renderer/components/dock/log-resource-selector.tsx +++ b/src/renderer/components/dock/log-resource-selector.tsx @@ -24,7 +24,7 @@ import "./log-resource-selector.scss"; import React, { useEffect } from "react"; import { observer } from "mobx-react"; -import { Pod } from "../../api/endpoints"; +import { Pod } from "../../../common/k8s-api/endpoints"; import { Badge } from "../badge"; import { Select, SelectOption } from "../select"; import { LogTabData, logTabStore } from "./log-tab.store"; diff --git a/src/renderer/components/dock/log-tab.store.ts b/src/renderer/components/dock/log-tab.store.ts index bd7d61539b..5b6b73904f 100644 --- a/src/renderer/components/dock/log-tab.store.ts +++ b/src/renderer/components/dock/log-tab.store.ts @@ -23,8 +23,8 @@ import uniqueId from "lodash/uniqueId"; import { reaction } from "mobx"; import { podsStore } from "../+workloads-pods/pods.store"; -import { IPodContainer, Pod } from "../../api/endpoints"; -import type { WorkloadKubeObject } from "../../api/workload-kube-object"; +import { IPodContainer, Pod } from "../../../common/k8s-api/endpoints"; +import type { WorkloadKubeObject } from "../../../common/k8s-api/workload-kube-object"; import { DockTabStore } from "./dock-tab.store"; import { dockStore, DockTabCreateSpecific, TabKind } from "./dock.store"; diff --git a/src/renderer/components/dock/log.store.ts b/src/renderer/components/dock/log.store.ts index 710ed3a690..b03e00becb 100644 --- a/src/renderer/components/dock/log.store.ts +++ b/src/renderer/components/dock/log.store.ts @@ -21,7 +21,7 @@ import { autorun, computed, observable, makeObservable } from "mobx"; -import { IPodLogsQuery, Pod, podsApi } from "../../api/endpoints"; +import { IPodLogsQuery, Pod, podsApi } from "../../../common/k8s-api/endpoints"; import { autoBind, interval } from "../../utils"; import { dockStore, TabId, TabKind } from "./dock.store"; import { logTabStore } from "./log-tab.store"; diff --git a/src/renderer/components/dock/upgrade-chart.store.ts b/src/renderer/components/dock/upgrade-chart.store.ts index 4a43ae4ab1..7667f7c00e 100644 --- a/src/renderer/components/dock/upgrade-chart.store.ts +++ b/src/renderer/components/dock/upgrade-chart.store.ts @@ -22,7 +22,7 @@ import { action, autorun, computed, IReactionDisposer, reaction, makeObservable } from "mobx"; import { dockStore, DockTab, DockTabCreateSpecific, TabId, TabKind } from "./dock.store"; import { DockTabStore } from "./dock-tab.store"; -import { getReleaseValues, HelmRelease } from "../../api/endpoints/helm-releases.api"; +import { getReleaseValues, HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { releaseStore } from "../+apps-releases/release.store"; import { iter } from "../../utils"; diff --git a/src/renderer/components/dock/upgrade-chart.tsx b/src/renderer/components/dock/upgrade-chart.tsx index 0628aeb19e..582bd6b8e0 100644 --- a/src/renderer/components/dock/upgrade-chart.tsx +++ b/src/renderer/components/dock/upgrade-chart.tsx @@ -33,7 +33,7 @@ import { releaseStore } from "../+apps-releases/release.store"; import { Badge } from "../badge"; import { EditorPanel } from "./editor-panel"; import { helmChartStore, IChartVersion } from "../+apps-helm-charts/helm-chart.store"; -import type { HelmRelease } from "../../api/endpoints/helm-releases.api"; +import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { Select, SelectOption } from "../select"; interface Props { diff --git a/src/renderer/components/item-object-list/item-list-layout.tsx b/src/renderer/components/item-object-list/item-list-layout.tsx index 5b27858740..d19e9d20c8 100644 --- a/src/renderer/components/item-object-list/item-list-layout.tsx +++ b/src/renderer/components/item-object-list/item-list-layout.tsx @@ -31,7 +31,7 @@ import { boundMethod, createStorage, cssNames, IClassName, isReactNode, noop, Ob import { AddRemoveButtons, AddRemoveButtonsProps } from "../add-remove-buttons"; import { NoItems } from "../no-items"; import { Spinner } from "../spinner"; -import type { ItemObject, ItemStore } from "../../item.store"; +import type { ItemObject, ItemStore } from "../../../common/item.store"; import { SearchInputUrlProps, SearchInputUrl } from "../input"; import { Filter, FilterType, pageFilters } from "./page-filters.store"; import { PageFiltersList } from "./page-filters-list"; diff --git a/src/renderer/components/kube-object-details/kube-object-details.tsx b/src/renderer/components/kube-object-details/kube-object-details.tsx index c561b29221..be888c6505 100644 --- a/src/renderer/components/kube-object-details/kube-object-details.tsx +++ b/src/renderer/components/kube-object-details/kube-object-details.tsx @@ -25,9 +25,9 @@ import React from "react"; import { disposeOnUnmount, observer } from "mobx-react"; import { computed, observable, reaction, makeObservable } from "mobx"; import { Drawer } from "../drawer"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { Spinner } from "../spinner"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { crdStore } from "../+custom-resources/crd.store"; import { KubeObjectMenu } from "../kube-object-menu"; import { KubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; diff --git a/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx b/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx index 0f0c130fbd..d55e30b28f 100644 --- a/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx +++ b/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx @@ -23,11 +23,11 @@ import React from "react"; import { computed, makeObservable } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { cssNames } from "../../utils"; -import type { KubeObject } from "../../api/kube-object"; -import { ItemListLayout, ItemListLayoutProps } from "../item-object-list"; -import type { KubeObjectStore } from "../../kube-object.store"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; +import { ItemListLayout, ItemListLayoutProps } from "../item-object-list/item-list-layout"; +import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectMenu } from "../kube-object-menu"; -import { kubeWatchApi } from "../../api/kube-watch-api"; +import { kubeWatchApi } from "../../../common/k8s-api/kube-watch-api"; import { clusterContext } from "../context"; import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter"; import { ResourceKindMap, ResourceNames } from "../../utils/rbac"; diff --git a/src/renderer/components/kube-object-menu/kube-object-menu.tsx b/src/renderer/components/kube-object-menu/kube-object-menu.tsx index 5da4427778..1848fa2906 100644 --- a/src/renderer/components/kube-object-menu/kube-object-menu.tsx +++ b/src/renderer/components/kube-object-menu/kube-object-menu.tsx @@ -21,11 +21,11 @@ import React from "react"; import { boundMethod, cssNames } from "../../utils"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { editResourceTab } from "../dock/edit-resource.store"; import { MenuActions, MenuActionsProps } from "../menu/menu-actions"; import { hideDetails } from "../kube-detail-params"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { KubeObjectMenuRegistry } from "../../../extensions/registries/kube-object-menu-registry"; export interface KubeObjectMenuProps extends MenuActionsProps { diff --git a/src/renderer/components/kube-object-meta/kube-object-meta.tsx b/src/renderer/components/kube-object-meta/kube-object-meta.tsx index ad3cac5998..f9b03b8738 100644 --- a/src/renderer/components/kube-object-meta/kube-object-meta.tsx +++ b/src/renderer/components/kube-object-meta/kube-object-meta.tsx @@ -20,9 +20,9 @@ */ import React from "react"; -import type { KubeMetaField, KubeObject } from "../../api/kube-object"; +import type { KubeMetaField, KubeObject } from "../../../common/k8s-api/kube-object"; import { DrawerItem, DrawerItemLabels } from "../drawer"; -import { apiManager } from "../../api/api-manager"; +import { apiManager } from "../../../common/k8s-api/api-manager"; import { Link } from "react-router-dom"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { LocaleDate } from "../locale-date"; diff --git a/src/renderer/components/kubeconfig-dialog/kubeconfig-dialog.tsx b/src/renderer/components/kubeconfig-dialog/kubeconfig-dialog.tsx index 82903f7b5c..a9a9aacfdc 100644 --- a/src/renderer/components/kubeconfig-dialog/kubeconfig-dialog.tsx +++ b/src/renderer/components/kubeconfig-dialog/kubeconfig-dialog.tsx @@ -26,7 +26,7 @@ import { observable, makeObservable } from "mobx"; import { observer } from "mobx-react"; import jsYaml from "js-yaml"; import { AceEditor } from "../ace-editor"; -import type { ServiceAccount } from "../../api/endpoints"; +import type { ServiceAccount } from "../../../common/k8s-api/endpoints"; import { copyToClipboard, cssNames, saveFileDialog } from "../../utils"; import { Button } from "../button"; import { Dialog, DialogProps } from "../dialog"; diff --git a/src/renderer/components/notifications/notifications.store.tsx b/src/renderer/components/notifications/notifications.store.tsx index 63ab5d5e05..9a47f588ac 100644 --- a/src/renderer/components/notifications/notifications.store.tsx +++ b/src/renderer/components/notifications/notifications.store.tsx @@ -23,7 +23,7 @@ import type React from "react"; import { action, observable, makeObservable } from "mobx"; import { autoBind } from "../../utils"; import uniqueId from "lodash/uniqueId"; -import type { JsonApiErrorParsed } from "../../api/json-api"; +import type { JsonApiErrorParsed } from "../../../common/k8s-api/json-api"; export type NotificationId = string | number; export type NotificationMessage = React.ReactNode | React.ReactNode[] | JsonApiErrorParsed; diff --git a/src/renderer/components/notifications/notifications.tsx b/src/renderer/components/notifications/notifications.tsx index b4e9344aa0..3aa138ef4e 100644 --- a/src/renderer/components/notifications/notifications.tsx +++ b/src/renderer/components/notifications/notifications.tsx @@ -24,7 +24,7 @@ import "./notifications.scss"; import React from "react"; import { reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; -import { JsonApiErrorParsed } from "../../api/json-api"; +import { JsonApiErrorParsed } from "../../../common/k8s-api/json-api"; import { cssNames, prevDefault } from "../../utils"; import { Notification, NotificationMessage, notificationsStore, NotificationStatus } from "./notifications.store"; import { Animate } from "../animate"; diff --git a/src/renderer/components/resource-metrics/resource-metrics-text.tsx b/src/renderer/components/resource-metrics/resource-metrics-text.tsx index a83ef8118c..7708711569 100644 --- a/src/renderer/components/resource-metrics/resource-metrics-text.tsx +++ b/src/renderer/components/resource-metrics/resource-metrics-text.tsx @@ -20,8 +20,8 @@ */ import React from "react"; -import type { IPodMetrics } from "../../api/endpoints"; -import { getMetricLastPoints, IMetrics } from "../../api/endpoints/metrics.api"; +import type { IPodMetrics } from "../../../common/k8s-api/endpoints"; +import { getMetricLastPoints, IMetrics } from "../../../common/k8s-api/endpoints/metrics.api"; import { bytesToUnits } from "../../utils"; import { Badge } from "../badge"; import { DrawerItem } from "../drawer"; diff --git a/src/renderer/components/resource-metrics/resource-metrics.tsx b/src/renderer/components/resource-metrics/resource-metrics.tsx index aaf111a8cb..3b7a214fbb 100644 --- a/src/renderer/components/resource-metrics/resource-metrics.tsx +++ b/src/renderer/components/resource-metrics/resource-metrics.tsx @@ -24,7 +24,7 @@ import "./resource-metrics.scss"; import React, { createContext, useEffect, useState } from "react"; import { Radio, RadioGroup } from "../radio"; import { useInterval } from "../../hooks"; -import type { KubeObject } from "../../api/kube-object"; +import type { KubeObject } from "../../../common/k8s-api/kube-object"; import { cssNames } from "../../utils"; import { Spinner } from "../spinner"; diff --git a/src/renderer/components/table/table-row.tsx b/src/renderer/components/table/table-row.tsx index 9b3ce613e1..d4c148b4e3 100644 --- a/src/renderer/components/table/table-row.tsx +++ b/src/renderer/components/table/table-row.tsx @@ -23,7 +23,7 @@ import "./table-row.scss"; import React, { CSSProperties } from "react"; import { cssNames } from "../../utils"; -import type { ItemObject } from "../../item.store"; +import type { ItemObject } from "../../../common/item.store"; export type TableRowElem = React.ReactElement; diff --git a/src/renderer/components/virtual-list/virtual-list.tsx b/src/renderer/components/virtual-list/virtual-list.tsx index ad6d93af3a..36f62dff93 100644 --- a/src/renderer/components/virtual-list/virtual-list.tsx +++ b/src/renderer/components/virtual-list/virtual-list.tsx @@ -28,7 +28,7 @@ import { observer } from "mobx-react"; import { Align, ListChildComponentProps, ListOnScrollProps, VariableSizeList } from "react-window"; import { cssNames, noop } from "../../utils"; import type { TableRowProps } from "../table/table-row"; -import type { ItemObject } from "../../item.store"; +import type { ItemObject } from "../../../common/item.store"; import debounce from "lodash/debounce"; import isEqual from "lodash/isEqual"; import AutoSizer from "react-virtualized-auto-sizer"; diff --git a/src/renderer/utils/index.ts b/src/renderer/utils/index.ts index a0b20d1e2d..537aab13ba 100755 --- a/src/renderer/utils/index.ts +++ b/src/renderer/utils/index.ts @@ -32,10 +32,9 @@ export * from "./storageHelper"; export * from "./createStorage"; export * from "./interval"; export * from "./copyToClipboard"; -export * from "./formatDuration"; export * from "./isReactNode"; -export * from "./convertMemory"; -export * from "./convertCpu"; +export * from "../../common/utils/convertMemory"; +export * from "../../common/utils/convertCpu"; export * from "./metricUnitsToNumber"; export * from "./display-booleans"; export * from "./isMiddleClick"; diff --git a/webpack.main.ts b/webpack.main.ts index ae78d06d09..33d9daf6af 100755 --- a/webpack.main.ts +++ b/webpack.main.ts @@ -22,13 +22,15 @@ import path from "path"; import type webpack from "webpack"; import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin"; -import { isProduction, mainDir, buildDir, isDevelopment } from "./src/common/vars"; +import { isProduction, mainDir, buildDir, isDevelopment, preloadEntrypoint } from "./src/common/vars"; import nodeExternals from "webpack-node-externals"; import ProgressBarPlugin from "progress-bar-webpack-plugin"; import * as vars from "./src/common/vars"; import getTSLoader from "./src/common/getTSLoader"; -export default function (): webpack.Configuration { +const configs: {(): webpack.Configuration}[] = []; + +configs.push((): webpack.Configuration => { console.info("WEBPACK:main", vars); return { @@ -64,4 +66,43 @@ export default function (): webpack.Configuration { new ForkTsCheckerPlugin(), ].filter(Boolean) }; -} +}); + +configs.push((): webpack.Configuration => { + console.info("WEBPACK:preload", vars); + + return { + context: __dirname, + target: "electron-main", + mode: isProduction ? "production" : "development", + devtool: isProduction ? "source-map" : "cheap-eval-source-map", + cache: isDevelopment, + entry: { + main: path.resolve(preloadEntrypoint), + }, + output: { + libraryTarget: "global", + path: buildDir, + filename: "preload.js" + }, + resolve: { + extensions: [".json", ".js", ".ts"], + mainFields: ["main"] + }, + module: { + rules: [ + { + test: /\.node$/, + use: "node-loader" + }, + getTSLoader(/\.ts$/) + ] + }, + plugins: [ + new ProgressBarPlugin(), + new ForkTsCheckerPlugin(), + ].filter(Boolean) + }; +}); + +export default configs; diff --git a/yarn.lock b/yarn.lock index 26a1aa7263..054c84ffa6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1685,6 +1685,14 @@ resolved "https://registry.yarnpkg.com/@types/module-alias/-/module-alias-2.0.0.tgz#882668f8b8cdbda44812c3b592c590909e18849e" integrity sha512-e3sW4oEH0qS1QxSfX7PT6xIi5qk/YSMsrB9Lq8EtkhQBZB+bKyfkP+jpLJRySanvBhAQPSv2PEBe81M8Iy/7yg== +"@types/node-fetch@^2.5.12": + version "2.5.12" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.12.tgz#8a6f779b1d4e60b7a57fb6fd48d84fb545b9cc66" + integrity sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw== + dependencies: + "@types/node" "*" + form-data "^3.0.0" + "@types/node@*": version "14.14.41" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.41.tgz#d0b939d94c1d7bd53d04824af45f1139b8c45615" @@ -4081,7 +4089,7 @@ colors@1.0.3: resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs= -colors@^1.1.2, colors@^1.2.1: +colors@^1.1.2, colors@^1.2.1, colors@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== @@ -4102,7 +4110,7 @@ columnify@~1.5.4: strip-ansi "^3.0.0" wcwidth "^1.0.0" -combined-stream@^1.0.6, combined-stream@~1.0.6: +combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6: version "1.0.8" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== @@ -6415,6 +6423,15 @@ form-data@^2.5.0: combined-stream "^1.0.6" mime-types "^2.1.12" +form-data@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f" + integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + form-data@~2.3.2: version "2.3.3" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6" @@ -10174,7 +10191,7 @@ node-fetch-npm@^2.0.2: json-parse-better-errors "^1.0.0" safe-buffer "^5.1.1" -node-fetch@2.6.1: +node-fetch@2.6.1, node-fetch@^2.6.1: version "2.6.1" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== @@ -15271,6 +15288,15 @@ win-ca@^3.2.0: node-forge "^0.8.2" split "^1.0.1" +winston-console-format@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/winston-console-format/-/winston-console-format-1.0.8.tgz#591adc8e9567c3397a3fa2e29e596d56e48db840" + integrity sha512-dq7t/E0D0QRi4XIOwu6HM1+5e//WPqylH88GVjKEhQVrzGFg34MCz+G7pMJcXFBen9C0kBsu5GYgbYsE2LDwKw== + dependencies: + colors "^1.4.0" + logform "^2.2.0" + triple-beam "^1.3.0" + winston-transport-browserconsole@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/winston-transport-browserconsole/-/winston-transport-browserconsole-1.0.5.tgz#8ef1bc32da5fb0a66604f2b8b6f127ed725108c9"