Skip to content

Commit

Permalink
Adds namespace,version,repo to Helm
Browse files Browse the repository at this point in the history
Fixes: cdk8s-team#940

Signed-off-by: Yair Fried <5310525+yfried@users.noreply.github.com>
  • Loading branch information
yfried committed Dec 25, 2022
1 parent e013345 commit 7b3a42a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ export interface HelmProps {
*/
readonly chart: string;

/**
* Chart repository url where to locate the requested chart
*/
readonly repo?: string;

/**
* Version constraint for the chart version to use.
* This constraint can be a specific tag (e.g. 1.1.1)
* or it may reference a valid range (e.g. ^2.0.0).
* If this is not specified, the latest version is used
*
* This name is passed to `helm template --version` and has all the relevant semantics.
*
* @example "1.1.1"
* @example "^2.0.0"
*/
readonly version?: string;

/**
* Scope all resources in to a given namespace.
*/
readonly namespace?: string;

/**
* The release name.
*
Expand Down Expand Up @@ -77,6 +100,18 @@ export class Helm extends Include {
args.push('-f', valuesPath);
}

if (props.repo) {
args.push('--repo', props.repo);
}

if (props.version) {
args.push('--version', props.version);
}

if (props.namespace) {
args.push('--namespace', props.namespace);
}

// custom flags
if (props.helmFlags) {
args.push(...props.helmFlags);
Expand Down
35 changes: 35 additions & 0 deletions test/helm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,41 @@ test('helmFlags can be used to specify additional helm options', () => {
expect(spawnMock).toHaveBeenCalledWith('helm', expectedArgs, { maxBuffer: 10485760 });
});

test('repo can be used to specify helm repo', () => {
// GIVEN
const spawnMock = jest.spyOn(_child_process, 'spawnSync').mockReturnValue({
status: 0,
stderr: Buffer.from(''),
stdout: Buffer.from(''),
pid: 123,
output: [Buffer.from('stdout', 'utf8'), Buffer.from('stderr', 'utf8')],
signal: null,
});

const chart = Testing.chart();

// WHEN
new Helm(chart, 'sample', {
chart: SAMPLE_CHART_PATH,
repo: 'foo-repo',
version: 'foo-version',
namespace: 'foo-namespace',
});

// THEN
const expectedArgs: string[] = [
'template',
'--repo', 'foo-repo',
'--version', 'foo-version',
'--namespace', 'foo-namespace',
'test-sample-c8e2763d',
SAMPLE_CHART_PATH,
];

expect(spawnMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledWith('helm', expectedArgs, { maxBuffer: 10485760 });
});

test('propagates helm failures', () => {
// GIVEN
const chart = Testing.chart();
Expand Down

0 comments on commit 7b3a42a

Please sign in to comment.