fix(opensearch,mwaa): remove containers on explicit delete when shutdown retention is on (#4225)

keepRunningOnShutdown made stopDomain and stopEnvironment return early, so
DeleteDomain and DeleteEnvironment left their containers running. Only the
shutdown hook now honours the setting, matching how MWAA already guards its
shutdown path.
This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-09-23 10:17:48 -04:00
1 parent 4b3923712a
commit 2c3332c7cf
7 files changed
+52 -19

No files matched your search

@@ -319,10 +319,6 @@ public class MwaaEnvironmentManager {
/** Stops and removes both containers and all three named volumes for the given environment. */
public void stopEnvironment(Environment environment) {
if (config.services().mwaa().keepRunningOnShutdown()) {
LOG.infov("Leaving MWAA containers for environment {0} running", environment.getName());
return;
}
String name = environment.getName();
if (environment.getAirflowContainerId() != null) {
lifecycleManager.stopAndRemove(environment.getAirflowContainerId(), null);
@@ -207,15 +207,9 @@ public class OpenSearchDomainManager {
if (domain.getContainerId() == null) {
return;
}
if (config.services().opensearch().keepRunningOnShutdown()) {
LOG.infov("Leaving OpenSearch container for domain {0} running", domain.getDomainName());
return;
}
lifecycleManager.stopAndRemove(domain.getContainerId(), null);
// The container no longer holds the binding, so the reservation must go with
// it. Repeated create/delete would otherwise exhaust the configured range.
// The keep-running early return above deliberately keeps the reservation:
// the surviving container still owns the binding.
if (domain.getHostPort() != null) {
portAllocator.release(domain.getHostPort());
domain.setHostPort(null);
@@ -76,7 +76,7 @@ public class OpenSearchService implements ResourceProvider {
@PreDestroy
public void shutdown() {
poller.shutdownNow();
if (!config.services().opensearch().mock()) {
if (!config.services().opensearch().mock() && !config.services().opensearch().keepRunningOnShutdown()) {
for (Domain domain : allDomains()) {
domainManager.stopDomain(domain);
}