Allows for non-blocking stop of containers

This commit is contained in:
Ben 2024-03-13 10:57:26 +01:00
parent 90b90be3cb
commit c5fb066c75
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
7 changed files with 16 additions and 15 deletions

View File

@ -49,13 +49,14 @@ namespace KubernetesWorkflow
return CreatePodInfo(pod);
}
public void Stop(StartResult startResult)
public void Stop(StartResult startResult, bool waitTillStopped)
{
log.Debug();
if (startResult.InternalService != null) DeleteService(startResult.InternalService);
if (startResult.ExternalService != null) DeleteService(startResult.ExternalService);
DeleteDeployment(startResult.Deployment);
WaitUntilPodsForDeploymentAreOffline(startResult.Deployment);
if (waitTillStopped) WaitUntilPodsForDeploymentAreOffline(startResult.Deployment);
}
public void DownloadPodLog(RunningContainer container, ILogHandler logHandler, int? tailLines)

View File

@ -14,7 +14,7 @@ namespace KubernetesWorkflow
PodInfo GetPodInfo(RunningContainer container);
PodInfo GetPodInfo(RunningContainers containers);
CrashWatcher CreateCrashWatcher(RunningContainer container);
void Stop(RunningContainers containers);
void Stop(RunningContainers containers, bool waitTillStopped);
void DownloadContainerLog(RunningContainer container, ILogHandler logHandler, int? tailLines = null);
string ExecuteCommand(RunningContainer container, string command, params string[] args);
void DeleteNamespace();
@ -86,11 +86,11 @@ namespace KubernetesWorkflow
return K8s(c => c.CreateCrashWatcher(container));
}
public void Stop(RunningContainers runningContainers)
public void Stop(RunningContainers runningContainers, bool waitTillStopped)
{
K8s(controller =>
{
controller.Stop(runningContainers.StartResult);
controller.Stop(runningContainers.StartResult, waitTillStopped);
cluster.Configuration.Hooks.OnContainersStopped(runningContainers);
});
}

View File

@ -33,7 +33,7 @@ namespace CodexContractsPlugin
try
{
var result = DeployContract(container, workflow, gethNode);
workflow.Stop(containers);
workflow.Stop(containers, waitTillStopped: false);
Log("Container stopped.");
return result;
}

View File

@ -26,7 +26,7 @@ namespace CodexPlugin
CrashWatcher CrashWatcher { get; }
PodInfo GetPodInfo();
ITransferSpeeds TransferSpeeds { get; }
void Stop();
void Stop(bool waitTillStopped);
}
public class CodexNode : ICodexNode
@ -153,13 +153,13 @@ namespace CodexPlugin
return CodexAccess.GetPodInfo();
}
public void Stop()
public void Stop(bool waitTillStopped)
{
if (Group.Count() > 1) throw new InvalidOperationException("Codex-nodes that are part of a group cannot be " +
"individually shut down. Use 'BringOffline()' on the group object to stop the group. This method is only " +
"available for codex-nodes in groups of 1.");
Group.BringOffline();
Group.BringOffline(waitTillStopped);
}
public void EnsureOnlineGetVersionResponse()

View File

@ -7,7 +7,7 @@ namespace CodexPlugin
{
public interface ICodexNodeGroup : IEnumerable<ICodexNode>, IHasManyMetricScrapeTargets
{
void BringOffline();
void BringOffline(bool waitTillStopped);
ICodexNode this[int index] { get; }
}
@ -31,9 +31,9 @@ namespace CodexPlugin
}
}
public void BringOffline()
public void BringOffline(bool waitTillStopped)
{
starter.BringOffline(this);
starter.BringOffline(this, waitTillStopped);
// Clear everything. Prevent accidental use.
Nodes = Array.Empty<CodexNode>();
Containers = null!;

View File

@ -48,14 +48,14 @@ namespace CodexPlugin
return group;
}
public void BringOffline(CodexNodeGroup group)
public void BringOffline(CodexNodeGroup group, bool waitTillStopped)
{
Log($"Stopping {group.Describe()}...");
StopCrashWatcher(group);
var workflow = pluginTools.CreateWorkflow();
foreach (var c in group.Containers)
{
workflow.Stop(c);
workflow.Stop(c, waitTillStopped);
}
Log("Stopped.");
}

View File

@ -21,7 +21,7 @@ namespace CodexTests.BasicTests
{
var primary = Ci.StartCodexNode();
primary.Stop();
primary.Stop(waitTillStopped: true);
primary = Ci.StartCodexNode();