diff --git a/src/odo.ts b/src/odo.ts index 214b95bed..9015e48e5 100644 --- a/src/odo.ts +++ b/src/odo.ts @@ -620,9 +620,9 @@ export class OdoImpl implements Odo { return deployedComponents; } - public getKubeconfigEnv(): {KUBECONFIG?: string} { - const addEnv: {KUBECONFIG?: string} = {}; - let kc: KubeConfig; + public getKubeconfigEnv(): {KUBECONFIG?: string, HTTP_PROXY?: string, HTTPS_PROXY?: string, [key: string] : any} { + const addEnv: {KUBECONFIG?: string, HTTP_PROXY?: string, HTTPS_PROXY?: string, [key: string] : any} = {}; + let kc: KubeConfigUtils; // TODO: Remove when odo works without kubeconfig present try { kc = new KubeConfigUtils(); @@ -631,8 +631,25 @@ export class OdoImpl implements Odo { } const configPath = path.join(Platform.getUserHomePath(), '.kube', 'config'); + // kc loaded ether from files listed in env variable or default config location + if (kc && process.env.KUBECONFIG || pathExistsSync(configPath)) { + // add HTTP(S)_PROXY env var in case cluster from current context has proxy-url property + const cccp:string = kc.getProxy(); + if (cccp) { + const cccpu = Uri.parse(cccp); + // no scheme means http proxy + if (!cccpu.scheme || cccpu.scheme === 'http') { + addEnv.HTTP_PROXY = cccp; + } else { + // everything else is https proxy for now + addEnv.HTTPS_PROXY = cccp; + } + } + } - if (kc && !pathExistsSync(configPath)) { // config is loaded, yay! But there is still use case for missing config file + // config is loaded, but in case of no KUBECONFIG var or config file + // dummy config is created + if (kc && !addEnv.KUBECONFIG && !pathExistsSync(configPath)) { // use fake config to let odo get component types from registry addEnv.KUBECONFIG = path.resolve(__dirname, '..', '..', 'config', 'kubeconfig'); } @@ -640,7 +657,7 @@ export class OdoImpl implements Odo { } public async getCompTypesJson(): Promise { - const result: cliInstance.CliExitData = await this.execute(Command.listCatalogComponentsJson(), undefined, true, this.getKubeconfigEnv()); + const result: cliInstance.CliExitData = await this.execute(Command.listCatalogComponentsJson(), undefined, true); const compTypesJson: ComponentTypesJson = this.loadJSON(result.stdout); return compTypesJson?.items; } @@ -658,7 +675,7 @@ export class OdoImpl implements Odo { public async getComponentTypes(): Promise { // if kc is produced, KUBECONFIG env var is empty or pointing - const result: cliInstance.CliExitData = await this.execute(Command.listCatalogComponentsJson(), undefined, true, this.getKubeconfigEnv()); + const result: cliInstance.CliExitData = await this.execute(Command.listCatalogComponentsJson(), undefined, true); const compTypesJson: ComponentTypesJson = this.loadJSON(result.stdout); const devfileItems: ComponentTypeAdapter[] = []; @@ -773,7 +790,7 @@ export class OdoImpl implements Odo { } public createEnv(): any { - const env = {...process.env }; + const env = {...process.env, ...this.getKubeconfigEnv() }; env.ODO_DISABLE_TELEMETRY = 'true'; return env; } diff --git a/src/util/kubeUtils.ts b/src/util/kubeUtils.ts index f1bc17c1a..d6eec92eb 100644 --- a/src/util/kubeUtils.ts +++ b/src/util/kubeUtils.ts @@ -31,7 +31,7 @@ export class KubeConfigUtils extends KubeConfig { return findHomeDir(); } - getProxy(contextName: string): string | undefined { + getProxy(contextName: string = this.currentContext): string | undefined { if (process.env.KUBECONFIG?.[1]) { const cFiles = process.env.KUBECONFIG.split(path.delimiter).filter(file => file); //const yaml =