Skip to content

Commit

Permalink
Ensure provider InvokeOption is passed to function
Browse files Browse the repository at this point in the history
This commit ensure that provider options specified are passed to the
YAML Decoding function if supplied to a ConfigGroup. This prevents the
unnecessary instantiation of a default provider where this is used in a
mode where only explicitly created providers are otherwise in play.
  • Loading branch information
jen20 committed Jun 6, 2021
1 parent 8d00716 commit 4d72a1d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 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)

- `ConfigGroup` now respects explicit provider instances when parsing YAML.

## 3.3.0 (May 26, 2021)

- Automatically mark Secret data as Pulumi secrets. (https://github.com/pulumi/pulumi-kubernetes/pull/1577)
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

0 comments on commit 4d72a1d

Please sign in to comment.