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,
|
||||
};
|
||||
|
||||
async install(cluster: Cluster): Promise<boolean> {
|
||||
async install(cluster: Cluster): Promise<void> {
|
||||
// Check if there are storageclasses
|
||||
const storageClient = cluster.proxyKubeconfig().makeApiClient(k8s.StorageV1Api)
|
||||
const scs = await storageClient.listStorageClass();
|
||||
scs.body.items.forEach(sc => {
|
||||
if(sc.metadata.annotations &&
|
||||
(await cluster
|
||||
.proxyKubeconfig()
|
||||
.makeApiClient(k8s.StorageV1Api)
|
||||
.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')) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@ -6,12 +6,12 @@ export class UserModeFeature extends Feature {
|
||||
name = 'user-mode';
|
||||
latestVersion = "v2.0.0"
|
||||
|
||||
async install(cluster: Cluster): Promise<boolean> {
|
||||
async install(cluster: Cluster): Promise<void> {
|
||||
return super.install(cluster)
|
||||
}
|
||||
|
||||
async upgrade(cluster: Cluster): Promise<boolean> {
|
||||
return true
|
||||
async upgrade(cluster: Cluster): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async featureStatus(kc: KubeConfig): Promise<FeatureStatus> {
|
||||
|
||||
@ -152,12 +152,8 @@ export class ContextHandler {
|
||||
return serverPort
|
||||
}
|
||||
|
||||
public async withTemporaryKubeconfig(callback: (kubeconfig: string) => Promise<any>) {
|
||||
try {
|
||||
await callback(this.cluster.proxyKubeconfigPath())
|
||||
} catch (error) {
|
||||
throw(error)
|
||||
}
|
||||
public applyHeaders(req: http.IncomingMessage) {
|
||||
req.headers["authorization"] = `Bearer ${this.id}`
|
||||
}
|
||||
|
||||
public async ensureServer() {
|
||||
|
||||
@ -29,26 +29,16 @@ export abstract class Feature {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Return types for these?
|
||||
async install(cluster: Cluster): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
// Read and process yamls through handlebar
|
||||
const resources = this.renderTemplates();
|
||||
|
||||
// Apply processed manifests
|
||||
cluster.contextHandler.withTemporaryKubeconfig(async (kubeconfigPath) => {
|
||||
const resourceApplier = new ResourceApplier(cluster, kubeconfigPath)
|
||||
try {
|
||||
await resourceApplier.kubectlApplyAll(resources)
|
||||
resolve(true)
|
||||
} catch(error) {
|
||||
reject(error)
|
||||
}
|
||||
});
|
||||
});
|
||||
async install(cluster: Cluster): Promise<void> {
|
||||
// Read and process yamls through handlebar
|
||||
const resources = this.renderTemplates();
|
||||
const kubeconfigPath = cluster.kubeconfigPath();
|
||||
const resourceApplier = new ResourceApplier(cluster, kubeconfigPath)
|
||||
|
||||
await resourceApplier.kubectlApplyAll(resources)
|
||||
}
|
||||
|
||||
abstract async upgrade(cluster: Cluster): Promise<boolean>;
|
||||
abstract async upgrade(cluster: Cluster): Promise<void>;
|
||||
|
||||
abstract async uninstall(cluster: Cluster): Promise<boolean>;
|
||||
|
||||
|
||||
@ -104,24 +104,28 @@ export class LensProxy {
|
||||
}
|
||||
|
||||
protected createWsListener() {
|
||||
const ws = new WebSocket.Server({ noServer: true })
|
||||
ws.on("connection", ((con: WebSocket, req: http.IncomingMessage) => {
|
||||
const ws = new WebSocket.Server({ noServer: true})
|
||||
ws.on("connection", (async (con: WebSocket, req: http.IncomingMessage) => {
|
||||
const cluster = this.clusterManager.getClusterForRequest(req)
|
||||
const contextHandler = cluster.contextHandler
|
||||
const nodeParam = url.parse(req.url, true).query["node"]?.toString();
|
||||
const nodeParam = this.getNodeParam(req.url)
|
||||
|
||||
contextHandler.withTemporaryKubeconfig((kubeconfigPath) => {
|
||||
return new Promise<boolean>(async (resolve, reject) => {
|
||||
const shellSession = await shell.open(con, kubeconfigPath, cluster, nodeParam)
|
||||
shellSession.on("exit", () => {
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
}))
|
||||
try {
|
||||
await shell.open(con, cluster.kubeConfigPath, cluster, nodeParam)
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}).bind(this))
|
||||
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> {
|
||||
const prefix = apiPrefix.KUBE_BASE;
|
||||
if (req.url.startsWith(prefix)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user