diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a5ecd4bc5..7bd692492d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## HEAD (Unreleased) - [sdk/python] Add ready attribute to await Helm charts (https://github.com/pulumi/pulumi-kubernetes/pull/1782) +- [sdk/go] Add ready attribute to await Helm charts (https://github.com/pulumi/pulumi-kubernetes/pull/1784) ## 3.8.3 (October 29, 2021) diff --git a/provider/pkg/gen/_go-templates/helm/v2/chart.go b/provider/pkg/gen/_go-templates/helm/v2/chart.go index 6b64af3a52..30a31df22a 100644 --- a/provider/pkg/gen/_go-templates/helm/v2/chart.go +++ b/provider/pkg/gen/_go-templates/helm/v2/chart.go @@ -1,4 +1,4 @@ -// Copyright 2016-2020, Pulumi Corporation. +// Copyright 2016-2021, Pulumi Corporation. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -221,6 +221,7 @@ import ( type Chart struct { pulumi.ResourceState + Ready pulumi.ResourceArrayOutput Resources pulumi.Output } @@ -253,6 +254,15 @@ func NewChart(ctx *pulumi.Context, return nil, errors.Wrap(err, "registering child resources") } + chart.Ready = resources.ApplyT(func(x interface{}) []pulumi.Resource { + resources := x.(map[string]pulumi.Resource) + var outputs []pulumi.Resource + for _, r := range resources { + outputs = append(outputs, r) + } + return outputs + }).(pulumi.ResourceArrayOutput) + return chart, nil } diff --git a/provider/pkg/gen/_go-templates/helm/v3/chart.go b/provider/pkg/gen/_go-templates/helm/v3/chart.go index 517db98e70..414c201726 100644 --- a/provider/pkg/gen/_go-templates/helm/v3/chart.go +++ b/provider/pkg/gen/_go-templates/helm/v3/chart.go @@ -213,6 +213,7 @@ import ( type Chart struct { pulumi.ResourceState + Ready pulumi.ResourceArrayOutput Resources pulumi.Output } @@ -251,6 +252,15 @@ func NewChart(ctx *pulumi.Context, return nil, errors.Wrap(err, "registering child resources") } + chart.Ready = resources.ApplyT(func(x interface{}) []pulumi.Resource { + resources := x.(map[string]pulumi.Resource) + var outputs []pulumi.Resource + for _, r := range resources { + outputs = append(outputs, r) + } + return outputs + }).(pulumi.ResourceArrayOutput) + return chart, nil } diff --git a/sdk/go.mod b/sdk/go.mod index 015f7c76cb..9aca321c9b 100644 --- a/sdk/go.mod +++ b/sdk/go.mod @@ -4,7 +4,8 @@ go 1.16 require ( github.com/blang/semver v3.5.1+incompatible + github.com/kr/pretty v0.3.0 // indirect github.com/pkg/errors v0.9.1 - github.com/pulumi/pulumi/sdk/v3 v3.13.2 + github.com/pulumi/pulumi/sdk/v3 v3.16.0 github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/sdk/go.sum b/sdk/go.sum index c976e7aaca..a88936a8ea 100644 --- a/sdk/go.sum +++ b/sdk/go.sum @@ -113,8 +113,9 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -161,9 +162,11 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/pulumi/pulumi/sdk/v3 v3.13.2 h1:WACuLmogYmUubf3jKcnkN9ACJ5G+3PLSPkCI86DpY9k= -github.com/pulumi/pulumi/sdk/v3 v3.13.2/go.mod h1:aT7YmFdR6/T7tp2tMIZ68WRD1Xyv5a6Y4BhsuaCNpW0= +github.com/pulumi/pulumi/sdk/v3 v3.16.0 h1:yqGysCf1LqlkengBnYqcbl5JI6JGySPN67+g60dMieU= +github.com/pulumi/pulumi/sdk/v3 v3.16.0/go.mod h1:252ou/zAU1g6E8iTwe2Y9ht7pb5BDl2fJlOuAgZCHiA= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 h1:G04eS0JkAIVZfaJLjla9dNxkJCPiKIGZlw9AfOhzOD0= github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94/go.mod h1:b18R55ulyQ/h3RaWyloPyER7fWQVZvimKKhnI5OfrJQ= @@ -322,6 +325,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.28 h1:n1tBJnnK2r7g9OW2btFH91V92STTUevLXYFb8gy9EMk= gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= diff --git a/sdk/go/kubernetes/helm/v2/chart.go b/sdk/go/kubernetes/helm/v2/chart.go index 6b64af3a52..30a31df22a 100644 --- a/sdk/go/kubernetes/helm/v2/chart.go +++ b/sdk/go/kubernetes/helm/v2/chart.go @@ -1,4 +1,4 @@ -// Copyright 2016-2020, Pulumi Corporation. +// Copyright 2016-2021, Pulumi Corporation. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -221,6 +221,7 @@ import ( type Chart struct { pulumi.ResourceState + Ready pulumi.ResourceArrayOutput Resources pulumi.Output } @@ -253,6 +254,15 @@ func NewChart(ctx *pulumi.Context, return nil, errors.Wrap(err, "registering child resources") } + chart.Ready = resources.ApplyT(func(x interface{}) []pulumi.Resource { + resources := x.(map[string]pulumi.Resource) + var outputs []pulumi.Resource + for _, r := range resources { + outputs = append(outputs, r) + } + return outputs + }).(pulumi.ResourceArrayOutput) + return chart, nil } diff --git a/sdk/go/kubernetes/helm/v3/chart.go b/sdk/go/kubernetes/helm/v3/chart.go index 517db98e70..414c201726 100644 --- a/sdk/go/kubernetes/helm/v3/chart.go +++ b/sdk/go/kubernetes/helm/v3/chart.go @@ -213,6 +213,7 @@ import ( type Chart struct { pulumi.ResourceState + Ready pulumi.ResourceArrayOutput Resources pulumi.Output } @@ -251,6 +252,15 @@ func NewChart(ctx *pulumi.Context, return nil, errors.Wrap(err, "registering child resources") } + chart.Ready = resources.ApplyT(func(x interface{}) []pulumi.Resource { + resources := x.(map[string]pulumi.Resource) + var outputs []pulumi.Resource + for _, r := range resources { + outputs = append(outputs, r) + } + return outputs + }).(pulumi.ResourceArrayOutput) + return chart, nil } diff --git a/tests/go.mod b/tests/go.mod index e15587d629..9eea51f2e8 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,6 +13,6 @@ require ( github.com/pulumi/pulumi-kubernetes/provider/v3 v3.0.0-rc.1 github.com/pulumi/pulumi-kubernetes/sdk/v3 v3.0.0-rc.1 github.com/pulumi/pulumi/pkg/v3 v3.14.1-0.20211007232357-25a4c9d4398b - github.com/pulumi/pulumi/sdk/v3 v3.14.0 + github.com/pulumi/pulumi/sdk/v3 v3.16.0 github.com/stretchr/testify v1.7.0 ) diff --git a/tests/go.sum b/tests/go.sum index f28617a16a..870c7f29e1 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -745,8 +745,9 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= @@ -969,15 +970,17 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/pulumi/pulumi/pkg/v3 v3.14.1-0.20211007232357-25a4c9d4398b h1:3ZM4P/K+2lsvNLq/cHxpVdjcC4iTn0xgY5vUITdy2nY= github.com/pulumi/pulumi/pkg/v3 v3.14.1-0.20211007232357-25a4c9d4398b/go.mod h1:0w8C+JDP+OuihIgj/TNljRJdNHyW1vNiH1zzbeB4xeM= -github.com/pulumi/pulumi/sdk/v3 v3.13.2/go.mod h1:aT7YmFdR6/T7tp2tMIZ68WRD1Xyv5a6Y4BhsuaCNpW0= -github.com/pulumi/pulumi/sdk/v3 v3.14.0 h1:UXLRHGQCsO1tLWdv4IO3IQOXrUoZUHhDtDXFoGMmAtA= github.com/pulumi/pulumi/sdk/v3 v3.14.0/go.mod h1:aT7YmFdR6/T7tp2tMIZ68WRD1Xyv5a6Y4BhsuaCNpW0= +github.com/pulumi/pulumi/sdk/v3 v3.16.0 h1:yqGysCf1LqlkengBnYqcbl5JI6JGySPN67+g60dMieU= +github.com/pulumi/pulumi/sdk/v3 v3.16.0/go.mod h1:252ou/zAU1g6E8iTwe2Y9ht7pb5BDl2fJlOuAgZCHiA= github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8= github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rubenv/sql-migrate v0.0.0-20210614095031-55d5740dbbcc/go.mod h1:HFLT6i9iR4QBOF5rdCyjddC9t59ArqWJV2xx+jwcCMo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/tests/sdk/go/go_test.go b/tests/sdk/go/go_test.go index 7f402bbb45..505481ae11 100644 --- a/tests/sdk/go/go_test.go +++ b/tests/sdk/go/go_test.go @@ -17,13 +17,14 @@ package test import ( b64 "encoding/base64" "encoding/json" + "fmt" "os" "path/filepath" + "regexp" "strings" "testing" "github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/openapi" - "github.com/pulumi/pulumi/pkg/v3/testing/integration" "github.com/stretchr/testify/assert" ) @@ -63,6 +64,34 @@ func TestGo(t *testing.T) { options := baseOptions.With(integration.ProgramTestOptions{ Dir: filepath.Join(cwd, "helm-local", "step1"), Quick: true, + ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) { + // Verify resource creation order using the Event stream. The Chart resources must be created + // first, followed by the dependent ConfigMap. (The ConfigMap doesn't actually need the Chart, but + // it creates almost instantly, so it's a good choice to test creation ordering) + cmRegex := regexp.MustCompile(`ConfigMap::nginx-server-block`) + svcRegex := regexp.MustCompile(`Service::nginx`) + deployRegex := regexp.MustCompile(`Deployment::nginx`) + dependentRegex := regexp.MustCompile(`ConfigMap::foo`) + + var configmapFound, serviceFound, deploymentFound, dependentFound bool + for _, e := range stackInfo.Events { + if e.ResOutputsEvent != nil { + switch { + case cmRegex.MatchString(e.ResOutputsEvent.Metadata.URN): + configmapFound = true + case svcRegex.MatchString(e.ResOutputsEvent.Metadata.URN): + serviceFound = true + case deployRegex.MatchString(e.ResOutputsEvent.Metadata.URN): + deploymentFound = true + case dependentRegex.MatchString(e.ResOutputsEvent.Metadata.URN): + dependentFound = true + } + assert.Falsef(t, dependentFound && !(configmapFound && serviceFound && deploymentFound), + "dependent ConfigMap created before all chart resources were ready") + fmt.Println(e.ResOutputsEvent.Metadata.URN) + } + } + }, EditDirs: []integration.EditDir{ { Dir: filepath.Join(cwd, "helm-local", "step2"), diff --git a/tests/sdk/go/helm-local/step1/main.go b/tests/sdk/go/helm-local/step1/main.go index 98f889d61b..9fc675650b 100644 --- a/tests/sdk/go/helm-local/step1/main.go +++ b/tests/sdk/go/helm-local/step1/main.go @@ -24,6 +24,16 @@ func main() { }) ctx.Export("svc_ip", svc) + _, err = corev1.NewConfigMap(ctx, "cm", &corev1.ConfigMapArgs{ + Data: pulumi.StringMap{ + "foo": pulumi.String("bar"), + }, + }, pulumi.DependsOnInputs(chart.Ready)) + if err != nil { + return err + } + + return nil }) } diff --git a/tests/sdk/go/helm-local/step2/main.go b/tests/sdk/go/helm-local/step2/main.go index 54d520ba91..4afb826509 100644 --- a/tests/sdk/go/helm-local/step2/main.go +++ b/tests/sdk/go/helm-local/step2/main.go @@ -24,6 +24,15 @@ func main() { }) ctx.Export("svc_ip", svc) + _, err = corev1.NewConfigMap(ctx, "cm", &corev1.ConfigMapArgs{ + Data: pulumi.StringMap{ + "foo": pulumi.String("bar"), + }, + }, pulumi.DependsOnInputs(chart.Ready)) + if err != nil { + return err + } + return nil }) }