Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure provider InvokeOption is passed to functions #1601

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (Unreleased)

- [sdk/go] `ConfigGroup` now respects explicit provider instances when parsing YAML. (https://github.com/pulumi/pulumi-kubernetes/pull/1601)

## 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
3 changes: 2 additions & 1 deletion provider/pkg/gen/_go-templates/yaml/configGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ func NewConfigGroup(ctx *pulumi.Context,
}

// Parse and decode the YAML files.
rs, err := parseDecodeYamlFiles(ctx, args, true, pulumi.Parent(configGroup))
parseOpts := append(opts, pulumi.Parent(configGroup))
rs, err := parseDecodeYamlFiles(ctx, args, true, parseOpts...)
if err != nil {
return nil, err
}
Expand Down
14 changes: 11 additions & 3 deletions provider/pkg/gen/_go-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ func parseDecodeYamlFiles(ctx *pulumi.Context, args *ConfigGroupArgs, glob bool,
}
}

// Find options which are also Invoke options, and prepare them to pass to Invoke functions
var invokeOpts []pulumi.InvokeOption
for _, opt := range opts {
if invokeOpt, ok := opt.(pulumi.InvokeOption); ok {
invokeOpts = append(invokeOpts, invokeOpt)
}
}

// Next parse all YAML documents into objects.
for _, yaml := range yamls {
// Parse the resulting YAML bytes and turn them into raw Kubernetes objects.
dec, err := yamlDecode(ctx, yaml, opts...)
dec, err := yamlDecode(ctx, yaml, invokeOpts...)
if err != nil {
return nil, errors.Wrapf(err, "decoding YAML")
}
Expand All @@ -94,15 +102,15 @@ func parseDecodeYamlFiles(ctx *pulumi.Context, args *ConfigGroupArgs, glob bool,
}

// yamlDecode invokes the function to decode a single YAML file and decompose it into object structures.
func yamlDecode(ctx *pulumi.Context, text string, opts ...pulumi.ResourceOption) ([]map[string]interface{}, error) {
func yamlDecode(ctx *pulumi.Context, text string, opts ...pulumi.InvokeOption) ([]map[string]interface{}, error) {
args := struct {
Text string `pulumi:"text"`
}{Text: text}
var ret struct {
Result []map[string]interface{} `pulumi:"result"`
}

if err := ctx.Invoke("kubernetes:yaml:decode", &args, &ret); err != nil {
if err := ctx.Invoke("kubernetes:yaml:decode", &args, &ret, opts...); err != nil {
return nil, err
}
return ret.Result, nil
Expand Down
3 changes: 2 additions & 1 deletion sdk/go/kubernetes/yaml/configGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ func NewConfigGroup(ctx *pulumi.Context,
}

// Parse and decode the YAML files.
rs, err := parseDecodeYamlFiles(ctx, args, true, pulumi.Parent(configGroup))
parseOpts := append(opts, pulumi.Parent(configGroup))
rs, err := parseDecodeYamlFiles(ctx, args, true, parseOpts...)
if err != nil {
return nil, err
}
Expand Down
14 changes: 11 additions & 3 deletions sdk/go/kubernetes/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,18 @@ func parseDecodeYamlFiles(ctx *pulumi.Context, args *ConfigGroupArgs, glob bool,
}
}

// Find options which are also Invoke options, and prepare them to pass to Invoke functions
var invokeOpts []pulumi.InvokeOption
for _, opt := range opts {
if invokeOpt, ok := opt.(pulumi.InvokeOption); ok {
invokeOpts = append(invokeOpts, invokeOpt)
}
}

// Next parse all YAML documents into objects.
for _, yaml := range yamls {
// Parse the resulting YAML bytes and turn them into raw Kubernetes objects.
dec, err := yamlDecode(ctx, yaml, opts...)
dec, err := yamlDecode(ctx, yaml, invokeOpts...)
if err != nil {
return nil, errors.Wrapf(err, "decoding YAML")
}
Expand All @@ -141,15 +149,15 @@ func parseDecodeYamlFiles(ctx *pulumi.Context, args *ConfigGroupArgs, glob bool,
}

// yamlDecode invokes the function to decode a single YAML file and decompose it into object structures.
func yamlDecode(ctx *pulumi.Context, text string, opts ...pulumi.ResourceOption) ([]map[string]interface{}, error) {
func yamlDecode(ctx *pulumi.Context, text string, opts ...pulumi.InvokeOption) ([]map[string]interface{}, error) {
args := struct {
Text string `pulumi:"text"`
}{Text: text}
var ret struct {
Result []map[string]interface{} `pulumi:"result"`
}

if err := ctx.Invoke("kubernetes:yaml:decode", &args, &ret); err != nil {
if err := ctx.Invoke("kubernetes:yaml:decode", &args, &ret, opts...); err != nil {
return nil, err
}
return ret.Result, nil
Expand Down