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

Support for validation failures from Construct RPC #16132

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented May 6, 2024

Description

Implements support for returning Failures from the Construct RPC. Design doc:
https://docs.google.com/document/d/1CK5YgSBK2g3LzY-bZVMMrMwyel-7nbQYisSYExJQ4Fw/edit?usp=sharing

Implementation Details

An important aspect of validation failures is that they don't cause spurious error messages like "rpc error" or "bailed". With that in mind, this implements strives to handle failure in the way that it is handled for Check RPC.

To recap how Check works: the resource monitor receives a registration request, sends a registerResourceEvent to the registration channel, and then blocks. The step executor calls Check, reports on the failures, then cancels the deployment, with the event's done channel left open. The resource monitor is ultimately cancelled.

Unlike Check, Construct is handled directly by the resource monitor and doesn't involve a step. The resource monitor needs a way to poison the deployment via the iterator. So, the monitor simply closes an abort channel, causing the iterator to bail to nice effect.

Fixes #6933

Example

Given a component provider whose construct function resembles:

func (k *ConfigGroupProvider) Construct(ctx *pulumi.Context, typ, name string, inputs pulumiprovider.ConstructInputs, options pulumi.ResourceOption) (*pulumiprovider.ConstructResult, error) {
	comp := &ConfigGroupState{}
	err := ctx.RegisterComponentResource(typ, name, comp, options)

	var failures []pulumiprovider.ConstructFailure
	failures = append(failures, pulumiprovider.ConstructFailure{Property: "files", Reason: "bad files"})
	
	return pulumiprovider.NewConstructResult(comp, pulumiprovider.Failures(failures))
}

And a program:

package main

import (
	yamlv2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml/v2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := yamlv2.NewConfigGroup(ctx, "example", &yamlv2.ConfigGroupArgs{
		    Files: pulumi.StringArray{
		    	pulumi.String("./manifest.yaml"),
		    },
		})
		return err
	})
}

We see the expected behavior:

❯ pulumi preview
Previewing update (dev)

                       View in Browser (Ctrl+O): https://app.pulumi.com/eron-pulumi-corp/issue-6933/dev/previews/52c65d4f-a104-4bda-a2f1-698bb07ed67f

     Type                               Name            Plan       Info
     pulumi:pulumi:Stack                issue-6933-dev             5 warnings
 +   └─ kubernetes:yaml/v2:ConfigGroup  example         create     1 error

Diagnostics:
  kubernetes:yaml/v2:ConfigGroup (example):
    error: kubernetes:yaml/v2:ConfigGroup resource 'example': property files value {[{./manifest.yaml}]} has a problem: bad files.

Checklist

  • I have run make tidy to update any new dependencies
  • I have run make lint to verify my code passes the lint check
    • I have formatted my code using gofumpt
  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version

@EronWright EronWright self-assigned this May 6, 2024
@EronWright EronWright requested a review from tgummerer May 6, 2024 16:41
@pulumi-bot
Copy link
Contributor

pulumi-bot commented May 6, 2024

Changelog

[uncommitted] (2024-05-09)

Features

  • [components] Support for validation failures from Construct RPC
    #16132

@EronWright EronWright marked this pull request as ready for review May 7, 2024 22:20
@EronWright EronWright requested a review from a team as a code owner May 7, 2024 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve how we handle/surface errors in multi-language components
2 participants