mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix shell env cache (#461)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
8f0c785f58
commit
47082adecd
@ -10,7 +10,7 @@ import { Cluster, ClusterPreferences } from "./cluster"
|
||||
import { helmCli } from "./helm-cli"
|
||||
|
||||
export class ShellSession extends EventEmitter {
|
||||
static shellEnv: any
|
||||
static shellEnvs: Map<string, any> = new Map()
|
||||
|
||||
protected websocket: WebSocket
|
||||
protected shellProcess: pty.IPty
|
||||
@ -21,6 +21,7 @@ export class ShellSession extends EventEmitter {
|
||||
protected helmBinDir: string;
|
||||
protected preferences: ClusterPreferences;
|
||||
protected running = false;
|
||||
protected clusterId: string;
|
||||
|
||||
constructor(socket: WebSocket, pathToKubeconfig: string, cluster: Cluster) {
|
||||
super()
|
||||
@ -28,6 +29,7 @@ export class ShellSession extends EventEmitter {
|
||||
this.kubeconfigPath = pathToKubeconfig
|
||||
this.kubectl = new Kubectl(cluster.version)
|
||||
this.preferences = cluster.preferences || {}
|
||||
this.clusterId = cluster.id
|
||||
}
|
||||
|
||||
public async open() {
|
||||
@ -79,16 +81,14 @@ export class ShellSession extends EventEmitter {
|
||||
}
|
||||
|
||||
protected async getCachedShellEnv() {
|
||||
let env: any
|
||||
if (!ShellSession.shellEnv) {
|
||||
let env = ShellSession.shellEnvs.get(this.clusterId)
|
||||
if (!env) {
|
||||
env = await this.getShellEnv()
|
||||
ShellSession.shellEnv = env
|
||||
ShellSession.shellEnvs.set(this.clusterId, env)
|
||||
} else {
|
||||
env = ShellSession.shellEnv
|
||||
|
||||
// refresh env in the background
|
||||
this.getShellEnv().then((shellEnv: any) => {
|
||||
ShellSession.shellEnv = shellEnv
|
||||
ShellSession.shellEnvs.set(this.clusterId, shellEnv)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user