-
Notifications
You must be signed in to change notification settings - Fork 647
Use orchestrator container delay start feature for better WithExplictStart
+ ContainerLifetime.Persistent
support
#9471
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
Conversation
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.
Pull Request Overview
This PR enables the orchestrator’s delay-start feature by adding a Start
flag to containers and updating snapshot building and execution logic to honor it, improving support for persistent containers with explicit starts.
- Add
Start
property toContainerSpec
to mark a resource for delayed start. - Treat pending container state as
NotStarted
whenStart
is false in snapshots and status checks. - Update executor to set
Spec.Start
on explicit start and adjust creation flow for delayed-start containers.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Aspire.Hosting/Dcp/ResourceSnapshotBuilder.cs | Treat pending container states as NotStarted when Spec.Start is false |
src/Aspire.Hosting/Dcp/Model/Container.cs | Add nullable Start flag with XML docs to enable delayed-start marking |
src/Aspire.Hosting/Dcp/DcpExecutor.cs | Honor Spec.Start in status checks, set flag on explicit start, and adjust creation |
Comments suppressed due to low confidence (2)
src/Aspire.Hosting/Dcp/ResourceSnapshotBuilder.cs:29
- Consider adding unit tests for this new delay-start handling to verify that pending states are correctly mapped to
NotStarted
whenSpec.Start
is false.
if (container.Spec.Start == false && (state == null || state == ContainerState.Pending))
src/Aspire.Hosting/Dcp/DcpExecutor.cs:1234
- After setting
Spec.Start = false
for delayed-start containers, we should restore thecontinue;
to skip scheduling creation (the original logic prevented creating containers until an explicit start). Without it,CreateContainerAsyncCore
will still run and may create the container prematurely.
container.Spec.Start = false;
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@@ -1223,8 +1229,10 @@ async Task CreateContainerAsyncCore(AppResource cr, CancellationToken cancellati | |||
|
|||
if (cr.ModelResource.TryGetLastAnnotation<ExplicitStartupAnnotation>(out _)) | |||
{ | |||
await _executorEvents.PublishAsync(new OnResourceChangedContext(cancellationToken, KnownResourceTypes.Container, cr.ModelResource, cr.DcpResourceName, new ResourceStatus(KnownResourceStates.NotStarted, null, null), s => s with { State = new ResourceStateSnapshot(KnownResourceStates.NotStarted, null) })).ConfigureAwait(false); |
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 feels scary, what else does firing this event do that is being missed now?
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 event was a virtual status update; the app model was skipping creating the DCP resource and just reporting it as "NotStarted". Now that DCP has support for a resource that should be explicitly started, the resource still ends up with a "NotStarted" status event, but it's in response to the actual DCP resource status (State=pending + Start=false).
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.
What happens if the user sets environment variables in before start. Does that fire still?
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.
ProcessEnvironmentVariableValuesAsync gets called and the environment gets generated.
@JamesNK can you review this? |
There are no unit tests. Are changes already covered by existing unit tests? Existing explicit start unit tests: aspire/tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs Lines 156 to 297 in 9e4ed4f
|
I've added a new test case |
Description
The orchestrator now supports explicitly marking a container resource as delayed start. This PR updates the explicit start behavior to create containers with delay start enabled (instead of delaying DCP resource creation until the user manually starts the container). This specifically allows us to better support persistent containers combined with explicit start.
If a container is marked as both persistent and delayed start, DCP will still check for an existing valid container and transition the resource to running if one is found, but won't create a new container if one isn't found.
Fixes #8073
Checklist
<remarks />
and<code />
elements on your triple slash comments?doc-idea
templatebreaking-change
templatediagnostic
template