Skip to content

Commit

Permalink
Add helm template apiVersions flag
Browse files Browse the repository at this point in the history
Co-authored-by: RichardWLaub <[email protected]>
  • Loading branch information
lblackstone and RichardWLaub authored Jan 16, 2020
1 parent bdccb03 commit cb8c50b
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
- Fix deprecation warnings and docs. (https://github.com/pulumi/pulumi-kubernetes/pull/929).
- Fix projection of array-valued output properties in .NET. (https://github.com/pulumi/pulumi-kubernetes/pull/931)

### Improvements

- Add helm template `apiVersions` flag. (https://github.com/pulumi/pulumi-kubernetes/pull/894)

## 1.4.1 (December 17, 2019)

### Bug fixes
Expand Down
13 changes: 12 additions & 1 deletion pkg/gen/nodejs-templates/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import * as path from "../../path";
import * as yaml from "../../yaml/index";

interface BaseChartOpts {
/**
* The optional kubernetes api versions used for Capabilities.APIVersions.
*/
apiVersions?: pulumi.Input<pulumi.Input<string>[]>;
/**
* The optional namespace to install chart resources into.
*/
Expand Down Expand Up @@ -189,10 +193,17 @@ export class Chart extends yaml.CollectionComponentResource {
// > is done.
const release = shell.quote([releaseName]);
const values = path.quotePath(overrides.name);
const apiVersionsArgs = cfg.apiVersions
? cfg.apiVersions.length > 1
? `--api-versions={${cfg.apiVersions
.map(apiVersion => shell.quote([apiVersion]))
.join(',')}}`
: `--api-versions=${shell.quote(cfg.apiVersions)}`
: '';
const namespaceArg = cfg.namespace
? `--namespace ${shell.quote([cfg.namespace])}`
: "";
let cmd = `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`;
let cmd = `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${apiVersionsArgs} ${namespaceArg}`;

// Use the HELM_HOME environment variable value if set.
const home = process.env.HELM_HOME || undefined;
Expand Down
13 changes: 12 additions & 1 deletion sdk/nodejs/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import * as path from "../../path";
import * as yaml from "../../yaml/index";

interface BaseChartOpts {
/**
* The optional kubernetes api versions used for Capabilities.APIVersions.
*/
apiVersions?: pulumi.Input<pulumi.Input<string>[]>;
/**
* The optional namespace to install chart resources into.
*/
Expand Down Expand Up @@ -189,10 +193,17 @@ export class Chart extends yaml.CollectionComponentResource {
// > is done.
const release = shell.quote([releaseName]);
const values = path.quotePath(overrides.name);
const apiVersionsArgs = cfg.apiVersions
? cfg.apiVersions.length > 1
? `--api-versions={${cfg.apiVersions
.map(apiVersion => shell.quote([apiVersion]))
.join(',')}}`
: `--api-versions=${shell.quote(cfg.apiVersions)}`
: '';
const namespaceArg = cfg.namespace
? `--namespace ${shell.quote([cfg.namespace])}`
: "";
let cmd = `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${namespaceArg}`;
let cmd = `helm template ${chart} --name-template ${release} --values ${defaultValues} --values ${values} ${apiVersionsArgs} ${namespaceArg}`;

// Use the HELM_HOME environment variable value if set.
const home = process.env.HELM_HOME || undefined;
Expand Down
17 changes: 17 additions & 0 deletions tests/examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ func TestAccHelm(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAccHelmApiVersions(t *testing.T) {
skipIfShort(t)
test := getBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "helm-api-versions"),
SkipRefresh: true,
ExtraRuntimeValidation: func(
t *testing.T, stackInfo integration.RuntimeValidationStackInfo,
) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 6, len(stackInfo.Deployment.Resources))
},
})

integration.ProgramTest(t, &test)
}

func TestAccHelmLocal(t *testing.T) {
skipIfShort(t)
test := getBaseOptions(t).
Expand Down
3 changes: 3 additions & 0 deletions tests/examples/helm-api-versions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/bin/
/node_modules/
/stable/
3 changes: 3 additions & 0 deletions tests/examples/helm-api-versions/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: helm-api-versions
runtime: nodejs
description: Deploys a simple Helm chart with .Capabilities.ApiVersions conditional
21 changes: 21 additions & 0 deletions tests/examples/helm-api-versions/helm-api-versions/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
4 changes: 4 additions & 0 deletions tests/examples/helm-api-versions/helm-api-versions/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deprecated: true
description: Chart to test .Capabilities.APIVersions
name: apiversions-test
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if and ( .Capabilities.APIVersions.Has "foo" ) ( .Capabilities.APIVersions.Has "bar") }}
apiVersion: v1
kind: Pod
metadata:
name: api-versions-test
namespace: {{ .Release.Namespace }}
spec:
containers:
- name: api-versions-test
image: nginx
{{- end }}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deprecated: true
description: Chart to test .Capabilities.APIVersions
name: apiversions-test
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if and ( .Capabilities.APIVersions.Has "foo" ) }}
apiVersion: v1
kind: Pod
metadata:
name: single-api-version-test
namespace: {{ .Release.Namespace }}
spec:
containers:
- name: single-api-version-test
image: nginx
{{- end }}
Empty file.
15 changes: 15 additions & 0 deletions tests/examples/helm-api-versions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as k8s from "@pulumi/kubernetes";

const namespace = new k8s.core.v1.Namespace("test");

new k8s.helm.v2.Chart("api-versions", {
apiVersions: ["foo", "bar"],
namespace: namespace.metadata.name,
path: "helm-api-versions",
});

new k8s.helm.v2.Chart("single-api-version", {
apiVersions: ["foo"],
namespace: namespace.metadata.name,
path: "helm-single-api-version",
});
14 changes: 14 additions & 0 deletions tests/examples/helm-api-versions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "nodeserver",
"version": "0.1.0",
"dependencies": {
"@pulumi/pulumi": "latest"
},
"devDependencies": {
"@types/node": "^9.3.0"
},
"peerDependencies": {
"@pulumi/kubernetes": "latest"
},
"license": "MIT"
}
21 changes: 21 additions & 0 deletions tests/examples/helm-api-versions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"outDir": "bin",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"stripInternal": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true
},
"files": [
"index.ts"
]
}

0 comments on commit cb8c50b

Please sign in to comment.