diff --git a/extensions/metrics-cluster-feature/src/metrics-feature.ts b/extensions/metrics-cluster-feature/src/metrics-feature.ts index cb536072b5..3401773cdc 100644 --- a/extensions/metrics-cluster-feature/src/metrics-feature.ts +++ b/extensions/metrics-cluster-feature/src/metrics-feature.ts @@ -109,6 +109,8 @@ export class MetricsFeature { } catch(e) { if (e?.error?.code === 404) { status.installed = false; + } else { + console.warn("[LENS-METRICS] failed to resolve install state", e); } } diff --git a/package.json b/package.json index 192d94a8cf..1bad46ade7 100644 --- a/package.json +++ b/package.json @@ -293,7 +293,7 @@ "@types/proper-lockfile": "^4.1.1", "@types/randomcolor": "^0.5.5", "@types/react": "^17.0.0", - "@types/react-beautiful-dnd": "^13.0.0", + "@types/react-beautiful-dnd": "^13.1.1", "@types/react-dom": "^17.0.6", "@types/react-router-dom": "^5.1.6", "@types/react-select": "3.1.2", @@ -318,7 +318,7 @@ "@types/webpack-env": "^1.15.2", "@types/webpack-node-externals": "^1.7.1", "@typescript-eslint/eslint-plugin": "^4.29.0", - "@typescript-eslint/parser": "^4.0.0", + "@typescript-eslint/parser": "^4.29.1", "ansi_up": "^5.0.0", "chart.js": "^2.9.4", "circular-dependency-plugin": "^5.2.2", diff --git a/src/common/k8s-api/index.ts b/src/common/k8s-api/index.ts index 791ee09285..e464c307d7 100644 --- a/src/common/k8s-api/index.ts +++ b/src/common/k8s-api/index.ts @@ -23,19 +23,28 @@ import { JsonApi } from "./json-api"; import { KubeJsonApi } from "./kube-json-api"; import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars"; import { isClusterPageContext } from "../utils/cluster-id-url-parsing"; +import { appEventBus } from "../event-bus"; let apiBase: JsonApi; let apiKube: KubeJsonApi; if (typeof window === "undefined") { - apiBase = new JsonApi({ - serverAddress: `http://127.0.0.1:${process.env.LENS_PROXY_PORT}`, - apiBase: apiPrefix, - debug: isDevelopment || isDebugging, - }, { - headers: { - "Host": `localhost:${process.env.LENS_PROXY_PORT}` - } + appEventBus.addListener((event) => { + if (event.name !== "lens-proxy" && event.action !== "listen") return; + + const params = event.params as { port?: number }; + + if (!params.port) return; + + apiBase = new JsonApi({ + serverAddress: `http://127.0.0.1:${params.port}`, + apiBase: apiPrefix, + debug: isDevelopment || isDebugging, + }, { + headers: { + "Host": `localhost:${params.port}` + } + }); }); } else { apiBase = new JsonApi({ diff --git a/src/common/k8s-api/kube-api.ts b/src/common/k8s-api/kube-api.ts index 1131119a3b..79c750dae7 100644 --- a/src/common/k8s-api/kube-api.ts +++ b/src/common/k8s-api/kube-api.ts @@ -96,13 +96,14 @@ export interface IKubeApiCluster { } export function forCluster(cluster: IKubeApiCluster, kubeClass: KubeObjectConstructor): KubeApi { + const url = new URL(apiBase.config.serverAddress); const request = new KubeJsonApi({ serverAddress: apiBase.config.serverAddress, apiBase: apiKubePrefix, debug: isDevelopment, }, { headers: { - "Host": apiBase.config.serverAddress + "Host": `${cluster.metadata.uid}.localhost:${url.port}` } }); diff --git a/src/common/k8s-api/kube-object.store.ts b/src/common/k8s-api/kube-object.store.ts index 3215306d93..dc428eb08b 100644 --- a/src/common/k8s-api/kube-object.store.ts +++ b/src/common/k8s-api/kube-object.store.ts @@ -42,7 +42,7 @@ export interface KubeObjectStoreLoadingParams { export abstract class KubeObjectStore extends ItemStore { static defaultContext = observable.box(); // TODO: support multiple cluster contexts - abstract api: KubeApi; + public api: KubeApi; public readonly limit?: number; public readonly bufferSize: number = 50000; @observable private loadedNamespaces?: string[]; @@ -55,8 +55,10 @@ export abstract class KubeObjectStore extends ItemStore return when(() => Boolean(this.loadedNamespaces)); } - constructor() { + constructor(api?: KubeApi) { super(); + if (api) this.api = api; + makeObservable(this); autoBind(this); this.bindWatchEventsUpdater(); diff --git a/src/extensions/main-api/k8s-api.ts b/src/extensions/main-api/k8s-api.ts index 991415cc56..0664cbc1d9 100644 --- a/src/extensions/main-api/k8s-api.ts +++ b/src/extensions/main-api/k8s-api.ts @@ -24,6 +24,7 @@ export { ResourceStack } from "../../common/k8s/resource-stack"; export { apiManager } from "../../common/k8s-api/api-manager"; export { KubeApi, forCluster } from "../../common/k8s-api/kube-api"; export { KubeObject } from "../../common/k8s-api/kube-object"; +export { KubeObjectStore } from "../../common/k8s-api/kube-object.store"; export { Pod, podsApi, PodsApi } from "../../common/k8s-api/endpoints/pods.api"; export { Node, nodesApi, NodesApi } from "../../common/k8s-api/endpoints/nodes.api"; export { Deployment, deploymentApi, DeploymentApi } from "../../common/k8s-api/endpoints/deployment.api"; diff --git a/src/main/lens-proxy.ts b/src/main/lens-proxy.ts index 353ed935e7..3cd5182677 100644 --- a/src/main/lens-proxy.ts +++ b/src/main/lens-proxy.ts @@ -30,6 +30,7 @@ import logger from "./logger"; import { Singleton } from "../common/utils"; import type { Cluster } from "./cluster"; import type { ProxyApiRequestArgs } from "./proxy-functions"; +import { appEventBus } from "../common/event-bus"; type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | null; @@ -97,7 +98,7 @@ export class LensProxy extends Singleton { }); this.port = port; - process.env.LENS_PROXY_PORT = port.toString(); + appEventBus.emit({ name: "lens-proxy", action: "listen", params: { port }}); resolve(); }) .once("error", (error) => { diff --git a/src/renderer/components/+custom-resources/crd-resource.store.ts b/src/renderer/components/+custom-resources/crd-resource.store.ts index f71f8e6400..4eff3d496a 100644 --- a/src/renderer/components/+custom-resources/crd-resource.store.ts +++ b/src/renderer/components/+custom-resources/crd-resource.store.ts @@ -24,10 +24,7 @@ import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { KubeObject } from "../../../common/k8s-api/kube-object"; export class CRDResourceStore extends KubeObjectStore { - api: KubeApi; - constructor(api: KubeApi) { - super(); - this.api = api; + super(api); } } diff --git a/yarn.lock b/yarn.lock index da574d2bd8..1becc3fbb8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1790,10 +1790,10 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== -"@types/react-beautiful-dnd@^13.0.0": - version "13.0.0" - resolved "https://registry.yarnpkg.com/@types/react-beautiful-dnd/-/react-beautiful-dnd-13.0.0.tgz#e60d3d965312fcf1516894af92dc3e9249587db4" - integrity sha512-by80tJ8aTTDXT256Gl+RfLRtFjYbUWOnZuEigJgNsJrSEGxvFe5eY6k3g4VIvf0M/6+xoLgfYWoWonlOo6Wqdg== +"@types/react-beautiful-dnd@^13.1.1": + version "13.1.1" + resolved "https://registry.yarnpkg.com/@types/react-beautiful-dnd/-/react-beautiful-dnd-13.1.1.tgz#fb3fe24a334cc757d290e75722e4d3c8368ce3a3" + integrity sha512-1lBBxVSutE8CQM37Jq7KvJwuA94qaEEqsx+G0dnwzG6Sfwf6JGcNeFk5jjjhJli1q2naeMZm+D/dvT/zyX4QPw== dependencies: "@types/react" "*" @@ -2157,15 +2157,15 @@ eslint-scope "^5.1.1" eslint-utils "^3.0.0" -"@typescript-eslint/parser@^4.0.0": - version "4.8.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.8.2.tgz#78dccbe5124de2b8dea2d4c363dee9f769151ca8" - integrity sha512-u0leyJqmclYr3KcXOqd2fmx6SDGBO0MUNHHAjr0JS4Crbb3C3d8dwAdlazy133PLCcPn+aOUFiHn72wcuc5wYw== +"@typescript-eslint/parser@^4.29.1": + version "4.29.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.29.1.tgz#17dfbb45c9032ffa0fe15881d20fbc2a4bdeb02d" + integrity sha512-3fL5iN20hzX3Q4OkG7QEPFjZV2qsVGiDhEwwh+EkmE/w7oteiOvUNzmpu5eSwGJX/anCryONltJ3WDmAzAoCMg== dependencies: - "@typescript-eslint/scope-manager" "4.8.2" - "@typescript-eslint/types" "4.8.2" - "@typescript-eslint/typescript-estree" "4.8.2" - debug "^4.1.1" + "@typescript-eslint/scope-manager" "4.29.1" + "@typescript-eslint/types" "4.29.1" + "@typescript-eslint/typescript-estree" "4.29.1" + debug "^4.3.1" "@typescript-eslint/scope-manager@4.29.0": version "4.29.0" @@ -2175,23 +2175,23 @@ "@typescript-eslint/types" "4.29.0" "@typescript-eslint/visitor-keys" "4.29.0" -"@typescript-eslint/scope-manager@4.8.2": - version "4.8.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.8.2.tgz#a18388c63ae9c17adde519384f539392f2c4f0d9" - integrity sha512-qHQ8ODi7mMin4Sq2eh/6eu03uVzsf5TX+J43xRmiq8ujng7ViQSHNPLOHGw/Wr5dFEoxq/ubKhzClIIdQy5q3g== +"@typescript-eslint/scope-manager@4.29.1": + version "4.29.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.29.1.tgz#f25da25bc6512812efa2ce5ebd36619d68e61358" + integrity sha512-Hzv/uZOa9zrD/W5mftZa54Jd5Fed3tL6b4HeaOpwVSabJK8CJ+2MkDasnX/XK4rqP5ZTWngK1ZDeCi6EnxPQ7A== dependencies: - "@typescript-eslint/types" "4.8.2" - "@typescript-eslint/visitor-keys" "4.8.2" + "@typescript-eslint/types" "4.29.1" + "@typescript-eslint/visitor-keys" "4.29.1" "@typescript-eslint/types@4.29.0": version "4.29.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.29.0.tgz#c8f1a1e4441ea4aca9b3109241adbc145f7f8a4e" integrity sha512-2YJM6XfWfi8pgU2HRhTp7WgRw78TCRO3dOmSpAvIQ8MOv4B46JD2chnhpNT7Jq8j0APlIbzO1Bach734xxUl4A== -"@typescript-eslint/types@4.8.2": - version "4.8.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.8.2.tgz#c862dd0e569d9478eb82d6aee662ea53f5661a36" - integrity sha512-z1/AVcVF8ju5ObaHe2fOpZYEQrwHyZ7PTOlmjd3EoFeX9sv7UekQhfrCmgUO7PruLNfSHrJGQvrW3Q7xQ8EoAw== +"@typescript-eslint/types@4.29.1": + version "4.29.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.29.1.tgz#94cce6cf7cc83451df03339cda99d326be2feaf5" + integrity sha512-Jj2yu78IRfw4nlaLtKjVaGaxh/6FhofmQ/j8v3NXmAiKafbIqtAPnKYrf0sbGjKdj0hS316J8WhnGnErbJ4RCA== "@typescript-eslint/typescript-estree@4.29.0": version "4.29.0" @@ -2206,19 +2206,18 @@ semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@4.8.2": - version "4.8.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.2.tgz#eeec34707d8577600fb21661b5287226cc8b3bed" - integrity sha512-HToGNwI6fekH0dOw3XEVESUm71Onfam0AKin6f26S2FtUmO7o3cLlWgrIaT1q3vjB3wCTdww3Dx2iGq5wtUOCg== +"@typescript-eslint/typescript-estree@4.29.1": + version "4.29.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.29.1.tgz#7b32a25ff8e51f2671ccc6b26cdbee3b1e6c5e7f" + integrity sha512-lIkkrR9E4lwZkzPiRDNq0xdC3f2iVCUjw/7WPJ4S2Sl6C3nRWkeE1YXCQ0+KsiaQRbpY16jNaokdWnm9aUIsfw== dependencies: - "@typescript-eslint/types" "4.8.2" - "@typescript-eslint/visitor-keys" "4.8.2" - debug "^4.1.1" - globby "^11.0.1" + "@typescript-eslint/types" "4.29.1" + "@typescript-eslint/visitor-keys" "4.29.1" + debug "^4.3.1" + globby "^11.0.3" is-glob "^4.0.1" - lodash "^4.17.15" - semver "^7.3.2" - tsutils "^3.17.1" + semver "^7.3.5" + tsutils "^3.21.0" "@typescript-eslint/visitor-keys@4.29.0": version "4.29.0" @@ -2228,12 +2227,12 @@ "@typescript-eslint/types" "4.29.0" eslint-visitor-keys "^2.0.0" -"@typescript-eslint/visitor-keys@4.8.2": - version "4.8.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.2.tgz#62cd3fbbbf65f8eccfbe6f159eb1b84a243a3f77" - integrity sha512-Vg+/SJTMZJEKKGHW7YC21QxgKJrSbxoYYd3MEUGtW7zuytHuEcksewq0DUmo4eh/CTNrVJGSdIY9AtRb6riWFw== +"@typescript-eslint/visitor-keys@4.29.1": + version "4.29.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.29.1.tgz#0615be8b55721f5e854f3ee99f1a714f2d093e5d" + integrity sha512-zLqtjMoXvgdZY/PG6gqA73V8BjqPs4af1v2kiiETBObp+uC6gRYnJLmJHxC0QyUrrHDLJPIWNYxoBV3wbcRlag== dependencies: - "@typescript-eslint/types" "4.8.2" + "@typescript-eslint/types" "4.29.1" eslint-visitor-keys "^2.0.0" "@webassemblyjs/ast@1.9.0": @@ -6875,18 +6874,6 @@ globalthis@^1.0.1: dependencies: define-properties "^1.1.3" -globby@^11.0.1: - version "11.0.1" - resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.1.tgz#9a2bf107a068f3ffeabc49ad702c79ede8cfd357" - integrity sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ== - dependencies: - array-union "^2.1.0" - dir-glob "^3.0.1" - fast-glob "^3.1.1" - ignore "^5.1.4" - merge2 "^1.3.0" - slash "^3.0.0" - globby@^11.0.3: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" @@ -11332,9 +11319,9 @@ path-key@^3.0.0, path-key@^3.1.0: integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== path-parse@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" - integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + version "1.0.7" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== path-to-regexp@0.1.7: version "0.1.7" @@ -14392,7 +14379,7 @@ tslib@^2.1.0, tslib@^2.2.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.0.tgz#803b8cdab3e12ba581a4ca41c8839bbb0dacb09e" integrity sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg== -tsutils@^3.17.1, tsutils@^3.21.0: +tsutils@^3.21.0: version "3.21.0" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623" integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==