Skip to content

add support for targetgroupbinding cross-account AZ aware registration - #4877

Open
cqi1217 wants to merge 2 commits into
kubernetes-sigs:mainfrom
cqi1217:main
Open

add support for targetgroupbinding cross-account AZ aware registration#4877
cqi1217 wants to merge 2 commits into
kubernetes-sigs:mainfrom
cqi1217:main

Conversation

@cqi1217

@cqi1217 cqi1217 commented Aug 12, 2026

Copy link
Copy Markdown

Issue

#4831

Description

Cross-account TargetGroupBindings always register IP targets with AvailabilityZone: "all".
Because every zonal load balancer node can then forward to every target, disabling NLB
cross-zone load balancing has no effect and inter-AZ data transfer is unavoidable for
anyone using the hub/spoke pattern (NLB + target groups in a central account, workloads
in spoke accounts).

The "all" value is hardcoded for cross-account in prepareRegistrationCall, which gated
the pod-AZ path on usePodAZ && !usingCrossAccount.

This PR adds an opt-in spec.registerTargetsWithPodAvailabilityZone field that registers
each target with the AZ of the node its pod runs on.

Why the AZ name can't be used directly

AZ names are randomized per account — us-west-2a in the cluster's account is usually a
different physical zone than us-west-2a in the target group owner's account. AZ IDs
(e.g. usw2-az1) are stable across accounts, so the new AZIDTranslator resolves:

pod's zone name --(CO credentials)--> zone ID --(assumed role)--> TGO zone name

Key changes

  • pkg/networking/az_id_translator.go (new) — AZIDTranslator.TranslateAZName()
    performs the two-hop lookup above. Results are cached for 60 minutes to avoid throttling
    DescribeAvailabilityZones on every reconcile. The cache key is
    {scope, lookup} where scope is the assumed role ARN (empty for the cluster's own
    account), so zone names from different accounts can never collide — an important detail
    given that the same name means different things per account.

  • Assumed-role EC2 client — the translator's second lookup has to run with TGO
    credentials, so EC2 gained AssumeRole() and defaultCloud gained GetAssumedRoleEC2()
    plus an assumeRoleEc2Cache, mirroring the existing GetAssumedRoleELBV2() path. The STS
    assume-role + config construction shared by both is factored out into
    generateAssumedRoleConfig(). All ec2Client methods now route through a getClient()
    helper so a statically-provided assumed-role client is honored.

  • pkg/targetgroupbinding/resource_manager.go — the gate becomes
    (usePodAZ && !usingCrossAccount) || usePodAZForCrossAccount. The new
    resolveTargetAvailabilityZone() looks up the pod AZ and translates it when cross-account.

  • Webhook validation — rejects the field without iamRoleArnToAssume.

  • API/CRD — field added to both v1beta1 and v1alpha1. Since the CRD has no
    conversion webhook (strategy: None), a field present in only one served version would be
    pruned when the object is read or written through the other, so both need it. This matches
    how the existing iamRoleArnToAssume / assumeRoleExternalId fields are defined.

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 12, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 12, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: cqi1217 / name: cqi1217 (cab5bca)

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @cqi1217!

It looks like this is your first PR to kubernetes-sigs/aws-load-balancer-controller 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/aws-load-balancer-controller has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 12, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @cqi1217. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@kubernetes-prow kubernetes-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 12, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cqi1217
Once this PR has been reviewed and has the lgtm label, please assign shraddhabang for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 12, 2026
@cqi1217
cqi1217 marked this pull request as ready for review August 17, 2026 20:19
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 17, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from shuqz and zac-nixon August 17, 2026 20:19
@cqi1217

cqi1217 commented Sep 2, 2026

Copy link
Copy Markdown
Author

hi @wweiwei-li @shraddhabang can you review the code? thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant