1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix rancher on kubernetes

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-09-15 17:20:30 +03:00
parent 6246a3034f
commit 4c182e88b9
4 changed files with 9 additions and 5 deletions

View File

@ -44,7 +44,7 @@ export class ClusterManager {
// lens-server is connecting to 127.0.0.1:<port>/<uid> // lens-server is connecting to 127.0.0.1:<port>/<uid>
if (req.headers.host.startsWith("127.0.0.1")) { if (req.headers.host.startsWith("127.0.0.1")) {
const clusterId = req.url.split("/")[1] const clusterId = req.url.split("/")[1]
const cluster = clusterStore.getById(clusterId) cluster = clusterStore.getById(clusterId)
if (cluster) { if (cluster) {
// we need to swap path prefix so that request is proxied to kube api // we need to swap path prefix so that request is proxied to kube api
req.url = req.url.replace(`/${clusterId}`, apiKubePrefix) req.url = req.url.replace(`/${clusterId}`, apiKubePrefix)

View File

@ -92,7 +92,7 @@ export class Cluster implements ClusterModel {
async init(port: number) { async init(port: number) {
try { try {
this.contextHandler = new ContextHandler(this); this.contextHandler = new ContextHandler(this);
this.kubeconfigManager = new KubeconfigManager(this, this.contextHandler); this.kubeconfigManager = new KubeconfigManager(this, this.contextHandler, port);
this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`; this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`;
this.initialized = true; this.initialized = true;
logger.info(`[CLUSTER]: "${this.contextName}" init success`, { logger.info(`[CLUSTER]: "${this.contextName}" init success`, {

View File

@ -68,7 +68,7 @@ export class ContextHandler {
return this.prometheusPath; return this.prometheusPath;
} }
async resolveAuthProxyUrl() { protected async resolveAuthProxyUrl() {
const proxyPort = await this.ensurePort(); const proxyPort = await this.ensurePort();
const path = this.clusterUrl.path !== "/" ? this.clusterUrl.path : "" const path = this.clusterUrl.path !== "/" ? this.clusterUrl.path : ""
return `http://127.0.0.1:${proxyPort}${path}`; return `http://127.0.0.1:${proxyPort}${path}`;

View File

@ -11,7 +11,7 @@ export class KubeconfigManager {
protected configDir = app.getPath("temp") protected configDir = app.getPath("temp")
protected tempFile: string; protected tempFile: string;
constructor(protected cluster: Cluster, protected contextHandler: ContextHandler) { constructor(protected cluster: Cluster, protected contextHandler: ContextHandler, protected port: number) {
this.init(); this.init();
} }
@ -28,6 +28,10 @@ export class KubeconfigManager {
return this.tempFile; return this.tempFile;
} }
protected resolveProxyUrl() {
return `http://127.0.0.1:${this.port}/${this.cluster.id}`
}
/** /**
* Creates new "temporary" kubeconfig that point to the kubectl-proxy. * Creates new "temporary" kubeconfig that point to the kubectl-proxy.
* This way any user of the config does not need to know anything about the auth etc. details. * This way any user of the config does not need to know anything about the auth etc. details.
@ -42,7 +46,7 @@ export class KubeconfigManager {
clusters: [ clusters: [
{ {
name: contextName, name: contextName,
server: await contextHandler.resolveAuthProxyUrl(), server: this.resolveProxyUrl(),
skipTLSVerify: undefined, skipTLSVerify: undefined,
} }
], ],