mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert runMany and runManySync to use injectManyWithMeta + move to seperate package (#7244)
* Convert runMany and runManySync to use injectManyWithMeta Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup type errors due to new Runnable requirements Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add documentation for verifyRunnablesAreDAG Signed-off-by: Sebastian Malton <sebastian@malton.name> * Simplify convertToWithIdWith Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move all utility functions to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move testing utilities to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move run-many and run-many-sync to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace all internal uses of utilities with new packages Signed-off-by: Sebastian Malton <sebastian@malton.name> * Use new @k8slens/run-many package in core Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add dep to open-lens Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup uses of @k8slens/test-utils Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup getGlobalOverride Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move tests to new package too Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup uses of AsyncResult and autoBind Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup remaining import issues Signed-off-by: Sebastian Malton <sebastian@malton.name> * Finial fixups to fix build Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Revert moving "testUsingFakeTime" to separate package - This fixes tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix integration tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix unit test failing due to spelling fix Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ad9bafe2a5
commit
2789bcebcb
754 files changed
+2715
-2752
No files matched your search
@@ -10,7 +10,7 @@ import type { Fetch } from "../../fetch/fetch.injectable";
|
||||
import fetchInjectable from "../../fetch/fetch.injectable";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import { flushPromises } from "../../test-utils/flush-promises";
|
||||
import { flushPromises } from "@k8slens/test-utils";
|
||||
import setupAutoRegistrationInjectable from "../../../renderer/before-frame-starts/runnables/setup-auto-registration.injectable";
|
||||
import { createMockResponseFromString } from "../../../test-utils/mock-responses";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable";
|
||||
@@ -119,7 +119,7 @@ describe("KubeApi", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
describe("when resource request fufills with a resource", () => {
|
||||
describe("when resource request fulfills with a resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1"],
|
||||
@@ -281,7 +281,7 @@ describe("KubeApi", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when resource request fufills with no resource", () => {
|
||||
describe("when resource request fulfills with no resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1"],
|
||||
@@ -305,7 +305,7 @@ describe("KubeApi", () => {
|
||||
|
||||
|
||||
|
||||
describe("when resource request fufills with a resource", () => {
|
||||
describe("when resource request fulfills with a resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1"],
|
||||
@@ -507,7 +507,7 @@ describe("KubeApi", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
describe("when resource request fufills with a resource", () => {
|
||||
describe("when resource request fulfills with a resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/extensions"],
|
||||
|
||||
@@ -15,7 +15,7 @@ import type { CreateKubeApiForRemoteCluster } from "../create-kube-api-for-remot
|
||||
import createKubeApiForRemoteClusterInjectable from "../create-kube-api-for-remote-cluster.injectable";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import { flushPromises } from "../../test-utils/flush-promises";
|
||||
import { flushPromises } from "@k8slens/test-utils";
|
||||
import createKubeJsonApiInjectable from "../create-kube-json-api.injectable";
|
||||
import type { IKubeWatchEvent } from "../kube-watch-event";
|
||||
import type { KubeJsonApiDataFor } from "../kube-object";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { noop } from "../../utils";
|
||||
import { noop } from "@k8slens/utilities";
|
||||
import type { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeObjectStoreLoadingParams } from "../kube-object.store";
|
||||
|
||||
@@ -10,7 +10,7 @@ import { autorun, action, observable } from "mobx";
|
||||
import type { KubeApi } from "../kube-api";
|
||||
import type { KubeObject, ObjectReference } from "../kube-object";
|
||||
import { parseKubeApi, createKubeApiURL } from "../kube-api-parse";
|
||||
import { chain, find } from "../../utils/iter";
|
||||
import { iter } from "@k8slens/utilities";
|
||||
|
||||
export type RegisterableStore<Store> = Store extends KubeObjectStore<any, any, any>
|
||||
? Store
|
||||
@@ -38,7 +38,7 @@ export class ApiManager {
|
||||
constructor(private readonly dependencies: Dependencies) {
|
||||
// NOTE: this is done to preserve the old behaviour of an API being discoverable using all previous apiBases
|
||||
autorun(() => {
|
||||
const apis = chain(this.dependencies.apis.get().values())
|
||||
const apis = iter.chain(this.dependencies.apis.get().values())
|
||||
.concat(this.externalApis.values());
|
||||
const removedApis = new Set(this.apis.values());
|
||||
const newState = new Map(this.apis);
|
||||
@@ -62,7 +62,7 @@ export class ApiManager {
|
||||
|
||||
getApi(pathOrCallback: string | FindApiCallback) {
|
||||
if (typeof pathOrCallback === "function") {
|
||||
return find(this.apis.values(), pathOrCallback);
|
||||
return iter.find(this.apis.values(), pathOrCallback);
|
||||
}
|
||||
|
||||
const { apiBase } = parseKubeApi(pathOrCallback);
|
||||
@@ -130,7 +130,7 @@ export class ApiManager {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return chain(this.dependencies.stores.get().values())
|
||||
return iter.chain(this.dependencies.stores.get().values())
|
||||
.concat(this.externalStores.values())
|
||||
.find(store => store.api.apiBase === api.apiBase);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { autoBind } from "../../utils";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export interface ConfigMapData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
|
||||
data?: Partial<Record<string, string>>;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import moment from "moment";
|
||||
import type { NamespaceScopedMetadata, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { formatDuration } from "../../utils/formatDuration";
|
||||
import { formatDuration } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { JobTemplateSpec } from "./types/job-template-spec";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import customResourcesRouteInjectable from "../../front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
|
||||
import { buildURL } from "../../utils/buildUrl";
|
||||
import { buildURL } from "@k8slens/utilities";
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
|
||||
@@ -10,7 +10,7 @@ import { KubeApi } from "../kube-api";
|
||||
import type { PodSpec } from "./pod.api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isNumber, isObject } from "../../utils";
|
||||
import { hasTypedProperty, isNumber, isObject } from "@k8slens/utilities";
|
||||
|
||||
export class DeploymentApi extends KubeApi<Deployment> {
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { autoBind } from "../../utils";
|
||||
import autoBind from "auto-bind";
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import moment from "moment";
|
||||
import type { KubeObjectMetadata, KubeObjectScope, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { formatDuration } from "../../utils/formatDuration";
|
||||
import { formatDuration } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { autoBind, bifurcateArray } from "../../utils";
|
||||
import { array } from "@k8slens/utilities";
|
||||
import autoBind from "auto-bind";
|
||||
import Joi from "joi";
|
||||
|
||||
export interface RawHelmChart {
|
||||
@@ -263,7 +264,7 @@ export class HelmChart implements HelmChartData {
|
||||
return new HelmChart(result.value);
|
||||
}
|
||||
|
||||
const [actualErrors, unknownDetails] = bifurcateArray(result.error.details, ({ type }) => type === "object.unknown");
|
||||
const [actualErrors, unknownDetails] = array.bifurcate(result.error.details, ({ type }) => type === "object.unknown");
|
||||
|
||||
if (unknownDetails.length > 0) {
|
||||
console.warn("HelmChart data has unexpected fields", { original: data, unknownFields: unknownDetails.flatMap(d => d.path) });
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { RawHelmChart } from "../helm-charts.api";
|
||||
import { HelmChart } from "../helm-charts.api";
|
||||
import { isDefined } from "../../../utils";
|
||||
import { isDefined } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmCharts = () => Promise<HelmChart[]>;
|
||||
|
||||
+3
-3
@@ -3,13 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestReadmeEndpoint = urlBuilderFor("/v2/charts/:repo/:name/readme");
|
||||
|
||||
export type RequestHelmChartReadme = (repo: string, name: string, version?: string) => Promise<AsyncResult<string>>;
|
||||
export type RequestHelmChartReadme = (repo: string, name: string, version?: string) => AsyncResult<string>;
|
||||
|
||||
const requestHelmChartReadmeInjectable = getInjectable({
|
||||
id: "request-helm-chart-readme",
|
||||
|
||||
+3
-3
@@ -3,13 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values");
|
||||
|
||||
export type RequestHelmChartValues = (repo: string, name: string, version: string) => Promise<AsyncResult<string>>;
|
||||
export type RequestHelmChartValues = (repo: string, name: string, version: string) => AsyncResult<string>;
|
||||
|
||||
const requestHelmChartValuesInjectable = getInjectable({
|
||||
id: "request-helm-chart-values",
|
||||
|
||||
+1
-2
@@ -3,10 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor, isDefined } from "@k8slens/utilities";
|
||||
import { HelmChart } from "../helm-charts.api";
|
||||
import type { RawHelmChart } from "../helm-charts.api";
|
||||
import { isDefined } from "../../../utils";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestVersionsEndpoint = urlBuilderFor("/v2/charts/:repo/:name/versions");
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../../../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import requestHelmReleaseConfigurationInjectable from "./request-configuration.injectable";
|
||||
|
||||
export default getGlobalOverride(requestHelmReleaseConfigurationInjectable, () => () => {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseConfiguration = (
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import yaml from "js-yaml";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { HelmReleaseUpdateDetails } from "../helm-releases.api";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
interface HelmReleaseCreatePayload {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestDeleteHelmRelease = (name: string, namespace: string) => Promise<void>;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export interface HelmReleaseDetails {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export interface HelmReleaseRevision {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { HelmReleaseDto } from "../helm-releases.api";
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseRollback = (name: string, namespace: string, revision: number) => Promise<void>;
|
||||
|
||||
+3
-3
@@ -3,8 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
interface HelmReleaseUpdatePayload {
|
||||
@@ -18,7 +18,7 @@ export type RequestHelmReleaseUpdate = (
|
||||
name: string,
|
||||
namespace: string,
|
||||
payload: HelmReleaseUpdatePayload
|
||||
) => Promise<AsyncResult<void, unknown>>;
|
||||
) => AsyncResult<void, unknown>;
|
||||
|
||||
const requestUpdateEndpoint = urlBuilderFor("/v2/releases/:namespace/:name");
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseValues = (name: string, namespace: string, all?: boolean) => Promise<string>;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { OptionVarient } from "../../utils";
|
||||
import type { OptionVariant } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
@@ -46,7 +46,7 @@ export interface V2Beta1ContainerResourceMetricSource {
|
||||
targetAverageValue?: string;
|
||||
}
|
||||
|
||||
export type ContainerResourceMetricSource =
|
||||
export type ContainerResourceMetricSource =
|
||||
| V2ContainerResourceMetricSource
|
||||
| V2Beta1ContainerResourceMetricSource;
|
||||
|
||||
@@ -74,7 +74,7 @@ export interface V2Beta1ExternalMetricSource {
|
||||
};
|
||||
}
|
||||
|
||||
export type ExternalMetricSource =
|
||||
export type ExternalMetricSource =
|
||||
| V2Beta1ExternalMetricSource
|
||||
| V2ExternalMetricSource;
|
||||
|
||||
@@ -152,11 +152,11 @@ export interface BaseHorizontalPodAutoscalerMetricSpec {
|
||||
}
|
||||
|
||||
export type HorizontalPodAutoscalerMetricSpec =
|
||||
| OptionVarient<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricSpec, "resource">
|
||||
| OptionVarient<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricSpec, "external">
|
||||
| OptionVarient<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricSpec, "object">
|
||||
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricSpec, "pods">
|
||||
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricSpec, "containerResource">;
|
||||
| OptionVariant<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricSpec, "resource">
|
||||
| OptionVariant<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricSpec, "external">
|
||||
| OptionVariant<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricSpec, "object">
|
||||
| OptionVariant<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricSpec, "pods">
|
||||
| OptionVariant<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricSpec, "containerResource">;
|
||||
|
||||
interface HorizontalPodAutoscalerBehavior {
|
||||
scaleUp?: HPAScalingRules;
|
||||
@@ -294,11 +294,11 @@ export interface BaseHorizontalPodAutoscalerMetricStatus {
|
||||
}
|
||||
|
||||
export type HorizontalPodAutoscalerMetricStatus =
|
||||
| OptionVarient<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricStatus, "resource">
|
||||
| OptionVarient<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricStatus, "external">
|
||||
| OptionVarient<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricStatus, "object">
|
||||
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricStatus, "pods">
|
||||
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricStatus, "containerResource">;
|
||||
| OptionVariant<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricStatus, "resource">
|
||||
| OptionVariant<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricStatus, "external">
|
||||
| OptionVariant<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricStatus, "object">
|
||||
| OptionVariant<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricStatus, "pods">
|
||||
| OptionVariant<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricStatus, "containerResource">;
|
||||
|
||||
export interface HorizontalPodAutoscalerSpec {
|
||||
scaleTargetRef: CrossVersionObjectReference;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isString, iter } from "../../utils";
|
||||
import { hasTypedProperty, isString, iter } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { RequireExactlyOne } from "type-fest";
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// Metrics api
|
||||
|
||||
import moment from "moment";
|
||||
import { isDefined, object } from "../../utils";
|
||||
import { isDefined, object } from "@k8slens/utilities";
|
||||
|
||||
export interface MetricData {
|
||||
status: string;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils";
|
||||
import { cpuUnitsToNumber, unitsToBytes, isObject } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { TypedRegEx } from "typed-regex";
|
||||
|
||||
@@ -8,7 +8,7 @@ import { KubeObject } from "../kube-object";
|
||||
import type { Pod } from "./pod.api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { object } from "../../utils";
|
||||
import { object } from "@k8slens/utilities";
|
||||
import type { ResourceRequirements } from "./types/resource-requirements";
|
||||
|
||||
export class PersistentVolumeClaimApi extends KubeApi<PersistentVolumeClaim> {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { ClusterScopedMetadata, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { unitsToBytes } from "../../utils";
|
||||
import { unitsToBytes } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { ResourceRequirements } from "./types/resource-requirements";
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, Na
|
||||
import type { SecretReference } from "./secret.api";
|
||||
import type { PersistentVolumeClaimSpec } from "./persistent-volume-claim.api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { isDefined } from "../../utils";
|
||||
import { isDefined } from "@k8slens/utilities";
|
||||
import type { PodSecurityContext } from "./types/pod-security-context";
|
||||
import type { Probe } from "./types/probe";
|
||||
import type { Container } from "./types/container";
|
||||
|
||||
+3
-3
@@ -5,10 +5,10 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Patch } from "rfc6902";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult, Result } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => AsyncResult<KubeJsonApiData, string>;
|
||||
|
||||
const requestKubeObjectPatchInjectable = getInjectable({
|
||||
id: "request-kube-object-patch",
|
||||
@@ -23,7 +23,7 @@ const requestKubeObjectPatchInjectable = getInjectable({
|
||||
ns,
|
||||
patch,
|
||||
},
|
||||
}) as AsyncResult<string, string>;
|
||||
}) as Result<string, string>;
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
return result;
|
||||
|
||||
+3
-3
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult, Result } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||
export type RequestKubeObjectCreation = (resourceDescriptor: string) => AsyncResult<KubeJsonApiData, string>;
|
||||
|
||||
const requestKubeObjectCreationInjectable = getInjectable({
|
||||
id: "request-kube-object-creation",
|
||||
@@ -15,7 +15,7 @@ const requestKubeObjectCreationInjectable = getInjectable({
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return async (data) => {
|
||||
const result = await apiBase.post("/stack", { data }) as AsyncResult<string, string>;
|
||||
const result = await apiBase.post("/stack", { data }) as Result<string, string>;
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
return result;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { autoBind } from "../../utils";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export enum SecretType {
|
||||
Opaque = "Opaque",
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { autoBind } from "../../utils";
|
||||
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export interface TopologySelectorLabelRequirement {
|
||||
key: string;
|
||||
|
||||
@@ -15,8 +15,8 @@ import type { PartialDeep, ValueOf } from "type-fest";
|
||||
import { EventEmitter } from "../../common/event-emitter";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { Fetch } from "../fetch/fetch.injectable";
|
||||
import type { Defaulted } from "../utils";
|
||||
import { json } from "../utils";
|
||||
import type { Defaulted } from "@k8slens/utilities";
|
||||
import { isObject, isString, json } from "@k8slens/utilities";
|
||||
|
||||
export interface JsonApiData {}
|
||||
|
||||
@@ -184,20 +184,17 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
||||
|
||||
const res = await this.dependencies.fetch(reqUrl, reqInit);
|
||||
|
||||
return this.parseResponse<OutData>(res, infoLog);
|
||||
return await this.parseResponse(res, infoLog) as OutData;
|
||||
}
|
||||
|
||||
protected async parseResponse<OutData>(res: Response, log: JsonApiLog): Promise<OutData> {
|
||||
protected async parseResponse(res: Response, log: JsonApiLog): Promise<Data> {
|
||||
const { status } = res;
|
||||
|
||||
const text = await res.text();
|
||||
let data: any;
|
||||
|
||||
try {
|
||||
data = text ? json.parse(text) : ""; // DELETE-requests might not have response-body
|
||||
} catch (e) {
|
||||
data = text;
|
||||
}
|
||||
const parseResponse = json.parse(text || "{}");
|
||||
const data = parseResponse.callWasSuccessful
|
||||
? parseResponse.response as Data
|
||||
: text as Data;
|
||||
|
||||
if (status >= 200 && status < 300) {
|
||||
this.onData.emit(data, res);
|
||||
@@ -211,7 +208,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
||||
throw data;
|
||||
}
|
||||
|
||||
const error = new JsonApiErrorParsed(data, this.parseError(data, res));
|
||||
const error = new JsonApiErrorParsed(data as JsonApiError, this.parseError(data, res));
|
||||
|
||||
this.onError.emit(error, res);
|
||||
this.writeLog({ ...log, error });
|
||||
@@ -219,16 +216,20 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
||||
throw error;
|
||||
}
|
||||
|
||||
protected parseError(error: JsonApiError | string, res: Response): string[] {
|
||||
if (typeof error === "string") {
|
||||
protected parseError(error: unknown, res: Response): string[] {
|
||||
if (isString(error)) {
|
||||
return [error];
|
||||
}
|
||||
|
||||
if (!isObject(error)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (Array.isArray(error.errors)) {
|
||||
return error.errors.map(error => error.title);
|
||||
}
|
||||
|
||||
if (error.message) {
|
||||
if (isString(error.message)) {
|
||||
return [error.message];
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
// Parse kube-api path and get api-version, group, etc.
|
||||
|
||||
import { splitArray } from "../utils";
|
||||
import { array } from "@k8slens/utilities";
|
||||
|
||||
export interface IKubeApiLinkRef {
|
||||
apiPrefix?: string;
|
||||
@@ -26,7 +26,7 @@ export function parseKubeApi(path: string): IKubeApiParsed {
|
||||
const apiPath = new URL(path, "https://localhost").pathname;
|
||||
const [, prefix, ...parts] = apiPath.split("/");
|
||||
const apiPrefix = `/${prefix}`;
|
||||
const [left, right, namespaced] = splitArray(parts, "namespaces");
|
||||
const [left, right, namespaced] = array.split(parts, "namespaces");
|
||||
let apiGroup!: string;
|
||||
let apiVersion!: string;
|
||||
let namespace!: string;
|
||||
|
||||
@@ -13,8 +13,8 @@ import { KubeObject, KubeStatus, isKubeStatusData } from "./kube-object";
|
||||
import byline from "byline";
|
||||
import type { IKubeWatchEvent } from "./kube-watch-event";
|
||||
import type { KubeJsonApiData, KubeJsonApi } from "./kube-json-api";
|
||||
import type { Disposer } from "../utils";
|
||||
import { isDefined, noop, WrappedAbortController } from "../utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { isDefined, noop, WrappedAbortController } from "@k8slens/utilities";
|
||||
import type { RequestInit, Response } from "@k8slens/node-fetch";
|
||||
import type { Patch } from "rfc6902";
|
||||
import assert from "assert";
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
*/
|
||||
|
||||
import { action, computed, makeObservable, observable, reaction } from "mobx";
|
||||
import type { Disposer } from "../utils";
|
||||
import { waitUntilDefined, autoBind, includes, rejectPromiseBy } from "../utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { waitUntilDefined, includes, rejectPromiseBy, object } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiDataFor, KubeObject } from "./kube-object";
|
||||
import { KubeStatus } from "./kube-object";
|
||||
import type { IKubeWatchEvent } from "./kube-watch-event";
|
||||
@@ -17,9 +17,9 @@ import type { Patch } from "rfc6902";
|
||||
import type { Logger } from "../logger";
|
||||
import assert from "assert";
|
||||
import type { PartialDeep } from "type-fest";
|
||||
import { entries } from "../utils/objects";
|
||||
import AbortController from "abort-controller";
|
||||
import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export type OnLoadFailure = (error: unknown) => void;
|
||||
|
||||
@@ -179,7 +179,7 @@ export abstract class KubeObjectStore<
|
||||
return this.items.filter((item: K) => {
|
||||
const itemLabels = item.metadata.labels || {};
|
||||
|
||||
return entries(labels)
|
||||
return object.entries(labels)
|
||||
.every(([key, value]) => itemLabels[key] === value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import moment from "moment";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList, KubeJsonApiListMetadata } from "./kube-json-api";
|
||||
import { autoBind, formatDuration, hasOptionalTypedProperty, hasTypedProperty, isObject, isString, isNumber, bindPredicate, isTypedArray, isRecord, json } from "../utils";
|
||||
import { formatDuration, hasOptionalTypedProperty, hasTypedProperty, isObject, isString, isNumber, bindPredicate, isTypedArray, isRecord } from "@k8slens/utilities";
|
||||
import type { ItemObject } from "../item.store";
|
||||
import type { Patch } from "rfc6902";
|
||||
import assert from "assert";
|
||||
@@ -17,6 +17,7 @@ import { apiKubeInjectionToken } from "./api-kube";
|
||||
import requestKubeObjectCreationInjectable from "./endpoints/resource-applier.api/request-update.injectable";
|
||||
import { dump } from "js-yaml";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export type KubeJsonApiDataFor<K> = K extends KubeObject<infer Metadata, infer Status, infer Spec>
|
||||
? KubeJsonApiData<Metadata, Status, Spec>
|
||||
@@ -624,7 +625,7 @@ export class KubeObject<
|
||||
}
|
||||
|
||||
toPlainObject() {
|
||||
return json.parse(JSON.stringify(this)) as JsonObject;
|
||||
return JSON.parse(JSON.stringify(this)) as JsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import windowLocationInjectable from "./window-location.injectable";
|
||||
|
||||
export default getGlobalOverride(windowLocationInjectable, () => ({
|
||||
|
||||
Reference in new issue
Block a user