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

Use proxy kubeconfig for shell and resource applier (#754)

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-08-27 14:11:32 +03:00 committed by GitHub
parent 659d8bd0ab
commit ecbdb326e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -20,12 +20,12 @@ export class ResourceApplier {
} }
protected async kubectlApply(content: string): Promise<string> { protected async kubectlApply(content: string): Promise<string> {
const { kubeCtl, kubeConfigPath } = this.cluster; const { kubeCtl } = this.cluster;
const kubectlPath = await kubeCtl.getPath() const kubectlPath = await kubeCtl.getPath()
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {
const fileName = tempy.file({ name: "resource.yaml" }) const fileName = tempy.file({ name: "resource.yaml" })
fs.writeFileSync(fileName, content) fs.writeFileSync(fileName, content)
const cmd = `"${kubectlPath}" apply --kubeconfig "${kubeConfigPath}" -o json -f "${fileName}"` const cmd = `"${kubectlPath}" apply --kubeconfig "${this.cluster.getProxyKubeconfigPath()}" -o json -f "${fileName}"`
logger.debug("shooting manifests with: " + cmd); logger.debug("shooting manifests with: " + cmd);
const execEnv: NodeJS.ProcessEnv = Object.assign({}, process.env) const execEnv: NodeJS.ProcessEnv = Object.assign({}, process.env)
const httpsProxy = this.cluster.preferences?.httpsProxy const httpsProxy = this.cluster.preferences?.httpsProxy
@ -46,7 +46,7 @@ export class ResourceApplier {
} }
public async kubectlApplyAll(resources: string[]): Promise<string> { public async kubectlApplyAll(resources: string[]): Promise<string> {
const { kubeCtl, kubeConfigPath } = this.cluster; const { kubeCtl } = this.cluster;
const kubectlPath = await kubeCtl.getPath() const kubectlPath = await kubeCtl.getPath()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const tmpDir = tempy.directory() const tmpDir = tempy.directory()
@ -54,7 +54,7 @@ export class ResourceApplier {
resources.forEach((resource, index) => { resources.forEach((resource, index) => {
fs.writeFileSync(path.join(tmpDir, `${index}.yaml`), resource); fs.writeFileSync(path.join(tmpDir, `${index}.yaml`), resource);
}) })
const cmd = `"${kubectlPath}" apply --kubeconfig "${kubeConfigPath}" -o json -f "${tmpDir}"` const cmd = `"${kubectlPath}" apply --kubeconfig "${this.cluster.getProxyKubeconfigPath()}" -o json -f "${tmpDir}"`
console.log("shooting manifests with:", cmd); console.log("shooting manifests with:", cmd);
exec(cmd, (error, stdout, stderr) => { exec(cmd, (error, stdout, stderr) => {
if (error) { if (error) {

View File

@ -28,7 +28,7 @@ export class ShellSession extends EventEmitter {
constructor(socket: WebSocket, cluster: Cluster) { constructor(socket: WebSocket, cluster: Cluster) {
super() super()
this.websocket = socket this.websocket = socket
this.kubeconfigPath = cluster.kubeConfigPath this.kubeconfigPath = cluster.getProxyKubeconfigPath()
this.kubectl = new Kubectl(cluster.version) this.kubectl = new Kubectl(cluster.version)
this.preferences = cluster.preferences || {} this.preferences = cluster.preferences || {}
this.clusterId = cluster.id this.clusterId = cluster.id