Skip to content

Commit

Permalink
Use HELM_HOME as default if set (#855)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lblackstone authored Dec 3, 2019
1 parent 7c624e7 commit 127ed57
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions pkg/gen/nodejs-templates/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ${path.quotePath(home)}`;
}

const yamlStream = execSync(
`helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`,
cmd,
{
maxBuffer: 512 * 1024 * 1024 // 512 MB
},
Expand Down Expand Up @@ -394,7 +402,12 @@ 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) {
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.
// 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])}`); }
Expand Down
11 changes: 9 additions & 2 deletions pkg/gen/python-templates/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions sdk/nodejs/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ${path.quotePath(home)}`;
}

const yamlStream = execSync(
`helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`,
cmd,
{
maxBuffer: 512 * 1024 * 1024 // 512 MB
},
Expand Down Expand Up @@ -394,7 +402,12 @@ 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) {
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.
// 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])}`); }
Expand Down
11 changes: 9 additions & 2 deletions sdk/python/pulumi_kubernetes/helm/v2/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 127ed57

Please sign in to comment.