mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow to configure default namespace used in terminal (#3706)
* Allow to configure default namespace used in terminal Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Fix lint issues Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
1 parent
1f7cdcdb01
commit
584d45c5e0
4 files changed
+86
-16
No files matched your search
@@ -216,6 +216,18 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
return toJS({ prometheus, prometheusProvider });
|
||||
}
|
||||
|
||||
/**
|
||||
* defaultNamespace preference
|
||||
*
|
||||
* @computed
|
||||
* @internal
|
||||
*/
|
||||
@computed get defaultNamespace(): string {
|
||||
const { defaultNamespace } = this.preferences;
|
||||
|
||||
return defaultNamespace;
|
||||
}
|
||||
|
||||
constructor(model: ClusterModel) {
|
||||
makeObservable(this);
|
||||
this.id = model.id;
|
||||
@@ -298,10 +310,25 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
clearInterval(refreshTimer);
|
||||
clearInterval(refreshMetadataTimer);
|
||||
},
|
||||
reaction(() => this.defaultNamespace, () => this.recreateProxyKubeconfig()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async recreateProxyKubeconfig() {
|
||||
logger.info("Recreate proxy kubeconfig");
|
||||
|
||||
try {
|
||||
this.kubeconfigManager.clear();
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
this.getProxyKubeconfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* internal
|
||||
*/
|
||||
|
||||
@@ -56,6 +56,15 @@ export class KubeconfigManager {
|
||||
return this.tempFile;
|
||||
}
|
||||
|
||||
async clear() {
|
||||
if (!this.tempFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(`Deleting temporary kubeconfig: ${this.tempFile}`);
|
||||
await fs.unlink(this.tempFile);
|
||||
}
|
||||
|
||||
async unlink() {
|
||||
if (!this.tempFile) {
|
||||
return;
|
||||
@@ -106,7 +115,7 @@ export class KubeconfigManager {
|
||||
user: "proxy",
|
||||
name: contextName,
|
||||
cluster: contextName,
|
||||
namespace: kubeConfig.getContextObject(contextName).namespace,
|
||||
namespace: cluster.defaultNamespace || kubeConfig.getContextObject(contextName).namespace,
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user