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
Resources now inherit the DeletedWith Resource Option across SDKs. #12572
Conversation
Changelog[uncommitted] (2023-06-02)Features
|
cbd19e8
to
fb272a5
Compare
// TestResourceInheritsOptionsFromParentNoGoal checks that configureGoal does not error when the parent goal is not | ||
// present in the step generator. This can occur for Read resources (i.e. pkg.Resource.get()) and MLCs. | ||
func TestResourceInheritsOptionsFromParentNoGoal(t *testing.T) { | ||
t.Parallel() | ||
|
||
parentURN := resource.NewURN("a", "proj", "d:e:f", "a:b:c", "parent") | ||
|
||
childURN := resource.NewURN("a", "proj", "d:e:f", "a:b:c", "child") | ||
goal := &resource.Goal{ | ||
Parent: parentURN, | ||
Type: childURN.Type(), | ||
Name: childURN.Name(), | ||
} | ||
|
||
// Create a step generator without the parent goal. | ||
sg := stepGenerator{ | ||
urns: map[resource.URN]bool{ | ||
parentURN: true, | ||
}, | ||
resourceGoals: map[resource.URN]*resource.Goal{}, | ||
} | ||
err := sg.configureGoal(goal) | ||
|
||
assert.Nil(t, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catches the regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed approach to track goals in the resource monitor.
Resources without goals should show up in the resource monitor (even MLCs). Read resources don't actually have resource options sent over the wire to propagate and expectation for imported resources to be inherited by child resources are an inaccuracy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if the parent is an MLC or read resource we don't propagate the options? That feels wrong.
45bd920
to
81dc491
Compare
@@ -360,3 +360,107 @@ func TestEngineDiff(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestResourceInheritsOptionsFromParent(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how much I'd trust tests around the step_generator like this. I'd rather see a test in pkg/engine/lifecycletest that runs a whole deployment checking that we can have parent child combinations of the product of [mlc, readResource, registerResource].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadResource requests don't have ResourceOptions attached other than Parent
pulumi/sdk/proto/go/resource.pb.go
Lines 135 to 153 in ec1b046
// ReadResourceRequest contains enough information to uniquely qualify and read a resource's state. | |
type ReadResourceRequest struct { | |
state protoimpl.MessageState | |
sizeCache protoimpl.SizeCache | |
unknownFields protoimpl.UnknownFields | |
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // the ID of the resource to read. | |
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` // the type of the resource object. | |
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` // the name, for URN purposes, of the object. | |
Parent string `protobuf:"bytes,4,opt,name=parent,proto3" json:"parent,omitempty"` // an optional parent URN that this child resource belongs to. | |
Properties *structpb.Struct `protobuf:"bytes,5,opt,name=properties,proto3" json:"properties,omitempty"` // optional state sufficient to uniquely identify the resource. | |
Dependencies []string `protobuf:"bytes,6,rep,name=dependencies,proto3" json:"dependencies,omitempty"` // a list of URNs that this read depends on, as observed by the language host. | |
Provider string `protobuf:"bytes,7,opt,name=provider,proto3" json:"provider,omitempty"` // an optional reference to the provider to use for this read. | |
Version string `protobuf:"bytes,8,opt,name=version,proto3" json:"version,omitempty"` // the version of the provider to use when servicing this request. | |
AcceptSecrets bool `protobuf:"varint,9,opt,name=acceptSecrets,proto3" json:"acceptSecrets,omitempty"` // when true operations should return secrets as strongly typed. | |
AdditionalSecretOutputs []string `protobuf:"bytes,10,rep,name=additionalSecretOutputs,proto3" json:"additionalSecretOutputs,omitempty"` // a list of output properties that should also be treated as secret, in addition to ones we detect. | |
AcceptResources bool `protobuf:"varint,12,opt,name=acceptResources,proto3" json:"acceptResources,omitempty"` // when true operations should return resource references as strongly typed. | |
PluginDownloadURL string `protobuf:"bytes,13,opt,name=pluginDownloadURL,proto3" json:"pluginDownloadURL,omitempty"` // the server url of the provider to use when servicing this request. | |
} |
Nothing in deploytest indicates to me that we call RegisterResource on ReadResources.
This leads me to believe that a ReadResource shouldn't have any ResourceOptions for the Child resource to Inherit.
9dec774
to
c7b26ba
Compare
c7b26ba
to
f7c75fa
Compare
assert.Nil(t, res) | ||
} | ||
|
||
// TODO determine if this is redundant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems redundant at this point. This test checks that a RegisterResource call inside of a MLC provider is properly parented, but the distinction between the MLC provider and the program itself parenting an MLC resource seems irrelevant.
f7c75fa
to
88c4521
Compare
326f18e
to
b84f498
Compare
@@ -993,6 +996,16 @@ func (rm *resmon) ReadResource(ctx context.Context, | |||
}, nil | |||
} | |||
|
|||
// inheritFromParent returns a new goal that inherits from the given parent goal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh this really sucks that we're getting inheritance logic in step_generator and source_eval now. That's gonna bite us in the ass at some point for sure.
I don't think there's any quick fix for that, so probably have to live with it for this change but this is tech debt that needs paying down. (cc @justinvp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, now it's only in source_eval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Frassle, do you mean alias inheritance in step_generator, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alias inheritance but also checking for parent correctness and defaulting that to the stack resource if it exists
08a7387
to
3835d75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok, I think we'll want to work out a way to move parent logic consistently to step_generator at some point but will take time to think that through
This is implemented in the engine and interprets the empty string `""` to inherit the value from the resource's parent if it exists signifying that it was unspecified by the user's program. There is currently no way to override this in a child to unset it when set by the parent, but can be addressed by not parenting the resource to a resource with `deletedWith` set.
3835d75
to
653adbe
Compare
bors merge |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Description
This PR uses this information to set the
DeletedWith
when it is left unset by the user's program and there is a Parent resource to inherit the value from.From #12446 which was reverted due to #12562 having difficulty with MLCs and Read resources.
TODO
Fixes #12158
Needs follow up on: pulumi/pulumi-hugo#2566
Checklist
make changelog
and committed thechangelog/pending/<file>
documenting my change