Added logic to the target_group_synthesizer to ensure the controller can recover when the maximum unique target groups per ALB is reached - #4882
Conversation
…can recover when the maximum unique target groups per ALB is reached
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dominikhei The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @dominikhei. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4882 +/- ##
==========================================
+ Coverage 57.44% 57.57% +0.12%
==========================================
Files 396 396
Lines 31619 31695 +76
==========================================
+ Hits 18164 18248 +84
+ Misses 12398 12382 -16
- Partials 1057 1065 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
P1 — The PR handles the error at the wrong AWS operation. The new code catches TooManyUniqueTargetGroupsPerLoadBalancer from tgManager.Create(), which calls CreateTargetGroup. But AWS does not return that error from CreateTargetGroup; its documented quota error is TooManyTargetGroups, the account-level TG quota. TooManyUniqueTargetGroupsPerLoadBalancer is produced when a TG becomes associated with the load balancer, e.g. through CreateRule—which is exactly where issue #4848 reports the failure. So in the reported production scenario, this new branch is never reached. The new test masks this by having mockTargetGroupManager.Create() synthesize an error that the real CreateTargetGroup API doesn't produce. |
Thank you for the detailed feedback. I will have a look at it once I am back from holidays on Sunday! |
Issue
Fixes #4848
Description
Previously stale target groups were deleted by
PostSynthesizeas target groups can't be deleted while listener rules still reference them, so deletion is deferred until after the listener rule synthesizer has already cleaned up its stale rules. However ifSynthesizehits the quota error and returns early,PostSynthesizenever runs, so the stale TGs never get deleted, so the slot never gets freed, so the next reconcile hits the exact same error again.This PR introduces logic to fix this by adding an inline delete to
Synthesize. When the quota error is hit, instead of returning immediately, one stale TG is deleted withinSynthesizeto free a slot and retry the create in the same reconcile cycle. Because the inline delete runs before the listener rule synthesizer has cleaned up stale rules in the current cycle, the delete may fail withResourceInUseon the first attempt. In that case the controller requeues. On the next cycle the listener rules from the previous cycle are already gone, so the stale TG delete succeeds and the create goes through / the current deadlock is resolved. The controller recovers in at most two reconcile cycles instead of being stuck forever.Compared to the
ListenerRuleSynthesizerthis one for target groups handles quota logic insideSynthesizeon the struct and not via a separate function. Due to this there needs to be the full environment thatSynthesizeexpectsand tests for the new functionality became a bit complex.
Note: The logic for deleting and creating TGs could be made easier to understand and tests could be simplified by rewriting the range loop as an index-based loop with the same three-branch structure as the listener rule synthesizer. Would be interested on some thoughts on that?
Checklist
README.md, or thedocsdirectory)BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯