mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(elbv2): stop mutating immutable fallbacks on the delete paths (#4030)
DeleteListener and DeleteLoadBalancer took their region map with getOrDefault(region, Map.of()) and then removed from it. For a region that has no map yet, that removes from the immutable Map.of() sentinel and throws UnsupportedOperationException, which the Query path reports as InternalFailure with a null message. The Terraform AWS provider treats InternalFailure as retryable, so a teardown against an untouched region polls "Still destroying..." instead of failing. Both methods now look the region map up and return when it is absent, which is the same no-op AWS performs for a resource that is not there. The listener and rule maps that the cascade writes back use computeIfAbsent, matching the create paths: getOrDefault would have stored the immutable sentinel as the region's value, so every later call for that region would fail the same way, including CreateListener. The two ARN indexes had the same defect with List.of(), so the removal goes through a helper that looks the list up instead.
This commit is contained in:
1 parent
628952ecf0
commit
a0089b3548
2 files changed
+48
-8
No files matched your search
@@ -101,6 +101,18 @@ public class ElbV2Service implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops one entry from an ARN index. The list has to be looked up rather than defaulted:
|
||||
* {@code getOrDefault(key, List.of())} hands back an immutable list whose {@code remove}
|
||||
* throws, which the Query path reports as an {@code InternalFailure}.
|
||||
*/
|
||||
private static void removeFromIndex(Map<String, List<String>> index, String key, String value) {
|
||||
List<String> entries = index.get(key);
|
||||
if (entries != null) {
|
||||
entries.remove(value);
|
||||
}
|
||||
}
|
||||
|
||||
private <V> void persistRegion(Map<String, Map<String, V>> resources, String region) {
|
||||
Map<String, V> regionResources = resources.get(region);
|
||||
if (regionResources != null) {
|
||||
@@ -248,16 +260,19 @@ public class ElbV2Service implements ResourceProvider {
|
||||
}
|
||||
|
||||
public void deleteLoadBalancer(String region, String arn) {
|
||||
Map<String, LoadBalancer> regionLbs = loadBalancers.getOrDefault(region, Map.of());
|
||||
Map<String, LoadBalancer> regionLbs = loadBalancers.get(region);
|
||||
if (regionLbs == null) {
|
||||
return; // AWS silently ignores non-existent LBs on delete
|
||||
}
|
||||
LoadBalancer lb = regionLbs.remove(arn);
|
||||
if (lb == null) {
|
||||
return; // AWS silently ignores non-existent LBs on delete
|
||||
return;
|
||||
}
|
||||
// cascade: listeners → rules
|
||||
List<String> listenerArns = lbToListeners.remove(arn);
|
||||
if (listenerArns != null) {
|
||||
Map<String, Listener> regionListeners = listeners.getOrDefault(region, Map.of());
|
||||
Map<String, Rule> regionRules = rules.getOrDefault(region, Map.of());
|
||||
Map<String, Listener> regionListeners = listeners.computeIfAbsent(region, k -> new ConcurrentHashMap<>());
|
||||
Map<String, Rule> regionRules = rules.computeIfAbsent(region, k -> new ConcurrentHashMap<>());
|
||||
for (String listenerArn : listenerArns) {
|
||||
dataPlane.stopListener(listenerArn);
|
||||
regionListeners.remove(listenerArn);
|
||||
@@ -540,15 +555,18 @@ public class ElbV2Service implements ResourceProvider {
|
||||
}
|
||||
|
||||
public void deleteListener(String region, String listenerArn) {
|
||||
Map<String, Listener> regionListeners = listeners.getOrDefault(region, Map.of());
|
||||
Map<String, Listener> regionListeners = listeners.get(region);
|
||||
if (regionListeners == null) {
|
||||
return;
|
||||
}
|
||||
Listener listener = regionListeners.remove(listenerArn);
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
dataPlane.stopListener(listenerArn);
|
||||
lbToListeners.getOrDefault(listener.getLoadBalancerArn(), List.of()).remove(listenerArn);
|
||||
removeFromIndex(lbToListeners, listener.getLoadBalancerArn(), listenerArn);
|
||||
|
||||
Map<String, Rule> regionRules = rules.getOrDefault(region, Map.of());
|
||||
Map<String, Rule> regionRules = rules.computeIfAbsent(region, k -> new ConcurrentHashMap<>());
|
||||
List<String> ruleArns = listenerToRules.remove(listenerArn);
|
||||
if (ruleArns != null) {
|
||||
ruleArns.forEach(regionRules::remove);
|
||||
@@ -692,7 +710,7 @@ public class ElbV2Service implements ResourceProvider {
|
||||
String listenerArn = rule.getListenerArn();
|
||||
regionRules.remove(ruleArn);
|
||||
rules.put(region, regionRules);
|
||||
listenerToRules.getOrDefault(listenerArn, List.of()).remove(ruleArn);
|
||||
removeFromIndex(listenerToRules, listenerArn, ruleArn);
|
||||
tags.remove(ruleArn);
|
||||
Listener listener = listeners.getOrDefault(region, Map.of()).get(listenerArn);
|
||||
if (listener != null) {
|
||||
|
||||
@@ -251,6 +251,28 @@ class ElbV2ServiceTest {
|
||||
assertEquals(listenerArn, listenerCaptor.getValue().getListenerArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteListenerIsIgnoredForRegionWithNoListeners() {
|
||||
String emptyRegion = "eu-central-1";
|
||||
|
||||
service.deleteListener(emptyRegion, "arn:aws:elasticloadbalancing:" + emptyRegion
|
||||
+ ":000000000000:listener/app/sample-lb/1111111111111111/2222222222222222");
|
||||
|
||||
assertTrue(service.describeListeners(emptyRegion, null, null).isEmpty());
|
||||
verifyNoInteractions(dataPlane);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteLoadBalancerIsIgnoredForRegionWithNoLoadBalancers() {
|
||||
String emptyRegion = "eu-central-1";
|
||||
|
||||
service.deleteLoadBalancer(emptyRegion, "arn:aws:elasticloadbalancing:" + emptyRegion
|
||||
+ ":000000000000:loadbalancer/app/sample-lb/1111111111111111");
|
||||
|
||||
assertTrue(service.describeLoadBalancers(emptyRegion, null, null, null, null).isEmpty());
|
||||
verifyNoInteractions(dataPlane);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeTargetHealthReturnsUnusedForExplicitUnregisteredTarget() {
|
||||
String tgArn = createTargetGroup("sample-tg");
|
||||
|
||||
Reference in new issue
Block a user