Skip to content

Re-execute envvar and arg callbacks when restarting resources#7329

Merged
davidfowl merged 4 commits intomainfrom
jamesnk/dcpexecutor-cleanup
Feb 7, 2025
Merged

Re-execute envvar and arg callbacks when restarting resources#7329
davidfowl merged 4 commits intomainfrom
jamesnk/dcpexecutor-cleanup

Conversation

@JamesNK
Copy link
Copy Markdown
Member

@JamesNK JamesNK commented Jan 30, 2025

Description

When a resource is first started by DCP it applies envvar and arg settings based on values from callbacks. Restarting a resource now reuses the same code to apply values again.

Also in this PR is a refactor of how callbacks are executed and applied. They're moved to new methods and reused between containers and executables.

Fixes #5879

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@JamesNK JamesNK added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jan 30, 2025
@JamesNK JamesNK requested review from davidfowl and eerhardt January 30, 2025 09:41
@JamesNK JamesNK requested a review from mitchdenny as a code owner January 30, 2025 10:38
@JamesNK JamesNK force-pushed the jamesnk/dcpexecutor-cleanup branch from 40b15e6 to 1c0cf60 Compare January 30, 2025 13:46
@JamesNK
Copy link
Copy Markdown
Member Author

JamesNK commented Jan 31, 2025

The isinitialized check isn’t needed anymore after the last dcp refactor. Resource is now initialized on every start

@davidfowl
Copy link
Copy Markdown
Contributor

Need to rewrite this against my refactor #7360

@danmoseley danmoseley added the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 2, 2025
@danmoseley danmoseley requested a review from Copilot February 3, 2025 21:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (4)

src/Aspire.Hosting/Dcp/DcpExecutor.cs:1248

  • The variable 'value' is cast to 'string' without checking if it is indeed a 'string'. This could potentially cause a runtime error. Ensure 'value' is a 'string' before casting.
var resolvedValue = value switch

src/Aspire.Hosting/Dcp/DcpExecutor.cs:1258

  • The variable 'resolvedValue' is cast to 'string' without checking if it is indeed a 'string'. This could potentially cause a runtime error. Ensure 'resolvedValue' is a 'string' before casting.
specs.Add((string)resolvedValue);

src/Aspire.Hosting/Dcp/DcpExecutor.cs:1221

  • [nitpick] The error message 'Failed to apply argument '{ConfigKey}'' should be more specific about which argument failed. Consider including the argument name or value in the message.
resourceLogger.LogCritical(ex, "Failed to apply argument '{ConfigKey}'. A dependency may have failed to start.", value);

src/Aspire.Hosting/Dcp/DcpExecutor.cs:1263

  • [nitpick] The error message 'Failed to apply container runtime argument '{ConfigKey}'' should be more specific about which argument failed. Consider including the argument name or value in the message.
resourceLogger.LogCritical(ex, "Failed to apply container runtime argument '{ConfigKey}'. A dependency may have failed to start.", value);

Comment thread tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs Outdated
Comment thread src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs
@JamesNK JamesNK force-pushed the jamesnk/dcpexecutor-cleanup branch from 1c0cf60 to 308dbcd Compare February 6, 2025 15:40
@JamesNK JamesNK removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 6, 2025
@JamesNK
Copy link
Copy Markdown
Member Author

JamesNK commented Feb 6, 2025

@davidfowl Updated. Please take a look.

@davidfowl davidfowl requested a review from karolz-ms February 6, 2025 15:57
Copy link
Copy Markdown
Contributor

@karolz-ms karolz-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes a lot of sense

@davidfowl
Copy link
Copy Markdown
Contributor

Where are the conflicts??

@davidfowl
Copy link
Copy Markdown
Contributor

Oh @adamint 's change 😄

@adamint
Copy link
Copy Markdown
Member

adamint commented Feb 6, 2025

😄

@JamesNK JamesNK force-pushed the jamesnk/dcpexecutor-cleanup branch from 308dbcd to 3b32398 Compare February 7, 2025 00:22
@JamesNK
Copy link
Copy Markdown
Member Author

JamesNK commented Feb 7, 2025

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@JamesNK
Copy link
Copy Markdown
Member Author

JamesNK commented Feb 7, 2025

Are these real test failures or no?

@davidfowl
Copy link
Copy Markdown
Contributor

No, #7448

@davidfowl davidfowl merged commit dd868c2 into main Feb 7, 2025
@davidfowl davidfowl deleted the jamesnk/dcpexecutor-cleanup branch February 7, 2025 02:17
davidfowl added a commit that referenced this pull request Feb 7, 2025
davidfowl added a commit that referenced this pull request Feb 7, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it possible to start and stop containers and executables that aren't weren't fully initialized by DCP

6 participants