From b96e115e17e884d6cab73f5f29c11fa2ca204402 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 7 Nov 2022 14:21:05 -0500 Subject: [PATCH] Fix type errors Signed-off-by: Sebastian Malton --- src/common/cluster/cluster.ts | 3 +-- src/main/get-metrics.injectable.ts | 10 +++++++--- src/main/lens-proxy/stop-proxy-on-quit.injectable.ts | 6 +++--- .../runnables/lens-proxy/teardown.injectable.ts | 4 +--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/common/cluster/cluster.ts b/src/common/cluster/cluster.ts index ff0857869d..c44b9b8e1a 100644 --- a/src/common/cluster/cluster.ts +++ b/src/common/cluster/cluster.ts @@ -17,7 +17,6 @@ import plimit from "p-limit"; import type { ClusterState, ClusterMetricsResourceType, ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, UpdateClusterModel, KubeAuthUpdate, ClusterConfigData } from "../cluster-types"; import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus, clusterModelIdChecker, updateClusterModelChecker } from "../cluster-types"; import { disposer, isDefined, isRequestError, toJS } from "../utils"; -import type { Response } from "request"; import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster"; import type { CanI } from "./authorization-review.injectable"; import type { ListNamespacesFor } from "./list-namespaces.injectable"; @@ -652,7 +651,7 @@ export class Cluster implements ClusterModel { const namespaceList = [ctx?.namespace].filter(isDefined); if (namespaceList.length === 0 && error instanceof HttpError && error.statusCode === 403) { - const { response } = error as HttpError & { response: Response }; + const { response } = error as HttpError & { response: { body: unknown }}; this.dependencies.logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error: response.body }); this.dependencies.broadcastMessage(clusterListNamespaceForbiddenChannel, this.id); diff --git a/src/main/get-metrics.injectable.ts b/src/main/get-metrics.injectable.ts index 0ceaf01735..94eb9223e1 100644 --- a/src/main/get-metrics.injectable.ts +++ b/src/main/get-metrics.injectable.ts @@ -3,6 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import FormData from "form-data"; import type { Cluster } from "../common/cluster/cluster"; import type { RequestMetricsParams } from "../common/k8s-api/endpoints/metrics.api/request-metrics.injectable"; import k8sRequestInjectable from "./k8s-request.injectable"; @@ -22,13 +23,16 @@ const getMetricsInjectable = getInjectable({ ) => { const prometheusPrefix = cluster.preferences.prometheus?.prefix || ""; const metricsPath = `/api/v1/namespaces/${prometheusPath}/proxy${prometheusPrefix}/api/v1/query_range`; + const body = new FormData(); + + for (const [key, value] of Object.entries(queryParams)) { + body.append(key, value); + } return k8sRequest(cluster, metricsPath, { timeout: 0, - resolveWithFullResponse: false, - json: true, method: "POST", - form: queryParams, + body, }); }; }, diff --git a/src/main/lens-proxy/stop-proxy-on-quit.injectable.ts b/src/main/lens-proxy/stop-proxy-on-quit.injectable.ts index 71132527fa..3e939cc044 100644 --- a/src/main/lens-proxy/stop-proxy-on-quit.injectable.ts +++ b/src/main/lens-proxy/stop-proxy-on-quit.injectable.ts @@ -4,6 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { beforeQuitOfBackEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token"; +import stopSettingUpLensProxyInjectable from "../start-main-application/runnables/lens-proxy/teardown.injectable"; import lensProxyInjectable from "./lens-proxy.injectable"; const stopLensProxyOnQuitInjectable = getInjectable({ @@ -13,9 +14,8 @@ const stopLensProxyOnQuitInjectable = getInjectable({ return { id: "stop-lens-proxy", - run: () => { - lensProxy.close(); - }, + run: () => void lensProxy.close(), + runAfter: di.inject(stopSettingUpLensProxyInjectable), }; }, injectionToken: beforeQuitOfBackEndInjectionToken, diff --git a/src/main/start-main-application/runnables/lens-proxy/teardown.injectable.ts b/src/main/start-main-application/runnables/lens-proxy/teardown.injectable.ts index 84cde3b0af..9c715d1ba9 100644 --- a/src/main/start-main-application/runnables/lens-proxy/teardown.injectable.ts +++ b/src/main/start-main-application/runnables/lens-proxy/teardown.injectable.ts @@ -13,9 +13,7 @@ const stopSettingUpLensProxyInjectable = getInjectable({ return { id: "stop-setting-up-lens-proxy", - run: () => { - setupLensProxyStartableStoppable.stop(); - }, + run: () => void setupLensProxyStartableStoppable.stop(), }; }, injectionToken: beforeQuitOfBackEndInjectionToken,