-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add a self reference to CallRequest and ConstructRequest #533
Draft
Frassle
wants to merge
1
commit into
main
Choose a base branch
from
fraser/selfref
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+401
−127
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,13 +363,15 @@ public DeleteRequest(Urn urn, string id, ImmutableDictionary<string, PropertyVal | |
|
||
public sealed class ConstructRequest | ||
{ | ||
public ProviderResource? Provider { get; init; } | ||
public string Type { get; init; } | ||
public string Name { get; init; } | ||
public ImmutableDictionary<string, PropertyValue> Inputs { get; init; } | ||
public ComponentResourceOptions Options { get; init; } | ||
|
||
public ConstructRequest(string type, string name, ImmutableDictionary<string, PropertyValue> inputs, ComponentResourceOptions options) | ||
public ConstructRequest(ProviderResource? provider, string type, string name, ImmutableDictionary<string, PropertyValue> inputs, ComponentResourceOptions options) | ||
{ | ||
Provider = provider; | ||
Type = type; | ||
Name = name; | ||
Inputs = inputs; | ||
|
@@ -393,12 +395,14 @@ public ConstructResponse(Urn urn, IDictionary<string, PropertyValue> state, IDic | |
|
||
public sealed class CallRequest | ||
{ | ||
public ProviderResource? Provider { get; init; } | ||
public ResourceReference? Self { get; } | ||
public string Tok { get; init; } | ||
public ImmutableDictionary<string, PropertyValue> Args { get; init; } | ||
|
||
public CallRequest(ResourceReference? self, string tok, ImmutableDictionary<string, PropertyValue> args) | ||
public CallRequest(ProviderResource? provider, ResourceReference? self, string tok, ImmutableDictionary<string, PropertyValue> args) | ||
{ | ||
Provider = provider; | ||
Self = self; | ||
Tok = tok; | ||
Args = args; | ||
|
@@ -611,6 +615,9 @@ class ResourceProviderService : ResourceProvider.ResourceProviderBase, IDisposab | |
private Provider? implementation; | ||
private readonly string version; | ||
private string? engineAddress; | ||
// More recent versions of the engine send URN and ID of the provider to `Configure`. With that we can construct | ||
// a `DependencyProviderResource` to use in `Construct` and `Call` to refer to the provider itself. | ||
private string? providerSelfReference; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no value in sending a ProviderResource to any of the normal CRUD methods, but maybe we should send the URN for logging reasons? That would allow you to log a message to the provider resource, while performing a Create/Update for another resource. |
||
|
||
Provider Implementation | ||
{ | ||
|
@@ -876,6 +883,12 @@ private ImmutableDictionary<string, PropertyValue> Unmarshal(Struct? properties) | |
{ | ||
return WrapProviderCall(async () => | ||
{ | ||
// Save the URN and ID for self provider references in Construct/Call later. | ||
if (request.HasId && request.HasUrn) | ||
{ | ||
this.providerSelfReference = request.Urn + "::" + request.Id; | ||
} | ||
|
||
var domRequest = new ConfigureRequest(request.Variables.ToImmutableDictionary(), Unmarshal(request.Args), request.AcceptSecrets, | ||
request.AcceptResources); | ||
using var cts = GetToken(context); | ||
|
@@ -1057,7 +1070,13 @@ public override Task<Empty> Delete(Pulumirpc.DeleteRequest request, ServerCallCo | |
}, | ||
}; | ||
|
||
var domRequest = new ConstructRequest(request.Type, request.Name, | ||
ProviderResource? provider = null; | ||
if (providerSelfReference != null) | ||
{ | ||
provider = new DependencyProviderResource(providerSelfReference); | ||
} | ||
|
||
var domRequest = new ConstructRequest(provider, request.Type, request.Name, | ||
Unmarshal(request.Inputs), opts); | ||
using var cts = GetToken(context); | ||
|
||
|
@@ -1098,7 +1117,13 @@ public override Task<Empty> Delete(Pulumirpc.DeleteRequest request, ServerCallCo | |
|
||
domArgs = PatchArgDependencies(request, domArgs); | ||
|
||
var domRequest = new CallRequest(self, request.Tok, domArgs); | ||
ProviderResource? provider = null; | ||
if (providerSelfReference != null) | ||
{ | ||
provider = new DependencyProviderResource(providerSelfReference); | ||
} | ||
|
||
var domRequest = new CallRequest(provider, self, request.Tok, domArgs); | ||
using var cts = GetToken(context); | ||
|
||
var inlineDeploymentSettings = new InlineDeploymentSettings(logger, EngineAddress, request.MonitorEndpoint, request.Config, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Arguably this should be non-nullable and throw with a message like "self provider references aren't supported update your pulumi CLI", that would match how we handle other cases like this that depend on engine support.