From bc36d4867749158f54ce1be1f6d625c75d73e242 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Sat, 2 Oct 2021 00:12:01 +0300 Subject: [PATCH] Release v5.2.5 (#3926) Co-authored-by: Jim Ehrismann <40840436+jim-docker@users.noreply.github.com> Co-authored-by: Sebastian Malton --- package.json | 2 +- src/common/vars.ts | 2 +- src/extensions/npm/extensions/package.json | 6 +-- .../index.ts => __test__/lens-proxy.test.ts} | 37 ++++++++++++++++++- src/main/context-handler.ts | 6 +-- src/main/lens-proxy.ts | 13 ++++++- src/main/routes/helm-route.ts | 2 +- src/main/{routes => }/utils/parse-query.ts | 0 8 files changed, 56 insertions(+), 12 deletions(-) rename src/main/{routes/utils/index.ts => __test__/lens-proxy.test.ts} (52%) rename src/main/{routes => }/utils/parse-query.ts (100%) diff --git a/package.json b/package.json index 1548ca3aeb..5dba768a49 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "productName": "OpenLens", "description": "OpenLens - Open Source IDE for Kubernetes", "homepage": "https://github.com/lensapp/lens", - "version": "5.2.4", + "version": "5.2.5", "main": "static/build/main.js", "copyright": "© 2021 OpenLens Authors", "license": "MIT", diff --git a/src/common/vars.ts b/src/common/vars.ts index 6462be4db5..b18a1cb97e 100644 --- a/src/common/vars.ts +++ b/src/common/vars.ts @@ -69,7 +69,7 @@ export const apiKubePrefix = "/api-kube" as string; // k8s cluster apis // Links export const issuesTrackerUrl = "https://github.com/lensapp/lens/issues" as string; -export const slackUrl = "https://join.slack.com/t/k8slens/shared_invite/enQtOTc5NjAyNjYyOTk4LWU1NDQ0ZGFkOWJkNTRhYTc2YjVmZDdkM2FkNGM5MjhiYTRhMDU2NDQ1MzIyMDA4ZGZlNmExOTc0N2JmY2M3ZGI" as string; +export const slackUrl = "https://join.slack.com/t/k8slens/shared_invite/zt-wcl8jq3k-68R5Wcmk1o95MLBE5igUDQ" as string; export const supportUrl = "https://docs.k8slens.dev/latest/support/" as string; export const appSemVer = new SemVer(packageInfo.version); diff --git a/src/extensions/npm/extensions/package.json b/src/extensions/npm/extensions/package.json index 594f26f56e..09db697b35 100644 --- a/src/extensions/npm/extensions/package.json +++ b/src/extensions/npm/extensions/package.json @@ -16,9 +16,9 @@ "name": "OpenLens Authors" }, "dependencies": { - "@types/node": "*", - "@types/react-select": "*", - "@material-ui/core": "*", + "@types/node": "14.17.14", + "@types/react-select": "3.1.2", + "@material-ui/core": "4.12.3", "conf": "^7.0.1", "typed-emitter": "^1.3.1" } diff --git a/src/main/routes/utils/index.ts b/src/main/__test__/lens-proxy.test.ts similarity index 52% rename from src/main/routes/utils/index.ts rename to src/main/__test__/lens-proxy.test.ts index 4a7de80225..f7767fc685 100644 --- a/src/main/routes/utils/index.ts +++ b/src/main/__test__/lens-proxy.test.ts @@ -18,4 +18,39 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -export * from "./parse-query"; + +import { isLongRunningRequest } from "../lens-proxy"; + +describe("isLongRunningRequest", () => { + it("returns true on watches", () => { + ["watch=true", "watch=1", "watch"].forEach((param) => { + expect( + isLongRunningRequest(`/api/v1/namespaces/default/pods?${param}`) + ).toBeTruthy(); + }); + }); + + it("returns false on disabled watches", () => { + ["watch=false", "watch=0", ""].forEach((param) => { + expect( + isLongRunningRequest(`/api/v1/namespaces/default/pods?${param}`) + ).toBeFalsy(); + }); + }); + + it("returns true on follows", () => { + ["follow=true", "follow=1", "follow"].forEach((param) => { + expect( + isLongRunningRequest(`/api/v1/namespaces/default/pods/foo/log?${param}`) + ).toBeTruthy(); + }); + }); + + it("returns false on disabled follows", () => { + ["follow=false", "follow=0", ""].forEach((param) => { + expect( + isLongRunningRequest(`/api/v1/namespaces/default/pods/foo/log?${param}`) + ).toBeFalsy(); + }); + }); +}); diff --git a/src/main/context-handler.ts b/src/main/context-handler.ts index 82c365e821..b6e14df4e5 100644 --- a/src/main/context-handler.ts +++ b/src/main/context-handler.ts @@ -117,10 +117,10 @@ export class ContextHandler { return `http://127.0.0.1:${this.kubeAuthProxy.port}${path}`; } - async getApiTarget(isWatchRequest = false): Promise { - const timeout = isWatchRequest ? 4 * 60 * 60 * 1000 : 30000; // 4 hours for watch request, 30 seconds for the rest + async getApiTarget(isLongRunningRequest = false): Promise { + const timeout = isLongRunningRequest ? 4 * 60 * 60_000 : 30_000; // 4 hours for long running request, 30 seconds for the rest - if (isWatchRequest) { + if (isLongRunningRequest) { return this.newApiTarget(timeout); } diff --git a/src/main/lens-proxy.ts b/src/main/lens-proxy.ts index 3cd5182677..47f4c4756f 100644 --- a/src/main/lens-proxy.ts +++ b/src/main/lens-proxy.ts @@ -31,6 +31,7 @@ import { Singleton } from "../common/utils"; import type { Cluster } from "./cluster"; import type { ProxyApiRequestArgs } from "./proxy-functions"; import { appEventBus } from "../common/event-bus"; +import { getBoolean } from "./utils/parse-query"; type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | null; @@ -40,6 +41,15 @@ export interface LensProxyFunctions { kubeApiRequest: (args: ProxyApiRequestArgs) => void | Promise; } +const watchParam = "watch"; +const followParam = "follow"; + +export function isLongRunningRequest(reqUrl: string) { + const url = new URL(reqUrl, "http://localhost"); + + return getBoolean(url.searchParams, watchParam) || getBoolean(url.searchParams, followParam); +} + export class LensProxy extends Singleton { protected origin: string; protected proxyServer: http.Server; @@ -174,9 +184,8 @@ export class LensProxy extends Singleton { if (req.url.startsWith(apiKubePrefix)) { delete req.headers.authorization; req.url = req.url.replace(apiKubePrefix, ""); - const isWatchRequest = req.url.includes("watch="); - return contextHandler.getApiTarget(isWatchRequest); + return contextHandler.getApiTarget(isLongRunningRequest(req.url)); } } diff --git a/src/main/routes/helm-route.ts b/src/main/routes/helm-route.ts index 5e104f6a11..2f217a3193 100644 --- a/src/main/routes/helm-route.ts +++ b/src/main/routes/helm-route.ts @@ -23,7 +23,7 @@ import type { LensApiRequest } from "../router"; import { helmService } from "../helm/helm-service"; import logger from "../logger"; import { respondJson, respondText } from "../utils/http-responses"; -import { getBoolean } from "./utils/parse-query"; +import { getBoolean } from "../utils/parse-query"; export class HelmApiRoute { static async listCharts(request: LensApiRequest) { diff --git a/src/main/routes/utils/parse-query.ts b/src/main/utils/parse-query.ts similarity index 100% rename from src/main/routes/utils/parse-query.ts rename to src/main/utils/parse-query.ts