Skip to content

Commit

Permalink
Use HELM_HOME as default if set
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 committed Dec 3, 2019
1 parent 2bec2dc commit 6f75c19
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- v1.15.x
- v1.14.x

### Improvements

- Use HELM_HOME as default if set. (https://github.com/pulumi/pulumi-kubernetes/pull/855).

## 1.3.3 (November 29, 2019)

### Supported Kubernetes versions
Expand Down
23 changes: 20 additions & 3 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 ${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,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])}`); }
Expand All @@ -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`); }
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
23 changes: 20 additions & 3 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 ${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,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])}`); }
Expand All @@ -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`); }
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 6f75c19

Please sign in to comment.