From 466ce79474eee1f3416d00088fc703e7255b8ab9 Mon Sep 17 00:00:00 2001 From: Levi Blackstone Date: Mon, 21 Oct 2019 14:19:33 -0600 Subject: [PATCH 1/2] Use HELM_HOME as default if set Previously, the Chart resource ignored the HELM_HOME environment variable. This value is now used as a default if set. Note that the fetch `home` option still takes precedence over HELM_HOME. --- CHANGELOG.md | 1 + pkg/gen/nodejs-templates/helm/v2/helm.ts | 23 +++++++++++++++++--- pkg/gen/python-templates/helm/v2/helm.py | 11 ++++++++-- sdk/nodejs/helm/v2/helm.ts | 23 +++++++++++++++++--- sdk/python/pulumi_kubernetes/helm/v2/helm.py | 11 ++++++++-- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13e9f3ff02..613e36029f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Improvements +- Use HELM_HOME as default if set. (https://github.com/pulumi/pulumi-kubernetes/pull/855). - Use `namespace` provided by `KUBECONFIG`, if it is not explicitly set in the provider (https://github.com/pulumi/pulumi-kubernetes/pull/903). ## 1.3.3 (November 29, 2019) diff --git a/pkg/gen/nodejs-templates/helm/v2/helm.ts b/pkg/gen/nodejs-templates/helm/v2/helm.ts index 76ba3a6b5a..0f92bafccd 100644 --- a/pkg/gen/nodejs-templates/helm/v2/helm.ts +++ b/pkg/gen/nodejs-templates/helm/v2/helm.ts @@ -192,8 +192,16 @@ export class Chart extends yaml.CollectionComponentResource { const namespaceArg = cfg.namespace ? `--namespace ${shell.quote([cfg.namespace])}` : ""; + let cmd = `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`; + + // Use the HELM_HOME environment variable value if set. + const home = process.env.HELM_HOME || undefined; + if (home !== undefined) { + cmd += ` --home ${home}`; + } + const yamlStream = execSync( - `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`, + cmd, { maxBuffer: 512 * 1024 * 1024 // 512 MB }, @@ -394,7 +402,17 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { // Untar by default. if(opts.untar !== false) { flags.push(`--untar`); } - // For arguments that are not paths to files, it is sufficent to use shell.quote to quote the arguments. + // Fallback to using the HELM_HOME environment variable if opts.home is not set. + if (opts.home !== undefined) { + flags.push(`--home ${path.quotePath(opts.home)}`); + } else { + const home = process.env.HELM_HOME || undefined; + if (home !== undefined) { + flags.push(`--home ${home}`); + } + } + + // For arguments that are not paths to files, it is sufficient to use shell.quote to quote the arguments. // However, for arguments that are actual paths to files we use path.quotePath (note that path here is // not the node path builtin module). This ensures proper escaping of paths on Windows. if (opts.version !== undefined) { flags.push(`--version ${shell.quote([opts.version])}`); } @@ -407,7 +425,6 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { if (opts.repo !== undefined) { flags.push(`--repo ${path.quotePath(opts.repo)}`); } if (opts.untardir !== undefined) { flags.push(`--untardir ${path.quotePath(opts.untardir)}`); } if (opts.username !== undefined) { flags.push(`--username ${shell.quote([opts.username])}`); } - if (opts.home !== undefined) { flags.push(`--home ${path.quotePath(opts.home)}`); } if (opts.devel === true) { flags.push(`--devel`); } if (opts.prov === true) { flags.push(`--prov`); } if (opts.verify === true) { flags.push(`--verify`); } diff --git a/pkg/gen/python-templates/helm/v2/helm.py b/pkg/gen/python-templates/helm/v2/helm.py index a97109f213..4451a36e5f 100644 --- a/pkg/gen/python-templates/helm/v2/helm.py +++ b/pkg/gen/python-templates/helm/v2/helm.py @@ -338,10 +338,14 @@ def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi namespace_arg = ['--namespace', config.namespace] if config.namespace else [] + home = os.environ.get('HELM_HOME') + home_arg = ['--home', home] if home else [] + # Use 'helm template' to create a combined YAML manifest. cmd = ['helm', 'template', chart, '--name-template', release_name, '--values', default_values, '--values', overrides_filename] cmd.extend(namespace_arg) + cmd.extend(home_arg) chart_resources = pulumi.Output.all(cmd, data).apply(_run_helm_cmd) @@ -360,6 +364,11 @@ def _fetch(chart: str, opts: FetchOpts) -> None: if opts.untar is not False: cmd.append('--untar') + if opts.home: + cmd.extend(['--home', opts.home]) + elif os.environ.get('HELM_HOME'): + cmd.extend(['--home', os.environ.get('HELM_HOME')]) + if opts.version: cmd.extend(['--version', opts.version]) if opts.ca_file: @@ -380,8 +389,6 @@ def _fetch(chart: str, opts: FetchOpts) -> None: cmd.extend(['--untardir', opts.untar_dir]) if opts.username: cmd.extend(['--username', opts.username]) - if opts.home: - cmd.extend(['--home', opts.home]) if opts.devel: cmd.append('--devel') if opts.prov: diff --git a/sdk/nodejs/helm/v2/helm.ts b/sdk/nodejs/helm/v2/helm.ts index 76ba3a6b5a..0f92bafccd 100644 --- a/sdk/nodejs/helm/v2/helm.ts +++ b/sdk/nodejs/helm/v2/helm.ts @@ -192,8 +192,16 @@ export class Chart extends yaml.CollectionComponentResource { const namespaceArg = cfg.namespace ? `--namespace ${shell.quote([cfg.namespace])}` : ""; + let cmd = `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`; + + // Use the HELM_HOME environment variable value if set. + const home = process.env.HELM_HOME || undefined; + if (home !== undefined) { + cmd += ` --home ${home}`; + } + const yamlStream = execSync( - `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`, + cmd, { maxBuffer: 512 * 1024 * 1024 // 512 MB }, @@ -394,7 +402,17 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { // Untar by default. if(opts.untar !== false) { flags.push(`--untar`); } - // For arguments that are not paths to files, it is sufficent to use shell.quote to quote the arguments. + // Fallback to using the HELM_HOME environment variable if opts.home is not set. + if (opts.home !== undefined) { + flags.push(`--home ${path.quotePath(opts.home)}`); + } else { + const home = process.env.HELM_HOME || undefined; + if (home !== undefined) { + flags.push(`--home ${home}`); + } + } + + // For arguments that are not paths to files, it is sufficient to use shell.quote to quote the arguments. // However, for arguments that are actual paths to files we use path.quotePath (note that path here is // not the node path builtin module). This ensures proper escaping of paths on Windows. if (opts.version !== undefined) { flags.push(`--version ${shell.quote([opts.version])}`); } @@ -407,7 +425,6 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { if (opts.repo !== undefined) { flags.push(`--repo ${path.quotePath(opts.repo)}`); } if (opts.untardir !== undefined) { flags.push(`--untardir ${path.quotePath(opts.untardir)}`); } if (opts.username !== undefined) { flags.push(`--username ${shell.quote([opts.username])}`); } - if (opts.home !== undefined) { flags.push(`--home ${path.quotePath(opts.home)}`); } if (opts.devel === true) { flags.push(`--devel`); } if (opts.prov === true) { flags.push(`--prov`); } if (opts.verify === true) { flags.push(`--verify`); } diff --git a/sdk/python/pulumi_kubernetes/helm/v2/helm.py b/sdk/python/pulumi_kubernetes/helm/v2/helm.py index a97109f213..4451a36e5f 100644 --- a/sdk/python/pulumi_kubernetes/helm/v2/helm.py +++ b/sdk/python/pulumi_kubernetes/helm/v2/helm.py @@ -338,10 +338,14 @@ def _parse_chart(all_config: Tuple[str, Union[ChartOpts, LocalChartOpts], pulumi namespace_arg = ['--namespace', config.namespace] if config.namespace else [] + home = os.environ.get('HELM_HOME') + home_arg = ['--home', home] if home else [] + # Use 'helm template' to create a combined YAML manifest. cmd = ['helm', 'template', chart, '--name-template', release_name, '--values', default_values, '--values', overrides_filename] cmd.extend(namespace_arg) + cmd.extend(home_arg) chart_resources = pulumi.Output.all(cmd, data).apply(_run_helm_cmd) @@ -360,6 +364,11 @@ def _fetch(chart: str, opts: FetchOpts) -> None: if opts.untar is not False: cmd.append('--untar') + if opts.home: + cmd.extend(['--home', opts.home]) + elif os.environ.get('HELM_HOME'): + cmd.extend(['--home', os.environ.get('HELM_HOME')]) + if opts.version: cmd.extend(['--version', opts.version]) if opts.ca_file: @@ -380,8 +389,6 @@ def _fetch(chart: str, opts: FetchOpts) -> None: cmd.extend(['--untardir', opts.untar_dir]) if opts.username: cmd.extend(['--username', opts.username]) - if opts.home: - cmd.extend(['--home', opts.home]) if opts.devel: cmd.append('--devel') if opts.prov: From 11d2654b0f8066540fe59978a43ae0e3aaa0ffc4 Mon Sep 17 00:00:00 2001 From: Levi Blackstone Date: Tue, 3 Dec 2019 11:39:12 -0700 Subject: [PATCH 2/2] Address feedback --- pkg/gen/nodejs-templates/helm/v2/helm.ts | 12 ++++-------- sdk/nodejs/helm/v2/helm.ts | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/pkg/gen/nodejs-templates/helm/v2/helm.ts b/pkg/gen/nodejs-templates/helm/v2/helm.ts index 0f92bafccd..5b41f4efe2 100644 --- a/pkg/gen/nodejs-templates/helm/v2/helm.ts +++ b/pkg/gen/nodejs-templates/helm/v2/helm.ts @@ -197,7 +197,7 @@ export class Chart extends yaml.CollectionComponentResource { // Use the HELM_HOME environment variable value if set. const home = process.env.HELM_HOME || undefined; if (home !== undefined) { - cmd += ` --home ${home}`; + cmd += ` --home ${path.quotePath(home)}`; } const yamlStream = execSync( @@ -403,13 +403,8 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { if(opts.untar !== false) { flags.push(`--untar`); } // Fallback to using the HELM_HOME environment variable if opts.home is not set. - if (opts.home !== undefined) { - flags.push(`--home ${path.quotePath(opts.home)}`); - } else { - const home = process.env.HELM_HOME || undefined; - if (home !== undefined) { - flags.push(`--home ${home}`); - } + if (!opts.home) { + opts.home = process.env.HELM_HOME || undefined; } // For arguments that are not paths to files, it is sufficient to use shell.quote to quote the arguments. @@ -425,6 +420,7 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { if (opts.repo !== undefined) { flags.push(`--repo ${path.quotePath(opts.repo)}`); } if (opts.untardir !== undefined) { flags.push(`--untardir ${path.quotePath(opts.untardir)}`); } if (opts.username !== undefined) { flags.push(`--username ${shell.quote([opts.username])}`); } + if (opts.home !== undefined) { flags.push(`--home ${path.quotePath(opts.home)}`); } if (opts.devel === true) { flags.push(`--devel`); } if (opts.prov === true) { flags.push(`--prov`); } if (opts.verify === true) { flags.push(`--verify`); } diff --git a/sdk/nodejs/helm/v2/helm.ts b/sdk/nodejs/helm/v2/helm.ts index 0f92bafccd..5b41f4efe2 100644 --- a/sdk/nodejs/helm/v2/helm.ts +++ b/sdk/nodejs/helm/v2/helm.ts @@ -197,7 +197,7 @@ export class Chart extends yaml.CollectionComponentResource { // Use the HELM_HOME environment variable value if set. const home = process.env.HELM_HOME || undefined; if (home !== undefined) { - cmd += ` --home ${home}`; + cmd += ` --home ${path.quotePath(home)}`; } const yamlStream = execSync( @@ -403,13 +403,8 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { if(opts.untar !== false) { flags.push(`--untar`); } // Fallback to using the HELM_HOME environment variable if opts.home is not set. - if (opts.home !== undefined) { - flags.push(`--home ${path.quotePath(opts.home)}`); - } else { - const home = process.env.HELM_HOME || undefined; - if (home !== undefined) { - flags.push(`--home ${home}`); - } + if (!opts.home) { + opts.home = process.env.HELM_HOME || undefined; } // For arguments that are not paths to files, it is sufficient to use shell.quote to quote the arguments. @@ -425,6 +420,7 @@ export function fetch(chart: string, opts?: ResolvedFetchOpts) { if (opts.repo !== undefined) { flags.push(`--repo ${path.quotePath(opts.repo)}`); } if (opts.untardir !== undefined) { flags.push(`--untardir ${path.quotePath(opts.untardir)}`); } if (opts.username !== undefined) { flags.push(`--username ${shell.quote([opts.username])}`); } + if (opts.home !== undefined) { flags.push(`--home ${path.quotePath(opts.home)}`); } if (opts.devel === true) { flags.push(`--devel`); } if (opts.prov === true) { flags.push(`--prov`); } if (opts.verify === true) { flags.push(`--verify`); }