Skip to content

Commit 648f967

Browse files
authored
Allow deleted containers to be restarted (#7282)
1 parent 500be3e commit 648f967

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Aspire.Hosting/ApplicationModel/CommandsConfigurationExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ internal static void AddLifeCycleCommands(this IResource resource)
115115
iconVariant: IconVariant.Regular,
116116
isHighlighted: false));
117117

118-
static bool IsStopped(string? state) => state is "Exited" or "Finished" or "FailedToStart";
118+
// Treat "Unknown" as stopped so the command to start the resource is available when "Unknown".
119+
// There is a situation where a container can be stopped with this state: https://github.com/dotnet/aspire/issues/5977
120+
static bool IsStopped(string? state) => state is "Exited" or "Finished" or "FailedToStart" or "Unknown";
119121
static bool IsStopping(string? state) => state is "Stopping";
120122
static bool IsStarting(string? state) => state is "Starting";
121123
static bool IsWaiting(string? state) => state is "Waiting";

tests/Aspire.Hosting.Tests/ResourceCommandAnnotationTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ResourceCommandAnnotationTests
1515
[InlineData(CommandsConfigurationExtensions.StartCommandName, "Exited", ResourceCommandState.Enabled)]
1616
[InlineData(CommandsConfigurationExtensions.StartCommandName, "Finished", ResourceCommandState.Enabled)]
1717
[InlineData(CommandsConfigurationExtensions.StartCommandName, "FailedToStart", ResourceCommandState.Enabled)]
18+
[InlineData(CommandsConfigurationExtensions.StartCommandName, "Unknown", ResourceCommandState.Enabled)]
1819
[InlineData(CommandsConfigurationExtensions.StartCommandName, "Waiting", ResourceCommandState.Enabled)]
1920
[InlineData(CommandsConfigurationExtensions.StartCommandName, "RuntimeUnhealthy", ResourceCommandState.Disabled)]
2021
[InlineData(CommandsConfigurationExtensions.StopCommandName, "Starting", ResourceCommandState.Hidden)]
@@ -23,6 +24,7 @@ public class ResourceCommandAnnotationTests
2324
[InlineData(CommandsConfigurationExtensions.StopCommandName, "Exited", ResourceCommandState.Hidden)]
2425
[InlineData(CommandsConfigurationExtensions.StopCommandName, "Finished", ResourceCommandState.Hidden)]
2526
[InlineData(CommandsConfigurationExtensions.StopCommandName, "FailedToStart", ResourceCommandState.Hidden)]
27+
[InlineData(CommandsConfigurationExtensions.StopCommandName, "Unknown", ResourceCommandState.Hidden)]
2628
[InlineData(CommandsConfigurationExtensions.StopCommandName, "Waiting", ResourceCommandState.Hidden)]
2729
[InlineData(CommandsConfigurationExtensions.StopCommandName, "RuntimeUnhealthy", ResourceCommandState.Hidden)]
2830
[InlineData(CommandsConfigurationExtensions.RestartCommandName, "Starting", ResourceCommandState.Disabled)]
@@ -31,6 +33,7 @@ public class ResourceCommandAnnotationTests
3133
[InlineData(CommandsConfigurationExtensions.RestartCommandName, "Exited", ResourceCommandState.Disabled)]
3234
[InlineData(CommandsConfigurationExtensions.RestartCommandName, "Finished", ResourceCommandState.Disabled)]
3335
[InlineData(CommandsConfigurationExtensions.RestartCommandName, "FailedToStart", ResourceCommandState.Disabled)]
36+
[InlineData(CommandsConfigurationExtensions.RestartCommandName, "Unknown", ResourceCommandState.Disabled)]
3437
[InlineData(CommandsConfigurationExtensions.RestartCommandName, "Waiting", ResourceCommandState.Disabled)]
3538
[InlineData(CommandsConfigurationExtensions.RestartCommandName, "RuntimeUnhealthy", ResourceCommandState.Disabled)]
3639
public void LifeCycleCommands_CommandState(string commandName, string resourceState, ResourceCommandState commandState)

0 commit comments

Comments
 (0)