-
Notifications
You must be signed in to change notification settings - Fork 520
[Dapr Extension] Allow defining custom placement container address #767
[Dapr Extension] Allow defining custom placement container address #767
Conversation
Is the placement container something we always need to be running with dapr now? If so, I think always creating the placement service and allowing someone to specify the service to override settings may be better, rather than having @davidfowl thoughts? |
I'm not sure which side of the boundary the placement container instantiation ownership should sit. I feel like if it's already there created and running by Dapr we should just use it. Now that I think about it, some sort of auto detection would be a lot smarter. |
To sum up our thoughts:
The only question now is auto detection of the placement container. Probably just checking for the image name daprio/dapr ./placement. Also we could add an argument to the extension called |
We can then have more fine grained control by using |
@jkotalik Let's consider these scenarios
If you can verify my assumptions are correct I can try and make the necessary changes. |
@jkotalik @davidfowl I've updated the PR to cover the scenarios captured in the discussion and also included a sample app to demonstrate it. I can move the sample app to a separate PR if required. The magic in this PR happens in the The build was successful till my last commit but it's broken now due to something else in the pipeline not related to this PR. Once that is fixed the PR will pass the build and tests. Please let me know if there are any more changes required. :) |
@dasiths yes I think you assumptions were correct! Apologies for not confirming earlier. |
@dasiths yes I think you assumptions were correct! Apologies for not confirming earlier. Looks like potentially our format checker is affected by the set_env issue in github actions. I'll look into that. |
var isCustomPlacementPort = false; | ||
|
||
var existingDaprPlacementDefinition = context.Application.Services.FirstOrDefault(s => | ||
s is ContainerServiceBuilder serviceBuilder && serviceBuilder.Image == "daprio/dapr"); |
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.
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.
The more I think about this, the more I don't like sniffing to determine if the placement port is already defined or not.
I think including an option called excludePlacementService
, which default to false, is enough to have people either include or exclude it as required.
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 have removed sniffing. It will now use an auto assigned port and be agnostic about the user defined services. The only way to control the port is via the placement-port
property.
@@ -20,12 +20,67 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati | |||
|
|||
if (context.Operation == ExtensionContext.OperationKind.LocalRun) | |||
{ | |||
// default placement port number | |||
var placementPort = 50005; |
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.
Can this be a random port instead of a specific port?
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.
It will now use the next available port, same as the other parts of the system.
Bindings = { | ||
new BindingBuilder() { | ||
Port = placementPort, | ||
ContainerPort = 50005, |
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.
Is the container port always supposted to be 50005 for the placement?
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.
Yes it's defined by Dapr. I did however introduce a new property called placement-container-port
to allow the developer to set it if required. (i.e. If Dapr releases a new image with a new port). Similarly I now have a placement-image
which allows the developers to define a custom image name if required. (i.e. daprio/dapr:edge
)
else | ||
{ | ||
// use the port defined in the custom service definition is possible | ||
var definedPlacementPort = existingDaprPlacementDefinition.Bindings.FirstOrDefault(b => b.Port.HasValue); |
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.
Based on my suggestion earlier, I think if someone sets excludePlacementService
, they must define placement-port so we know what that is.
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.
Yes I added this check now. It will ignore exclude-placement-service
if not placement-port
has been defined.
Sample looks great FYI. |
@@ -51,12 +106,12 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati | |||
|
|||
// These environment variables are replaced with environment variables | |||
// defined for this service. | |||
Args = $"-app-id {project.Name} -app-port %APP_PORT% -dapr-grpc-port %DAPR_GRPC_PORT% --dapr-http-port %DAPR_HTTP_PORT% --metrics-port %METRICS_PORT% --placement-address localhost:50005", | |||
Args = $"-app-id {project.Name} -app-port %APP_PORT% -dapr-grpc-port %DAPR_GRPC_PORT% --dapr-http-port %DAPR_HTTP_PORT% --metrics-port %METRICS_PORT% --placement-address localhost:{placementPort}", |
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.
That would be great this issue #802 also could be addressed here.
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.
Should be --placement-host-address
, instead of --placement-address
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.
@mtaghavi2005 @thangchung I incorporated this change here. Should now support Dapr rc1. :)
@jkotalik I have addressed all of the comments. Please let me know if you're happy with this revision. Cheers. Edit: There is something fishy happening with the build agents while running tests. The OSX one passed, Windows one is now hanging for 30 mins and Ubuntu one failed. There aren't any tests that are affected by my change. Weird. |
@jkotalik any feedback about this? |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
foreach (var binding in service.Description.Bindings) | ||
{ | ||
// Auto assign a port | ||
if (binding.Port == null) | ||
{ | ||
binding.Port = GetNextPort(); | ||
binding.Port = NextPortFinder.Instance.GetNextPort(); |
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.
Why have NextPortFinder as an instance rather than just a static method?
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 followed the pattern from the GitDetector
class but more than happy to make it static as it doesn't have any dependencies or logic in the constructor.
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.
LGTM besides a few nits.
@@ -0,0 +1,26 @@ | |||
using System.Net; |
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.
nit copyright
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.
done
@dasiths apologies, holidays in the states 😄 |
c1f45cc
to
ac1e237
Compare
No worries. Hope you had a good break Justin. Looking forward to holidays myself. It's another sweltering 40c December awaiting us in downunder. 😉 I've updated the PR with the changes now. |
@jkotalik Anything else required here? |
How was it going on, guys? Look like |
Thanks @dasiths! |
As referenced in #763
When running Dapr in Windows (with WSL2 backend) the Dapr placement container runs on 6050 port on the host. So it requires we do something like this in
Tye.yaml
(Example https://github.com/dotnet/tye/blob/master/samples/dapr/tye.yaml)Edit: With @jkotalik suggestions the PR now does the following