-
Notifications
You must be signed in to change notification settings - Fork 62
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
Dapr component schema #460
Open
FullStackChef
wants to merge
18
commits into
CommunityToolkit:main
Choose a base branch
from
FullStackChef:dapr-component-schema
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.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b518dff
Work in progress
FullStackChef 941569a
Add component models, with metadata and tests
FullStackChef 8ac830c
Update src/CommunityToolkit.Aspire.Hosting.Dapr/DaprComponentSecretAn…
FullStackChef fa694c8
Remove un-necessary default!
FullStackChef 8c3c081
Merge branch 'dapr-component-schema' of https://github.com/FullStackC…
FullStackChef accb128
Update examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.AppHost/Pro…
FullStackChef 148b588
Fix - set environment variables on sidecar rather than apphost
FullStackChef eb57614
Merge branch 'dapr-component-schema' of https://github.com/FullStackC…
FullStackChef 6d325a2
Make code less "cute" for David Fowler
FullStackChef 33fea9b
Update program - project shoudn't wait for dapr component
FullStackChef 8ab51c1
Fix component schema tests
FullStackChef d786a01
Switched rabbitmq out for redis - rabbitmq caused issues for unit tes…
FullStackChef 767385e
cleanup
FullStackChef 225a2bf
Make secrets relative to sidecar
FullStackChef 9055248
Merge branch 'main' into dapr-component-schema
aaronpowell 3bba6ee
Merge branch 'main' into dapr-component-schema
FullStackChef 1b683fa
Update - public api unshipped
FullStackChef 38eded5
Add parent relationship to dapr resource
FullStackChef 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
12 changes: 12 additions & 0 deletions
12
examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.AppHost/.dapr/components/pubsub.yaml
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: dapr.io/v1alpha1 | ||
kind: Component | ||
auth: | ||
secretStore: secretstore | ||
metadata: | ||
name: pubsub | ||
spec: | ||
type: pubsub.redis | ||
version: v1 | ||
metadata: | ||
- name: redisPassword | ||
value: '' |
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
21 changes: 12 additions & 9 deletions
21
examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.AppHost/Program.cs
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 |
---|---|---|
@@ -1,26 +1,29 @@ | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var rmq = builder.AddRabbitMQ("rabbitMQ") | ||
.WithManagementPlugin() | ||
.WithEndpoint("tcp", e => e.Port = 5672) | ||
.WithEndpoint("management", e => e.Port = 15672); | ||
var redis = builder.AddRedis("redis").WithRedisInsight(); | ||
|
||
|
||
var stateStore = builder.AddDaprStateStore("statestore"); | ||
|
||
var pubSub = builder.AddDaprPubSub("pubsub") | ||
.WaitFor(rmq); | ||
.WithMetadata("redisHost", "localhost:6379") | ||
.WaitFor(redis); | ||
|
||
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceA>("servicea") | ||
.WithDaprSidecar() | ||
.WithReference(stateStore) | ||
.WithReference(pubSub); | ||
.WithReference(pubSub) | ||
.WithDaprSidecar() | ||
.WaitFor(redis); | ||
|
||
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceB>("serviceb") | ||
.WithReference(pubSub) | ||
.WithDaprSidecar() | ||
.WithReference(pubSub); | ||
.WaitFor(redis); | ||
|
||
// console app with no appPort (sender only) | ||
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Dapr_ServiceC>("servicec") | ||
.WithReference(stateStore) | ||
.WithDaprSidecar(); | ||
.WithDaprSidecar() | ||
.WaitFor(redis); | ||
|
||
builder.Build().Run(); |
17 changes: 0 additions & 17 deletions
17
examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.AppHost/pubsub.yaml
This file was deleted.
Oops, something went wrong.
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
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
4 changes: 4 additions & 0 deletions
4
src/CommunityToolkit.Aspire.Hosting.Dapr/DaprComponentMetadataAnnotation.cs
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.Dapr; | ||
internal sealed record DaprComponentConfigurationAnnotation(Action<DaprComponentSchema> Configure) : IResourceAnnotation; |
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
134 changes: 134 additions & 0 deletions
134
src/CommunityToolkit.Aspire.Hosting.Dapr/DaprComponentSchema.cs
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 |
---|---|---|
@@ -0,0 +1,134 @@ | ||
using YamlDotNet.Serialization; | ||
using YamlDotNet.Serialization.NamingConventions; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.Dapr; | ||
|
||
internal interface IDaprComponentSpecMetadata : IList<DaprComponentSpecMetadata>; | ||
|
||
internal class DaprComponentSchema | ||
{ | ||
private static readonly ISerializer serializer = BuildSerializer(); | ||
private static readonly IDeserializer deserializer = BuildDeSerializer(); | ||
|
||
public string ApiVersion { get; init; } = "dapr.io/v1alpha1"; | ||
public string Kind { get; init; } = "Component"; | ||
public DaprComponentAuth? Auth { get; set; } | ||
public DaprComponentMetadata Metadata { get; init; } = default!; | ||
public DaprComponentSpec Spec { get; init; } = default!; | ||
|
||
// Required for deserialization | ||
public DaprComponentSchema() { } | ||
|
||
public DaprComponentSchema(string name, string type) | ||
{ | ||
Metadata = new DaprComponentMetadata { Name = name }; | ||
Spec = new DaprComponentSpec | ||
{ | ||
Type = type, | ||
Metadata = [] | ||
}; | ||
} | ||
public override string ToString() => serializer.Serialize(this); | ||
|
||
public static DaprComponentSchema FromYaml(string yamlContent) => | ||
deserializer.Deserialize<DaprComponentSchema>(yamlContent); | ||
private static IDeserializer BuildDeSerializer() | ||
{ | ||
DeserializerBuilder builder = new(); | ||
builder.WithNamingConvention(CamelCaseNamingConvention.Instance) | ||
.WithTypeDiscriminatingNodeDeserializer(static o => | ||
{ | ||
Dictionary<string, Type> keyMappings = new() | ||
{ | ||
["value"] = typeof(DaprComponentSpecMetadataValue), | ||
["secretKeyRef"] = typeof(DaprComponentSpecMetadataSecret) | ||
}; | ||
o.AddUniqueKeyTypeDiscriminator<DaprComponentSpecMetadata>(keyMappings); | ||
}); | ||
return builder.Build(); | ||
} | ||
|
||
private static ISerializer BuildSerializer() | ||
{ | ||
SerializerBuilder builder = new(); | ||
builder.WithNamingConvention(CamelCaseNamingConvention.Instance) | ||
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults); | ||
return builder.Build(); | ||
} | ||
|
||
} | ||
internal class DaprComponentMetadata | ||
{ | ||
public required string Name { get; init; } | ||
public string? Namespace { get; init; } | ||
|
||
} | ||
|
||
internal class DaprComponentAuth | ||
{ | ||
public required string SecretStore { get; init; } | ||
} | ||
|
||
internal class GenericDaprComponentSpecMetadata : List<DaprComponentSpecMetadata>, IDaprComponentSpecMetadata; | ||
|
||
internal class DaprComponentSpec : DaprComponentSpec<GenericDaprComponentSpecMetadata> { } | ||
|
||
internal class DaprComponentSpec<TSpecMetadata> where TSpecMetadata : IDaprComponentSpecMetadata | ||
{ | ||
public required string Type { get; init; } | ||
public string Version { get; init; } = "v1"; | ||
public required TSpecMetadata Metadata { get; init; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr component spec metadata item | ||
/// </summary> | ||
public abstract class DaprComponentSpecMetadata | ||
{ | ||
/// <summary> | ||
/// The name of the metadata item | ||
/// </summary> | ||
[YamlMember(Order = 1)] | ||
public required string Name { get; init; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr component spec metadata item with a value | ||
/// </summary> | ||
public sealed class DaprComponentSpecMetadataValue : DaprComponentSpecMetadata | ||
{ | ||
/// <summary> | ||
/// The value of the metadata item | ||
/// </summary> | ||
[YamlMember(Order = 2)] | ||
public required string Value { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr component spec metadata item with a secret key reference | ||
/// </summary> | ||
public sealed class DaprComponentSpecMetadataSecret : DaprComponentSpecMetadata | ||
{ | ||
/// <summary> | ||
/// The secret key reference of the metadata item | ||
/// </summary> | ||
[YamlMember(Order = 2)] | ||
public required DaprSecretKeyRef SecretKeyRef { get; set; } | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Represents a Dapr secret key reference | ||
/// </summary> | ||
public sealed class DaprSecretKeyRef | ||
{ | ||
/// <summary> | ||
/// The name of the secret | ||
/// </summary> | ||
public required string Name { get; init; } | ||
/// <summary> | ||
/// The key of the secret | ||
/// </summary> | ||
public required string Key { get; init; } | ||
}; | ||
|
5 changes: 5 additions & 0 deletions
5
src/CommunityToolkit.Aspire.Hosting.Dapr/DaprComponentSecretAnnotation.cs
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.Dapr; | ||
|
||
internal record DaprComponentSecretAnnotation(string Key, string Value) : IResourceAnnotation; | ||
FullStackChef marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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.
From a developer standpoint I would more expect something like:
Because you configure the sidecare to use the pubSub reference as a pubsub. Not the project.
That would also mean that we would need to break with the Fluent API their or have some
WithDaprSidecar
parameter that accepts a action or so to configure the sidecar.You can look for the AzurePostgreSql resource of aspire how you can configure the development contianer. I would prefer an API like their
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.
To prevent breaking changes for now closing this comment.
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 is up to the developer the both work the same