mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove ContextHandler.withTemporaryKubeconfig()
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
parent
55687b7d35
commit
92dd81b461
@ -51,21 +51,26 @@ export class MetricsFeature extends Feature {
|
|||||||
storageClass: null,
|
storageClass: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
async install(cluster: Cluster): Promise<boolean> {
|
async install(cluster: Cluster): Promise<void> {
|
||||||
// Check if there are storageclasses
|
// Check if there are storageclasses
|
||||||
const storageClient = cluster.proxyKubeconfig().makeApiClient(k8s.StorageV1Api)
|
(await cluster
|
||||||
const scs = await storageClient.listStorageClass();
|
.proxyKubeconfig()
|
||||||
scs.body.items.forEach(sc => {
|
.makeApiClient(k8s.StorageV1Api)
|
||||||
if(sc.metadata.annotations &&
|
.listStorageClass()
|
||||||
|
)
|
||||||
|
.body
|
||||||
|
.items
|
||||||
|
.forEach(sc => {
|
||||||
|
if(sc.metadata.annotations &&
|
||||||
(sc.metadata.annotations['storageclass.kubernetes.io/is-default-class'] === 'true' || sc.metadata.annotations['storageclass.beta.kubernetes.io/is-default-class'] === 'true')) {
|
(sc.metadata.annotations['storageclass.kubernetes.io/is-default-class'] === 'true' || sc.metadata.annotations['storageclass.beta.kubernetes.io/is-default-class'] === 'true')) {
|
||||||
this.config.persistence.enabled = true;
|
this.config.persistence.enabled = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return super.install(cluster)
|
return super.install(cluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
async upgrade(cluster: Cluster): Promise<boolean> {
|
async upgrade(cluster: Cluster): Promise<void> {
|
||||||
return this.install(cluster)
|
return this.install(cluster)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,12 @@ export class UserModeFeature extends Feature {
|
|||||||
name = 'user-mode';
|
name = 'user-mode';
|
||||||
latestVersion = "v2.0.0"
|
latestVersion = "v2.0.0"
|
||||||
|
|
||||||
async install(cluster: Cluster): Promise<boolean> {
|
async install(cluster: Cluster): Promise<void> {
|
||||||
return super.install(cluster)
|
return super.install(cluster)
|
||||||
}
|
}
|
||||||
|
|
||||||
async upgrade(cluster: Cluster): Promise<boolean> {
|
async upgrade(cluster: Cluster): Promise<void> {
|
||||||
return true
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async featureStatus(kc: KubeConfig): Promise<FeatureStatus> {
|
async featureStatus(kc: KubeConfig): Promise<FeatureStatus> {
|
||||||
|
|||||||
@ -152,12 +152,8 @@ export class ContextHandler {
|
|||||||
return serverPort
|
return serverPort
|
||||||
}
|
}
|
||||||
|
|
||||||
public async withTemporaryKubeconfig(callback: (kubeconfig: string) => Promise<any>) {
|
public applyHeaders(req: http.IncomingMessage) {
|
||||||
try {
|
req.headers["authorization"] = `Bearer ${this.id}`
|
||||||
await callback(this.cluster.proxyKubeconfigPath())
|
|
||||||
} catch (error) {
|
|
||||||
throw(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ensureServer() {
|
public async ensureServer() {
|
||||||
|
|||||||
@ -29,26 +29,16 @@ export abstract class Feature {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Return types for these?
|
async install(cluster: Cluster): Promise<void> {
|
||||||
async install(cluster: Cluster): Promise<boolean> {
|
// Read and process yamls through handlebar
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
const resources = this.renderTemplates();
|
||||||
// Read and process yamls through handlebar
|
const kubeconfigPath = cluster.kubeconfigPath();
|
||||||
const resources = this.renderTemplates();
|
const resourceApplier = new ResourceApplier(cluster, kubeconfigPath)
|
||||||
|
|
||||||
// Apply processed manifests
|
await resourceApplier.kubectlApplyAll(resources)
|
||||||
cluster.contextHandler.withTemporaryKubeconfig(async (kubeconfigPath) => {
|
|
||||||
const resourceApplier = new ResourceApplier(cluster, kubeconfigPath)
|
|
||||||
try {
|
|
||||||
await resourceApplier.kubectlApplyAll(resources)
|
|
||||||
resolve(true)
|
|
||||||
} catch(error) {
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract async upgrade(cluster: Cluster): Promise<boolean>;
|
abstract async upgrade(cluster: Cluster): Promise<void>;
|
||||||
|
|
||||||
abstract async uninstall(cluster: Cluster): Promise<boolean>;
|
abstract async uninstall(cluster: Cluster): Promise<boolean>;
|
||||||
|
|
||||||
|
|||||||
@ -104,24 +104,28 @@ export class LensProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected createWsListener() {
|
protected createWsListener() {
|
||||||
const ws = new WebSocket.Server({ noServer: true })
|
const ws = new WebSocket.Server({ noServer: true})
|
||||||
ws.on("connection", ((con: WebSocket, req: http.IncomingMessage) => {
|
ws.on("connection", (async (con: WebSocket, req: http.IncomingMessage) => {
|
||||||
const cluster = this.clusterManager.getClusterForRequest(req)
|
const cluster = this.clusterManager.getClusterForRequest(req)
|
||||||
const contextHandler = cluster.contextHandler
|
const nodeParam = this.getNodeParam(req.url)
|
||||||
const nodeParam = url.parse(req.url, true).query["node"]?.toString();
|
|
||||||
|
|
||||||
contextHandler.withTemporaryKubeconfig((kubeconfigPath) => {
|
try {
|
||||||
return new Promise<boolean>(async (resolve, reject) => {
|
await shell.open(con, cluster.kubeConfigPath, cluster, nodeParam)
|
||||||
const shellSession = await shell.open(con, kubeconfigPath, cluster, nodeParam)
|
} catch (err) {
|
||||||
shellSession.on("exit", () => {
|
console.error(err);
|
||||||
resolve(true)
|
}
|
||||||
})
|
}).bind(this))
|
||||||
})
|
|
||||||
})
|
|
||||||
}))
|
|
||||||
return ws
|
return ws
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getNodeParam(requestUrl: string) {
|
||||||
|
const [lastKey, lastValue] = Object.entries(url.parse(requestUrl, true).query)
|
||||||
|
.reverse()
|
||||||
|
.find(([key]) => key == "node");
|
||||||
|
|
||||||
|
return lastValue.toString();
|
||||||
|
}
|
||||||
|
|
||||||
protected async getProxyTarget(req: http.IncomingMessage, contextHandler: ContextHandler): Promise<httpProxy.ServerOptions> {
|
protected async getProxyTarget(req: http.IncomingMessage, contextHandler: ContextHandler): Promise<httpProxy.ServerOptions> {
|
||||||
const prefix = apiPrefix.KUBE_BASE;
|
const prefix = apiPrefix.KUBE_BASE;
|
||||||
if (req.url.startsWith(prefix)) {
|
if (req.url.startsWith(prefix)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user