From 1ab5323f6846a71e84904da6f3a5e7963d3f3af5 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Mon, 8 May 2023 12:07:54 +0300 Subject: [PATCH] chore: extract kube-api from core Signed-off-by: Jari Kolehmainen --- .../k8s-api/__tests__/api-manager.test.ts | 2 +- .../k8s-api/__tests__/deployment.api.test.ts | 3 +- .../kube-api-version-detection.test.ts | 4 +- .../common/k8s-api/__tests__/kube-api.test.ts | 1051 +-------------- .../__tests__/kube-object.store.test.ts | 2 +- .../__tests__/stateful-set.api.test.ts | 3 +- .../common/k8s-api/api-manager/api-manager.ts | 4 +- .../auto-registration-emitter.injectable.ts | 2 +- .../k8s-api/api-manager/crd-api-token.ts | 2 +- ...create-custom-resource-store.injectable.ts | 2 +- .../k8s-api/api-manager/manager.injectable.ts | 2 +- .../k8s-api/api-manager/resource.store.ts | 2 +- .../create-kube-api-for-cluster.injectable.ts | 2 +- ...-kube-api-for-remote-cluster.injectable.ts | 4 +- .../k8s-api/create-kube-api.injectable.ts | 2 +- ...te-kube-json-api-for-cluster.injectable.ts | 2 +- .../create-kube-json-api.injectable.ts | 2 +- .../cluster-role-binding.api.injectable.ts | 3 +- .../endpoints/cluster-role.api.injectable.ts | 3 +- .../endpoints/cluster.api.injectable.ts | 3 +- .../component-status.api.injectable.ts | 3 +- .../endpoints/config-map.api.injectable.ts | 3 +- .../endpoints/cron-job.api.injectable.ts | 3 +- ...stom-resource-definition.api.injectable.ts | 3 +- .../endpoints/daemon-set.api.injectable.ts | 3 +- .../endpoints/deployment.api.injectable.ts | 3 +- .../endpoints/endpoint.api.injectable.ts | 3 +- .../endpoints/events.api.injectable.ts | 3 +- ...orizontal-pod-autoscaler.api.injectable.ts | 3 +- .../endpoints/ingress-class.api.injectable.ts | 3 +- .../endpoints/ingress.api.injectable.ts | 3 +- .../k8s-api/endpoints/job.api.injectable.ts | 3 +- .../k8s-api/endpoints/lease.api.injectable.ts | 3 +- .../endpoints/limit-range.api.injectable.ts | 3 +- ...ng-webhook-configuration-api.injectable.ts | 3 +- .../endpoints/namespace.api.injectable.ts | 3 +- .../network-policy.api.injectable.ts | 3 +- .../k8s-api/endpoints/node.api.injectable.ts | 3 +- .../persistent-volume-claim.api.injectable.ts | 3 +- .../persistent-volume.api.injectable.ts | 3 +- .../pod-disruption-budget.api.injectable.ts | 3 +- .../endpoints/pod-metrics.api.injectable.ts | 3 +- .../pod-security-policy.api.injectable.ts | 3 +- .../k8s-api/endpoints/pod.api.injectable.ts | 3 +- .../priority-class.api.injectable.ts | 3 +- .../endpoints/replica-set.api.injectable.ts | 3 +- .../replication-controller.api.injectable.ts | 3 +- .../resource-quota.api.injectable.ts | 3 +- .../endpoints/role-binding.api.injectable.ts | 3 +- .../k8s-api/endpoints/role.api.injectable.ts | 3 +- .../endpoints/runtime-class.api.injectable.ts | 3 +- .../endpoints/secret.api.injectable.ts | 3 +- ...lf-subject-rules-reviews.api.injectable.ts | 3 +- .../service-account.api.injectable.ts | 3 +- .../endpoints/service.api.injectable.ts | 3 +- .../endpoints/stateful-set.api.injectable.ts | 3 +- .../endpoints/storage-class.api.injectable.ts | 3 +- ...ng-webhook-configuration-api.injectable.ts | 3 +- .../vertical-pod-autoscaler.api.injectable.ts | 3 +- .../get-kube-api-from-path.injectable.ts | 5 +- .../src/common/k8s-api/kube-object.store.ts | 5 +- .../k8s-api/maybe-kube-api.injectable.ts | 2 +- .../core/src/extensions/common-api/k8s-api.ts | 6 +- ...tems-when-cluster-is-not-relevant.test.tsx | 2 +- ...vely-hide-kube-object-detail-item.test.tsx | 2 +- .../features/cluster/workloads/pods.test.tsx | 2 +- ...y-decorator-for-show-details.injectable.ts | 2 +- .../node-shell-session/node-shell-session.ts | 2 +- ...setup-auto-crd-api-creations.injectable.ts | 2 +- .../setup-auto-registration.injectable.ts | 2 +- .../src/renderer/components/cluster/store.ts | 2 +- .../store.ts | 2 +- .../components/config-leases/store.ts | 2 +- .../components/config-limit-ranges/store.ts | 2 +- .../renderer/components/config-maps/store.ts | 2 +- .../mutating-webhook-configuration-store.ts | 2 +- .../config-pod-disruption-budgets/store.ts | 2 +- .../config-priority-classes/store.ts | 2 +- .../add-dialog/view.tsx | 2 +- .../config-resource-quotas/store.ts | 2 +- .../config-runtime-classes/store.ts | 2 +- .../config-secrets/add-dialog/view.tsx | 2 +- .../components/config-secrets/store.ts | 2 +- .../validating-webhook-configuration-store.ts | 2 +- .../config-vertical-pod-autoscalers/store.ts | 2 +- .../custom-resources/definition.store.ts | 2 +- .../edit-resource-model.injectable.tsx | 2 +- .../request-kube-resource.injectable.ts | 2 +- .../request-patch-kube-resource.injectable.ts | 2 +- .../dock/logs/call-for-logs.injectable.ts | 2 +- .../dock/logs/download-all-logs.injectable.ts | 2 +- .../components/dock/logs/logs-view-model.ts | 2 +- .../src/renderer/components/events/events.tsx | 2 +- .../src/renderer/components/events/store.ts | 2 +- .../kube-object-list-layout.tsx | 2 +- .../kube-object-meta/kube-object-meta.tsx | 2 +- .../renderer/components/namespaces/store.ts | 2 +- .../components/network-endpoints/store.ts | 2 +- .../network-ingresses/ingress-class-store.ts | 2 +- .../network-ingresses/ingress-store.ts | 2 +- .../components/network-policies/store.ts | 2 +- .../port-forward-details.tsx | 2 +- .../components/network-services/store.ts | 2 +- .../src/renderer/components/nodes/store.ts | 2 +- .../components/pod-security-policies/store.ts | 2 +- .../components/storage-classes/store.ts | 2 +- .../components/storage-volume-claims/store.ts | 2 +- .../volume-claim-details.tsx | 2 +- .../storage-volume-claims/volume-claims.tsx | 2 +- .../components/storage-volumes/store.ts | 2 +- .../storage-volumes/volume-details.tsx | 2 +- .../components/storage-volumes/volumes.tsx | 2 +- .../cluster-role-bindings/store.ts | 2 +- .../user-management/cluster-roles/store.ts | 2 +- .../role-bindings/dialog/view.tsx | 2 +- .../user-management/role-bindings/store.ts | 2 +- .../components/user-management/roles/store.ts | 2 +- .../user-management/service-accounts/store.ts | 2 +- .../workloads-cronjobs/cron-job-menu.tsx | 2 +- .../components/workloads-cronjobs/store.ts | 2 +- .../trigger-dialog/view.tsx | 2 +- .../workloads-daemonsets/daemonset-menu.tsx | 2 +- .../components/workloads-daemonsets/store.ts | 2 +- .../workloads-deployments/deployment-menu.tsx | 2 +- .../scale/dialog.test.tsx | 2 +- .../workloads-deployments/scale/dialog.tsx | 2 +- .../components/workloads-deployments/store.ts | 2 +- .../components/workloads-jobs/store.ts | 2 +- .../details/volumes/variant-helpers.tsx | 2 +- .../details/volumes/variants/ceph-fs.tsx | 2 +- .../details/volumes/variants/config-map.tsx | 2 +- .../variants/container-storage-interface.tsx | 2 +- .../details/volumes/variants/flex-volume.tsx | 2 +- .../variants/persistent-volume-claim.tsx | 2 +- .../volumes/variants/rados-block-device.tsx | 2 +- .../details/volumes/variants/scale-io.tsx | 2 +- .../details/volumes/variants/secret.tsx | 2 +- .../details/volumes/variants/storage-os.tsx | 2 +- .../workloads-pods/pod-details-secrets.tsx | 2 +- .../components/workloads-pods/pod-details.tsx | 2 +- .../components/workloads-pods/store.ts | 2 +- .../scale-dialog/dialog.test.tsx | 2 +- .../scale-dialog/dialog.tsx | 2 +- .../components/workloads-replicasets/store.ts | 2 +- .../replication-controller-details.tsx | 2 +- .../replication-controller-store.ts | 2 +- .../scale/dialog.test.tsx | 2 +- .../workloads-statefulsets/scale/dialog.tsx | 2 +- .../statefulset-menu.tsx | 2 +- .../workloads-statefulsets/store.ts | 2 +- .../renderer/k8s/api-kube-get.injectable.ts | 2 +- .../renderer/k8s/api-kube-patch.injectable.ts | 2 +- .../src/renderer/k8s/api-kube.injectable.ts | 2 +- .../utility-features/kube-api/.eslintrc.js | 6 + .../utility-features/kube-api/.prettierrc | 1 + packages/utility-features/kube-api/.swcrc | 18 + packages/utility-features/kube-api/index.ts | 7 + .../utility-features/kube-api/jest.config.js | 1 + .../utility-features/kube-api/package.json | 54 + .../kube-api/src}/api-kube.ts | 0 .../endpoints/cluster-role-binding.api.ts | 0 .../src}/endpoints/cluster-role.api.ts | 0 .../kube-api/src}/endpoints/cluster.api.ts | 2 +- .../src}/endpoints/component-status.api.ts | 0 .../kube-api/src}/endpoints/config-map.api.ts | 2 +- .../kube-api/src}/endpoints/cron-job.api.ts | 12 +- .../custom-resource-definition.api.ts | 0 .../kube-api/src}/endpoints/daemon-set.api.ts | 0 .../kube-api/src}/endpoints/deployment.api.ts | 0 .../kube-api/src}/endpoints/endpoint.api.ts | 0 .../kube-api/src}/endpoints/events.api.ts | 0 .../horizontal-pod-autoscaler.api.ts | 0 .../kube-api/src}/endpoints/index.ts | 3 +- .../src}/endpoints/ingress-class.api.ts | 0 .../kube-api/src}/endpoints/ingress.api.ts | 0 .../kube-api/src}/endpoints/job.api.ts | 0 .../kube-api/src}/endpoints/lease.api.ts | 0 .../src}/endpoints/limit-range.api.ts | 0 .../mutating-webhook-configuration.api.ts | 0 .../kube-api/src}/endpoints/namespace.api.ts | 0 .../src}/endpoints/network-policy.api.ts | 0 .../kube-api/src}/endpoints/node.api.ts | 0 .../endpoints/persistent-volume-claim.api.ts | 0 .../src}/endpoints/persistent-volume.api.ts | 0 .../endpoints/pod-disruption-budget.api.ts | 0 .../src}/endpoints/pod-metrics.api.ts | 0 .../src}/endpoints/pod-security-policy.api.ts | 0 .../kube-api/src}/endpoints/pod.api.ts | 0 .../src}/endpoints/priority-class.api.ts | 0 .../src}/endpoints/replica-set.api.ts | 0 .../endpoints/replication-controller.api.ts | 0 .../src}/endpoints/resource-quota.api.ts | 0 .../src}/endpoints/role-binding.api.ts | 0 .../kube-api/src}/endpoints/role.api.ts | 0 .../src}/endpoints/runtime-class.api.ts | 0 .../kube-api/src}/endpoints/secret.api.ts | 0 .../self-subject-rules-reviews.api.ts | 0 .../src}/endpoints/service-account.api.ts | 0 .../kube-api/src}/endpoints/service.api.ts | 0 .../src}/endpoints/stateful-set.api.ts | 0 .../src}/endpoints/storage-class.api.ts | 1 - .../validating-webhook-configuration.api.ts | 0 .../endpoints/vertical-pod-autoscaler.api.ts | 0 .../kube-api/src}/get-match-for.test.ts | 2 +- .../kube-api/src}/get-match-for.ts | 0 .../kube-api/src}/kube-api-injection-token.ts | 2 +- .../kube-api/src}/kube-api-parse.test.ts | 207 +-- .../kube-api/src}/kube-api-parse.ts | 81 +- .../kube-api/src/kube-api.test.ts | 1188 +++++++++++++++++ .../kube-api/src}/kube-api.ts | 205 ++- .../kube-api/src}/kube-json-api.ts | 0 .../kube-api/src}/kube-watch-event.ts | 17 +- .../kube-api/src/mock-responses.ts | 78 ++ .../kube-api/src}/prepend.ts | 3 +- .../utility-features/kube-api/tsconfig.json | 7 + .../kube-api/webpack.config.js | 1 + 216 files changed, 1776 insertions(+), 1537 deletions(-) create mode 100644 packages/utility-features/kube-api/.eslintrc.js create mode 100644 packages/utility-features/kube-api/.prettierrc create mode 100644 packages/utility-features/kube-api/.swcrc create mode 100644 packages/utility-features/kube-api/index.ts create mode 100644 packages/utility-features/kube-api/jest.config.js create mode 100644 packages/utility-features/kube-api/package.json rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/api-kube.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/cluster-role-binding.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/cluster-role.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/cluster.api.ts (96%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/component-status.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/config-map.api.ts (96%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/cron-job.api.ts (87%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/custom-resource-definition.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/daemon-set.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/deployment.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/endpoint.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/events.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/horizontal-pod-autoscaler.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/index.ts (94%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/ingress-class.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/ingress.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/job.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/lease.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/limit-range.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/mutating-webhook-configuration.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/namespace.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/network-policy.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/node.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/persistent-volume-claim.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/persistent-volume.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/pod-disruption-budget.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/pod-metrics.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/pod-security-policy.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/pod.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/priority-class.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/replica-set.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/replication-controller.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/resource-quota.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/role-binding.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/role.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/runtime-class.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/secret.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/self-subject-rules-reviews.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/service-account.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/service.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/stateful-set.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/storage-class.api.ts (99%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/validating-webhook-configuration.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/endpoints/vertical-pod-autoscaler.api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/get-match-for.test.ts (92%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/get-match-for.ts (100%) rename packages/{core/src/common/k8s-api/kube-api => utility-features/kube-api/src}/kube-api-injection-token.ts (87%) rename packages/{core/src/common/k8s-api/__tests__ => utility-features/kube-api/src}/kube-api-parse.test.ts (57%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/kube-api-parse.ts (81%) create mode 100644 packages/utility-features/kube-api/src/kube-api.test.ts rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/kube-api.ts (85%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/kube-json-api.ts (100%) rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/kube-watch-event.ts (50%) create mode 100644 packages/utility-features/kube-api/src/mock-responses.ts rename packages/{core/src/common/k8s-api => utility-features/kube-api/src}/prepend.ts (87%) create mode 100644 packages/utility-features/kube-api/tsconfig.json create mode 100644 packages/utility-features/kube-api/webpack.config.js diff --git a/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts b/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts index 7ee1bcbfb5..3008b91916 100644 --- a/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts +++ b/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts @@ -14,7 +14,7 @@ import directoryForUserDataInjectable from "../../app-paths/directory-for-user-d import { loggerInjectionToken } from "@k8slens/logger"; import type { ApiManager } from "../api-manager"; import apiManagerInjectable from "../api-manager/manager.injectable"; -import { KubeApi } from "../kube-api"; +import { KubeApi } from "@k8slens/kube-api"; import { KubeObject } from "@k8slens/kube-object"; import { KubeObjectStore } from "../kube-object.store"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/__tests__/deployment.api.test.ts b/packages/core/src/common/k8s-api/__tests__/deployment.api.test.ts index 4db0e5bebe..af9dc386dd 100644 --- a/packages/core/src/common/k8s-api/__tests__/deployment.api.test.ts +++ b/packages/core/src/common/k8s-api/__tests__/deployment.api.test.ts @@ -6,9 +6,8 @@ import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting"; import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable"; import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable"; -import type { DeploymentApi } from "../endpoints/deployment.api"; import deploymentApiInjectable from "../endpoints/deployment.api.injectable"; -import type { KubeJsonApi } from "../kube-json-api"; +import type { KubeJsonApi, DeploymentApi } from "@k8slens/kube-api"; describe("DeploymentApi", () => { let deploymentApi: DeploymentApi; diff --git a/packages/core/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts b/packages/core/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts index 3c5e91f2eb..c73d024cce 100644 --- a/packages/core/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts +++ b/packages/core/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ApiManager } from "../api-manager"; -import type { IngressApi } from "../endpoints"; -import { HorizontalPodAutoscalerApi } from "../endpoints"; +import type { IngressApi } from "@k8slens/kube-api"; +import { HorizontalPodAutoscalerApi } from "@k8slens/kube-api"; import { Ingress } from "@k8slens/kube-object"; import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting"; import type { Fetch } from "../../fetch/fetch.injectable"; diff --git a/packages/core/src/common/k8s-api/__tests__/kube-api.test.ts b/packages/core/src/common/k8s-api/__tests__/kube-api.test.ts index 39b778b020..072f889824 100644 --- a/packages/core/src/common/k8s-api/__tests__/kube-api.test.ts +++ b/packages/core/src/common/k8s-api/__tests__/kube-api.test.ts @@ -2,12 +2,8 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { KubeApiWatchCallback } from "../kube-api"; -import { KubeApi } from "../kube-api"; -import { PassThrough } from "stream"; -import { PodApi } from "../endpoints"; -import type { DeploymentApi, NamespaceApi } from "../endpoints"; -import { Deployment, Pod } from "@k8slens/kube-object"; +import { KubeApi, PodApi } from "@k8slens/kube-api"; +import { Pod } from "@k8slens/kube-object"; import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting"; import type { Fetch } from "../../fetch/fetch.injectable"; import fetchInjectable from "../../fetch/fetch.injectable"; @@ -17,19 +13,16 @@ import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; import { flushPromises } from "@k8slens/test-utils"; import createKubeJsonApiInjectable from "../create-kube-json-api.injectable"; -import type { IKubeWatchEvent } from "../kube-watch-event"; -import type { KubeJsonApiDataFor, KubeStatusData, KubeJsonApiData } from "@k8slens/kube-object"; +import type { KubeStatusData } from "@k8slens/kube-object"; import setupAutoRegistrationInjectable from "../../../renderer/before-frame-starts/runnables/setup-auto-registration.injectable"; -import { createMockResponseFromStream, createMockResponseFromString } from "../../../test-utils/mock-responses"; +import { createMockResponseFromString } from "../../../test-utils/mock-responses"; import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable"; import directoryForUserDataInjectable from "../../app-paths/directory-for-user-data/directory-for-user-data.injectable"; import hostedClusterInjectable from "../../../renderer/cluster-frame-context/hosted-cluster.injectable"; import directoryForKubeConfigsInjectable from "../../app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable"; import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; -import deploymentApiInjectable from "../endpoints/deployment.api.injectable"; import podApiInjectable from "../endpoints/pod.api.injectable"; -import namespaceApiInjectable from "../endpoints/namespace.api.injectable"; // NOTE: this is fine because we are testing something that only exported // eslint-disable-next-line no-restricted-imports @@ -167,171 +160,6 @@ describe("KubeApi", () => { setupAutoRegistration.run(); }); - describe("patching deployments", () => { - let api: DeploymentApi; - - beforeEach(() => { - api = di.inject(deploymentApiInjectable); - }); - - describe("when patching a resource without providing a strategy", () => { - let patchRequest: Promise; - - beforeEach(async () => { - patchRequest = api.patch({ name: "test", namespace: "default" }, { - spec: { replicas: 2 }, - }); - - // This is needed because of how JS promises work - await flushPromises(); - }); - - it("requests a patch using strategic merge", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", - { - headers: { - "content-type": "application/strategic-merge-patch+json", - }, - method: "patch", - body: JSON.stringify({ spec: { replicas: 2 }}), - }, - ]); - }); - - describe("when the patch request resolves with data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({ - apiVersion: "v1", - kind: "Deployment", - metadata: { - name: "test", - namespace: "default", - resourceVersion: "1", - uid: "12345", - }, - spec: { - replicas: 2, - }, - })), - ); - }); - - it("resolves the patch call", async () => { - expect(await patchRequest).toBeInstanceOf(Deployment); - }); - }); - }); - - describe("when patching a resource using json patch", () => { - let patchRequest: Promise; - - beforeEach(async () => { - patchRequest = api.patch({ name: "test", namespace: "default" }, [ - { op: "replace", path: "/spec/replicas", value: 2 }, - ], "json"); - - // This is needed because of how JS promises work - await flushPromises(); - }); - - it("requests a patch using json merge", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", - { - headers: { - "content-type": "application/json-patch+json", - }, - method: "patch", - body: JSON.stringify([ - { op: "replace", path: "/spec/replicas", value: 2 }, - ]), - }, - ]); - }); - - describe("when the patch request resolves with data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({ - apiVersion: "v1", - kind: "Deployment", - metadata: { - name: "test", - namespace: "default", - resourceVersion: "1", - uid: "12345", - }, - spec: { - replicas: 2, - }, - })), - ); - }); - - it("resolves the patch call", async () => { - expect(await patchRequest).toBeInstanceOf(Deployment); - }); - }); - }); - - describe("when patching a resource using merge patch", () => { - let patchRequest: Promise; - - beforeEach(async () => { - patchRequest = api.patch( - { name: "test", namespace: "default" }, - { metadata: { annotations: { provisioned: "True" }}}, - "merge", - ); - - // This is needed because of how JS promises work - await flushPromises(); - }); - - it("requests a patch using json merge", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", - { - headers: { - "content-type": "application/merge-patch+json", - }, - method: "patch", - body: JSON.stringify({ metadata: { annotations: { provisioned: "True" }}}), - }, - ]); - }); - - describe("when the patch request resolves with data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", JSON.stringify({ - apiVersion: "v1", - kind: "Deployment", - metadata: { - name: "test", - namespace: "default", - resourceVersion: "1", - uid: "12345", - annotations: { - provisioned: "True", - }, - }, - })), - ); - }); - - it("resolves the patch call", async () => { - expect(await patchRequest).toBeInstanceOf(Deployment); - }); - }); - }); - }); - describe("deleting pods (namespace scoped resource)", () => { let api: PodApi; @@ -339,114 +167,6 @@ describe("KubeApi", () => { api = di.inject(podApiInjectable); }); - describe("when deleting by just name", () => { - let deleteRequest: Promise; - - beforeEach(async () => { - deleteRequest = api.delete({ name: "foo" }); - - // This is required for how JS promises work - await flushPromises(); - }); - - it("requests deleting pod in default namespace", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", - { - headers: { - "content-type": "application/json", - }, - method: "delete", - }, - ]); - }); - - describe("when request resolves", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", "{}"), - ); - }); - - it("resolves the call", async () => { - expect(await deleteRequest).toBeDefined(); - }); - }); - }); - - describe("when deleting by name and empty namespace", () => { - let deleteRequest: Promise; - - beforeEach(async () => { - deleteRequest = api.delete({ name: "foo", namespace: "" }); - - // This is required for how JS promises work - await flushPromises(); - }); - - it("requests deleting pod in default namespace", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", - { - headers: { - "content-type": "application/json", - }, - method: "delete", - }, - ]); - }); - - describe("when request resolves", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", "{}"), - ); - }); - - it("resolves the call", async () => { - expect(await deleteRequest).toBeDefined(); - }); - }); - }); - - describe("when deleting by name and namespace", () => { - let deleteRequest: Promise; - - beforeEach(async () => { - deleteRequest = api.delete({ name: "foo", namespace: "test" }); - - // This is required for how JS promises work - await flushPromises(); - }); - - it("requests deleting pod in given namespace", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background", - { - headers: { - "content-type": "application/json", - }, - method: "delete", - }, - ]); - }); - - describe("when request resolves", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background", "{}"), - ); - }); - - it("resolves the call", async () => { - expect(await deleteRequest).toBeDefined(); - }); - }); - }); - describe("eviction-api as better replacement for pod.delete() request", () => { let evictRequest: Promise; @@ -495,767 +215,4 @@ describe("KubeApi", () => { }); }); }); - - describe("deleting namespaces (cluster scoped resource)", () => { - let api: NamespaceApi; - - beforeEach(() => { - api = di.inject(namespaceApiInjectable); - }); - - describe("when deleting by just name", () => { - let deleteRequest: Promise; - - beforeEach(async () => { - deleteRequest = api.delete({ name: "foo" }); - - // This is required for how JS promises work - await flushPromises(); - }); - - it("requests deleting Namespace without namespace", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", - { - headers: { - "content-type": "application/json", - }, - method: "delete", - }, - ]); - }); - - describe("when request resolves", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", "{}"), - ); - }); - - it("resolves the call", async () => { - expect(await deleteRequest).toBeDefined(); - }); - }); - }); - - describe("when deleting by name and empty namespace", () => { - let deleteRequest: Promise; - - beforeEach(async () => { - deleteRequest = api.delete({ name: "foo", namespace: "" }); - - // This is required for how JS promises work - await flushPromises(); - }); - - it("requests deleting Namespace without namespace", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", - { - headers: { - "content-type": "application/json", - }, - method: "delete", - }, - ]); - }); - - describe("when request resolves", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", "{}"), - ); - }); - - it("resolves the call", async () => { - expect(await deleteRequest).toBeDefined(); - }); - }); - }); - }); - - describe("watching pods", () => { - let api: PodApi; - let stream: PassThrough; - - beforeEach(() => { - api = di.inject(podApiInjectable); - stream = new PassThrough(); - }); - - afterEach(() => { - stream.end(); - stream.destroy(); - }); - - describe("when watching in a namespace", () => { - let stopWatch: () => void; - let callback: jest.MockedFunction; - - beforeEach(async () => { - callback = jest.fn(); - stopWatch = api.watch({ - namespace: "kube-system", - callback, - }); - - await flushPromises(); - }); - - it("requests the watch", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", - { - headers: { - "content-type": "application/json", - }, - method: "get", - }, - ]); - }); - - describe("when the request resolves with a stream", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ([url, init]) => { - const isMatch = url === "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600"; - - if (isMatch) { - init?.signal?.addEventListener("abort", () => { - stream.destroy(); - }); - } - - return isMatch; - }, - createMockResponseFromStream("http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", stream), - ); - }); - - describe("when some data comes back on the stream", () => { - beforeEach(() => { - stream.emit("data", `${JSON.stringify({ - type: "ADDED", - object: { - apiVersion: "v1", - kind: "Pod", - metadata: { - name: "foobar", - namespace: "kube-system", - resourceVersion: "1", - uid: "123456", - }, - }, - } as IKubeWatchEvent>)}\n`); - }); - - it("calls the callback with the data", () => { - expect(callback).toBeCalledWith( - { - type: "ADDED", - object: { - apiVersion: "v1", - kind: "Pod", - metadata: { - name: "foobar", - namespace: "kube-system", - resourceVersion: "1", - selfLink: "/api/v1/namespaces/kube-system/pods/foobar", - uid: "123456", - }, - }, - }, - null, - ); - }); - - describe("when stopping the watch", () => { - beforeEach(() => { - stopWatch(); - }); - - it("closes the stream", () => { - expect(stream.destroyed).toBe(true); - }); - }); - }); - }); - }); - - describe("when watching in a namespace with an abort controller provided", () => { - let callback: jest.MockedFunction; - let abortController: AbortController; - - beforeEach(async () => { - callback = jest.fn(); - abortController = new AbortController(); - api.watch({ - namespace: "kube-system", - callback, - abortController, - }); - - await flushPromises(); - }); - - it("requests the watch", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", - { - headers: { - "content-type": "application/json", - }, - method: "get", - }, - ]); - }); - - describe("when the request resolves with a stream", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ([url, init]) => { - const isMatch = url === "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600"; - - if (isMatch) { - init?.signal?.addEventListener("abort", () => { - stream.destroy(); - }); - } - - return isMatch; - }, - createMockResponseFromStream("http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", stream), - ); - }); - - describe("when some data comes back on the stream", () => { - beforeEach(() => { - stream.emit("data", `${JSON.stringify({ - type: "ADDED", - object: { - apiVersion: "v1", - kind: "Pod", - metadata: { - name: "foobar", - namespace: "kube-system", - resourceVersion: "1", - uid: "123456", - }, - }, - } as IKubeWatchEvent>)}\n`); - }); - - it("calls the callback with the data", () => { - expect(callback).toBeCalledWith( - { - type: "ADDED", - object: { - apiVersion: "v1", - kind: "Pod", - metadata: { - name: "foobar", - namespace: "kube-system", - resourceVersion: "1", - selfLink: "/api/v1/namespaces/kube-system/pods/foobar", - uid: "123456", - }, - }, - }, - null, - ); - }); - - describe("when stopping the watch via the controller", () => { - beforeEach(() => { - abortController.abort(); - }); - - it("closes the stream", () => { - expect(stream.destroyed).toBe(true); - }); - }); - }); - }); - }); - - describe("when watching in a namespace with a timeout", () => { - let stopWatch: () => void; - let callback: jest.MockedFunction; - - beforeEach(async () => { - callback = jest.fn(); - stopWatch = api.watch({ - namespace: "kube-system", - callback, - timeout: 60, - }); - - await flushPromises(); - }); - - it("requests the watch", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60", - { - headers: { - "content-type": "application/json", - }, - method: "get", - }, - ]); - }); - - describe("when the request resolves with a stream", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ([url, init]) => { - const isMatch = url === "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60"; - - if (isMatch) { - init?.signal?.addEventListener("abort", () => { - stream.destroy(); - }); - } - - return isMatch; - }, - createMockResponseFromStream("http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60", stream), - ); - }); - - describe("when some data comes back on the stream", () => { - beforeEach(() => { - stream.emit("data", `${JSON.stringify({ - type: "ADDED", - object: { - apiVersion: "v1", - kind: "Pod", - metadata: { - name: "foobar", - namespace: "kube-system", - resourceVersion: "1", - uid: "123456", - }, - }, - } as IKubeWatchEvent>)}\n`); - }); - - it("calls the callback with the data", () => { - expect(callback).toBeCalledWith( - { - type: "ADDED", - object: { - apiVersion: "v1", - kind: "Pod", - metadata: { - name: "foobar", - namespace: "kube-system", - resourceVersion: "1", - selfLink: "/api/v1/namespaces/kube-system/pods/foobar", - uid: "123456", - }, - }, - }, - null, - ); - }); - - describe("when stopping the watch", () => { - beforeEach(() => { - stopWatch(); - }); - - it("closes the stream", () => { - expect(stream.destroyed).toBe(true); - }); - }); - - describe("when the watch ends", () => { - beforeEach(() => { - stream.end(); - }); - - it("requests a new watch", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60", - { - headers: { - "content-type": "application/json", - }, - method: "get", - }, - ]); - }); - - describe("when stopping the watch", () => { - beforeEach(() => { - stopWatch(); - }); - - it("closes the stream", () => { - expect(stream.destroyed).toBe(true); - }); - }); - }); - }); - }); - }); - }); - - describe("creating pods", () => { - let api: PodApi; - - beforeEach(() => { - api = di.inject(podApiInjectable); - }); - - describe("when creating a pod", () => { - let createRequest: Promise; - - beforeEach(async () => { - createRequest = api.create({ - name: "foobar", - namespace: "default", - }, { - metadata: { - labels: { - foo: "bar", - }, - }, - spec: { - containers: [ - { - name: "web", - image: "nginx", - ports: [ - { - name: "web", - containerPort: 80, - protocol: "TCP", - }, - ], - }, - ], - }, - }); - - // This is required because of how JS promises work - await flushPromises(); - }); - - it("should request to create a pod with full descriptor", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", - { - headers: { - "content-type": "application/json", - }, - method: "post", - body: JSON.stringify({ - metadata: { - labels: { - foo: "bar", - }, - name: "foobar", - namespace: "default", - }, - spec: { - containers: [{ - name: "web", - image: "nginx", - ports: [{ - name: "web", - containerPort: 80, - protocol: "TCP", - }], - }], - }, - kind: "Pod", - apiVersion: "v1", - }), - }, - ]); - }); - - describe("when request resolves with data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", JSON.stringify({ - kind: "Pod", - apiVersion: "v1", - metadata: { - name: "foobar", - namespace: "default", - labels: { - foo: "bar", - }, - resourceVersion: "1", - uid: "123456798", - }, - spec: { - containers: [{ - name: "web", - image: "nginx", - ports: [{ - name: "web", - containerPort: 80, - protocol: "TCP", - }], - }], - }, - })), - ); - }); - - it("call should resolve in a Pod instance", async () => { - expect(await createRequest).toBeInstanceOf(Pod); - }); - }); - }); - }); - - describe("updating pods", () => { - let api: PodApi; - - beforeEach(() => { - api = di.inject(podApiInjectable); - }); - - describe("when updating a pod", () => { - let updateRequest: Promise; - - beforeEach(async () => { - updateRequest = api.update({ - name: "foobar", - namespace: "default", - }, { - kind: "Pod", - apiVersion: "v1", - metadata: { - labels: { - foo: "bar", - }, - }, - spec: { - containers: [{ - name: "web", - image: "nginx", - ports: [{ - name: "web", - containerPort: 80, - protocol: "TCP", - }], - }], - }, - }); - - await flushPromises(); - }); - - it("should request that the pod is updated", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar", - { - headers: { - "content-type": "application/json", - }, - method: "put", - body: JSON.stringify({ - kind: "Pod", - apiVersion: "v1", - metadata: { - labels: { - foo: "bar", - }, - name: "foobar", - namespace: "default", - }, - spec: { - containers: [{ - name: "web", - image: "nginx", - ports: [{ - name: "web", - containerPort: 80, - protocol: "TCP", - }], - }], - }, - }), - }, - ]); - }); - - describe("when the request resolves with data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar", JSON.stringify({ - kind: "Pod", - apiVersion: "v1", - metadata: { - name: "foobar", - namespace: "default", - labels: { - foo: "bar", - }, - resourceVersion: "1", - uid: "123456798", - }, - spec: { - containers: [{ - name: "web", - image: "nginx", - ports: [{ - name: "web", - containerPort: 80, - protocol: "TCP", - }], - }], - }, - })), - ); - }); - - it("the call should resolve to a Pod", async () => { - expect(await updateRequest).toBeInstanceOf(Pod); - }); - }); - }); - }); - - describe("listing pods", () => { - let api: PodApi; - - beforeEach(() => { - api = di.inject(podApiInjectable); - }); - - describe("when listing pods with no descriptor", () => { - let listRequest: Promise; - - beforeEach(async () => { - listRequest = api.list(); - - await flushPromises(); - }); - - it("should request that the pods from all namespaces", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/pods", - { - headers: { - "content-type": "application/json", - }, - method: "get", - }, - ]); - }); - - describe("when the request resolves with empty data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/pods"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/pods", JSON.stringify({ - kind: "PodList", - apiVersion: "v1", - metadata: {}, - items: [], - })), - ); - }); - - it("the call should resolve to an empty list", async () => { - expect(await listRequest).toEqual([]); - }); - }); - }); - - describe("when listing pods with descriptor with namespace=''", () => { - let listRequest: Promise; - - beforeEach(async () => { - listRequest = api.list({ - namespace: "", - }); - - await flushPromises(); - }); - - it("should request that the pods from all namespaces", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/pods", - { - headers: { - "content-type": "application/json", - }, - method: "get", - }, - ]); - }); - - describe("when the request resolves with empty data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/pods"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/pods", JSON.stringify({ - kind: "PodList", - apiVersion: "v1", - metadata: {}, - items: [], - })), - ); - }); - - it("the call should resolve to an empty list", async () => { - expect(await listRequest).toEqual([]); - }); - }); - }); - - describe("when listing pods with descriptor with namespace='default'", () => { - let listRequest: Promise; - - beforeEach(async () => { - listRequest = api.list({ - namespace: "default", - }); - - await flushPromises(); - }); - - it("should request that the pods from just the default namespace", () => { - expect(fetchMock.mock.lastCall).toMatchObject([ - "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", - { - headers: { - "content-type": "application/json", - }, - method: "get", - }, - ]); - }); - - describe("when the request resolves with empty data", () => { - beforeEach(async () => { - await fetchMock.resolveSpecific( - ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods"], - createMockResponseFromString("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", JSON.stringify({ - kind: "PodList", - apiVersion: "v1", - metadata: {}, - items: [], - })), - ); - }); - - it("the call should resolve to an empty list", async () => { - expect(await listRequest).toEqual([]); - }); - }); - }); - }); }); diff --git a/packages/core/src/common/k8s-api/__tests__/kube-object.store.test.ts b/packages/core/src/common/k8s-api/__tests__/kube-object.store.test.ts index 62d5a83e55..608d3a2d5b 100644 --- a/packages/core/src/common/k8s-api/__tests__/kube-object.store.test.ts +++ b/packages/core/src/common/k8s-api/__tests__/kube-object.store.test.ts @@ -4,7 +4,7 @@ */ import { noop } from "@k8slens/utilities"; -import type { KubeApi } from "../kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import { KubeObject } from "@k8slens/kube-object"; import type { KubeObjectStoreLoadingParams } from "../kube-object.store"; import { KubeObjectStore } from "../kube-object.store"; diff --git a/packages/core/src/common/k8s-api/__tests__/stateful-set.api.test.ts b/packages/core/src/common/k8s-api/__tests__/stateful-set.api.test.ts index f99d866e75..aa601a0006 100644 --- a/packages/core/src/common/k8s-api/__tests__/stateful-set.api.test.ts +++ b/packages/core/src/common/k8s-api/__tests__/stateful-set.api.test.ts @@ -6,9 +6,8 @@ import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable"; import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting"; import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable"; -import type { StatefulSetApi } from "../endpoints"; import statefulSetApiInjectable from "../endpoints/stateful-set.api.injectable"; -import type { KubeJsonApi } from "../kube-json-api"; +import type { KubeJsonApi, StatefulSetApi } from "@k8slens/kube-api"; import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; import { flushPromises } from "@k8slens/test-utils"; diff --git a/packages/core/src/common/k8s-api/api-manager/api-manager.ts b/packages/core/src/common/k8s-api/api-manager/api-manager.ts index de8a9090ad..a42e29a5b5 100644 --- a/packages/core/src/common/k8s-api/api-manager/api-manager.ts +++ b/packages/core/src/common/k8s-api/api-manager/api-manager.ts @@ -7,9 +7,9 @@ import type { KubeObjectStore } from "../kube-object.store"; import type { IComputedValue } from "mobx"; import { autorun, action, observable } from "mobx"; -import type { KubeApi } from "../kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import type { KubeObject, ObjectReference } from "@k8slens/kube-object"; -import { parseKubeApi, createKubeApiURL } from "../kube-api-parse"; +import { parseKubeApi, createKubeApiURL } from "@k8slens/kube-api"; import { getOrInsertWith, iter } from "@k8slens/utilities"; import type { CreateCustomResourceStore } from "./create-custom-resource-store.injectable"; diff --git a/packages/core/src/common/k8s-api/api-manager/auto-registration-emitter.injectable.ts b/packages/core/src/common/k8s-api/api-manager/auto-registration-emitter.injectable.ts index 714e9d8952..47e53cd98c 100644 --- a/packages/core/src/common/k8s-api/api-manager/auto-registration-emitter.injectable.ts +++ b/packages/core/src/common/k8s-api/api-manager/auto-registration-emitter.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import EventEmitter from "events"; import type TypedEventEmitter from "typed-emitter"; -import type { KubeApi } from "../kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; export interface LegacyAutoRegistration { kubeApi: (api: KubeApi) => void; diff --git a/packages/core/src/common/k8s-api/api-manager/crd-api-token.ts b/packages/core/src/common/k8s-api/api-manager/crd-api-token.ts index d8f0c918c2..ea01fa18f6 100644 --- a/packages/core/src/common/k8s-api/api-manager/crd-api-token.ts +++ b/packages/core/src/common/k8s-api/api-manager/crd-api-token.ts @@ -4,7 +4,7 @@ */ import { getInjectionToken } from "@ogre-tools/injectable"; -import type { KubeApi } from "../kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; export const customResourceDefinitionApiInjectionToken = getInjectionToken({ id: "custom-resource-definition-api-token", diff --git a/packages/core/src/common/k8s-api/api-manager/create-custom-resource-store.injectable.ts b/packages/core/src/common/k8s-api/api-manager/create-custom-resource-store.injectable.ts index 747c966e10..52ff80fc4c 100644 --- a/packages/core/src/common/k8s-api/api-manager/create-custom-resource-store.injectable.ts +++ b/packages/core/src/common/k8s-api/api-manager/create-custom-resource-store.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import clusterFrameContextForNamespacedResourcesInjectable from "../../../renderer/cluster-frame-context/for-namespaced-resources.injectable"; import { loggerInjectionToken } from "@k8slens/logger"; -import type { KubeApi } from "../kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import type { KubeObject } from "@k8slens/kube-object"; import type { KubeObjectStoreDependencies } from "../kube-object.store"; import { CustomResourceStore } from "./resource.store"; diff --git a/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts b/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts index 6caca127f5..20770d8edf 100644 --- a/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts +++ b/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts @@ -7,7 +7,7 @@ import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-c import { ApiManager } from "./api-manager"; import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx"; import { kubeObjectStoreInjectionToken } from "./kube-object-store-token"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken } from "@k8slens/kube-api"; import { computed } from "mobx"; import { customResourceDefinitionApiInjectionToken } from "./crd-api-token"; import createCustomResourceStoreInjectable from "./create-custom-resource-store.injectable"; diff --git a/packages/core/src/common/k8s-api/api-manager/resource.store.ts b/packages/core/src/common/k8s-api/api-manager/resource.store.ts index c15d8970e3..aca1d38109 100644 --- a/packages/core/src/common/k8s-api/api-manager/resource.store.ts +++ b/packages/core/src/common/k8s-api/api-manager/resource.store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { KubeApi } from "../kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import type { KubeObjectStoreDependencies } from "../kube-object.store"; import { KubeObjectStore } from "../kube-object.store"; import type { KubeObject } from "@k8slens/kube-object"; diff --git a/packages/core/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts b/packages/core/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts index 98e2250e71..d237d90660 100644 --- a/packages/core/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts +++ b/packages/core/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts @@ -9,7 +9,7 @@ import isDevelopmentInjectable from "../vars/is-development.injectable"; import apiBaseInjectable from "./api-base.injectable"; import type { KubeApiConstructor } from "./create-kube-api-for-remote-cluster.injectable"; import createKubeJsonApiInjectable from "./create-kube-json-api.injectable"; -import { KubeApi } from "./kube-api"; +import { KubeApi } from "@k8slens/kube-api"; import type { KubeJsonApiDataFor, KubeObject, KubeObjectConstructor } from "@k8slens/kube-object"; export interface CreateKubeApiForLocalClusterConfig { diff --git a/packages/core/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts b/packages/core/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts index f76530b4eb..28377d4e88 100644 --- a/packages/core/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts +++ b/packages/core/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts @@ -9,8 +9,8 @@ import type { RequestInit } from "@k8slens/node-fetch"; import { loggerInjectionToken } from "@k8slens/logger"; import isDevelopmentInjectable from "../vars/is-development.injectable"; import createKubeJsonApiInjectable from "./create-kube-json-api.injectable"; -import type { KubeApiOptions } from "./kube-api"; -import { KubeApi } from "./kube-api"; +import type { KubeApiOptions } from "@k8slens/kube-api"; +import { KubeApi } from "@k8slens/kube-api"; import type { KubeJsonApiDataFor, KubeObject, KubeObjectConstructor } from "@k8slens/kube-object"; export interface CreateKubeApiForRemoteClusterConfig { diff --git a/packages/core/src/common/k8s-api/create-kube-api.injectable.ts b/packages/core/src/common/k8s-api/create-kube-api.injectable.ts index 0818a8902a..57fac06b97 100644 --- a/packages/core/src/common/k8s-api/create-kube-api.injectable.ts +++ b/packages/core/src/common/k8s-api/create-kube-api.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { loggerInjectionToken } from "@k8slens/logger"; -import type { DerivedKubeApiOptions, KubeApiDependencies } from "./kube-api"; +import type { DerivedKubeApiOptions, KubeApiDependencies } from "@k8slens/kube-api"; import maybeKubeApiInjectable from "./maybe-kube-api.injectable"; export interface CreateKubeApi { diff --git a/packages/core/src/common/k8s-api/create-kube-json-api-for-cluster.injectable.ts b/packages/core/src/common/k8s-api/create-kube-json-api-for-cluster.injectable.ts index 799b0bf963..f561cd016c 100644 --- a/packages/core/src/common/k8s-api/create-kube-json-api-for-cluster.injectable.ts +++ b/packages/core/src/common/k8s-api/create-kube-json-api-for-cluster.injectable.ts @@ -7,7 +7,7 @@ import { apiKubePrefix } from "../vars"; import isDebuggingInjectable from "../vars/is-debugging.injectable"; import { apiBaseHostHeaderInjectionToken, apiBaseServerAddressInjectionToken } from "./api-base-configs"; import createKubeJsonApiInjectable from "./create-kube-json-api.injectable"; -import type { KubeJsonApi } from "./kube-json-api"; +import type { KubeJsonApi } from "@k8slens/kube-api"; export type CreateKubeJsonApiForCluster = (clusterId: string) => KubeJsonApi; diff --git a/packages/core/src/common/k8s-api/create-kube-json-api.injectable.ts b/packages/core/src/common/k8s-api/create-kube-json-api.injectable.ts index f75096990f..235f381771 100644 --- a/packages/core/src/common/k8s-api/create-kube-json-api.injectable.ts +++ b/packages/core/src/common/k8s-api/create-kube-json-api.injectable.ts @@ -9,7 +9,7 @@ import lensProxyCertificateInjectable from "../certificate/lens-proxy-certificat import fetchInjectable from "../fetch/fetch.injectable"; import { loggerInjectionToken } from "@k8slens/logger"; import type { JsonApiConfig, JsonApiDependencies } from "@k8slens/json-api"; -import { KubeJsonApi } from "./kube-json-api"; +import { KubeJsonApi } from "@k8slens/kube-api"; export type CreateKubeJsonApi = (config: JsonApiConfig, reqInit?: RequestInit) => KubeJsonApi; diff --git a/packages/core/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts index a5034e9e4b..ba3dd62ab1 100644 --- a/packages/core/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ClusterRoleBindingApi } from "./cluster-role-binding.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ClusterRoleBindingApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts index 5e5dd516d4..7b309d33a5 100644 --- a/packages/core/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ClusterRoleApi } from "./cluster-role.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ClusterRoleApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/cluster.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/cluster.api.injectable.ts index 5747e4cf92..91733280f9 100644 --- a/packages/core/src/common/k8s-api/endpoints/cluster.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/cluster.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ClusterApi } from "./cluster.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ClusterApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/component-status.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/component-status.api.injectable.ts index b5ea9fb82d..dcc8bd708f 100644 --- a/packages/core/src/common/k8s-api/endpoints/component-status.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/component-status.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ComponentStatusApi } from "./component-status.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ComponentStatusApi } from "@k8slens/kube-api"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; import { loggerInjectionToken } from "@k8slens/logger"; diff --git a/packages/core/src/common/k8s-api/endpoints/config-map.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/config-map.api.injectable.ts index 4f719aaac1..fdd63a4433 100644 --- a/packages/core/src/common/k8s-api/endpoints/config-map.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/config-map.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ConfigMapApi } from "./config-map.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ConfigMapApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/cron-job.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/cron-job.api.injectable.ts index 50784c77e2..d9c26433b4 100644 --- a/packages/core/src/common/k8s-api/endpoints/cron-job.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/cron-job.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { CronJobApi } from "./cron-job.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, CronJobApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts index a2af7a9e53..464705bbfa 100644 --- a/packages/core/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { CustomResourceDefinitionApi } from "./custom-resource-definition.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, CustomResourceDefinitionApi } from "@k8slens/kube-api"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; import { loggerInjectionToken } from "@k8slens/logger"; diff --git a/packages/core/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts index 682ba6f7d5..929773154f 100644 --- a/packages/core/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { DaemonSetApi } from "./daemon-set.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, DaemonSetApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/deployment.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/deployment.api.injectable.ts index 6458c376ab..d95a45e255 100644 --- a/packages/core/src/common/k8s-api/endpoints/deployment.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/deployment.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { DeploymentApi } from "./deployment.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, DeploymentApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/endpoint.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/endpoint.api.injectable.ts index a03dc401b9..2a53b14090 100644 --- a/packages/core/src/common/k8s-api/endpoints/endpoint.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/endpoint.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { EndpointsApi } from "./endpoint.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, EndpointsApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/events.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/events.api.injectable.ts index dc34d7075e..9b56ab1d9c 100644 --- a/packages/core/src/common/k8s-api/endpoints/events.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/events.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { KubeEventApi } from "./events.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, KubeEventApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts index 3b7757781a..94c200b6de 100644 --- a/packages/core/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { HorizontalPodAutoscalerApi } from "./horizontal-pod-autoscaler.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, HorizontalPodAutoscalerApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/ingress-class.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/ingress-class.api.injectable.ts index 323becdf56..af186ee1ad 100644 --- a/packages/core/src/common/k8s-api/endpoints/ingress-class.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/ingress-class.api.injectable.ts @@ -3,8 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { IngressClassApi } from "./ingress-class.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, IngressClassApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/ingress.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/ingress.api.injectable.ts index 732d88476d..74d80be9cf 100644 --- a/packages/core/src/common/k8s-api/endpoints/ingress.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/ingress.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { IngressApi } from "./ingress.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, IngressApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/job.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/job.api.injectable.ts index d27d55cb3a..06acf62dd3 100644 --- a/packages/core/src/common/k8s-api/endpoints/job.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/job.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { JobApi } from "./job.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, JobApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/lease.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/lease.api.injectable.ts index c37834b3f7..47e423f542 100644 --- a/packages/core/src/common/k8s-api/endpoints/lease.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/lease.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { LeaseApi } from "./lease.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, LeaseApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/limit-range.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/limit-range.api.injectable.ts index 677f368cac..a13f3a0dc1 100644 --- a/packages/core/src/common/k8s-api/endpoints/limit-range.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/limit-range.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { LimitRangeApi } from "./limit-range.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, LimitRangeApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/mutating-webhook-configuration-api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/mutating-webhook-configuration-api.injectable.ts index 55f48e1d75..8a3edeb40e 100644 --- a/packages/core/src/common/k8s-api/endpoints/mutating-webhook-configuration-api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/mutating-webhook-configuration-api.injectable.ts @@ -5,10 +5,9 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, MutatingWebhookConfigurationApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; -import { MutatingWebhookConfigurationApi } from "./mutating-webhook-configuration.api"; const mutatingWebhookConfigurationApiInjectable = getInjectable({ id: "mutating-webhook-configuration", diff --git a/packages/core/src/common/k8s-api/endpoints/namespace.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/namespace.api.injectable.ts index 2238f9c4be..5a68bd12c4 100644 --- a/packages/core/src/common/k8s-api/endpoints/namespace.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/namespace.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { NamespaceApi } from "./namespace.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, NamespaceApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/network-policy.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/network-policy.api.injectable.ts index ac248358e3..4edb7b7ec5 100644 --- a/packages/core/src/common/k8s-api/endpoints/network-policy.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/network-policy.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { NetworkPolicyApi } from "./network-policy.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, NetworkPolicyApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/node.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/node.api.injectable.ts index 03d5f1e46f..3f6c09ccfd 100644 --- a/packages/core/src/common/k8s-api/endpoints/node.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/node.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { NodeApi } from "./node.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, NodeApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts index 759be7e09b..2b231fe229 100644 --- a/packages/core/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { PersistentVolumeClaimApi } from "./persistent-volume-claim.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, PersistentVolumeClaimApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts index a974964e5f..1990783a26 100644 --- a/packages/core/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { PersistentVolumeApi } from "./persistent-volume.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, PersistentVolumeApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts index 1298fde1a2..159b24d75b 100644 --- a/packages/core/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { PodDisruptionBudgetApi } from "./pod-disruption-budget.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, PodDisruptionBudgetApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts index b35512883e..4e407fef9a 100644 --- a/packages/core/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { PodMetricsApi } from "./pod-metrics.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, PodMetricsApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts index 40914af147..5fb9478f05 100644 --- a/packages/core/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { PodSecurityPolicyApi } from "./pod-security-policy.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, PodSecurityPolicyApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/pod.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/pod.api.injectable.ts index f79db5e31c..bb844c5039 100644 --- a/packages/core/src/common/k8s-api/endpoints/pod.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/pod.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { PodApi } from "./pod.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, PodApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/priority-class.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/priority-class.api.injectable.ts index d1e0fd0a32..5879895f22 100644 --- a/packages/core/src/common/k8s-api/endpoints/priority-class.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/priority-class.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { PriorityClassApi } from "./priority-class.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, PriorityClassApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/replica-set.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/replica-set.api.injectable.ts index f70c2ddce4..338bd5261c 100644 --- a/packages/core/src/common/k8s-api/endpoints/replica-set.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/replica-set.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ReplicaSetApi } from "./replica-set.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ReplicaSetApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/replication-controller.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/replication-controller.api.injectable.ts index aa01f6e39b..28f59cb8fa 100644 --- a/packages/core/src/common/k8s-api/endpoints/replication-controller.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/replication-controller.api.injectable.ts @@ -3,10 +3,9 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ReplicationControllerApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; -import { ReplicationControllerApi } from "./replication-controller.api"; const replicationControllerApiInjectable = getInjectable({ id: "replication-controller-api", diff --git a/packages/core/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts index 6dd8aefa6d..dcbb46a9ac 100644 --- a/packages/core/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ResourceQuotaApi } from "./resource-quota.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ResourceQuotaApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/role-binding.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/role-binding.api.injectable.ts index 5ecb1bf0e3..34536692fb 100644 --- a/packages/core/src/common/k8s-api/endpoints/role-binding.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/role-binding.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { RoleBindingApi } from "./role-binding.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, RoleBindingApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/role.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/role.api.injectable.ts index 8c5f16ed5d..a0f76f09be 100644 --- a/packages/core/src/common/k8s-api/endpoints/role.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/role.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { RoleApi } from "./role.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, RoleApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts index 5281ba8687..d784234118 100644 --- a/packages/core/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { RuntimeClassApi } from "./runtime-class.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, RuntimeClassApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/secret.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/secret.api.injectable.ts index a88aa9cf42..1115730180 100644 --- a/packages/core/src/common/k8s-api/endpoints/secret.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/secret.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { SecretApi } from "./secret.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, SecretApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts index 920579cd5d..ac28faa053 100644 --- a/packages/core/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { SelfSubjectRulesReviewApi } from "./self-subject-rules-reviews.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, SelfSubjectRulesReviewApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/service-account.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/service-account.api.injectable.ts index 936a685e29..8643806956 100644 --- a/packages/core/src/common/k8s-api/endpoints/service-account.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/service-account.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ServiceAccountApi } from "./service-account.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ServiceAccountApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/service.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/service.api.injectable.ts index a4901e6727..5afb0500e7 100644 --- a/packages/core/src/common/k8s-api/endpoints/service.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/service.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { ServiceApi } from "./service.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ServiceApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts index a31f46e07e..1d3b5851b5 100644 --- a/packages/core/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { StatefulSetApi } from "./stateful-set.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, StatefulSetApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/storage-class.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/storage-class.api.injectable.ts index 3cc3ae376e..284059abb3 100644 --- a/packages/core/src/common/k8s-api/endpoints/storage-class.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/storage-class.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { StorageClassApi } from "./storage-class.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, StorageClassApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/endpoints/validating-webhook-configuration-api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/validating-webhook-configuration-api.injectable.ts index d9d3ecf457..88e31b8194 100644 --- a/packages/core/src/common/k8s-api/endpoints/validating-webhook-configuration-api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/validating-webhook-configuration-api.injectable.ts @@ -5,10 +5,9 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, ValidatingWebhookConfigurationApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; -import { ValidatingWebhookConfigurationApi } from "./validating-webhook-configuration.api"; const validatingWebhookConfigurationApiInjectable = getInjectable({ id: "validating-webhook-configuration", diff --git a/packages/core/src/common/k8s-api/endpoints/vertical-pod-autoscaler.api.injectable.ts b/packages/core/src/common/k8s-api/endpoints/vertical-pod-autoscaler.api.injectable.ts index 09e6326469..13fc8e3b6e 100644 --- a/packages/core/src/common/k8s-api/endpoints/vertical-pod-autoscaler.api.injectable.ts +++ b/packages/core/src/common/k8s-api/endpoints/vertical-pod-autoscaler.api.injectable.ts @@ -5,8 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token"; -import { VerticalPodAutoscalerApi } from "./vertical-pod-autoscaler.api"; -import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; +import { kubeApiInjectionToken, VerticalPodAutoscalerApi } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; diff --git a/packages/core/src/common/k8s-api/kube-api/get-kube-api-from-path.injectable.ts b/packages/core/src/common/k8s-api/kube-api/get-kube-api-from-path.injectable.ts index 61ac7b1e96..601b9f749f 100644 --- a/packages/core/src/common/k8s-api/kube-api/get-kube-api-from-path.injectable.ts +++ b/packages/core/src/common/k8s-api/kube-api/get-kube-api-from-path.injectable.ts @@ -3,9 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { parseKubeApi } from "../kube-api-parse"; -import { kubeApiInjectionToken } from "./kube-api-injection-token"; -import type { KubeApi } from "../kube-api"; +import { kubeApiInjectionToken, parseKubeApi } from "@k8slens/kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; export type GetKubeApiFromPath = (apiPath: string) => KubeApi | undefined; diff --git a/packages/core/src/common/k8s-api/kube-object.store.ts b/packages/core/src/common/k8s-api/kube-object.store.ts index b1ba6b5597..78cf4f7fe2 100644 --- a/packages/core/src/common/k8s-api/kube-object.store.ts +++ b/packages/core/src/common/k8s-api/kube-object.store.ts @@ -8,10 +8,9 @@ import type { Disposer } from "@k8slens/utilities"; import { waitUntilDefined, includes, rejectPromiseBy, object } from "@k8slens/utilities"; import type { KubeJsonApiDataFor, KubeObject } from "@k8slens/kube-object"; import { KubeStatus } from "@k8slens/kube-object"; -import type { IKubeWatchEvent } from "./kube-watch-event"; +import type { IKubeWatchEvent, KubeApiQueryParams, KubeApi, KubeApiWatchCallback } from "@k8slens/kube-api"; import { ItemStore } from "../item.store"; -import type { KubeApiQueryParams, KubeApi, KubeApiWatchCallback } from "./kube-api"; -import { parseKubeApi } from "./kube-api-parse"; +import { parseKubeApi } from "@k8slens/kube-api"; import type { RequestInit } from "@k8slens/node-fetch"; import type { Patch } from "rfc6902"; import type { Logger } from "@k8slens/logger"; diff --git a/packages/core/src/common/k8s-api/maybe-kube-api.injectable.ts b/packages/core/src/common/k8s-api/maybe-kube-api.injectable.ts index 6717c00881..9265da0ce4 100644 --- a/packages/core/src/common/k8s-api/maybe-kube-api.injectable.ts +++ b/packages/core/src/common/k8s-api/maybe-kube-api.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { apiKubeInjectionToken } from "./api-kube"; +import { apiKubeInjectionToken } from "@k8slens/kube-api"; const maybeKubeApiInjectable = getInjectable({ id: "maybe-kube-api", diff --git a/packages/core/src/extensions/common-api/k8s-api.ts b/packages/core/src/extensions/common-api/k8s-api.ts index e9bed8de24..d53f240af5 100644 --- a/packages/core/src/extensions/common-api/k8s-api.ts +++ b/packages/core/src/extensions/common-api/k8s-api.ts @@ -17,16 +17,14 @@ import type { KubernetesCluster } from "./catalog"; import type { KubeApiDataFrom, KubeObjectStoreOptions } from "../../common/k8s-api/kube-object.store"; import { KubeObjectStore as InternalKubeObjectStore } from "../../common/k8s-api/kube-object.store"; import type { KubeJsonApiDataFor, KubeObject } from "@k8slens/kube-object"; -import type { DerivedKubeApiOptions, KubeApiDependencies, KubeApiOptions } from "../../common/k8s-api/kube-api"; -import { KubeApi as InternalKubeApi } from "../../common/k8s-api/kube-api"; +import type { DerivedKubeApiOptions, KubeApiDependencies, KubeApiOptions, KubeJsonApi as InternalKubeJsonApi } from "@k8slens/kube-api"; import clusterFrameContextForNamespacedResourcesInjectable from "../../renderer/cluster-frame-context/for-namespaced-resources.injectable"; import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context"; import { loggerInjectionToken } from "@k8slens/logger"; import maybeKubeApiInjectable from "../../common/k8s-api/maybe-kube-api.injectable"; -import { DeploymentApi as InternalDeploymentApi, IngressApi as InternalIngressApi, NodeApi, PersistentVolumeClaimApi, PodApi } from "../../common/k8s-api/endpoints"; +import { DeploymentApi as InternalDeploymentApi, IngressApi as InternalIngressApi, NodeApi, PersistentVolumeClaimApi, PodApi, KubeApi as InternalKubeApi } from "@k8slens/kube-api"; import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token"; import type { JsonApiConfig } from "@k8slens/json-api"; -import type { KubeJsonApi as InternalKubeJsonApi } from "../../common/k8s-api/kube-json-api"; import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-api.injectable"; import type { RequestInit } from "@k8slens/node-fetch"; import createKubeJsonApiForClusterInjectable from "../../common/k8s-api/create-kube-json-api-for-cluster.injectable"; diff --git a/packages/core/src/features/cluster/kube-object-details/extension-api/disable-kube-object-detail-items-when-cluster-is-not-relevant.test.tsx b/packages/core/src/features/cluster/kube-object-details/extension-api/disable-kube-object-detail-items-when-cluster-is-not-relevant.test.tsx index e97bd3320d..de1df7e5af 100644 --- a/packages/core/src/features/cluster/kube-object-details/extension-api/disable-kube-object-detail-items-when-cluster-is-not-relevant.test.tsx +++ b/packages/core/src/features/cluster/kube-object-details/extension-api/disable-kube-object-detail-items-when-cluster-is-not-relevant.test.tsx @@ -9,7 +9,7 @@ import React from "react"; import { KubeObject } from "@k8slens/kube-object"; import apiManagerInjectable from "../../../../common/k8s-api/api-manager/manager.injectable"; import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; -import type { KubeApi } from "../../../../common/k8s-api/kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import showDetailsInjectable from "../../../../renderer/components/kube-detail-params/show-details.injectable"; import type { FakeExtensionOptions } from "../../../../renderer/components/test-utils/get-extension-fake"; import { observable } from "mobx"; diff --git a/packages/core/src/features/cluster/kube-object-details/extension-api/reactively-hide-kube-object-detail-item.test.tsx b/packages/core/src/features/cluster/kube-object-details/extension-api/reactively-hide-kube-object-detail-item.test.tsx index de28061ce2..bdeac274f1 100644 --- a/packages/core/src/features/cluster/kube-object-details/extension-api/reactively-hide-kube-object-detail-item.test.tsx +++ b/packages/core/src/features/cluster/kube-object-details/extension-api/reactively-hide-kube-object-detail-item.test.tsx @@ -11,7 +11,7 @@ import React from "react"; import { KubeObject } from "@k8slens/kube-object"; import apiManagerInjectable from "../../../../common/k8s-api/api-manager/manager.injectable"; import type { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; -import type { KubeApi } from "../../../../common/k8s-api/kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import showDetailsInjectable from "../../../../renderer/components/kube-detail-params/show-details.injectable"; import assert from "assert"; import type { FakeExtensionOptions } from "../../../../renderer/components/test-utils/get-extension-fake"; diff --git a/packages/core/src/features/cluster/workloads/pods.test.tsx b/packages/core/src/features/cluster/workloads/pods.test.tsx index 948ab73c2e..74d9f7e2cc 100644 --- a/packages/core/src/features/cluster/workloads/pods.test.tsx +++ b/packages/core/src/features/cluster/workloads/pods.test.tsx @@ -9,7 +9,7 @@ import { type ApplicationBuilder, getApplicationBuilder } from "../../../rendere import podStoreInjectable from "../../../renderer/components/workloads-pods/store.injectable"; import type { PodMetrics, PodStatus } from "@k8slens/kube-object"; import { Pod } from "@k8slens/kube-object"; -import type { PodMetricsApi } from "../../../common/k8s-api/endpoints/pod-metrics.api"; +import type { PodMetricsApi } from "@k8slens/kube-api"; import podMetricsApiInjectable from "../../../common/k8s-api/endpoints/pod-metrics.api.injectable"; import type { RequestMetrics } from "../../../common/k8s-api/endpoints/metrics.api/request-metrics.injectable"; import requestMetricsInjectable from "../../../common/k8s-api/endpoints/metrics.api/request-metrics.injectable"; diff --git a/packages/core/src/features/telemetry/renderer/telemetry-decorator-for-show-details.injectable.ts b/packages/core/src/features/telemetry/renderer/telemetry-decorator-for-show-details.injectable.ts index 221bcd36fa..24b110538c 100644 --- a/packages/core/src/features/telemetry/renderer/telemetry-decorator-for-show-details.injectable.ts +++ b/packages/core/src/features/telemetry/renderer/telemetry-decorator-for-show-details.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable, createInstantiationTargetDecorator, instantiationDecoratorToken } from "@ogre-tools/injectable"; import { pick } from "lodash"; import { inspect } from "util"; -import { parseKubeApi } from "../../../common/k8s-api/kube-api-parse"; +import { parseKubeApi } from "@k8slens/kube-api"; import showDetailsInjectable from "../../../renderer/components/kube-detail-params/show-details.injectable"; import emitTelemetryInjectable from "./emit-telemetry.injectable"; diff --git a/packages/core/src/main/shell-session/node-shell-session/node-shell-session.ts b/packages/core/src/main/shell-session/node-shell-session/node-shell-session.ts index 7551e135b2..b564b33073 100644 --- a/packages/core/src/main/shell-session/node-shell-session/node-shell-session.ts +++ b/packages/core/src/main/shell-session/node-shell-session/node-shell-session.ts @@ -9,7 +9,7 @@ import type { KubeConfig } from "@kubernetes/client-node"; import type { ShellSessionArgs, ShellSessionDependencies } from "../shell-session"; import { ShellOpenError, ShellSession } from "../shell-session"; import { get, once } from "lodash"; -import { NodeApi } from "../../../common/k8s-api/endpoints"; +import { NodeApi } from "@k8slens/kube-api"; import { TerminalChannels } from "../../../common/terminal/channels"; import type { CreateKubeJsonApiForCluster } from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable"; import type { CreateKubeApi } from "../../../common/k8s-api/create-kube-api.injectable"; diff --git a/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-crd-api-creations.injectable.ts b/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-crd-api-creations.injectable.ts index f3e7e4a50b..df23d63e0f 100644 --- a/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-crd-api-creations.injectable.ts +++ b/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-crd-api-creations.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { reaction } from "mobx"; import { customResourceDefinitionApiInjectionToken } from "../../../common/k8s-api/api-manager/crd-api-token"; import type { CustomResourceDefinition } from "@k8slens/kube-object"; -import { KubeApi } from "../../../common/k8s-api/kube-api"; +import { KubeApi } from "@k8slens/kube-api"; import { KubeObject } from "@k8slens/kube-object"; import maybeKubeApiInjectable from "../../../common/k8s-api/maybe-kube-api.injectable"; import { loggerInjectionToken } from "@k8slens/logger"; diff --git a/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts b/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts index 78b1f90015..158c21509f 100644 --- a/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts +++ b/packages/core/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import autoRegistrationEmitterInjectable from "../../../common/k8s-api/api-manager/auto-registration-emitter.injectable"; import apiManagerInjectable from "../../../common/k8s-api/api-manager/manager.injectable"; -import type { KubeApi } from "../../../common/k8s-api/kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import { beforeClusterFrameStartsSecondInjectionToken } from "../tokens"; const setupAutoRegistrationInjectable = getInjectable({ diff --git a/packages/core/src/renderer/components/cluster/store.ts b/packages/core/src/renderer/components/cluster/store.ts index be9c296b40..f5b0fe7487 100644 --- a/packages/core/src/renderer/components/cluster/store.ts +++ b/packages/core/src/renderer/components/cluster/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { ClusterApi } from "../../../common/k8s-api/endpoints"; +import type { ClusterApi } from "@k8slens/kube-api"; import type { Cluster } from "@k8slens/kube-object"; export class ClusterStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-horizontal-pod-autoscalers/store.ts b/packages/core/src/renderer/components/config-horizontal-pod-autoscalers/store.ts index dca39d9384..7b735380ab 100644 --- a/packages/core/src/renderer/components/config-horizontal-pod-autoscalers/store.ts +++ b/packages/core/src/renderer/components/config-horizontal-pod-autoscalers/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { HorizontalPodAutoscalerApi } from "../../../common/k8s-api/endpoints/horizontal-pod-autoscaler.api"; +import type { HorizontalPodAutoscalerApi } from "@k8slens/kube-api"; import type { HorizontalPodAutoscaler } from "@k8slens/kube-object"; export class HorizontalPodAutoscalerStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-leases/store.ts b/packages/core/src/renderer/components/config-leases/store.ts index 86b956190f..ebb0fb26da 100644 --- a/packages/core/src/renderer/components/config-leases/store.ts +++ b/packages/core/src/renderer/components/config-leases/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { LeaseApi } from "../../../common/k8s-api/endpoints/lease.api"; +import type { LeaseApi } from "@k8slens/kube-api"; import type { Lease } from "@k8slens/kube-object"; export class LeaseStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-limit-ranges/store.ts b/packages/core/src/renderer/components/config-limit-ranges/store.ts index 80d96555f1..bec1f49120 100644 --- a/packages/core/src/renderer/components/config-limit-ranges/store.ts +++ b/packages/core/src/renderer/components/config-limit-ranges/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { LimitRangeApi } from "../../../common/k8s-api/endpoints/limit-range.api"; +import type { LimitRangeApi } from "@k8slens/kube-api"; import type { LimitRange } from "@k8slens/kube-object"; export class LimitRangeStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-maps/store.ts b/packages/core/src/renderer/components/config-maps/store.ts index 2774f3be4b..2913b09cea 100644 --- a/packages/core/src/renderer/components/config-maps/store.ts +++ b/packages/core/src/renderer/components/config-maps/store.ts @@ -5,7 +5,7 @@ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { ConfigMap, ConfigMapData } from "@k8slens/kube-object"; -import type { ConfigMapApi } from "../../../common/k8s-api/endpoints"; +import type { ConfigMapApi } from "@k8slens/kube-api"; export class ConfigMapStore extends KubeObjectStore { } diff --git a/packages/core/src/renderer/components/config-mutating-webhook-configurations/mutating-webhook-configuration-store.ts b/packages/core/src/renderer/components/config-mutating-webhook-configurations/mutating-webhook-configuration-store.ts index dbbdbccd55..4a8f5d58d4 100644 --- a/packages/core/src/renderer/components/config-mutating-webhook-configurations/mutating-webhook-configuration-store.ts +++ b/packages/core/src/renderer/components/config-mutating-webhook-configurations/mutating-webhook-configuration-store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { MutatingWebhookConfiguration } from "@k8slens/kube-object"; -import type { MutatingWebhookConfigurationApi } from "../../../common/k8s-api/endpoints"; +import type { MutatingWebhookConfigurationApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class MutatingWebhookConfigurationStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-pod-disruption-budgets/store.ts b/packages/core/src/renderer/components/config-pod-disruption-budgets/store.ts index cdb97187ac..31dba4d550 100644 --- a/packages/core/src/renderer/components/config-pod-disruption-budgets/store.ts +++ b/packages/core/src/renderer/components/config-pod-disruption-budgets/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { PodDisruptionBudgetApi } from "../../../common/k8s-api/endpoints/pod-disruption-budget.api"; +import type { PodDisruptionBudgetApi } from "@k8slens/kube-api"; import type { PodDisruptionBudget } from "@k8slens/kube-object"; export class PodDisruptionBudgetStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-priority-classes/store.ts b/packages/core/src/renderer/components/config-priority-classes/store.ts index 40d0c796d9..9812b799d5 100644 --- a/packages/core/src/renderer/components/config-priority-classes/store.ts +++ b/packages/core/src/renderer/components/config-priority-classes/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { PriorityClassApi } from "../../../common/k8s-api/endpoints/priority-class.api"; +import type { PriorityClassApi } from "@k8slens/kube-api"; import type { PriorityClass } from "@k8slens/kube-object"; export class PriorityClassStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-resource-quotas/add-dialog/view.tsx b/packages/core/src/renderer/components/config-resource-quotas/add-dialog/view.tsx index 067c6f08ff..91a2957ad0 100644 --- a/packages/core/src/renderer/components/config-resource-quotas/add-dialog/view.tsx +++ b/packages/core/src/renderer/components/config-resource-quotas/add-dialog/view.tsx @@ -15,7 +15,7 @@ import { Wizard, WizardStep } from "../../wizard"; import { Input } from "../../input"; import { systemName } from "../../input/input_validators"; import type { ResourceQuotaValues } from "@k8slens/kube-object"; -import type { ResourceQuotaApi } from "../../../../common/k8s-api/endpoints"; +import type { ResourceQuotaApi } from "@k8slens/kube-api"; import { Select } from "../../select"; import { Icon } from "../../icon"; import { Button } from "@k8slens/button"; diff --git a/packages/core/src/renderer/components/config-resource-quotas/store.ts b/packages/core/src/renderer/components/config-resource-quotas/store.ts index 0df729b9b9..a724191ffc 100644 --- a/packages/core/src/renderer/components/config-resource-quotas/store.ts +++ b/packages/core/src/renderer/components/config-resource-quotas/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { ResourceQuotaApi } from "../../../common/k8s-api/endpoints/resource-quota.api"; +import type { ResourceQuotaApi } from "@k8slens/kube-api"; import type { ResourceQuota } from "@k8slens/kube-object"; export class ResourceQuotaStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-runtime-classes/store.ts b/packages/core/src/renderer/components/config-runtime-classes/store.ts index 86156e24fe..ccba53a69d 100644 --- a/packages/core/src/renderer/components/config-runtime-classes/store.ts +++ b/packages/core/src/renderer/components/config-runtime-classes/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { RuntimeClassApi } from "../../../common/k8s-api/endpoints/runtime-class.api"; +import type { RuntimeClassApi } from "@k8slens/kube-api"; import type { RuntimeClass } from "@k8slens/kube-object"; export class RuntimeClassStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-secrets/add-dialog/view.tsx b/packages/core/src/renderer/components/config-secrets/add-dialog/view.tsx index 8acf8226a1..64fee00598 100644 --- a/packages/core/src/renderer/components/config-secrets/add-dialog/view.tsx +++ b/packages/core/src/renderer/components/config-secrets/add-dialog/view.tsx @@ -14,7 +14,7 @@ import { Dialog } from "../../dialog"; import { Wizard, WizardStep } from "../../wizard"; import { Input } from "../../input"; import { systemName } from "../../input/input_validators"; -import type { SecretApi } from "../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import { reverseSecretTypeMap, SecretType } from "@k8slens/kube-object"; import { SubTitle } from "../../layout/sub-title"; import { NamespaceSelect } from "../../namespaces/namespace-select"; diff --git a/packages/core/src/renderer/components/config-secrets/store.ts b/packages/core/src/renderer/components/config-secrets/store.ts index 0f9162be15..9e8c8cac3d 100644 --- a/packages/core/src/renderer/components/config-secrets/store.ts +++ b/packages/core/src/renderer/components/config-secrets/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { SecretApi } from "../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import type { Secret, SecretData } from "@k8slens/kube-object"; export class SecretStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-validating-webhook-configurations/validating-webhook-configuration-store.ts b/packages/core/src/renderer/components/config-validating-webhook-configurations/validating-webhook-configuration-store.ts index be34506072..c5b10dcb94 100644 --- a/packages/core/src/renderer/components/config-validating-webhook-configurations/validating-webhook-configuration-store.ts +++ b/packages/core/src/renderer/components/config-validating-webhook-configurations/validating-webhook-configuration-store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ValidatingWebhookConfiguration } from "@k8slens/kube-object"; -import type { ValidatingWebhookConfigurationApi } from "../../../common/k8s-api/endpoints"; +import type { ValidatingWebhookConfigurationApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class ValidatingWebhookConfigurationStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/config-vertical-pod-autoscalers/store.ts b/packages/core/src/renderer/components/config-vertical-pod-autoscalers/store.ts index bf475f5c0c..ba04320534 100644 --- a/packages/core/src/renderer/components/config-vertical-pod-autoscalers/store.ts +++ b/packages/core/src/renderer/components/config-vertical-pod-autoscalers/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { VerticalPodAutoscalerApi } from "../../../common/k8s-api/endpoints/vertical-pod-autoscaler.api"; +import type { VerticalPodAutoscalerApi } from "@k8slens/kube-api"; import type { VerticalPodAutoscaler } from "@k8slens/kube-object"; export class VerticalPodAutoscalerStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/custom-resources/definition.store.ts b/packages/core/src/renderer/components/custom-resources/definition.store.ts index a41ce573b6..0f8dbf5eb8 100644 --- a/packages/core/src/renderer/components/custom-resources/definition.store.ts +++ b/packages/core/src/renderer/components/custom-resources/definition.store.ts @@ -8,7 +8,7 @@ import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { CustomResourceDefinition, KubeObject } from "@k8slens/kube-object"; import autoBind from "auto-bind"; -import type { CustomResourceDefinitionApi } from "../../../common/k8s-api/endpoints"; +import type { CustomResourceDefinitionApi } from "@k8slens/kube-api"; export class CustomResourceDefinitionStore extends KubeObjectStore { constructor( diff --git a/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/edit-resource-model.injectable.tsx b/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/edit-resource-model.injectable.tsx index fb5d1cc052..1671247eb8 100644 --- a/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/edit-resource-model.injectable.tsx +++ b/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/edit-resource-model.injectable.tsx @@ -19,7 +19,7 @@ import type { ShowNotification } from "../../../notifications"; import showSuccessNotificationInjectable from "../../../notifications/show-success-notification.injectable"; import React from "react"; import showErrorNotificationInjectable from "../../../notifications/show-error-notification.injectable"; -import { createKubeApiURL, parseKubeApi } from "../../../../../common/k8s-api/kube-api-parse"; +import { createKubeApiURL, parseKubeApi } from "@k8slens/kube-api"; const editResourceModelInjectable = getInjectable({ id: "edit-resource-model", diff --git a/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable.ts b/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable.ts index 5a907712e5..4a45ecdbf6 100644 --- a/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable.ts +++ b/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-kube-resource.injectable.ts @@ -8,7 +8,7 @@ import { KubeObject } from "@k8slens/kube-object"; import type { AsyncResult } from "@k8slens/utilities"; import { getErrorMessage } from "../../../../../common/utils/get-error-message"; import type { Writable } from "type-fest"; -import { parseKubeApi } from "../../../../../common/k8s-api/kube-api-parse"; +import { parseKubeApi } from "@k8slens/kube-api"; import apiKubeGetInjectable from "../../../../k8s/api-kube-get.injectable"; export type RequestKubeResource = (selfLink: string) => AsyncResult; diff --git a/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-patch-kube-resource.injectable.ts b/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-patch-kube-resource.injectable.ts index 880d63e785..47fbf4e66a 100644 --- a/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-patch-kube-resource.injectable.ts +++ b/packages/core/src/renderer/components/dock/edit-resource/edit-resource-model/request-patch-kube-resource.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import type { AsyncResult } from "@k8slens/utilities"; import type { JsonPatch } from "../../../../../common/k8s-api/kube-object.store"; import { getErrorMessage } from "../../../../../common/utils/get-error-message"; -import { patchTypeHeaders } from "../../../../../common/k8s-api/kube-api"; +import { patchTypeHeaders } from "@k8slens/kube-api"; import apiKubePatchInjectable from "../../../../k8s/api-kube-patch.injectable"; export type RequestPatchKubeResource = (selfLink: string, patch: JsonPatch) => AsyncResult<{ name: string; kind: string }>; diff --git a/packages/core/src/renderer/components/dock/logs/call-for-logs.injectable.ts b/packages/core/src/renderer/components/dock/logs/call-for-logs.injectable.ts index e2563d732c..7823c363b9 100644 --- a/packages/core/src/renderer/components/dock/logs/call-for-logs.injectable.ts +++ b/packages/core/src/renderer/components/dock/logs/call-for-logs.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import type { PodLogsQuery } from "@k8slens/kube-object"; import podApiInjectable from "../../../../common/k8s-api/endpoints/pod.api.injectable"; -import type { ResourceDescriptor } from "../../../../common/k8s-api/kube-api"; +import type { ResourceDescriptor } from "@k8slens/kube-api"; export type CallForLogs = (params: ResourceDescriptor, query?: PodLogsQuery) => Promise; diff --git a/packages/core/src/renderer/components/dock/logs/download-all-logs.injectable.ts b/packages/core/src/renderer/components/dock/logs/download-all-logs.injectable.ts index 5c64a40c59..1b9f87f1cf 100644 --- a/packages/core/src/renderer/components/dock/logs/download-all-logs.injectable.ts +++ b/packages/core/src/renderer/components/dock/logs/download-all-logs.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { PodLogsQuery } from "@k8slens/kube-object"; -import type { ResourceDescriptor } from "../../../../common/k8s-api/kube-api"; +import type { ResourceDescriptor } from "@k8slens/kube-api"; import { loggerInjectionToken } from "@k8slens/logger"; import openSaveFileDialogInjectable from "../../../utils/save-file.injectable"; import showErrorNotificationInjectable from "../../notifications/show-error-notification.injectable"; diff --git a/packages/core/src/renderer/components/dock/logs/logs-view-model.ts b/packages/core/src/renderer/components/dock/logs/logs-view-model.ts index 7df6bb3745..d225cba102 100644 --- a/packages/core/src/renderer/components/dock/logs/logs-view-model.ts +++ b/packages/core/src/renderer/components/dock/logs/logs-view-model.ts @@ -13,7 +13,7 @@ import assert from "assert"; import type { GetPodById } from "../../workloads-pods/get-pod-by-id.injectable"; import type { GetPodsByOwnerId } from "../../workloads-pods/get-pods-by-owner-id.injectable"; import type { LoadLogs } from "./load-logs.injectable"; -import type { ResourceDescriptor } from "../../../../common/k8s-api/kube-api"; +import type { ResourceDescriptor } from "@k8slens/kube-api"; export interface LogTabViewModelDependencies { getLogs: (tabId: TabId) => string[]; diff --git a/packages/core/src/renderer/components/events/events.tsx b/packages/core/src/renderer/components/events/events.tsx index bf8b1e3215..e59bea2168 100644 --- a/packages/core/src/renderer/components/events/events.tsx +++ b/packages/core/src/renderer/components/events/events.tsx @@ -31,7 +31,7 @@ import eventStoreInjectable from "./store.injectable"; import type { GetDetailsUrl } from "../kube-detail-params/get-details-url.injectable"; import getDetailsUrlInjectable from "../kube-detail-params/get-details-url.injectable"; import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; -import type { KubeEventApi } from "../../../common/k8s-api/endpoints"; +import type { KubeEventApi } from "@k8slens/kube-api"; enum columnId { message = "message", diff --git a/packages/core/src/renderer/components/events/store.ts b/packages/core/src/renderer/components/events/store.ts index 8ec4301e4c..17f9b75a8d 100644 --- a/packages/core/src/renderer/components/events/store.ts +++ b/packages/core/src/renderer/components/events/store.ts @@ -11,7 +11,7 @@ import type { KubeEvent, KubeObject } from "@k8slens/kube-object"; import { Pod } from "@k8slens/kube-object"; import type { GetPodById } from "../workloads-pods/get-pod-by-id.injectable"; import autoBind from "auto-bind"; -import type { KubeEventApi } from "../../../common/k8s-api/endpoints"; +import type { KubeEventApi } from "@k8slens/kube-api"; export interface EventStoreDependencies extends KubeObjectStoreDependencies { getPodById: GetPodById; diff --git a/packages/core/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx b/packages/core/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx index fe8b87dc68..ec88303fd5 100644 --- a/packages/core/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx +++ b/packages/core/src/renderer/components/kube-object-list-layout/kube-object-list-layout.tsx @@ -21,7 +21,7 @@ import { TooltipPosition } from "@k8slens/tooltip"; import { withInjectables } from "@ogre-tools/injectable-react"; import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable"; import type { SubscribableStore, SubscribeStores } from "../../kube-watch-api/kube-watch-api"; -import type { KubeApi } from "../../../common/k8s-api/kube-api"; +import type { KubeApi } from "@k8slens/kube-api"; import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable"; import type { PageParam } from "../../navigation/page-param"; import type { ToggleKubeDetailsPane } from "../kube-detail-params/toggle-details.injectable"; diff --git a/packages/core/src/renderer/components/kube-object-meta/kube-object-meta.tsx b/packages/core/src/renderer/components/kube-object-meta/kube-object-meta.tsx index 16d6a91c0a..3fce56f936 100644 --- a/packages/core/src/renderer/components/kube-object-meta/kube-object-meta.tsx +++ b/packages/core/src/renderer/components/kube-object-meta/kube-object-meta.tsx @@ -19,7 +19,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import getDetailsUrlInjectable from "../kube-detail-params/get-details-url.injectable"; import apiManagerInjectable from "../../../common/k8s-api/api-manager/manager.injectable"; import { loggerInjectionToken } from "@k8slens/logger"; -import type { NamespaceApi } from "../../../common/k8s-api/endpoints"; +import type { NamespaceApi } from "@k8slens/kube-api"; import namespaceApiInjectable from "../../../common/k8s-api/endpoints/namespace.api.injectable"; export interface KubeObjectMetaProps { diff --git a/packages/core/src/renderer/components/namespaces/store.ts b/packages/core/src/renderer/components/namespaces/store.ts index 96fc6131c5..1bbb4446dd 100644 --- a/packages/core/src/renderer/components/namespaces/store.ts +++ b/packages/core/src/renderer/components/namespaces/store.ts @@ -9,7 +9,7 @@ import type { StorageLayer } from "../../utils/storage-helper"; import { noop, toggle } from "@k8slens/utilities"; import type { KubeObjectStoreDependencies, KubeObjectStoreLoadingParams } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { NamespaceApi } from "../../../common/k8s-api/endpoints/namespace.api"; +import type { NamespaceApi } from "@k8slens/kube-api"; import { Namespace } from "@k8slens/kube-object"; import autoBind from "auto-bind"; diff --git a/packages/core/src/renderer/components/network-endpoints/store.ts b/packages/core/src/renderer/components/network-endpoints/store.ts index bb7cf7d5a7..ee8a198305 100644 --- a/packages/core/src/renderer/components/network-endpoints/store.ts +++ b/packages/core/src/renderer/components/network-endpoints/store.ts @@ -4,7 +4,7 @@ */ import type { Endpoints, EndpointsData } from "@k8slens/kube-object"; -import type { EndpointsApi } from "../../../common/k8s-api/endpoints"; +import type { EndpointsApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class EndpointsStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/network-ingresses/ingress-class-store.ts b/packages/core/src/renderer/components/network-ingresses/ingress-class-store.ts index 4eda578720..7ff33610d7 100644 --- a/packages/core/src/renderer/components/network-ingresses/ingress-class-store.ts +++ b/packages/core/src/renderer/components/network-ingresses/ingress-class-store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { IngressClassApi } from "../../../common/k8s-api/endpoints/ingress-class.api"; +import type { IngressClassApi } from "@k8slens/kube-api"; import type { IngressClass } from "@k8slens/kube-object"; export class IngressClassStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/network-ingresses/ingress-store.ts b/packages/core/src/renderer/components/network-ingresses/ingress-store.ts index cfc551ed3a..cdd08a66ff 100644 --- a/packages/core/src/renderer/components/network-ingresses/ingress-store.ts +++ b/packages/core/src/renderer/components/network-ingresses/ingress-store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { Ingress } from "@k8slens/kube-object"; -import type { IngressApi } from "../../../common/k8s-api/endpoints"; +import type { IngressApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class IngressStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/network-policies/store.ts b/packages/core/src/renderer/components/network-policies/store.ts index 0546e87b47..4ecb0cb9db 100644 --- a/packages/core/src/renderer/components/network-policies/store.ts +++ b/packages/core/src/renderer/components/network-policies/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { NetworkPolicyApi } from "../../../common/k8s-api/endpoints/network-policy.api"; +import type { NetworkPolicyApi } from "@k8slens/kube-api"; import type { NetworkPolicy } from "@k8slens/kube-object"; export class NetworkPolicyStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/network-port-forwards/port-forward-details.tsx b/packages/core/src/renderer/components/network-port-forwards/port-forward-details.tsx index b36ce40ea1..923e2757f2 100644 --- a/packages/core/src/renderer/components/network-port-forwards/port-forward-details.tsx +++ b/packages/core/src/renderer/components/network-port-forwards/port-forward-details.tsx @@ -11,7 +11,7 @@ import type { PortForwardItem } from "../../port-forward"; import { portForwardAddress } from "../../port-forward"; import { Drawer, DrawerItem } from "../drawer"; import { cssNames } from "@k8slens/utilities"; -import type { PodApi, ServiceApi } from "../../../common/k8s-api/endpoints"; +import type { PodApi, ServiceApi } from "@k8slens/kube-api"; import { PortForwardMenu } from "./port-forward-menu"; import { withInjectables } from "@ogre-tools/injectable-react"; import serviceApiInjectable from "../../../common/k8s-api/endpoints/service.api.injectable"; diff --git a/packages/core/src/renderer/components/network-services/store.ts b/packages/core/src/renderer/components/network-services/store.ts index 162b79ff58..0e0920af13 100644 --- a/packages/core/src/renderer/components/network-services/store.ts +++ b/packages/core/src/renderer/components/network-services/store.ts @@ -4,7 +4,7 @@ */ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { ServiceApi } from "../../../common/k8s-api/endpoints/service.api"; +import type { ServiceApi } from "@k8slens/kube-api"; import type { Service } from "@k8slens/kube-object"; export class ServiceStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/nodes/store.ts b/packages/core/src/renderer/components/nodes/store.ts index d452447387..7d18278923 100644 --- a/packages/core/src/renderer/components/nodes/store.ts +++ b/packages/core/src/renderer/components/nodes/store.ts @@ -6,7 +6,7 @@ import type { Node } from "@k8slens/kube-object"; import autoBind from "auto-bind"; import { sum } from "lodash"; import { computed, makeObservable } from "mobx"; -import type { NodeApi } from "../../../common/k8s-api/endpoints"; +import type { NodeApi } from "@k8slens/kube-api"; import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; diff --git a/packages/core/src/renderer/components/pod-security-policies/store.ts b/packages/core/src/renderer/components/pod-security-policies/store.ts index f7f16f7708..55f5e2322e 100644 --- a/packages/core/src/renderer/components/pod-security-policies/store.ts +++ b/packages/core/src/renderer/components/pod-security-policies/store.ts @@ -4,7 +4,7 @@ */ import type { PodSecurityPolicy } from "@k8slens/kube-object"; -import type { PodSecurityPolicyApi } from "../../../common/k8s-api/endpoints"; +import type { PodSecurityPolicyApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class PodSecurityPolicyStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/storage-classes/store.ts b/packages/core/src/renderer/components/storage-classes/store.ts index 0d90772140..ef34bbaaa3 100644 --- a/packages/core/src/renderer/components/storage-classes/store.ts +++ b/packages/core/src/renderer/components/storage-classes/store.ts @@ -7,7 +7,7 @@ import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { StorageClass, StorageClassData } from "@k8slens/kube-object"; import type { GetPersistentVolumesByStorageClass } from "../storage-volumes/get-persistent-volumes-by-storage-class.injectable"; -import type { StorageClassApi } from "../../../common/k8s-api/endpoints"; +import type { StorageClassApi } from "@k8slens/kube-api"; export interface StorageClassStoreDependencies extends KubeObjectStoreDependencies { getPersistentVolumesByStorageClass: GetPersistentVolumesByStorageClass; diff --git a/packages/core/src/renderer/components/storage-volume-claims/store.ts b/packages/core/src/renderer/components/storage-volume-claims/store.ts index 4865e1f4ed..7a980391a2 100644 --- a/packages/core/src/renderer/components/storage-volume-claims/store.ts +++ b/packages/core/src/renderer/components/storage-volume-claims/store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { PersistentVolumeClaim } from "@k8slens/kube-object"; -import type { PersistentVolumeClaimApi } from "../../../common/k8s-api/endpoints"; +import type { PersistentVolumeClaimApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class PersistentVolumeClaimStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/storage-volume-claims/volume-claim-details.tsx b/packages/core/src/renderer/components/storage-volume-claims/volume-claim-details.tsx index b8c188bd59..f59beef672 100644 --- a/packages/core/src/renderer/components/storage-volume-claims/volume-claim-details.tsx +++ b/packages/core/src/renderer/components/storage-volume-claims/volume-claim-details.tsx @@ -11,7 +11,7 @@ import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; import { Link } from "react-router-dom"; import type { KubeObjectDetailsProps } from "../kube-object-details"; -import type { StorageClassApi } from "../../../common/k8s-api/endpoints"; +import type { StorageClassApi } from "@k8slens/kube-api"; import { PersistentVolumeClaim } from "@k8slens/kube-object"; import type { Logger } from "@k8slens/logger"; import { withInjectables } from "@ogre-tools/injectable-react"; diff --git a/packages/core/src/renderer/components/storage-volume-claims/volume-claims.tsx b/packages/core/src/renderer/components/storage-volume-claims/volume-claims.tsx index 9170226538..1ba6f68f5a 100644 --- a/packages/core/src/renderer/components/storage-volume-claims/volume-claims.tsx +++ b/packages/core/src/renderer/components/storage-volume-claims/volume-claims.tsx @@ -10,7 +10,7 @@ import { observer } from "mobx-react"; import { Link } from "react-router-dom"; import { KubeObjectListLayout } from "../kube-object-list-layout"; import { unitsToBytes, stopPropagation } from "@k8slens/utilities"; -import type { StorageClassApi } from "../../../common/k8s-api/endpoints"; +import type { StorageClassApi } from "@k8slens/kube-api"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { KubeObjectAge } from "../kube-object/age"; diff --git a/packages/core/src/renderer/components/storage-volumes/store.ts b/packages/core/src/renderer/components/storage-volumes/store.ts index 151f874d08..339c1591b2 100644 --- a/packages/core/src/renderer/components/storage-volumes/store.ts +++ b/packages/core/src/renderer/components/storage-volumes/store.ts @@ -5,7 +5,7 @@ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { PersistentVolume, StorageClass } from "@k8slens/kube-object"; -import type { PersistentVolumeApi } from "../../../common/k8s-api/endpoints"; +import type { PersistentVolumeApi } from "@k8slens/kube-api"; export class PersistentVolumeStore extends KubeObjectStore { getByStorageClass(storageClass: StorageClass): PersistentVolume[] { diff --git a/packages/core/src/renderer/components/storage-volumes/volume-details.tsx b/packages/core/src/renderer/components/storage-volumes/volume-details.tsx index ed2fe49d2a..e22385d4e8 100644 --- a/packages/core/src/renderer/components/storage-volumes/volume-details.tsx +++ b/packages/core/src/renderer/components/storage-volumes/volume-details.tsx @@ -11,7 +11,7 @@ import { Link } from "react-router-dom"; import { observer } from "mobx-react"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Badge } from "../badge"; -import type { PersistentVolumeClaimApi, StorageClassApi } from "../../../common/k8s-api/endpoints"; +import type { PersistentVolumeClaimApi, StorageClassApi } from "@k8slens/kube-api"; import { PersistentVolume } from "@k8slens/kube-object"; import type { KubeObjectDetailsProps } from "../kube-object-details"; import type { Logger } from "@k8slens/logger"; diff --git a/packages/core/src/renderer/components/storage-volumes/volumes.tsx b/packages/core/src/renderer/components/storage-volumes/volumes.tsx index c1cdd3d09a..5f51224884 100644 --- a/packages/core/src/renderer/components/storage-volumes/volumes.tsx +++ b/packages/core/src/renderer/components/storage-volumes/volumes.tsx @@ -10,7 +10,7 @@ import { observer } from "mobx-react"; import { Link } from "react-router-dom"; import { KubeObjectListLayout } from "../kube-object-list-layout"; import { stopPropagation } from "@k8slens/utilities"; -import type { PersistentVolumeClaimApi, StorageClassApi } from "../../../common/k8s-api/endpoints"; +import type { PersistentVolumeClaimApi, StorageClassApi } from "@k8slens/kube-api"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { KubeObjectAge } from "../kube-object/age"; diff --git a/packages/core/src/renderer/components/user-management/cluster-role-bindings/store.ts b/packages/core/src/renderer/components/user-management/cluster-role-bindings/store.ts index ecab995d2f..b67166269c 100644 --- a/packages/core/src/renderer/components/user-management/cluster-role-bindings/store.ts +++ b/packages/core/src/renderer/components/user-management/cluster-role-bindings/store.ts @@ -7,7 +7,7 @@ import type { Subject, ClusterRoleBinding, ClusterRoleBindingData } from "@k8sle import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import { HashSet } from "@k8slens/utilities"; import { hashSubject } from "../hashers"; -import type { ClusterRoleBindingApi } from "../../../../common/k8s-api/endpoints"; +import type { ClusterRoleBindingApi } from "@k8slens/kube-api"; export class ClusterRoleBindingStore extends KubeObjectStore { protected sortItems(items: ClusterRoleBinding[]) { diff --git a/packages/core/src/renderer/components/user-management/cluster-roles/store.ts b/packages/core/src/renderer/components/user-management/cluster-roles/store.ts index dd3ebb6600..407cf6dc81 100644 --- a/packages/core/src/renderer/components/user-management/cluster-roles/store.ts +++ b/packages/core/src/renderer/components/user-management/cluster-roles/store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { ClusterRole, ClusterRoleData } from "@k8slens/kube-object"; -import type { ClusterRoleApi } from "../../../../common/k8s-api/endpoints"; +import type { ClusterRoleApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; export class ClusterRoleStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/user-management/role-bindings/dialog/view.tsx b/packages/core/src/renderer/components/user-management/role-bindings/dialog/view.tsx index 06662e0812..92374feba7 100644 --- a/packages/core/src/renderer/components/user-management/role-bindings/dialog/view.tsx +++ b/packages/core/src/renderer/components/user-management/role-bindings/dialog/view.tsx @@ -38,7 +38,7 @@ import serviceAccountStoreInjectable from "../../service-accounts/store.injectab import roleApiInjectable from "../../../../../common/k8s-api/endpoints/role.api.injectable"; import type { ShowCheckedErrorNotification } from "../../../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../../../notifications/show-checked-error.injectable"; -import type { RoleApi } from "../../../../../common/k8s-api/endpoints"; +import type { RoleApi } from "@k8slens/kube-api"; export interface RoleBindingDialogProps extends Partial { } diff --git a/packages/core/src/renderer/components/user-management/role-bindings/store.ts b/packages/core/src/renderer/components/user-management/role-bindings/store.ts index 4fe76ca61b..b574995974 100644 --- a/packages/core/src/renderer/components/user-management/role-bindings/store.ts +++ b/packages/core/src/renderer/components/user-management/role-bindings/store.ts @@ -7,7 +7,7 @@ import type { RoleBinding, RoleBindingData, Subject } from "@k8slens/kube-object import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; import { HashSet } from "@k8slens/utilities"; import { hashSubject } from "../hashers"; -import type { RoleBindingApi } from "../../../../common/k8s-api/endpoints"; +import type { RoleBindingApi } from "@k8slens/kube-api"; export class RoleBindingStore extends KubeObjectStore { protected sortItems(items: RoleBinding[]) { diff --git a/packages/core/src/renderer/components/user-management/roles/store.ts b/packages/core/src/renderer/components/user-management/roles/store.ts index d352260bd1..c04eae6277 100644 --- a/packages/core/src/renderer/components/user-management/roles/store.ts +++ b/packages/core/src/renderer/components/user-management/roles/store.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { Role, RoleData } from "@k8slens/kube-object"; -import type { RoleApi } from "../../../../common/k8s-api/endpoints"; +import type { RoleApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; export class RoleStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/user-management/service-accounts/store.ts b/packages/core/src/renderer/components/user-management/service-accounts/store.ts index 1c16173e9a..0f80fad8a0 100644 --- a/packages/core/src/renderer/components/user-management/service-accounts/store.ts +++ b/packages/core/src/renderer/components/user-management/service-accounts/store.ts @@ -4,7 +4,7 @@ */ import type { ServiceAccount, ServiceAccountData } from "@k8slens/kube-object"; -import type { ServiceAccountApi } from "../../../../common/k8s-api/endpoints"; +import type { ServiceAccountApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../../common/k8s-api/kube-object.store"; export class ServiceAccountStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/workloads-cronjobs/cron-job-menu.tsx b/packages/core/src/renderer/components/workloads-cronjobs/cron-job-menu.tsx index e42ea97190..a298277cca 100644 --- a/packages/core/src/renderer/components/workloads-cronjobs/cron-job-menu.tsx +++ b/packages/core/src/renderer/components/workloads-cronjobs/cron-job-menu.tsx @@ -15,7 +15,7 @@ import openCronJobTriggerDialogInjectable from "./trigger-dialog/open.injectable import cronJobApiInjectable from "../../../common/k8s-api/endpoints/cron-job.api.injectable"; import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable"; -import type { CronJobApi } from "../../../common/k8s-api/endpoints"; +import type { CronJobApi } from "@k8slens/kube-api"; export interface CronJobMenuProps extends KubeObjectMenuProps {} diff --git a/packages/core/src/renderer/components/workloads-cronjobs/store.ts b/packages/core/src/renderer/components/workloads-cronjobs/store.ts index 4382aee9cb..aebb209d26 100644 --- a/packages/core/src/renderer/components/workloads-cronjobs/store.ts +++ b/packages/core/src/renderer/components/workloads-cronjobs/store.ts @@ -7,7 +7,7 @@ import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { CronJob } from "@k8slens/kube-object"; import type { GetJobsByOwner } from "../workloads-jobs/get-jobs-by-owner.injectable"; -import type { CronJobApi } from "../../../common/k8s-api/endpoints"; +import type { CronJobApi } from "@k8slens/kube-api"; interface Dependencies extends KubeObjectStoreDependencies { getJobsByOwner: GetJobsByOwner; diff --git a/packages/core/src/renderer/components/workloads-cronjobs/trigger-dialog/view.tsx b/packages/core/src/renderer/components/workloads-cronjobs/trigger-dialog/view.tsx index 8dfd8c93dc..798ef7e5c1 100644 --- a/packages/core/src/renderer/components/workloads-cronjobs/trigger-dialog/view.tsx +++ b/packages/core/src/renderer/components/workloads-cronjobs/trigger-dialog/view.tsx @@ -24,7 +24,7 @@ import cronJobTriggerDialogStateInjectable from "./state.injectable"; import type { ShowCheckedErrorNotification } from "../../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../../notifications/show-checked-error.injectable"; import showErrorNotificationInjectable from "../../notifications/show-error-notification.injectable"; -import type { JobApi } from "../../../../common/k8s-api/endpoints"; +import type { JobApi } from "@k8slens/kube-api"; export interface CronJobTriggerDialogProps extends Partial { } diff --git a/packages/core/src/renderer/components/workloads-daemonsets/daemonset-menu.tsx b/packages/core/src/renderer/components/workloads-daemonsets/daemonset-menu.tsx index 189c60894a..fbe03b1c58 100644 --- a/packages/core/src/renderer/components/workloads-daemonsets/daemonset-menu.tsx +++ b/packages/core/src/renderer/components/workloads-daemonsets/daemonset-menu.tsx @@ -13,7 +13,7 @@ import type { OpenConfirmDialog } from "../confirm-dialog/open.injectable"; import openConfirmDialogInjectable from "../confirm-dialog/open.injectable"; import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable"; -import type { DaemonSetApi } from "../../../common/k8s-api/endpoints"; +import type { DaemonSetApi } from "@k8slens/kube-api"; export interface DaemonSetMenuProps extends KubeObjectMenuProps {} diff --git a/packages/core/src/renderer/components/workloads-daemonsets/store.ts b/packages/core/src/renderer/components/workloads-daemonsets/store.ts index 05694e373b..0892209a6e 100644 --- a/packages/core/src/renderer/components/workloads-daemonsets/store.ts +++ b/packages/core/src/renderer/components/workloads-daemonsets/store.ts @@ -8,7 +8,7 @@ import type { DaemonSet, Pod } from "@k8slens/kube-object"; import { PodStatusPhase } from "@k8slens/kube-object"; import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { DaemonSetApi } from "../../../common/k8s-api/endpoints"; +import type { DaemonSetApi } from "@k8slens/kube-api"; export interface DaemonSetStoreDependencies extends KubeObjectStoreDependencies { readonly getPodsByOwnerId: GetPodsByOwnerId; diff --git a/packages/core/src/renderer/components/workloads-deployments/deployment-menu.tsx b/packages/core/src/renderer/components/workloads-deployments/deployment-menu.tsx index 52bf67cdeb..3110321b42 100644 --- a/packages/core/src/renderer/components/workloads-deployments/deployment-menu.tsx +++ b/packages/core/src/renderer/components/workloads-deployments/deployment-menu.tsx @@ -15,7 +15,7 @@ import type { OpenConfirmDialog } from "../confirm-dialog/open.injectable"; import openConfirmDialogInjectable from "../confirm-dialog/open.injectable"; import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable"; -import type { DeploymentApi } from "../../../common/k8s-api/endpoints"; +import type { DeploymentApi } from "@k8slens/kube-api"; export interface DeploymentMenuProps extends KubeObjectMenuProps {} diff --git a/packages/core/src/renderer/components/workloads-deployments/scale/dialog.test.tsx b/packages/core/src/renderer/components/workloads-deployments/scale/dialog.test.tsx index 272a0a38d8..de2c128835 100644 --- a/packages/core/src/renderer/components/workloads-deployments/scale/dialog.test.tsx +++ b/packages/core/src/renderer/components/workloads-deployments/scale/dialog.test.tsx @@ -6,7 +6,7 @@ import React from "react"; import { waitFor, fireEvent } from "@testing-library/react"; import { DeploymentScaleDialog } from "./dialog"; -import type { DeploymentApi } from "../../../../common/k8s-api/endpoints/deployment.api"; +import type { DeploymentApi } from "@k8slens/kube-api"; import { Deployment } from "@k8slens/kube-object"; import { getDiForUnitTesting } from "../../../getDiForUnitTesting"; import deploymentApiInjectable from "../../../../common/k8s-api/endpoints/deployment.api.injectable"; diff --git a/packages/core/src/renderer/components/workloads-deployments/scale/dialog.tsx b/packages/core/src/renderer/components/workloads-deployments/scale/dialog.tsx index 233cd5d22d..8a43aeb4c7 100644 --- a/packages/core/src/renderer/components/workloads-deployments/scale/dialog.tsx +++ b/packages/core/src/renderer/components/workloads-deployments/scale/dialog.tsx @@ -21,7 +21,7 @@ import deploymentApiInjectable from "../../../../common/k8s-api/endpoints/deploy import deploymentScaleDialogStateInjectable from "./dialog-state.injectable"; import type { ShowCheckedErrorNotification } from "../../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../../notifications/show-checked-error.injectable"; -import type { DeploymentApi } from "../../../../common/k8s-api/endpoints"; +import type { DeploymentApi } from "@k8slens/kube-api"; export interface DeploymentScaleDialogProps extends Partial { } diff --git a/packages/core/src/renderer/components/workloads-deployments/store.ts b/packages/core/src/renderer/components/workloads-deployments/store.ts index 5cc4141ac8..25128aa6bd 100644 --- a/packages/core/src/renderer/components/workloads-deployments/store.ts +++ b/packages/core/src/renderer/components/workloads-deployments/store.ts @@ -8,7 +8,7 @@ import type { Deployment } from "@k8slens/kube-object"; import { PodStatusPhase } from "@k8slens/kube-object"; import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { DeploymentApi } from "../../../common/k8s-api/endpoints"; +import type { DeploymentApi } from "@k8slens/kube-api"; // This needs to be disables because of https://github.com/microsoft/TypeScript/issues/15300 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions diff --git a/packages/core/src/renderer/components/workloads-jobs/store.ts b/packages/core/src/renderer/components/workloads-jobs/store.ts index 118c097e93..e1656c2a06 100644 --- a/packages/core/src/renderer/components/workloads-jobs/store.ts +++ b/packages/core/src/renderer/components/workloads-jobs/store.ts @@ -5,7 +5,7 @@ import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { JobApi } from "../../../common/k8s-api/endpoints/job.api"; +import type { JobApi } from "@k8slens/kube-api"; import type { CronJob, Job, Pod } from "@k8slens/kube-object"; import { PodStatusPhase } from "@k8slens/kube-object"; import type { GetPodsByOwnerId } from "../workloads-pods/get-pods-by-owner-id.injectable"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variant-helpers.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variant-helpers.tsx index b1ffc9cff5..f25f527b92 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variant-helpers.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variant-helpers.tsx @@ -6,7 +6,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; import { Link } from "react-router-dom"; import type { PodVolumeVariants, Pod, SecretReference, LocalObjectReference } from "@k8slens/kube-object"; -import type { KubeApiQueryParams, ResourceDescriptor } from "../../../../../common/k8s-api/kube-api"; +import type { KubeApiQueryParams, ResourceDescriptor } from "@k8slens/kube-api"; import { DrawerItem } from "../../../drawer"; import type { GetDetailsUrl } from "../../../kube-detail-params/get-details-url.injectable"; import getDetailsUrlInjectable from "../../../kube-detail-params/get-details-url.injectable"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/ceph-fs.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/ceph-fs.tsx index 64b68436a3..466be4a49b 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/ceph-fs.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/ceph-fs.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { SecretApi } from "../../../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import secretApiInjectable from "../../../../../../common/k8s-api/endpoints/secret.api.injectable"; import { DrawerItem } from "../../../../drawer"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/config-map.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/config-map.tsx index e59fed5633..d2c9321728 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/config-map.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/config-map.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { ConfigMapApi } from "../../../../../../common/k8s-api/endpoints"; +import type { ConfigMapApi } from "@k8slens/kube-api"; import configMapApiInjectable from "../../../../../../common/k8s-api/endpoints/config-map.api.injectable"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; import { LocalRef } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/container-storage-interface.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/container-storage-interface.tsx index 78576a8ed5..2c3f2b4bfb 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/container-storage-interface.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/container-storage-interface.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { SecretApi } from "../../../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import secretApiInjectable from "../../../../../../common/k8s-api/endpoints/secret.api.injectable"; import { DrawerItem } from "../../../../drawer"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/flex-volume.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/flex-volume.tsx index 130edfaaa6..33e2ffaee4 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/flex-volume.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/flex-volume.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { SecretApi } from "../../../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import secretApiInjectable from "../../../../../../common/k8s-api/endpoints/secret.api.injectable"; import { DrawerItem } from "../../../../drawer"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/persistent-volume-claim.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/persistent-volume-claim.tsx index 9893a65931..3892e57ed9 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/persistent-volume-claim.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/persistent-volume-claim.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { PersistentVolumeClaimApi } from "../../../../../../common/k8s-api/endpoints"; +import type { PersistentVolumeClaimApi } from "@k8slens/kube-api"; import persistentVolumeClaimApiInjectable from "../../../../../../common/k8s-api/endpoints/persistent-volume-claim.api.injectable"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; import { LocalRef } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/rados-block-device.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/rados-block-device.tsx index eac32050d7..19fb06e090 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/rados-block-device.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/rados-block-device.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { SecretApi } from "../../../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import secretApiInjectable from "../../../../../../common/k8s-api/endpoints/secret.api.injectable"; import { DrawerItem } from "../../../../drawer"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/scale-io.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/scale-io.tsx index 717be48fe5..8668f3b895 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/scale-io.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/scale-io.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { SecretApi } from "../../../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import secretApiInjectable from "../../../../../../common/k8s-api/endpoints/secret.api.injectable"; import { DrawerItem } from "../../../../drawer"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/secret.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/secret.tsx index 5ad1ee542c..24150e04be 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/secret.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/secret.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { SecretApi } from "../../../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import secretApiInjectable from "../../../../../../common/k8s-api/endpoints/secret.api.injectable"; import { DrawerItem } from "../../../../drawer"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/storage-os.tsx b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/storage-os.tsx index a69ec5918b..bdf009db25 100644 --- a/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/storage-os.tsx +++ b/packages/core/src/renderer/components/workloads-pods/details/volumes/variants/storage-os.tsx @@ -5,7 +5,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { SecretApi } from "../../../../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; import secretApiInjectable from "../../../../../../common/k8s-api/endpoints/secret.api.injectable"; import { DrawerItem } from "../../../../drawer"; import type { PodVolumeVariantSpecificProps } from "../variant-helpers"; diff --git a/packages/core/src/renderer/components/workloads-pods/pod-details-secrets.tsx b/packages/core/src/renderer/components/workloads-pods/pod-details-secrets.tsx index 00f9cc66d4..a266b77e00 100644 --- a/packages/core/src/renderer/components/workloads-pods/pod-details-secrets.tsx +++ b/packages/core/src/renderer/components/workloads-pods/pod-details-secrets.tsx @@ -14,7 +14,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import secretApiInjectable from "../../../common/k8s-api/endpoints/secret.api.injectable"; import type { GetDetailsUrl } from "../kube-detail-params/get-details-url.injectable"; import getDetailsUrlInjectable from "../kube-detail-params/get-details-url.injectable"; -import type { SecretApi } from "../../../common/k8s-api/endpoints"; +import type { SecretApi } from "@k8slens/kube-api"; export interface PodDetailsSecretsProps { pod: Pod; diff --git a/packages/core/src/renderer/components/workloads-pods/pod-details.tsx b/packages/core/src/renderer/components/workloads-pods/pod-details.tsx index a6c0f3ee2b..21a35048c3 100644 --- a/packages/core/src/renderer/components/workloads-pods/pod-details.tsx +++ b/packages/core/src/renderer/components/workloads-pods/pod-details.tsx @@ -10,7 +10,7 @@ import kebabCase from "lodash/kebabCase"; import { observer } from "mobx-react"; import { Link } from "react-router-dom"; import { Pod } from "@k8slens/kube-object"; -import type { NodeApi, PriorityClassApi, RuntimeClassApi, ServiceAccountApi } from "../../../common/k8s-api/endpoints"; +import type { NodeApi, PriorityClassApi, RuntimeClassApi, ServiceAccountApi } from "@k8slens/kube-api"; import { DrawerItem } from "../drawer"; import { Badge } from "../badge"; import { cssNames, stopPropagation } from "@k8slens/utilities"; diff --git a/packages/core/src/renderer/components/workloads-pods/store.ts b/packages/core/src/renderer/components/workloads-pods/store.ts index e7d1978fef..1c8ab8f57d 100644 --- a/packages/core/src/renderer/components/workloads-pods/store.ts +++ b/packages/core/src/renderer/components/workloads-pods/store.ts @@ -9,7 +9,7 @@ import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import { cpuUnitsToNumber, unitsToBytes } from "@k8slens/utilities"; import type { Pod, PodMetrics, KubeObject, NamespaceScopedMetadata } from "@k8slens/kube-object"; -import type { PodApi, PodMetricsApi } from "../../../common/k8s-api/endpoints"; +import type { PodApi, PodMetricsApi } from "@k8slens/kube-api"; export interface PodStoreDependencies extends KubeObjectStoreDependencies { readonly podMetricsApi: PodMetricsApi; diff --git a/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.test.tsx b/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.test.tsx index 7378332ada..2a9c55a93e 100755 --- a/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.test.tsx +++ b/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.test.tsx @@ -5,7 +5,7 @@ import { ReplicaSetScaleDialog } from "./dialog"; import { waitFor, fireEvent } from "@testing-library/react"; import React from "react"; -import type { ReplicaSetApi } from "../../../../common/k8s-api/endpoints/replica-set.api"; +import type { ReplicaSetApi } from "@k8slens/kube-api"; import { ReplicaSet } from "@k8slens/kube-object"; import type { OpenReplicaSetScaleDialog } from "./open.injectable"; import replicaSetApiInjectable from "../../../../common/k8s-api/endpoints/replica-set.api.injectable"; diff --git a/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.tsx b/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.tsx index 37078bbb00..1d5f7f0495 100644 --- a/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.tsx +++ b/packages/core/src/renderer/components/workloads-replicasets/scale-dialog/dialog.tsx @@ -21,7 +21,7 @@ import replicaSetApiInjectable from "../../../../common/k8s-api/endpoints/replic import replicaSetScaleDialogStateInjectable from "./state.injectable"; import type { ShowCheckedErrorNotification } from "../../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../../notifications/show-checked-error.injectable"; -import type { ReplicaSetApi } from "../../../../common/k8s-api/endpoints"; +import type { ReplicaSetApi } from "@k8slens/kube-api"; export interface ReplicaSetScaleDialogProps extends Partial { } diff --git a/packages/core/src/renderer/components/workloads-replicasets/store.ts b/packages/core/src/renderer/components/workloads-replicasets/store.ts index 2e7faac5ed..4cd222dc72 100644 --- a/packages/core/src/renderer/components/workloads-replicasets/store.ts +++ b/packages/core/src/renderer/components/workloads-replicasets/store.ts @@ -8,7 +8,7 @@ import { PodStatusPhase } from "@k8slens/kube-object"; import type { Deployment, ReplicaSet } from "@k8slens/kube-object"; import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { ReplicaSetApi } from "../../../common/k8s-api/endpoints"; +import type { ReplicaSetApi } from "@k8slens/kube-api"; export interface ReplicaSetStoreDependencies extends KubeObjectStoreDependencies { getPodsByOwnerId: GetPodsByOwnerId; diff --git a/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-details.tsx b/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-details.tsx index fde9f1647e..84324e2264 100644 --- a/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-details.tsx +++ b/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-details.tsx @@ -16,7 +16,7 @@ import replicationControllerApiInjectable from "../../../common/k8s-api/endpoint import showErrorNotificationInjectable from "../notifications/show-error-notification.injectable"; import type { ShowNotification } from "../notifications"; import { Slider } from "../slider"; -import type { ReplicationControllerApi } from "../../../common/k8s-api/endpoints"; +import type { ReplicationControllerApi } from "@k8slens/kube-api"; export interface ReplicationControllerDetailsProps extends KubeObjectDetailsProps { } diff --git a/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-store.ts b/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-store.ts index 304d1b5d70..0ad1eb65d0 100644 --- a/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-store.ts +++ b/packages/core/src/renderer/components/workloads-replication-controllers/replication-controller-store.ts @@ -4,7 +4,7 @@ */ import type { ReplicationController } from "@k8slens/kube-object"; -import type { ReplicationControllerApi } from "../../../common/k8s-api/endpoints"; +import type { ReplicationControllerApi } from "@k8slens/kube-api"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; export class ReplicationControllerStore extends KubeObjectStore { diff --git a/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.test.tsx b/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.test.tsx index 68915b990a..b965dc01fd 100755 --- a/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.test.tsx +++ b/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.test.tsx @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { StatefulSetApi } from "../../../../common/k8s-api/endpoints"; +import type { StatefulSetApi } from "@k8slens/kube-api"; import { StatefulSet } from "@k8slens/kube-object"; import { StatefulSetScaleDialog } from "./dialog"; import { waitFor, fireEvent } from "@testing-library/react"; diff --git a/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.tsx b/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.tsx index 047a7bb148..b357319518 100644 --- a/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.tsx +++ b/packages/core/src/renderer/components/workloads-statefulsets/scale/dialog.tsx @@ -21,7 +21,7 @@ import statefulSetApiInjectable from "../../../../common/k8s-api/endpoints/state import statefulSetDialogStateInjectable from "./dialog-state.injectable"; import type { ShowCheckedErrorNotification } from "../../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../../notifications/show-checked-error.injectable"; -import type { StatefulSetApi } from "../../../../common/k8s-api/endpoints"; +import type { StatefulSetApi } from "@k8slens/kube-api"; export interface StatefulSetScaleDialogProps extends Partial { } diff --git a/packages/core/src/renderer/components/workloads-statefulsets/statefulset-menu.tsx b/packages/core/src/renderer/components/workloads-statefulsets/statefulset-menu.tsx index 6d7731cc5c..e0f78610d2 100644 --- a/packages/core/src/renderer/components/workloads-statefulsets/statefulset-menu.tsx +++ b/packages/core/src/renderer/components/workloads-statefulsets/statefulset-menu.tsx @@ -13,7 +13,7 @@ import type { OpenConfirmDialog } from "../confirm-dialog/open.injectable"; import openConfirmDialogInjectable from "../confirm-dialog/open.injectable"; import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable"; -import type { StatefulSetApi } from "../../../common/k8s-api/endpoints"; +import type { StatefulSetApi } from "@k8slens/kube-api"; export interface StatefulSetMenuProps extends KubeObjectMenuProps {} diff --git a/packages/core/src/renderer/components/workloads-statefulsets/store.ts b/packages/core/src/renderer/components/workloads-statefulsets/store.ts index 6ef21a3544..5469685e05 100644 --- a/packages/core/src/renderer/components/workloads-statefulsets/store.ts +++ b/packages/core/src/renderer/components/workloads-statefulsets/store.ts @@ -8,7 +8,7 @@ import type { StatefulSet } from "@k8slens/kube-object"; import { PodStatusPhase } from "@k8slens/kube-object"; import type { KubeObjectStoreDependencies, KubeObjectStoreOptions } from "../../../common/k8s-api/kube-object.store"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; -import type { StatefulSetApi } from "../../../common/k8s-api/endpoints"; +import type { StatefulSetApi } from "@k8slens/kube-api"; interface Dependencies extends KubeObjectStoreDependencies { getPodsByOwnerId: GetPodsByOwnerId; diff --git a/packages/core/src/renderer/k8s/api-kube-get.injectable.ts b/packages/core/src/renderer/k8s/api-kube-get.injectable.ts index 7adc182a0f..70deca56a5 100644 --- a/packages/core/src/renderer/k8s/api-kube-get.injectable.ts +++ b/packages/core/src/renderer/k8s/api-kube-get.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { KubeJsonApi } from "../../common/k8s-api/kube-json-api"; +import type { KubeJsonApi } from "@k8slens/kube-api"; import apiKubeInjectable from "./api-kube.injectable"; export type ApiKubeGet = KubeJsonApi["get"]; diff --git a/packages/core/src/renderer/k8s/api-kube-patch.injectable.ts b/packages/core/src/renderer/k8s/api-kube-patch.injectable.ts index 3f649b10d8..e06a100e08 100644 --- a/packages/core/src/renderer/k8s/api-kube-patch.injectable.ts +++ b/packages/core/src/renderer/k8s/api-kube-patch.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { KubeJsonApi } from "../../common/k8s-api/kube-json-api"; +import type { KubeJsonApi } from "@k8slens/kube-api"; import apiKubeInjectable from "./api-kube.injectable"; export type ApiKubePatch = KubeJsonApi["patch"]; diff --git a/packages/core/src/renderer/k8s/api-kube.injectable.ts b/packages/core/src/renderer/k8s/api-kube.injectable.ts index 9e6bd8c7f8..f0dd8287df 100644 --- a/packages/core/src/renderer/k8s/api-kube.injectable.ts +++ b/packages/core/src/renderer/k8s/api-kube.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; import { apiKubePrefix } from "../../common/vars"; -import { apiKubeInjectionToken } from "../../common/k8s-api/api-kube"; +import { apiKubeInjectionToken } from "@k8slens/kube-api"; import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token"; import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-api.injectable"; import isDevelopmentInjectable from "../../common/vars/is-development.injectable"; diff --git a/packages/utility-features/kube-api/.eslintrc.js b/packages/utility-features/kube-api/.eslintrc.js new file mode 100644 index 0000000000..19a14e85a4 --- /dev/null +++ b/packages/utility-features/kube-api/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + extends: "@k8slens/eslint-config/eslint", + parserOptions: { + project: "./tsconfig.json", + }, +}; \ No newline at end of file diff --git a/packages/utility-features/kube-api/.prettierrc b/packages/utility-features/kube-api/.prettierrc new file mode 100644 index 0000000000..edd47b479e --- /dev/null +++ b/packages/utility-features/kube-api/.prettierrc @@ -0,0 +1 @@ +"@k8slens/eslint-config/prettier" diff --git a/packages/utility-features/kube-api/.swcrc b/packages/utility-features/kube-api/.swcrc new file mode 100644 index 0000000000..aaf7dd113a --- /dev/null +++ b/packages/utility-features/kube-api/.swcrc @@ -0,0 +1,18 @@ +{ + "module": { + "type": "commonjs" + }, + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": true, + "decorators": true, + "dynamicImport": false + }, + "transform": { + "legacyDecorator": true, + "decoratorMetadata": true + }, + "target": "es2019" + } +} \ No newline at end of file diff --git a/packages/utility-features/kube-api/index.ts b/packages/utility-features/kube-api/index.ts new file mode 100644 index 0000000000..49d7be28d8 --- /dev/null +++ b/packages/utility-features/kube-api/index.ts @@ -0,0 +1,7 @@ +export * from "./src/kube-api-injection-token"; +export * from "./src/api-kube"; +export * from "./src/kube-api"; +export * from "./src/kube-api-parse"; +export * from "./src/kube-json-api"; +export * from "./src/kube-watch-event"; +export * from "./src/endpoints"; diff --git a/packages/utility-features/kube-api/jest.config.js b/packages/utility-features/kube-api/jest.config.js new file mode 100644 index 0000000000..c6074967eb --- /dev/null +++ b/packages/utility-features/kube-api/jest.config.js @@ -0,0 +1 @@ +module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForNode; diff --git a/packages/utility-features/kube-api/package.json b/packages/utility-features/kube-api/package.json new file mode 100644 index 0000000000..6ba5c987bc --- /dev/null +++ b/packages/utility-features/kube-api/package.json @@ -0,0 +1,54 @@ +{ + "name": "@k8slens/kube-api", + "private": false, + "version": "1.0.0-alpha.1", + "description": "Kube api", + "type": "commonjs", + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, + "files": [ + "dist" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/lensapp/lens.git" + }, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "author": { + "name": "OpenLens Authors", + "email": "info@k8slens.dev" + }, + "license": "MIT", + "homepage": "https://github.com/lensapp/lens", + "scripts": { + "build": "webpack", + "clean": "rimraf dist/", + "dev": "webpack --mode=development --watch", + "test": "jest --coverage --runInBand", + "lint": "lens-lint", + "lint:fix": "lens-lint --fix" + }, + "dependencies": { + "@k8slens/node-fetch": "^6.5.0-alpha.3" + }, + "peerDependencies": { + "@k8slens/json-api": "^1.0.0-alpha.1", + "@k8slens/kube-object": "^1.0.0-alpha.1", + "@k8slens/logger": "^1.0.0-alpha.5", + "@k8slens/utilities": "^1.0.0-alpha.1", + "@ogre-tools/injectable": "^15.8.1", + "byline": "^5.0.0", + "lodash": "^4.17.15", + "mobx": "^6.8.0", + "moment": "^2.29.4", + "rfc6902": "^5.0.1" + }, + "devDependencies": { + "@k8slens/eslint-config": "^6.5.0-alpha.2", + "@k8slens/jest": "^6.5.0-alpha.4", + "@k8slens/typescript": "^6.5.0-alpha.2" + } +} diff --git a/packages/core/src/common/k8s-api/api-kube.ts b/packages/utility-features/kube-api/src/api-kube.ts similarity index 100% rename from packages/core/src/common/k8s-api/api-kube.ts rename to packages/utility-features/kube-api/src/api-kube.ts diff --git a/packages/core/src/common/k8s-api/endpoints/cluster-role-binding.api.ts b/packages/utility-features/kube-api/src/endpoints/cluster-role-binding.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/cluster-role-binding.api.ts rename to packages/utility-features/kube-api/src/endpoints/cluster-role-binding.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/cluster-role.api.ts b/packages/utility-features/kube-api/src/endpoints/cluster-role.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/cluster-role.api.ts rename to packages/utility-features/kube-api/src/endpoints/cluster-role.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/cluster.api.ts b/packages/utility-features/kube-api/src/endpoints/cluster.api.ts similarity index 96% rename from packages/core/src/common/k8s-api/endpoints/cluster.api.ts rename to packages/utility-features/kube-api/src/endpoints/cluster.api.ts index 36fe6b4a90..1061d5607a 100644 --- a/packages/core/src/common/k8s-api/endpoints/cluster.api.ts +++ b/packages/utility-features/kube-api/src/endpoints/cluster.api.ts @@ -20,7 +20,7 @@ export class ClusterApi extends KubeApi { constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { super(deps, { - ...opts ?? {}, + ...(opts ?? {}), objectConstructor: Cluster, }); } diff --git a/packages/core/src/common/k8s-api/endpoints/component-status.api.ts b/packages/utility-features/kube-api/src/endpoints/component-status.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/component-status.api.ts rename to packages/utility-features/kube-api/src/endpoints/component-status.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/config-map.api.ts b/packages/utility-features/kube-api/src/endpoints/config-map.api.ts similarity index 96% rename from packages/core/src/common/k8s-api/endpoints/config-map.api.ts rename to packages/utility-features/kube-api/src/endpoints/config-map.api.ts index b8e0c589db..d9b142d98d 100644 --- a/packages/core/src/common/k8s-api/endpoints/config-map.api.ts +++ b/packages/utility-features/kube-api/src/endpoints/config-map.api.ts @@ -12,7 +12,7 @@ export class ConfigMapApi extends KubeApi { constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { super(deps, { objectConstructor: ConfigMap, - ...opts ?? {}, + ...(opts ?? {}), }); } } diff --git a/packages/core/src/common/k8s-api/endpoints/cron-job.api.ts b/packages/utility-features/kube-api/src/endpoints/cron-job.api.ts similarity index 87% rename from packages/core/src/common/k8s-api/endpoints/cron-job.api.ts rename to packages/utility-features/kube-api/src/endpoints/cron-job.api.ts index 4c61c259ac..8ee14dbfe4 100644 --- a/packages/core/src/common/k8s-api/endpoints/cron-job.api.ts +++ b/packages/utility-features/kube-api/src/endpoints/cron-job.api.ts @@ -16,11 +16,15 @@ export class CronJobApi extends KubeApi { } private requestSetSuspend(params: NamespacedResourceDescriptor, suspend: boolean) { - return this.patch(params, { - spec: { - suspend, + return this.patch( + params, + { + spec: { + suspend, + }, }, - }, "strategic"); + "strategic", + ); } suspend(params: NamespacedResourceDescriptor) { diff --git a/packages/core/src/common/k8s-api/endpoints/custom-resource-definition.api.ts b/packages/utility-features/kube-api/src/endpoints/custom-resource-definition.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/custom-resource-definition.api.ts rename to packages/utility-features/kube-api/src/endpoints/custom-resource-definition.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/daemon-set.api.ts b/packages/utility-features/kube-api/src/endpoints/daemon-set.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/daemon-set.api.ts rename to packages/utility-features/kube-api/src/endpoints/daemon-set.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/deployment.api.ts b/packages/utility-features/kube-api/src/endpoints/deployment.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/deployment.api.ts rename to packages/utility-features/kube-api/src/endpoints/deployment.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/endpoint.api.ts b/packages/utility-features/kube-api/src/endpoints/endpoint.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/endpoint.api.ts rename to packages/utility-features/kube-api/src/endpoints/endpoint.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/events.api.ts b/packages/utility-features/kube-api/src/endpoints/events.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/events.api.ts rename to packages/utility-features/kube-api/src/endpoints/events.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts b/packages/utility-features/kube-api/src/endpoints/horizontal-pod-autoscaler.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts rename to packages/utility-features/kube-api/src/endpoints/horizontal-pod-autoscaler.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/index.ts b/packages/utility-features/kube-api/src/endpoints/index.ts similarity index 94% rename from packages/core/src/common/k8s-api/endpoints/index.ts rename to packages/utility-features/kube-api/src/endpoints/index.ts index ee2a75dfe1..e5eca79e1e 100644 --- a/packages/core/src/common/k8s-api/endpoints/index.ts +++ b/packages/utility-features/kube-api/src/endpoints/index.ts @@ -4,7 +4,7 @@ */ // Kubernetes apis -// Docs: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/ +// Docs: https://kubernetes.io/docs/reference/kubernetes-api/ export * from "./cluster.api"; export * from "./cluster-role.api"; @@ -12,6 +12,7 @@ export * from "./cluster-role-binding.api"; export * from "./config-map.api"; export * from "./custom-resource-definition.api"; export * from "./cron-job.api"; +export * from "./component-status.api"; export * from "./daemon-set.api"; export * from "./deployment.api"; export * from "./endpoint.api"; diff --git a/packages/core/src/common/k8s-api/endpoints/ingress-class.api.ts b/packages/utility-features/kube-api/src/endpoints/ingress-class.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/ingress-class.api.ts rename to packages/utility-features/kube-api/src/endpoints/ingress-class.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/ingress.api.ts b/packages/utility-features/kube-api/src/endpoints/ingress.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/ingress.api.ts rename to packages/utility-features/kube-api/src/endpoints/ingress.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/job.api.ts b/packages/utility-features/kube-api/src/endpoints/job.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/job.api.ts rename to packages/utility-features/kube-api/src/endpoints/job.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/lease.api.ts b/packages/utility-features/kube-api/src/endpoints/lease.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/lease.api.ts rename to packages/utility-features/kube-api/src/endpoints/lease.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/limit-range.api.ts b/packages/utility-features/kube-api/src/endpoints/limit-range.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/limit-range.api.ts rename to packages/utility-features/kube-api/src/endpoints/limit-range.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/mutating-webhook-configuration.api.ts b/packages/utility-features/kube-api/src/endpoints/mutating-webhook-configuration.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/mutating-webhook-configuration.api.ts rename to packages/utility-features/kube-api/src/endpoints/mutating-webhook-configuration.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/namespace.api.ts b/packages/utility-features/kube-api/src/endpoints/namespace.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/namespace.api.ts rename to packages/utility-features/kube-api/src/endpoints/namespace.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/network-policy.api.ts b/packages/utility-features/kube-api/src/endpoints/network-policy.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/network-policy.api.ts rename to packages/utility-features/kube-api/src/endpoints/network-policy.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/node.api.ts b/packages/utility-features/kube-api/src/endpoints/node.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/node.api.ts rename to packages/utility-features/kube-api/src/endpoints/node.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/persistent-volume-claim.api.ts b/packages/utility-features/kube-api/src/endpoints/persistent-volume-claim.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/persistent-volume-claim.api.ts rename to packages/utility-features/kube-api/src/endpoints/persistent-volume-claim.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/persistent-volume.api.ts b/packages/utility-features/kube-api/src/endpoints/persistent-volume.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/persistent-volume.api.ts rename to packages/utility-features/kube-api/src/endpoints/persistent-volume.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/pod-disruption-budget.api.ts b/packages/utility-features/kube-api/src/endpoints/pod-disruption-budget.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/pod-disruption-budget.api.ts rename to packages/utility-features/kube-api/src/endpoints/pod-disruption-budget.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/pod-metrics.api.ts b/packages/utility-features/kube-api/src/endpoints/pod-metrics.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/pod-metrics.api.ts rename to packages/utility-features/kube-api/src/endpoints/pod-metrics.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/pod-security-policy.api.ts b/packages/utility-features/kube-api/src/endpoints/pod-security-policy.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/pod-security-policy.api.ts rename to packages/utility-features/kube-api/src/endpoints/pod-security-policy.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/pod.api.ts b/packages/utility-features/kube-api/src/endpoints/pod.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/pod.api.ts rename to packages/utility-features/kube-api/src/endpoints/pod.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/priority-class.api.ts b/packages/utility-features/kube-api/src/endpoints/priority-class.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/priority-class.api.ts rename to packages/utility-features/kube-api/src/endpoints/priority-class.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/replica-set.api.ts b/packages/utility-features/kube-api/src/endpoints/replica-set.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/replica-set.api.ts rename to packages/utility-features/kube-api/src/endpoints/replica-set.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/replication-controller.api.ts b/packages/utility-features/kube-api/src/endpoints/replication-controller.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/replication-controller.api.ts rename to packages/utility-features/kube-api/src/endpoints/replication-controller.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/resource-quota.api.ts b/packages/utility-features/kube-api/src/endpoints/resource-quota.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/resource-quota.api.ts rename to packages/utility-features/kube-api/src/endpoints/resource-quota.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/role-binding.api.ts b/packages/utility-features/kube-api/src/endpoints/role-binding.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/role-binding.api.ts rename to packages/utility-features/kube-api/src/endpoints/role-binding.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/role.api.ts b/packages/utility-features/kube-api/src/endpoints/role.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/role.api.ts rename to packages/utility-features/kube-api/src/endpoints/role.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/runtime-class.api.ts b/packages/utility-features/kube-api/src/endpoints/runtime-class.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/runtime-class.api.ts rename to packages/utility-features/kube-api/src/endpoints/runtime-class.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/secret.api.ts b/packages/utility-features/kube-api/src/endpoints/secret.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/secret.api.ts rename to packages/utility-features/kube-api/src/endpoints/secret.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.ts b/packages/utility-features/kube-api/src/endpoints/self-subject-rules-reviews.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.ts rename to packages/utility-features/kube-api/src/endpoints/self-subject-rules-reviews.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/service-account.api.ts b/packages/utility-features/kube-api/src/endpoints/service-account.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/service-account.api.ts rename to packages/utility-features/kube-api/src/endpoints/service-account.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/service.api.ts b/packages/utility-features/kube-api/src/endpoints/service.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/service.api.ts rename to packages/utility-features/kube-api/src/endpoints/service.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/stateful-set.api.ts b/packages/utility-features/kube-api/src/endpoints/stateful-set.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/stateful-set.api.ts rename to packages/utility-features/kube-api/src/endpoints/stateful-set.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/storage-class.api.ts b/packages/utility-features/kube-api/src/endpoints/storage-class.api.ts similarity index 99% rename from packages/core/src/common/k8s-api/endpoints/storage-class.api.ts rename to packages/utility-features/kube-api/src/endpoints/storage-class.api.ts index 08831201f3..f942b02954 100644 --- a/packages/core/src/common/k8s-api/endpoints/storage-class.api.ts +++ b/packages/utility-features/kube-api/src/endpoints/storage-class.api.ts @@ -8,7 +8,6 @@ import { StorageClass } from "@k8slens/kube-object"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import { KubeApi } from "../kube-api"; - export class StorageClassApi extends KubeApi { constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { super(deps, { diff --git a/packages/core/src/common/k8s-api/endpoints/validating-webhook-configuration.api.ts b/packages/utility-features/kube-api/src/endpoints/validating-webhook-configuration.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/validating-webhook-configuration.api.ts rename to packages/utility-features/kube-api/src/endpoints/validating-webhook-configuration.api.ts diff --git a/packages/core/src/common/k8s-api/endpoints/vertical-pod-autoscaler.api.ts b/packages/utility-features/kube-api/src/endpoints/vertical-pod-autoscaler.api.ts similarity index 100% rename from packages/core/src/common/k8s-api/endpoints/vertical-pod-autoscaler.api.ts rename to packages/utility-features/kube-api/src/endpoints/vertical-pod-autoscaler.api.ts diff --git a/packages/core/src/common/k8s-api/get-match-for.test.ts b/packages/utility-features/kube-api/src/get-match-for.test.ts similarity index 92% rename from packages/core/src/common/k8s-api/get-match-for.test.ts rename to packages/utility-features/kube-api/src/get-match-for.test.ts index 255c39bb78..f2157473b2 100644 --- a/packages/core/src/common/k8s-api/get-match-for.test.ts +++ b/packages/utility-features/kube-api/src/get-match-for.test.ts @@ -23,7 +23,7 @@ describe("get-match-for", () => { expect(match).toEqual(["match"]); }); - it("given multiple matching regex, when called with a string, returns first match", () => { + it("given multiple matching regex with one non-matching, when called with a string, returns first match", () => { const getMatch = getMatchFor(/non-match/, /some-match/, /match/); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion diff --git a/packages/core/src/common/k8s-api/get-match-for.ts b/packages/utility-features/kube-api/src/get-match-for.ts similarity index 100% rename from packages/core/src/common/k8s-api/get-match-for.ts rename to packages/utility-features/kube-api/src/get-match-for.ts diff --git a/packages/core/src/common/k8s-api/kube-api/kube-api-injection-token.ts b/packages/utility-features/kube-api/src/kube-api-injection-token.ts similarity index 87% rename from packages/core/src/common/k8s-api/kube-api/kube-api-injection-token.ts rename to packages/utility-features/kube-api/src/kube-api-injection-token.ts index 92b6636274..65b6481faf 100644 --- a/packages/core/src/common/k8s-api/kube-api/kube-api-injection-token.ts +++ b/packages/utility-features/kube-api/src/kube-api-injection-token.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectionToken } from "@ogre-tools/injectable"; -import type { KubeApi } from "../kube-api"; +import type { KubeApi } from "./kube-api"; export const kubeApiInjectionToken = getInjectionToken>({ id: "kube-api-injection-token", diff --git a/packages/core/src/common/k8s-api/__tests__/kube-api-parse.test.ts b/packages/utility-features/kube-api/src/kube-api-parse.test.ts similarity index 57% rename from packages/core/src/common/k8s-api/__tests__/kube-api-parse.test.ts rename to packages/utility-features/kube-api/src/kube-api-parse.test.ts index f0f0635d21..9960b77f55 100644 --- a/packages/core/src/common/k8s-api/__tests__/kube-api-parse.test.ts +++ b/packages/utility-features/kube-api/src/kube-api-parse.test.ts @@ -3,17 +3,10 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -jest.mock("../kube-api"); -jest.mock("../api-manager", () => ({ - apiManager() { - return { - registerStore: jest.fn(), - }; - }, -})); +import type { IKubeApiParsed } from "./kube-api-parse"; +import { parseKubeApi } from "./kube-api-parse"; -import type { IKubeApiParsed } from "../kube-api-parse"; -import { parseKubeApi } from "../kube-api-parse"; +jest.mock("@k8slens/kube-api"); /** * [, ] @@ -22,14 +15,66 @@ type KubeApiParseTestData = [string, IKubeApiParsed]; const tests: KubeApiParseTestData[] = [ [ - "http://some-irrelevant-domain/api/v1/secrets?some-irrelevant-parameter=some-irrelevant-value", + "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", { - apiBase: "/api/v1/secrets", + apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions", + apiPrefix: "/apis", + apiGroup: "apiextensions.k8s.io", + apiVersion: "v1beta1", + apiVersionWithGroup: "apiextensions.k8s.io/v1beta1", + namespace: undefined, + resource: "customresourcedefinitions", + name: "prometheuses.monitoring.coreos.com", + }, + ], + [ + "/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27", + { + apiBase: "/api/v1/pods", apiPrefix: "/api", apiGroup: "", apiVersion: "v1", apiVersionWithGroup: "v1", - resource: "secrets", + namespace: "kube-system", + resource: "pods", + name: "coredns-6955765f44-v8p27", + }, + ], + [ + "/apis/stable.example.com/foo1/crontabs", + { + apiBase: "/apis/stable.example.com/foo1/crontabs", + apiPrefix: "/apis", + apiGroup: "stable.example.com", + apiVersion: "foo1", + apiVersionWithGroup: "stable.example.com/foo1", + resource: "crontabs", + name: undefined, + namespace: undefined, + }, + ], + [ + "/apis/cluster.k8s.io/v1alpha1/clusters", + { + apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters", + apiPrefix: "/apis", + apiGroup: "cluster.k8s.io", + apiVersion: "v1alpha1", + apiVersionWithGroup: "cluster.k8s.io/v1alpha1", + resource: "clusters", + name: undefined, + namespace: undefined, + }, + ], + [ + "/api/v1/namespaces", + { + apiBase: "/api/v1/namespaces", + apiPrefix: "/api", + apiGroup: "", + apiVersion: "v1", + apiVersionWithGroup: "v1", + resource: "namespaces", name: undefined, namespace: undefined, }, @@ -47,21 +92,6 @@ const tests: KubeApiParseTestData[] = [ namespace: undefined, }, ], - - [ - "/api/v1/namespaces", - { - apiBase: "/api/v1/namespaces", - apiPrefix: "/api", - apiGroup: "", - apiVersion: "v1", - apiVersionWithGroup: "v1", - resource: "namespaces", - name: undefined, - namespace: undefined, - }, - ], - [ "/api/v1/nodes/minikube", { @@ -75,7 +105,6 @@ const tests: KubeApiParseTestData[] = [ namespace: undefined, }, ], - [ "/api/foo-bar/nodes/minikube", { @@ -89,7 +118,6 @@ const tests: KubeApiParseTestData[] = [ namespace: undefined, }, ], - [ "/api/v1/namespaces/kube-public", { @@ -103,129 +131,16 @@ const tests: KubeApiParseTestData[] = [ namespace: undefined, }, ], - - [ - "/apis/stable.example.com/foo1/crontabs", - { - apiBase: "/apis/stable.example.com/foo1/crontabs", - apiPrefix: "/apis", - apiGroup: "stable.example.com", - apiVersion: "foo1", - apiVersionWithGroup: "stable.example.com/foo1", - resource: "crontabs", - name: undefined, - namespace: undefined, - }, - ], - - [ - "/apis/cluster.k8s.io/v1alpha1/clusters", - { - apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters", - apiPrefix: "/apis", - apiGroup: "cluster.k8s.io", - apiVersion: "v1alpha1", - apiVersionWithGroup: "cluster.k8s.io/v1alpha1", - resource: "clusters", - name: undefined, - namespace: undefined, - }, - ], - - [ - "/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27", - { - apiBase: "/api/v1/pods", - apiPrefix: "/api", - apiGroup: "", - apiVersion: "v1", - apiVersionWithGroup: "v1", - namespace: "kube-system", - resource: "pods", - name: "coredns-6955765f44-v8p27", - }, - ], - - [ - "/apis/apps/v1/namespaces/default/deployments/some-deployment", - { - apiBase: "/apis/apps/v1/deployments", - apiGroup: "apps", - apiPrefix: "/apis", - apiVersion: "v1", - apiVersionWithGroup: "apps/v1", - name: "some-deployment", - namespace: "default", - resource: "deployments", - }, - ], - - [ - "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", - { - apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions", - apiPrefix: "/apis", - apiGroup: "apiextensions.k8s.io", - apiVersion: "v1beta1", - apiVersionWithGroup: "apiextensions.k8s.io/v1beta1", - namespace: undefined, - resource: "customresourcedefinitions", - name: "prometheuses.monitoring.coreos.com", - }, - ], - - [ - "/api/v1/namespaces/kube-system/pods", - { - apiBase: "/api/v1/pods", - apiPrefix: "/api", - apiGroup: "", - apiVersion: "v1", - apiVersionWithGroup: "v1", - namespace: "kube-system", - resource: "pods", - name: undefined, - }, - ], - - [ - "/apis/cluster.k8s.io/v1/namespaces/kube-system/pods", - { - apiBase: "/apis/cluster.k8s.io/v1/pods", - apiPrefix: "/apis", - apiGroup: "cluster.k8s.io", - apiVersion: "v1", - apiVersionWithGroup: "cluster.k8s.io/v1", - namespace: "kube-system", - resource: "pods", - name: undefined, - }, - ], ]; -const invalidTests = [ - undefined, - "", - "some-invalid-path", - "//apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", - "/apis//v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", - "/apis/apiextensions.k8s.io//customresourcedefinitions/prometheuses.monitoring.coreos.com", - "/apis/apiextensions.k8s.io/v1beta1//prometheuses.monitoring.coreos.com", - "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/", - - "//v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", - "/api//v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", - "/api//customresourcedefinitions/prometheuses.monitoring.coreos.com", - "/api/v1beta1//prometheuses.monitoring.coreos.com", - "/api/v1beta1/customresourcedefinitions/", -]; +const invalidTests = [undefined, "", "ajklsmh"]; describe("parseApi unit tests", () => { - it.each(tests)(`given path %j, parses as expected`, (url, expected) => { + it.each(tests)("testing %j", (url, expected) => { expect(parseKubeApi(url)).toStrictEqual(expected); }); - it.each(invalidTests)(`given path %j, parses as undefined`, (url) => { + it.each(invalidTests)("testing %j should return undefined", (url) => { expect(parseKubeApi(url as never)).toBe(undefined); }); }); diff --git a/packages/core/src/common/k8s-api/kube-api-parse.ts b/packages/utility-features/kube-api/src/kube-api-parse.ts similarity index 81% rename from packages/core/src/common/k8s-api/kube-api-parse.ts rename to packages/utility-features/kube-api/src/kube-api-parse.ts index b58215eef1..0ef26679c0 100644 --- a/packages/core/src/common/k8s-api/kube-api-parse.ts +++ b/packages/utility-features/kube-api/src/kube-api-parse.ts @@ -25,9 +25,34 @@ export interface IKubeApiParsed extends IKubeApiLinkRef { apiVersionWithGroup: string; } -export function parseKubeApi( - path: string | undefined, -): IKubeApiParsed | undefined { +const withoutDomainAddressOrParameters = (path: string) => new URL(path, "http://irrelevant").pathname; + +const getKubeApiPathMatch = getMatchFor( + /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, + /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)$/, + /^\/(?api)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, + /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, + /^\/(?api)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)$/, + /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, + /^\/(?api)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, + /^\/(?api)\/(?[^/]+?)\/(?[^/]+?)$/, +); + +const getParsedPath = (path: string) => + pipeline(path, withoutDomainAddressOrParameters, getKubeApiPathMatch, (match) => match?.groups); + +const joinTruthy = (delimiter: string) => (toBeJoined: string[]) => pipeline(toBeJoined, compact, join(delimiter)); + +const getApiBase = (apiOrApis: string, apiGroup: string, apiVersion: string, resource: string) => + pipeline([apiOrApis, apiGroup, apiVersion, resource], joinTruthy("/"), prepend("/")); + +const getApiPrefix = prepend("/"); + +const getApiVersionWithGroup = (apiGroup: string, apiVersion: string) => joinTruthy("/")([apiGroup, apiVersion]); + +const getApiGroup = (apiGroup: string) => apiGroup || ""; + +export function parseKubeApi(path: string | undefined): IKubeApiParsed | undefined { if (!path) { return undefined; } @@ -38,8 +63,7 @@ export function parseKubeApi( return undefined; } - const { apiOrApis, apiGroup, namespace, apiVersion, resource, name } = - parsedPath; + const { apiOrApis, apiGroup, namespace, apiVersion, resource, name } = parsedPath; return { apiBase: getApiBase(apiOrApis, apiGroup, apiVersion, resource), @@ -53,18 +77,14 @@ export function parseKubeApi( }; } -function isIKubeApiParsed( - refOrParsed: IKubeApiLinkRef | IKubeApiParsed, -): refOrParsed is IKubeApiParsed { +function isIKubeApiParsed(refOrParsed: IKubeApiLinkRef | IKubeApiParsed): refOrParsed is IKubeApiParsed { return "apiGroup" in refOrParsed && !!refOrParsed.apiGroup; } export function createKubeApiURL(linkRef: IKubeApiLinkRef): string; export function createKubeApiURL(linkParsed: IKubeApiParsed): string; -export function createKubeApiURL( - ref: IKubeApiLinkRef | IKubeApiParsed, -): string { +export function createKubeApiURL(ref: IKubeApiLinkRef | IKubeApiParsed): string { if (isIKubeApiParsed(ref)) { return createKubeApiURL({ apiPrefix: ref.apiPrefix, @@ -90,42 +110,3 @@ export function createKubeApiURL( return parts.join("/"); } - -const getKubeApiPathMatch = getMatchFor( - /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, - /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)$/, - /^\/(?api)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, - /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, - /^\/(?api)\/(?[^/]+?)\/namespaces\/(?[^/]+?)\/(?[^/]+?)$/, - /^\/(?apis)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, - /^\/(?api)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/]+?)$/, - /^\/(?api)\/(?[^/]+?)\/(?[^/]+?)$/, -); - -const getParsedPath = (path: string) => - pipeline(path, withoutDomainAddressOrParameters, getKubeApiPathMatch, (match) => match?.groups); - -const joinTruthy = (delimiter: string) => (toBeJoined: string[]) => - pipeline(toBeJoined, compact, join(delimiter)); - -const getApiBase = ( - apiOrApis: string, - apiGroup: string, - apiVersion: string, - resource: string, -) => - pipeline( - [apiOrApis, apiGroup, apiVersion, resource], - joinTruthy("/"), - prepend("/"), - ); - -const getApiPrefix = prepend("/"); - -const getApiVersionWithGroup = (apiGroup: string, apiVersion: string) => - joinTruthy("/")([apiGroup, apiVersion]); - -const getApiGroup = (apiGroup: string) => apiGroup || ""; - -const withoutDomainAddressOrParameters = (path: string) => - new URL(path, "http://irrelevant").pathname; diff --git a/packages/utility-features/kube-api/src/kube-api.test.ts b/packages/utility-features/kube-api/src/kube-api.test.ts new file mode 100644 index 0000000000..0f45cf44dd --- /dev/null +++ b/packages/utility-features/kube-api/src/kube-api.test.ts @@ -0,0 +1,1188 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import type { KubeApiWatchCallback } from "./kube-api"; +import { PassThrough } from "stream"; +import { Deployment, Pod } from "@k8slens/kube-object"; +import type Fetch from "@k8slens/node-fetch"; +import type { AsyncFnMock } from "@async-fn/jest"; +import asyncFn from "@async-fn/jest"; +import { flushPromises } from "@k8slens/test-utils"; +import type { IKubeWatchEvent } from "./kube-watch-event"; +import type { KubeJsonApiDataFor, KubeJsonApiData } from "@k8slens/kube-object"; +import { createMockResponseFromStream, createMockResponseFromString } from "./mock-responses"; +import type { Logger } from "@k8slens/logger"; +import { DeploymentApi, NamespaceApi, PodApi } from "./endpoints"; +import { KubeJsonApi } from "./kube-json-api"; + +describe("KubeApi", () => { + let fetchMock: AsyncFnMock; + let logger: Logger; + let kubeJsonApi: KubeJsonApi; + + beforeEach(() => { + fetchMock = asyncFn(); + + logger = { + info: jest.fn(), + debug: jest.fn(), + error: jest.fn(), + } as any; + + kubeJsonApi = new KubeJsonApi( + { + fetch: fetchMock, + logger, + }, + { + apiBase: "/api-kube", + serverAddress: "http://127.0.0.1:9999", + }, + { + headers: { + "content-type": "application/json", + }, + }, + ); + }); + + describe("patching deployments", () => { + let api: DeploymentApi; + + beforeEach(() => { + api = new DeploymentApi({ + logger, + maybeKubeApi: kubeJsonApi, + }); + }); + + describe("when patching a resource without providing a strategy", () => { + let patchRequest: Promise; + + beforeEach(async () => { + patchRequest = api.patch( + { name: "test", namespace: "default" }, + { + spec: { replicas: 2 }, + }, + ); + + // This is needed because of how JS promises work + await flushPromises(); + }); + + it("requests a patch using strategic merge", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", + { + headers: { + "content-type": "application/strategic-merge-patch+json", + }, + method: "patch", + body: JSON.stringify({ spec: { replicas: 2 } }), + }, + ]); + }); + + describe("when the patch request resolves with data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", + JSON.stringify({ + apiVersion: "v1", + kind: "Deployment", + metadata: { + name: "test", + namespace: "default", + resourceVersion: "1", + uid: "12345", + }, + spec: { + replicas: 2, + }, + }), + ), + ); + }); + + it("resolves the patch call", async () => { + expect(await patchRequest).toBeInstanceOf(Deployment); + }); + }); + }); + + describe("when patching a resource using json patch", () => { + let patchRequest: Promise; + + beforeEach(async () => { + patchRequest = api.patch( + { name: "test", namespace: "default" }, + [{ op: "replace", path: "/spec/replicas", value: 2 }], + "json", + ); + + // This is needed because of how JS promises work + await flushPromises(); + }); + + it("requests a patch using json merge", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", + { + headers: { + "content-type": "application/json-patch+json", + }, + method: "patch", + body: JSON.stringify([{ op: "replace", path: "/spec/replicas", value: 2 }]), + }, + ]); + }); + + describe("when the patch request resolves with data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", + JSON.stringify({ + apiVersion: "v1", + kind: "Deployment", + metadata: { + name: "test", + namespace: "default", + resourceVersion: "1", + uid: "12345", + }, + spec: { + replicas: 2, + }, + }), + ), + ); + }); + + it("resolves the patch call", async () => { + expect(await patchRequest).toBeInstanceOf(Deployment); + }); + }); + }); + + describe("when patching a resource using merge patch", () => { + let patchRequest: Promise; + + beforeEach(async () => { + patchRequest = api.patch( + { name: "test", namespace: "default" }, + { metadata: { annotations: { provisioned: "True" } } }, + "merge", + ); + + // This is needed because of how JS promises work + await flushPromises(); + }); + + it("requests a patch using json merge", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", + { + headers: { + "content-type": "application/merge-patch+json", + }, + method: "patch", + body: JSON.stringify({ metadata: { annotations: { provisioned: "True" } } }), + }, + ]); + }); + + describe("when the patch request resolves with data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/apis/apps/v1/namespaces/default/deployments/test", + JSON.stringify({ + apiVersion: "v1", + kind: "Deployment", + metadata: { + name: "test", + namespace: "default", + resourceVersion: "1", + uid: "12345", + annotations: { + provisioned: "True", + }, + }, + }), + ), + ); + }); + + it("resolves the patch call", async () => { + expect(await patchRequest).toBeInstanceOf(Deployment); + }); + }); + }); + }); + + describe("deleting pods (namespace scoped resource)", () => { + let api: PodApi; + + beforeEach(() => { + api = new PodApi({ + logger, + maybeKubeApi: kubeJsonApi, + }); + }); + + describe("when deleting by just name", () => { + let deleteRequest: Promise; + + beforeEach(async () => { + deleteRequest = api.delete({ name: "foo" }); + + // This is required for how JS promises work + await flushPromises(); + }); + + it("requests deleting pod in default namespace", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", + { + headers: { + "content-type": "application/json", + }, + method: "delete", + }, + ]); + }); + + describe("when request resolves", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", + "{}", + ), + ); + }); + + it("resolves the call", async () => { + expect(await deleteRequest).toBeDefined(); + }); + }); + }); + + describe("when deleting by name and empty namespace", () => { + let deleteRequest: Promise; + + beforeEach(async () => { + deleteRequest = api.delete({ name: "foo", namespace: "" }); + + // This is required for how JS promises work + await flushPromises(); + }); + + it("requests deleting pod in default namespace", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", + { + headers: { + "content-type": "application/json", + }, + method: "delete", + }, + ]); + }); + + describe("when request resolves", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background", + "{}", + ), + ); + }); + + it("resolves the call", async () => { + expect(await deleteRequest).toBeDefined(); + }); + }); + }); + + describe("when deleting by name and namespace", () => { + let deleteRequest: Promise; + + beforeEach(async () => { + deleteRequest = api.delete({ name: "foo", namespace: "test" }); + + // This is required for how JS promises work + await flushPromises(); + }); + + it("requests deleting pod in given namespace", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background", + { + headers: { + "content-type": "application/json", + }, + method: "delete", + }, + ]); + }); + + describe("when request resolves", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/test/pods/foo?propagationPolicy=Background", + "{}", + ), + ); + }); + + it("resolves the call", async () => { + expect(await deleteRequest).toBeDefined(); + }); + }); + }); + }); + + describe("deleting namespaces (cluster scoped resource)", () => { + let api: NamespaceApi; + + beforeEach(() => { + api = new NamespaceApi({ + logger, + maybeKubeApi: kubeJsonApi, + }); + }); + + describe("when deleting by just name", () => { + let deleteRequest: Promise; + + beforeEach(async () => { + deleteRequest = api.delete({ name: "foo" }); + + // This is required for how JS promises work + await flushPromises(); + }); + + it("requests deleting Namespace without namespace", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", + { + headers: { + "content-type": "application/json", + }, + method: "delete", + }, + ]); + }); + + describe("when request resolves", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", + "{}", + ), + ); + }); + + it("resolves the call", async () => { + expect(await deleteRequest).toBeDefined(); + }); + }); + }); + + describe("when deleting by name and empty namespace", () => { + let deleteRequest: Promise; + + beforeEach(async () => { + deleteRequest = api.delete({ name: "foo", namespace: "" }); + + // This is required for how JS promises work + await flushPromises(); + }); + + it("requests deleting Namespace without namespace", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", + { + headers: { + "content-type": "application/json", + }, + method: "delete", + }, + ]); + }); + + describe("when request resolves", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/foo?propagationPolicy=Background", + "{}", + ), + ); + }); + + it("resolves the call", async () => { + expect(await deleteRequest).toBeDefined(); + }); + }); + }); + }); + + describe("watching pods", () => { + let api: PodApi; + let stream: PassThrough; + + beforeEach(() => { + api = new PodApi({ + logger, + maybeKubeApi: kubeJsonApi, + }); + stream = new PassThrough(); + }); + + afterEach(() => { + stream.end(); + stream.destroy(); + }); + + describe("when watching in a namespace", () => { + let stopWatch: () => void; + let callback: jest.MockedFunction; + + beforeEach(async () => { + callback = jest.fn(); + stopWatch = api.watch({ + namespace: "kube-system", + callback, + }); + + await flushPromises(); + }); + + it("requests the watch", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", + { + headers: { + "content-type": "application/json", + }, + method: "get", + }, + ]); + }); + + describe("when the request resolves with a stream", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific(([url, init]) => { + const isMatch = + url === + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600"; + + if (isMatch) { + init?.signal?.addEventListener("abort", () => { + stream.destroy(); + }); + } + + return isMatch; + }, createMockResponseFromStream("http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", stream)); + }); + + describe("when some data comes back on the stream", () => { + beforeEach(() => { + stream.emit( + "data", + `${JSON.stringify({ + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foobar", + namespace: "kube-system", + resourceVersion: "1", + uid: "123456", + }, + }, + } as IKubeWatchEvent>)}\n`, + ); + }); + + it("calls the callback with the data", () => { + expect(callback).toBeCalledWith( + { + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foobar", + namespace: "kube-system", + resourceVersion: "1", + selfLink: "/api/v1/namespaces/kube-system/pods/foobar", + uid: "123456", + }, + }, + }, + null, + ); + }); + + describe("when stopping the watch", () => { + beforeEach(() => { + stopWatch(); + }); + + it("closes the stream", () => { + expect(stream.destroyed).toBe(true); + }); + }); + }); + }); + }); + + describe("when watching in a namespace with an abort controller provided", () => { + let callback: jest.MockedFunction; + let abortController: AbortController; + + beforeEach(async () => { + callback = jest.fn(); + abortController = new AbortController(); + api.watch({ + namespace: "kube-system", + callback, + abortController, + }); + + await flushPromises(); + }); + + it("requests the watch", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", + { + headers: { + "content-type": "application/json", + }, + method: "get", + }, + ]); + }); + + describe("when the request resolves with a stream", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific(([url, init]) => { + const isMatch = + url === + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600"; + + if (isMatch) { + init?.signal?.addEventListener("abort", () => { + stream.destroy(); + }); + } + + return isMatch; + }, createMockResponseFromStream("http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=600", stream)); + }); + + describe("when some data comes back on the stream", () => { + beforeEach(() => { + stream.emit( + "data", + `${JSON.stringify({ + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foobar", + namespace: "kube-system", + resourceVersion: "1", + uid: "123456", + }, + }, + } as IKubeWatchEvent>)}\n`, + ); + }); + + it("calls the callback with the data", () => { + expect(callback).toBeCalledWith( + { + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foobar", + namespace: "kube-system", + resourceVersion: "1", + selfLink: "/api/v1/namespaces/kube-system/pods/foobar", + uid: "123456", + }, + }, + }, + null, + ); + }); + + describe("when stopping the watch via the controller", () => { + beforeEach(() => { + abortController.abort(); + }); + + it("closes the stream", () => { + expect(stream.destroyed).toBe(true); + }); + }); + }); + }); + }); + + describe("when watching in a namespace with a timeout", () => { + let stopWatch: () => void; + let callback: jest.MockedFunction; + + beforeEach(async () => { + callback = jest.fn(); + stopWatch = api.watch({ + namespace: "kube-system", + callback, + timeout: 60, + }); + + await flushPromises(); + }); + + it("requests the watch", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60", + { + headers: { + "content-type": "application/json", + }, + method: "get", + }, + ]); + }); + + describe("when the request resolves with a stream", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific(([url, init]) => { + const isMatch = + url === + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60"; + + if (isMatch) { + init?.signal?.addEventListener("abort", () => { + stream.destroy(); + }); + } + + return isMatch; + }, createMockResponseFromStream("http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60", stream)); + }); + + describe("when some data comes back on the stream", () => { + beforeEach(() => { + stream.emit( + "data", + `${JSON.stringify({ + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foobar", + namespace: "kube-system", + resourceVersion: "1", + uid: "123456", + }, + }, + } as IKubeWatchEvent>)}\n`, + ); + }); + + it("calls the callback with the data", () => { + expect(callback).toBeCalledWith( + { + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foobar", + namespace: "kube-system", + resourceVersion: "1", + selfLink: "/api/v1/namespaces/kube-system/pods/foobar", + uid: "123456", + }, + }, + }, + null, + ); + }); + + describe("when stopping the watch", () => { + beforeEach(() => { + stopWatch(); + }); + + it("closes the stream", () => { + expect(stream.destroyed).toBe(true); + }); + }); + + describe("when the watch ends", () => { + beforeEach(() => { + stream.end(); + }); + + it("requests a new watch", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/kube-system/pods?watch=1&resourceVersion=&timeoutSeconds=60", + { + headers: { + "content-type": "application/json", + }, + method: "get", + }, + ]); + }); + + describe("when stopping the watch", () => { + beforeEach(() => { + stopWatch(); + }); + + it("closes the stream", () => { + expect(stream.destroyed).toBe(true); + }); + }); + }); + }); + }); + }); + }); + + describe("creating pods", () => { + let api: PodApi; + + beforeEach(() => { + api = new PodApi({ + logger, + maybeKubeApi: kubeJsonApi, + }); + }); + + describe("when creating a pod", () => { + let createRequest: Promise; + + beforeEach(async () => { + createRequest = api.create( + { + name: "foobar", + namespace: "default", + }, + { + metadata: { + labels: { + foo: "bar", + }, + }, + spec: { + containers: [ + { + name: "web", + image: "nginx", + ports: [ + { + name: "web", + containerPort: 80, + protocol: "TCP", + }, + ], + }, + ], + }, + }, + ); + + // This is required because of how JS promises work + await flushPromises(); + }); + + it("should request to create a pod with full descriptor", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", + { + headers: { + "content-type": "application/json", + }, + method: "post", + body: JSON.stringify({ + metadata: { + labels: { + foo: "bar", + }, + name: "foobar", + namespace: "default", + }, + spec: { + containers: [ + { + name: "web", + image: "nginx", + ports: [ + { + name: "web", + containerPort: 80, + protocol: "TCP", + }, + ], + }, + ], + }, + kind: "Pod", + apiVersion: "v1", + }), + }, + ]); + }); + + describe("when request resolves with data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", + JSON.stringify({ + kind: "Pod", + apiVersion: "v1", + metadata: { + name: "foobar", + namespace: "default", + labels: { + foo: "bar", + }, + resourceVersion: "1", + uid: "123456798", + }, + spec: { + containers: [ + { + name: "web", + image: "nginx", + ports: [ + { + name: "web", + containerPort: 80, + protocol: "TCP", + }, + ], + }, + ], + }, + }), + ), + ); + }); + + it("call should resolve in a Pod instance", async () => { + expect(await createRequest).toBeInstanceOf(Pod); + }); + }); + }); + }); + + describe("updating pods", () => { + let api: PodApi; + + beforeEach(() => { + api = new PodApi({ + logger, + maybeKubeApi: kubeJsonApi, + }); + }); + + describe("when updating a pod", () => { + let updateRequest: Promise; + + beforeEach(async () => { + updateRequest = api.update( + { + name: "foobar", + namespace: "default", + }, + { + kind: "Pod", + apiVersion: "v1", + metadata: { + labels: { + foo: "bar", + }, + }, + spec: { + containers: [ + { + name: "web", + image: "nginx", + ports: [ + { + name: "web", + containerPort: 80, + protocol: "TCP", + }, + ], + }, + ], + }, + }, + ); + + await flushPromises(); + }); + + it("should request that the pod is updated", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar", + { + headers: { + "content-type": "application/json", + }, + method: "put", + body: JSON.stringify({ + kind: "Pod", + apiVersion: "v1", + metadata: { + labels: { + foo: "bar", + }, + name: "foobar", + namespace: "default", + }, + spec: { + containers: [ + { + name: "web", + image: "nginx", + ports: [ + { + name: "web", + containerPort: 80, + protocol: "TCP", + }, + ], + }, + ], + }, + }), + }, + ]); + }); + + describe("when the request resolves with data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foobar", + JSON.stringify({ + kind: "Pod", + apiVersion: "v1", + metadata: { + name: "foobar", + namespace: "default", + labels: { + foo: "bar", + }, + resourceVersion: "1", + uid: "123456798", + }, + spec: { + containers: [ + { + name: "web", + image: "nginx", + ports: [ + { + name: "web", + containerPort: 80, + protocol: "TCP", + }, + ], + }, + ], + }, + }), + ), + ); + }); + + it("the call should resolve to a Pod", async () => { + expect(await updateRequest).toBeInstanceOf(Pod); + }); + }); + }); + }); + + describe("listing pods", () => { + let api: PodApi; + + beforeEach(() => { + api = new PodApi({ + logger, + maybeKubeApi: kubeJsonApi, + }); + }); + + describe("when listing pods with no descriptor", () => { + let listRequest: Promise; + + beforeEach(async () => { + listRequest = api.list(); + + await flushPromises(); + }); + + it("should request that the pods from all namespaces", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/pods", + { + headers: { + "content-type": "application/json", + }, + method: "get", + }, + ]); + }); + + describe("when the request resolves with empty data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/pods"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/pods", + JSON.stringify({ + kind: "PodList", + apiVersion: "v1", + metadata: {}, + items: [], + }), + ), + ); + }); + + it("the call should resolve to an empty list", async () => { + expect(await listRequest).toEqual([]); + }); + }); + }); + + describe("when listing pods with descriptor with namespace=''", () => { + let listRequest: Promise; + + beforeEach(async () => { + listRequest = api.list({ + namespace: "", + }); + + await flushPromises(); + }); + + it("should request that the pods from all namespaces", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/pods", + { + headers: { + "content-type": "application/json", + }, + method: "get", + }, + ]); + }); + + describe("when the request resolves with empty data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/pods"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/pods", + JSON.stringify({ + kind: "PodList", + apiVersion: "v1", + metadata: {}, + items: [], + }), + ), + ); + }); + + it("the call should resolve to an empty list", async () => { + expect(await listRequest).toEqual([]); + }); + }); + }); + + describe("when listing pods with descriptor with namespace='default'", () => { + let listRequest: Promise; + + beforeEach(async () => { + listRequest = api.list({ + namespace: "default", + }); + + await flushPromises(); + }); + + it("should request that the pods from just the default namespace", () => { + expect(fetchMock.mock.lastCall).toMatchObject([ + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", + { + headers: { + "content-type": "application/json", + }, + method: "get", + }, + ]); + }); + + describe("when the request resolves with empty data", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific( + ["http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods"], + createMockResponseFromString( + "http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods", + JSON.stringify({ + kind: "PodList", + apiVersion: "v1", + metadata: {}, + items: [], + }), + ), + ); + }); + + it("the call should resolve to an empty list", async () => { + expect(await listRequest).toEqual([]); + }); + }); + }); + }); +}); diff --git a/packages/core/src/common/k8s-api/kube-api.ts b/packages/utility-features/kube-api/src/kube-api.ts similarity index 85% rename from packages/core/src/common/k8s-api/kube-api.ts rename to packages/utility-features/kube-api/src/kube-api.ts index 31e5c7af39..760c27ce4d 100644 --- a/packages/core/src/common/k8s-api/kube-api.ts +++ b/packages/utility-features/kube-api/src/kube-api.ts @@ -8,8 +8,22 @@ import { merge } from "lodash"; import { stringify } from "querystring"; import { createKubeApiURL, parseKubeApi } from "./kube-api-parse"; -import type { KubeObjectConstructor, KubeJsonApiDataFor, KubeObjectMetadata, KubeJsonApiData, KubeObject, KubeObjectScope, Scale } from "@k8slens/kube-object"; -import { isJsonApiData, isJsonApiDataList, isPartialJsonApiData, KubeStatus, isKubeStatusData } from "@k8slens/kube-object"; +import type { + KubeObjectConstructor, + KubeJsonApiDataFor, + KubeObjectMetadata, + KubeJsonApiData, + KubeObject, + KubeObjectScope, + Scale, +} from "@k8slens/kube-object"; +import { + isJsonApiData, + isJsonApiDataList, + isPartialJsonApiData, + KubeStatus, + isKubeStatusData, +} from "@k8slens/kube-object"; import byline from "byline"; import type { IKubeWatchEvent } from "./kube-watch-event"; import type { KubeJsonApi } from "./kube-json-api"; @@ -27,7 +41,8 @@ import type { ScaleCreateOptions } from "@k8slens/kube-object/src/types/scale"; /** * The options used for creating a `KubeApi` */ -export interface KubeApiOptions = KubeJsonApiDataFor> extends DerivedKubeApiOptions { +export interface KubeApiOptions = KubeJsonApiDataFor> + extends DerivedKubeApiOptions { /** * base api-path for listing all resources, e.g. "/api/v1/pods" * @@ -149,16 +164,25 @@ export interface KubeApiResourceVersionList { versions: KubeApiResourceVersion[]; } -const not = (fn: (val: T) => boolean) => (val: T) => !(fn(val)); +const not = + (fn: (val: T) => boolean) => + (val: T) => + !fn(val); -const getOrderedVersions = (list: KubeApiResourceVersionList, allowedUsableVersions: string[] | undefined): KubeApiResourceVersion[] => [ - list.preferredVersion, - ...list.versions.filter(not(matches(list.preferredVersion))), -].filter(({ version }) => !allowedUsableVersions || allowedUsableVersions.includes(version)); +const getOrderedVersions = ( + list: KubeApiResourceVersionList, + allowedUsableVersions: string[] | undefined, +): KubeApiResourceVersion[] => + [list.preferredVersion, ...list.versions.filter(not(matches(list.preferredVersion)))].filter( + ({ version }) => !allowedUsableVersions || allowedUsableVersions.includes(version), + ); export type PropagationPolicy = undefined | "Orphan" | "Foreground" | "Background"; -export type KubeApiWatchCallback = (data: IKubeWatchEvent | null, error: KubeStatus | Response | null | Record) => void; +export type KubeApiWatchCallback = ( + data: IKubeWatchEvent | null, + error: KubeStatus | Response | null | Record, +) => void; export interface KubeApiWatchOptions> { /** @@ -195,9 +219,9 @@ export interface KubeApiWatchOptions = { - "merge": "application/merge-patch+json", - "json": "application/json-patch+json", - "strategic": "application/strategic-merge-patch+json", + merge: "application/merge-patch+json", + json: "application/json-patch+json", + strategic: "application/strategic-merge-patch+json", }; export interface ResourceDescriptor { @@ -223,20 +247,18 @@ export type SpecificResourceDescriptor = { * The name of the kubernetes resource */ name: string; -} & ( - Scope extends KubeObjectScope.Cluster - ? {} - : Scope extends KubeObjectScope.Namespace - ? { - /** - * The namespace that the resource lives in - */ - namespace: string; - } - : { - namespace?: string; - } -); +} & (Scope extends KubeObjectScope.Cluster + ? {} + : Scope extends KubeObjectScope.Namespace + ? { + /** + * The namespace that the resource lives in + */ + namespace: string; + } + : { + namespace?: string; + }); export type NamespacedResourceDescriptor = SpecificResourceDescriptor; export type ClusterScopedResourceDescriptor = SpecificResourceDescriptor; @@ -260,24 +282,37 @@ export class KubeApi< Data extends KubeJsonApiDataFor = KubeJsonApiDataFor, > { readonly kind: string; + readonly apiVersion: string; @observable apiBase: string; apiPrefix: string; + apiGroup: string; + apiVersionPreferred: string | undefined; + readonly apiResource: string; + readonly isNamespaced: boolean; public readonly objectConstructor: KubeObjectConstructor; + protected readonly request: KubeJsonApi; + protected readonly resourceVersions = new Map(); + protected readonly watchDisposer: Disposer | undefined; + private watchId = 1; + protected readonly doCheckPreferredVersion: boolean; + protected readonly fullApiPathname: string; + protected readonly fallbackApiBases: string[] | undefined; + protected readonly allowedUsableVersions: Partial> | undefined; constructor(protected readonly dependencies: KubeApiDependencies, opts: KubeApiOptions) { @@ -292,7 +327,10 @@ export class KubeApi< allowedUsableVersions, } = opts; - assert(fullApiPathname, "apiBase MUST be provided either via KubeApiOptions.apiBase or KubeApiOptions.objectConstructor.apiBase"); + assert( + fullApiPathname, + "apiBase MUST be provided either via KubeApiOptions.apiBase or KubeApiOptions.objectConstructor.apiBase", + ); assert(request, "request MUST be provided if not in a cluster page frame context"); const parsedApi = parseKubeApi(fullApiPathname); @@ -321,9 +359,7 @@ export class KubeApi< } get apiVersionWithGroup() { - return [this.apiGroup, this.apiVersionPreferred ?? this.apiVersion] - .filter(Boolean) - .join("/"); + return [this.apiGroup, this.apiVersionPreferred ?? this.apiVersion].filter(Boolean).join("/"); } /** @@ -332,11 +368,9 @@ export class KubeApi< */ private async getLatestApiPrefixGroup() { // Note that this.fullApiPathname is the "full" url, whereas this.apiBase is parsed - const rawApiBases = [ - this.fullApiPathname, - this.objectConstructor.apiBase, - ...this.fallbackApiBases ?? [], - ].filter(isDefined); + const rawApiBases = [this.fullApiPathname, this.objectConstructor.apiBase, ...(this.fallbackApiBases ?? [])].filter( + isDefined, + ); const apiBases = new Set(rawApiBases); for (const apiUrl of apiBases) { @@ -348,11 +382,13 @@ export class KubeApi< try { const { apiPrefix, apiGroup, resource } = parsedApi; - const list = await this.request.get(`${apiPrefix}/${apiGroup}`) as KubeApiResourceVersionList; + const list = (await this.request.get(`${apiPrefix}/${apiGroup}`)) as KubeApiResourceVersionList; const resourceVersions = getOrderedVersions(list, this.allowedUsableVersions?.[apiGroup]); for (const resourceVersion of resourceVersions) { - const { resources } = await this.request.get(`${apiPrefix}/${resourceVersion.groupVersion}`) as KubeApiResourceList; + const { resources } = (await this.request.get( + `${apiPrefix}/${resourceVersion.groupVersion}`, + )) as KubeApiResourceList; if (resources.some(({ name }) => name === resource)) { return { @@ -372,7 +408,9 @@ export class KubeApi< protected async checkPreferredVersion() { if (!this.doCheckPreferredVersion && (this.fallbackApiBases || this.allowedUsableVersions)) { - throw new Error("checkPreferredVersion must be enabled if either fallbackApiBases or allowedUsableVersions are set in KubeApi"); + throw new Error( + "checkPreferredVersion must be enabled if either fallbackApiBases or allowedUsableVersions are set in KubeApi", + ); } if (this.doCheckPreferredVersion && this.apiVersionPreferred === undefined) { @@ -385,6 +423,7 @@ export class KubeApi< } } + // eslint-disable-next-line @typescript-eslint/default-param-last setResourceVersion(namespace = "", newVersion: string) { this.resourceVersions.set(namespace, newVersion); } @@ -415,9 +454,7 @@ export class KubeApi< apiPrefix: this.apiPrefix, apiVersion: this.apiVersionWithGroup, resource: this.apiResource, - namespace: this.isNamespaced - ? namespace ?? "default" - : undefined, + namespace: this.isNamespaced ? namespace ?? "default" : undefined, }); return resourcePath + (query ? `?${stringify(this.normalizeQuery(query))}` : ""); @@ -431,9 +468,7 @@ export class KubeApi< apiPrefix: this.apiPrefix, apiVersion: this.apiVersionWithGroup, resource: this.apiResource, - namespace: this.isNamespaced - ? namespace || "default" - : undefined, + namespace: this.isNamespaced ? namespace || "default" : undefined, name, }); } @@ -512,7 +547,9 @@ export class KubeApi< .map((data) => new KubeObjectConstructor(data as Data)); } - private ensureMetadataSelfLink(metadata: T): asserts metadata is T & { selfLink: string } { + private ensureMetadataSelfLink( + metadata: T, + ): asserts metadata is T & { selfLink: string } { metadata.selfLink ||= createKubeApiURL({ apiPrefix: this.apiPrefix, apiVersion: this.apiVersionWithGroup, @@ -522,7 +559,10 @@ export class KubeApi< }); } - async list({ namespace = "", reqInit }: KubeApiListOptions = {}, query?: KubeApiQueryParams): Promise { + async list( + { namespace = "", reqInit }: KubeApiListOptions = {}, + query?: KubeApiQueryParams, + ): Promise { await this.checkPreferredVersion(); const url = this.formatUrlForListing(namespace); @@ -554,7 +594,10 @@ export class KubeApi< return parsed; } - async create({ name, namespace }: Partial, partialData?: PartialDeep): Promise { + async create( + { name, namespace }: Partial, + partialData?: PartialDeep, + ): Promise { await this.checkPreferredVersion(); const apiUrl = this.formatUrlForNotListing({ namespace }); @@ -609,7 +652,6 @@ export class KubeApi< return res as Scale; } - /** * An internal method for requesting the `/scale` sub-resource if it exists */ @@ -617,30 +659,50 @@ export class KubeApi< await this.checkPreferredVersion(); const apiUrl = this.formatUrlForNotListing(desc); - const res = await this.request.patch(`${apiUrl}/scale`, { - data: { ...data }, - }, { - headers: { - "content-type": patchTypeHeaders.merge, + const res = await this.request.patch( + `${apiUrl}/scale`, + { + data: { ...data }, }, - }); + { + headers: { + "content-type": patchTypeHeaders.merge, + }, + }, + ); return res as Scale; } async patch(desc: ResourceDescriptor, data: PartialDeep): Promise; - async patch(desc: ResourceDescriptor, data: PartialDeep, strategy: "strategic" | "merge"): Promise; + async patch( + desc: ResourceDescriptor, + data: PartialDeep, + strategy: "strategic" | "merge", + ): Promise; async patch(desc: ResourceDescriptor, data: Patch, strategy: "json"): Promise; - async patch(desc: ResourceDescriptor, data: PartialDeep | Patch, strategy: KubeApiPatchType): Promise; - async patch(desc: ResourceDescriptor, data: PartialDeep | Patch, strategy: KubeApiPatchType = "strategic"): Promise { + async patch( + desc: ResourceDescriptor, + data: PartialDeep | Patch, + strategy: KubeApiPatchType, + ): Promise; + async patch( + desc: ResourceDescriptor, + data: PartialDeep | Patch, + strategy: KubeApiPatchType = "strategic", + ): Promise { await this.checkPreferredVersion(); const apiUrl = this.formatUrlForNotListing(desc); - const res = await this.request.patch(apiUrl, { data }, { - headers: { - "content-type": patchTypeHeaders[strategy], + const res = await this.request.patch( + apiUrl, + { data }, + { + headers: { + "content-type": patchTypeHeaders[strategy], + }, }, - }); + ); const parsed = this.parseResponse(res); if (Array.isArray(parsed)) { @@ -691,27 +753,31 @@ export class KubeApi< // Create AbortController for this request const abortController = new WrappedAbortController(opts?.abortController); + const watchUrl = this.getWatchUrl(namespace); abortController.signal.addEventListener("abort", () => { this.dependencies.logger.info(`[KUBE-API] watch (${watchId}) aborted ${watchUrl}`); clearTimeout(timedRetry); }); - const requestParams = timeout ? { query: { timeoutSeconds: timeout }} : {}; - const watchUrl = this.getWatchUrl(namespace); + const requestParams = timeout ? { query: { timeoutSeconds: timeout } } : {}; const responsePromise = this.request.getResponse(watchUrl, requestParams, { signal: abortController.signal, }); - this.dependencies.logger.info(`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`); + this.dependencies.logger.info( + `[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`, + ); responsePromise - .then(response => { + .then((response) => { // True if the current watch request was retried let requestRetried = false; if (!response.ok) { - this.dependencies.logger.warn(`[KUBE-API] watch (${watchId}) error response ${watchUrl}`, { status: response.status }); + this.dependencies.logger.warn(`[KUBE-API] watch (${watchId}) error response ${watchUrl}`, { + status: response.status, + }); return callback(null, response); } @@ -746,7 +812,8 @@ export class KubeApi< requestRetried = true; clearTimeout(timedRetry); - timedRetry = setTimeout(() => { // we did not get any kubernetes errors so let's retry + timedRetry = setTimeout(() => { + // we did not get any kubernetes errors so let's retry this.watch({ ...opts, namespace, callback, watchId, retry: true }); }, 1000); @@ -754,6 +821,7 @@ export class KubeApi< } for (const eventName of ["end", "close", "error"]) { + // eslint-disable-next-line @typescript-eslint/no-loop-func response.body.on(eventName, () => { // We only retry if we haven't retried, haven't aborted and haven't received k8s error // kubernetes errors (=errorReceived set) should be handled in a callback @@ -766,7 +834,8 @@ export class KubeApi< requestRetried = true; clearTimeout(timedRetry); - timedRetry = setTimeout(() => { // we did not get any kubernetes errors so let's retry + timedRetry = setTimeout(() => { + // we did not get any kubernetes errors so let's retry this.watch({ ...opts, namespace, callback, watchId, retry: true }); }, 1000); }); diff --git a/packages/core/src/common/k8s-api/kube-json-api.ts b/packages/utility-features/kube-api/src/kube-json-api.ts similarity index 100% rename from packages/core/src/common/k8s-api/kube-json-api.ts rename to packages/utility-features/kube-api/src/kube-json-api.ts diff --git a/packages/core/src/common/k8s-api/kube-watch-event.ts b/packages/utility-features/kube-api/src/kube-watch-event.ts similarity index 50% rename from packages/core/src/common/k8s-api/kube-watch-event.ts rename to packages/utility-features/kube-api/src/kube-watch-event.ts index bcef6c234f..fe47f3a97e 100644 --- a/packages/core/src/common/k8s-api/kube-watch-event.ts +++ b/packages/utility-features/kube-api/src/kube-watch-event.ts @@ -5,11 +5,12 @@ import type { KubeStatusData } from "@k8slens/kube-object"; -export type IKubeWatchEvent = { - readonly type: "ADDED" | "MODIFIED" | "DELETED"; - readonly object: T; -} | { - readonly type: "ERROR"; - readonly object?: KubeStatusData; -}; - +export type IKubeWatchEvent = + | { + readonly type: "ADDED" | "MODIFIED" | "DELETED"; + readonly object: T; + } + | { + readonly type: "ERROR"; + readonly object?: KubeStatusData; + }; diff --git a/packages/utility-features/kube-api/src/mock-responses.ts b/packages/utility-features/kube-api/src/mock-responses.ts new file mode 100644 index 0000000000..8920e50862 --- /dev/null +++ b/packages/utility-features/kube-api/src/mock-responses.ts @@ -0,0 +1,78 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { Response, Headers as NodeFetchHeaders } from "@k8slens/node-fetch"; +import { PassThrough } from "stream"; + +export const createMockResponseFromString = (url: string, data: string, statusCode = 200) => { + const res: jest.Mocked = { + buffer: jest.fn(async () => { + throw new Error("buffer() is not supported"); + }), + clone: jest.fn(() => res), + arrayBuffer: jest.fn(async () => { + throw new Error("arrayBuffer() is not supported"); + }), + blob: jest.fn(async () => { + throw new Error("blob() is not supported"); + }), + body: new PassThrough(), + bodyUsed: false, + headers: new NodeFetchHeaders(), + json: jest.fn(async () => JSON.parse(await res.text())), + ok: 200 <= statusCode && statusCode < 300, + redirected: 300 <= statusCode && statusCode < 400, + size: data.length, + status: statusCode, + statusText: "some-text", + text: jest.fn(async () => data), + type: "basic", + url, + formData: jest.fn(async () => { + throw new Error("formData() is not supported"); + }), + }; + + return res; +}; + +export const createMockResponseFromStream = (url: string, stream: NodeJS.ReadableStream, statusCode = 200) => { + const res: jest.Mocked = { + buffer: jest.fn(async () => { + throw new Error("buffer() is not supported"); + }), + clone: jest.fn(() => res), + arrayBuffer: jest.fn(async () => { + throw new Error("arrayBuffer() is not supported"); + }), + blob: jest.fn(async () => { + throw new Error("blob() is not supported"); + }), + body: stream, + bodyUsed: false, + headers: new NodeFetchHeaders(), + json: jest.fn(async () => JSON.parse(await res.text())), + ok: 200 <= statusCode && statusCode < 300, + redirected: 300 <= statusCode && statusCode < 400, + size: 10, + status: statusCode, + statusText: "some-text", + text: jest.fn(() => { + const chunks: Buffer[] = []; + + return new Promise((resolve, reject) => { + stream.on("data", (chunk) => chunks.push(Buffer.from(chunk))); + stream.on("error", (err) => reject(err)); + stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8"))); + }); + }), + type: "basic", + url, + formData: jest.fn(async () => { + throw new Error("formData() is not supported"); + }), + }; + + return res; +}; diff --git a/packages/core/src/common/k8s-api/prepend.ts b/packages/utility-features/kube-api/src/prepend.ts similarity index 87% rename from packages/core/src/common/k8s-api/prepend.ts rename to packages/utility-features/kube-api/src/prepend.ts index 698de3f293..75298417bf 100644 --- a/packages/core/src/common/k8s-api/prepend.ts +++ b/packages/utility-features/kube-api/src/prepend.ts @@ -2,5 +2,4 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -export const prepend = (prependWith: string) => (what: string) => - `${prependWith}${what}`; +export const prepend = (prependWith: string) => (what: string) => `${prependWith}${what}`; diff --git a/packages/utility-features/kube-api/tsconfig.json b/packages/utility-features/kube-api/tsconfig.json new file mode 100644 index 0000000000..d140381aa7 --- /dev/null +++ b/packages/utility-features/kube-api/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "@k8slens/typescript/config/base.json", + "include": ["**/*.ts"], + "compilerOptions": { + "moduleResolution": "node" + } +} diff --git a/packages/utility-features/kube-api/webpack.config.js b/packages/utility-features/kube-api/webpack.config.js new file mode 100644 index 0000000000..b54738d0a7 --- /dev/null +++ b/packages/utility-features/kube-api/webpack.config.js @@ -0,0 +1 @@ +module.exports = require("@k8slens/webpack").configForReact; \ No newline at end of file