diff --git a/CHANGELOG.md b/CHANGELOG.md index 02ab3e3622..9499b525c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/provider/pkg/gen/nodejs-templates/helm/v3/helm.ts b/provider/pkg/gen/nodejs-templates/helm/v3/helm.ts index 63489425d3..d5fb5865c6 100644 --- a/provider/pkg/gen/nodejs-templates/helm/v3/helm.ts +++ b/provider/pkg/gen/nodejs-templates/helm/v3/helm.ts @@ -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() }; @@ -228,7 +239,7 @@ export class Chart extends yaml.CollectionComponentResource { { resourcePrefix: config.resourcePrefix, objs: p.result, - transformations: config.transformations || [], + transformations, }, { parent: this } )); @@ -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; } /** diff --git a/sdk/nodejs/helm/v3/helm.ts b/sdk/nodejs/helm/v3/helm.ts index 63489425d3..d5fb5865c6 100644 --- a/sdk/nodejs/helm/v3/helm.ts +++ b/sdk/nodejs/helm/v3/helm.ts @@ -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() }; @@ -228,7 +239,7 @@ export class Chart extends yaml.CollectionComponentResource { { resourcePrefix: config.resourcePrefix, objs: p.result, - transformations: config.transformations || [], + transformations, }, { parent: this } )); @@ -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; } /** diff --git a/tests/sdk/nodejs/examples/examples_test.go b/tests/sdk/nodejs/examples/examples_test.go index 7236ae8af7..71f0731dd5 100644 --- a/tests/sdk/nodejs/examples/examples_test.go +++ b/tests/sdk/nodejs/examples/examples_test.go @@ -20,6 +20,7 @@ import ( "path/filepath" "regexp" "sort" + "strings" "testing" "github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/openapi" @@ -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{}) @@ -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) diff --git a/tests/sdk/nodejs/examples/helm-skip-crd-rendering/step1/index.ts b/tests/sdk/nodejs/examples/helm-skip-crd-rendering/step1/index.ts index 6d5b3a9a24..6d389658dd 100644 --- a/tests/sdk/nodejs/examples/helm-skip-crd-rendering/step1/index.ts +++ b/tests/sdk/nodejs/examples/helm-skip-crd-rendering/step1/index.ts @@ -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", });