mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
chore(docker): share failed container cleanup policy (#6392)
Use one private helper from create and createAndStart while preserving ordinary cleanup, ephemeral volume removal and suppressed cleanup failures. Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
ec7cc6713f
commit
f10d98a9f1
1 file changed
+7
-11
+7
-11
@@ -142,16 +142,16 @@ public class ContainerLifecycleManager {
|
||||
try {
|
||||
return withPublishedHostPorts(startCreated(containerId, spec), spec);
|
||||
} catch (RuntimeException failure) {
|
||||
if (removeAnonymousVolumes) {
|
||||
removeFailedEphemeralContainer(containerId, failure);
|
||||
} else {
|
||||
removeIfExists(containerId);
|
||||
}
|
||||
removeFailedContainer(containerId, failure, removeAnonymousVolumes);
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFailedEphemeralContainer(String containerId, RuntimeException failure) {
|
||||
private void removeFailedContainer(String containerId, RuntimeException failure, boolean removeAnonymousVolumes) {
|
||||
if (!removeAnonymousVolumes) {
|
||||
removeIfExists(containerId);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
removeIfExistsStrict(containerId, true);
|
||||
} catch (RuntimeException cleanupFailure) {
|
||||
@@ -203,11 +203,7 @@ public class ContainerLifecycleManager {
|
||||
try {
|
||||
attachNetworkBeforeStart(containerId, spec);
|
||||
} catch (RuntimeException e) {
|
||||
if (removeAnonymousVolumes) {
|
||||
removeFailedEphemeralContainer(containerId, e);
|
||||
} else {
|
||||
removeIfExists(containerId);
|
||||
}
|
||||
removeFailedContainer(containerId, e, removeAnonymousVolumes);
|
||||
throw new IllegalStateException(
|
||||
"Failed to attach pre-start network configuration for container " + containerId, e);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user