Skip to content

Commit

Permalink
Add skipAwait option to Helm v3.Chart
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Jun 8, 2021
1 parent f252db9 commit fea5211
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (Unreleased)

- Add skipAwait option to helm.v3 SDKs. (https://github.com/pulumi/pulumi-kubernetes/pull/1603)

## 3.3.1 (June 8, 2021)

- [sdk/python] Fix YAML regression by pinning pulumi dependency to <3.4.0. (https://github.com/pulumi/pulumi-kubernetes/pull/1605)
Expand Down
18 changes: 17 additions & 1 deletion provider/pkg/gen/nodejs-templates/helm/v3/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ export class Chart extends yaml.CollectionComponentResource {

const jsonOpts = JSON.stringify(blob)

const transformations: ((o: any, opts: pulumi.CustomResourceOptions) => void)[] = config.transformations ?? [];
if (config.skipAwait) {
transformations.push((o: any, opts: pulumi.ComponentResourceOptions) => {
if (o.metadata.annotations === undefined) {
o.metadata.annotations = {"pulumi.com/skipAwait": "true"};
} else {
o.metadata.annotations["pulumi.com/skipAwait"] = "true";
}
});
}

// Rather than using the default provider for the following invoke call, use the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion() };
Expand All @@ -228,7 +239,7 @@ export class Chart extends yaml.CollectionComponentResource {
{
resourcePrefix: config.resourcePrefix,
objs: p.result,
transformations: config.transformations || [],
transformations,
},
{ parent: this }
));
Expand Down Expand Up @@ -267,6 +278,11 @@ interface BaseChartOpts {
* Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
*/
resourcePrefix?: string
/**
* Skip await logic for all resources in this Chart. Resources will be marked ready as soon as they are created.
* Warning: This option should not be used if you have resources depending on Outputs from the Chart.
*/
skipAwait?: pulumi.Input<boolean>;
}

/**
Expand Down
18 changes: 17 additions & 1 deletion sdk/nodejs/helm/v3/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ export class Chart extends yaml.CollectionComponentResource {

const jsonOpts = JSON.stringify(blob)

const transformations: ((o: any, opts: pulumi.CustomResourceOptions) => void)[] = config.transformations ?? [];
if (config.skipAwait) {
transformations.push((o: any, opts: pulumi.ComponentResourceOptions) => {
if (o.metadata.annotations === undefined) {
o.metadata.annotations = {"pulumi.com/skipAwait": "true"};
} else {
o.metadata.annotations["pulumi.com/skipAwait"] = "true";
}
});
}

// Rather than using the default provider for the following invoke call, use the version specified
// in package.json.
let invokeOpts: pulumi.InvokeOptions = { async: true, version: getVersion() };
Expand All @@ -228,7 +239,7 @@ export class Chart extends yaml.CollectionComponentResource {
{
resourcePrefix: config.resourcePrefix,
objs: p.result,
transformations: config.transformations || [],
transformations,
},
{ parent: this }
));
Expand Down Expand Up @@ -267,6 +278,11 @@ interface BaseChartOpts {
* Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
*/
resourcePrefix?: string
/**
* Skip await logic for all resources in this Chart. Resources will be marked ready as soon as they are created.
* Warning: This option should not be used if you have resources depending on Outputs from the Chart.
*/
skipAwait?: pulumi.Input<boolean>;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion tests/sdk/nodejs/examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strings"
"testing"

"github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/openapi"
Expand Down Expand Up @@ -139,7 +140,7 @@ func TestAccHelm(t *testing.T) {
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
// Ensure that all `Services` have `status` marked as a `Secret`
for _, res := range stackInfo.Deployment.Resources {
if res.Type == tokens.Type("kubernetes:core/v1:Service") {
if res.Type == "kubernetes:core/v1:Service" {
spec, has := res.Outputs["status"]
assert.True(t, has)
specMap, is := spec.(map[string]interface{})
Expand Down Expand Up @@ -195,6 +196,18 @@ func TestAccHelmAllowCRDRendering(t *testing.T) {
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 8, len(stackInfo.Deployment.Resources))

for _, res := range stackInfo.Deployment.Resources {
if res.Type == "kubernetes:core/v1:Pod" {
annotations, ok := openapi.Pluck(res.Inputs, "metadata", "annotations")
if strings.Contains(res.ID.String(), "skip-crd") {
assert.False(t, ok)
} else {
assert.True(t, ok)
assert.Contains(t, annotations, "pulumi.com/skipAwait")
}
}
}
},
})
integration.ProgramTest(t, &test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const namespace = new k8s.core.v1.Namespace("test");

new k8s.helm.v3.Chart("skip-crd-rendering", {
skipCRDRendering: true,
skipAwait: false,
namespace: namespace.metadata.name,
path: "helm-skip-crd-rendering",
});

new k8s.helm.v3.Chart("allow-crd-rendering", {
skipCRDRendering: false,
skipAwait: true,
namespace: namespace.metadata.name,
path: "helm-allow-crd-rendering",
});

0 comments on commit fea5211

Please sign in to comment.