mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into split-cluster-to-managed-cluster
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
commit
bde40ea198
@ -58,6 +58,7 @@ describe("kube auth proxy tests", () => {
|
|||||||
let port: number
|
let port: number
|
||||||
let mockedCP: MockProxy<ChildProcess>
|
let mockedCP: MockProxy<ChildProcess>
|
||||||
let listeners: Record<string, (...args: any[]) => void>
|
let listeners: Record<string, (...args: any[]) => void>
|
||||||
|
let proxy: KubeAuthProxy
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
port = await getFreePort()
|
port = await getFreePort()
|
||||||
@ -85,43 +86,41 @@ describe("kube auth proxy tests", () => {
|
|||||||
return mockedCP
|
return mockedCP
|
||||||
})
|
})
|
||||||
mockWaitUntilUsed.mockReturnValueOnce(Promise.resolve())
|
mockWaitUntilUsed.mockReturnValueOnce(Promise.resolve())
|
||||||
|
const cluster = new Cluster({ id: "foobar", kubeConfigPath: "fake-path.yml" })
|
||||||
|
jest.spyOn(cluster, "apiUrl", "get").mockReturnValue("https://fake.k8s.internal")
|
||||||
|
proxy = new KubeAuthProxy(cluster, port, {})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should call spawn and broadcast errors", async () => {
|
it("should call spawn and broadcast errors", async () => {
|
||||||
const kap = new KubeAuthProxy(new Cluster({ id: "foobar", kubeConfigPath: "fake-path.yml" }), port, {})
|
await proxy.run()
|
||||||
await kap.run()
|
|
||||||
listeners["error"]({ message: "foobarbat" })
|
listeners["error"]({ message: "foobarbat" })
|
||||||
|
|
||||||
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "foobarbat", error: true })
|
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "foobarbat", error: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should call spawn and broadcast exit", async () => {
|
it("should call spawn and broadcast exit", async () => {
|
||||||
const kap = new KubeAuthProxy(new Cluster({ id: "foobar", kubeConfigPath: "fake-path.yml" }), port, {})
|
await proxy.run()
|
||||||
await kap.run()
|
|
||||||
listeners["exit"](0)
|
listeners["exit"](0)
|
||||||
|
|
||||||
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "proxy exited with code: 0", error: false })
|
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "proxy exited with code: 0", error: false })
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should call spawn and broadcast errors from stderr", async () => {
|
it("should call spawn and broadcast errors from stderr", async () => {
|
||||||
const kap = new KubeAuthProxy(new Cluster({ id: "foobar", kubeConfigPath: "fake-path.yml" }), port, {})
|
await proxy.run()
|
||||||
await kap.run()
|
|
||||||
listeners["stderr/data"]("an error")
|
listeners["stderr/data"]("an error")
|
||||||
|
|
||||||
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "an error", error: true })
|
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "an error", error: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should call spawn and broadcast stdout serving info", async () => {
|
it("should call spawn and broadcast stdout serving info", async () => {
|
||||||
const kap = new KubeAuthProxy(new Cluster({ id: "foobar", kubeConfigPath: "fake-path.yml" }), port, {})
|
await proxy.run()
|
||||||
await kap.run()
|
|
||||||
listeners["stdout/data"]("Starting to serve on")
|
listeners["stdout/data"]("Starting to serve on")
|
||||||
|
|
||||||
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "Authentication proxy started\n" })
|
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "Authentication proxy started\n" })
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should call spawn and broadcast stdout other info", async () => {
|
it("should call spawn and broadcast stdout other info", async () => {
|
||||||
const kap = new KubeAuthProxy(new Cluster({ id: "foobar", kubeConfigPath: "fake-path.yml" }), port, {})
|
await proxy.run()
|
||||||
await kap.run()
|
|
||||||
listeners["stdout/data"]("some info")
|
listeners["stdout/data"]("some info")
|
||||||
|
|
||||||
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "some info" })
|
expect(mockBroadcastIpc).toBeCalledWith("kube-auth:foobar", { data: "some info" })
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import type { ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences } fro
|
|||||||
import type { WorkspaceId } from "../common/workspace-store";
|
import type { WorkspaceId } from "../common/workspace-store";
|
||||||
import { action, computed, observable, toJS, when } from "mobx";
|
import { action, computed, observable, toJS, when } from "mobx";
|
||||||
import { broadcastMessage } from "../common/ipc";
|
import { broadcastMessage } from "../common/ipc";
|
||||||
import { KubeConfig } from "@kubernetes/client-node"
|
import { KubeConfig } from "@kubernetes/client-node";
|
||||||
import { Kubectl } from "./kubectl";
|
import { Kubectl } from "./kubectl";
|
||||||
import { loadConfig } from "../common/kube-helpers"
|
import { loadConfig } from "../common/kube-helpers"
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
@ -15,8 +15,6 @@ export enum ClusterMetadataKey {
|
|||||||
LAST_SEEN = "lastSeen"
|
LAST_SEEN = "lastSeen"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export interface ClusterState {
|
export interface ClusterState {
|
||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
@ -151,6 +149,4 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
disconnected: this.disconnected,
|
disconnected: this.disconnected,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { broadcastMessage } from "../common/ipc";
|
|||||||
import type { Cluster } from "./cluster"
|
import type { Cluster } from "./cluster"
|
||||||
import { Kubectl } from "./kubectl"
|
import { Kubectl } from "./kubectl"
|
||||||
import logger from "./logger"
|
import logger from "./logger"
|
||||||
|
import * as url from "url"
|
||||||
|
|
||||||
export interface KubeAuthProxyLog {
|
export interface KubeAuthProxyLog {
|
||||||
data: string;
|
data: string;
|
||||||
@ -26,17 +27,22 @@ export class KubeAuthProxy {
|
|||||||
this.kubectl = Kubectl.bundled()
|
this.kubectl = Kubectl.bundled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get acceptHosts() {
|
||||||
|
return url.parse(this.cluster.apiUrl).hostname;
|
||||||
|
}
|
||||||
|
|
||||||
public async run(): Promise<void> {
|
public async run(): Promise<void> {
|
||||||
if (this.proxyProcess) {
|
if (this.proxyProcess) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const proxyBin = await this.kubectl.getPath()
|
const proxyBin = await this.kubectl.getPath()
|
||||||
const args = [
|
const args = [
|
||||||
"proxy",
|
"proxy",
|
||||||
"-p", `${this.port}`,
|
"-p", `${this.port}`,
|
||||||
"--kubeconfig", `${this.cluster.kubeConfigPath}`,
|
"--kubeconfig", `${this.cluster.kubeConfigPath}`,
|
||||||
"--context", `${this.cluster.contextName}`,
|
"--context", `${this.cluster.contextName}`,
|
||||||
"--accept-hosts", ".*",
|
"--accept-hosts", this.acceptHosts,
|
||||||
"--reject-paths", "^[^/]"
|
"--reject-paths", "^[^/]"
|
||||||
]
|
]
|
||||||
if (process.env.DEBUG_PROXY === "true") {
|
if (process.env.DEBUG_PROXY === "true") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user