Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't block TGB reconciliation loop on failed SG ingress reconciliation #3296

Merged
merged 4 commits into from
Aug 30, 2023

Conversation

michaelsaah
Copy link
Contributor

@michaelsaah michaelsaah commented Jul 26, 2023

Issue

#3285

Description

the controller performs an SG reconciliation step for all (cluster-wide) SGs gathered from all TGBs during the TGB reconciliation loop, before TG endpoints are reconciled:

if err := m.networkingManager.ReconcileForPodEndpoints(ctx, tgb, endpoints); err != nil {
return err
}

the way the code is currently written, this means that any failure during SG reconciliation blocks reconciliation of all targets across the whole cluster. such a failure can be caused by something as innocuous as a SG being deleted before the associated TGB is deleted, or a SG being entered on a TGB erroneously. this can easily lead to severe outages if not remediated quickly.

this commit changes the method reconcileWithIngressPermissionsPerSG to not exit on a single failed SG ingress reconciliation - instead it will log the offending error and continue through the loop.

I tested this by setting up two TGBs, modifying one to have a non-existent ingress SG, deleting a target pod, then ensuring that the new target is reconciled. the new error message was also logged:

{"level":"error","ts":"2023-07-26T19:39:03Z","msg":"Security group reconciliation failed for SG","SecurityGroupID":"sg-0d904125da9f258a7","error":"InvalidGroup.NotFound: The security group 'sg-0b4935e438dcca2ee' does not exist\n\tstatus code: 400, request id: 34e0001c-c85e-4f6e-b7e1-c32093afe402"}

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 🌟

the controller performs an SG reconciliation step for all (cluster-wide) SGs gathered from all TGBs during the TGB reconciliation loop, before TG endpoints are reconciled: https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/d177c898ddd86071eecc2fd918d72ebfb0af7892/pkg/targetgroupbinding/resource_manager.go#L139-L141

the way the code is currently written, this means that any failure during SG reconciliation blocks reconciliation of all targets across the whole cluster. such a failure can be caused by something as innocuous as a SG being deleted before the associated TGB is deleted, or a SG being entered on a TGB erroneously. this can easily lead to severe outages if not remediated quickly.

this commit changes the method `reconcileWithIngressPermissionsPerSG` to not exit on a single failed SG ingress reconciliation - instead it will log the offending error and continue through the loop.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 26, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 26, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @michaelsaah!

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

@k8s-ci-robot
Copy link
Contributor

Hi @michaelsaah. 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.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 26, 2023
@k8s-ci-robot k8s-ci-robot 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 Jul 26, 2023
Copy link
Contributor

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot support what-me-worry ignoring of errors. At the very least, the error needs to be surfaced as a Kubernetes event and the handler needs to mark the work item for retry.

@michaelsaah
Copy link
Contributor Author

thanks @johngmyers. surfacing the error via an Event sounds fine to me.

I'm not sure what you mean by "mark the work item for retry." can you point me towards any examples in the code where this is performed?

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 27, 2023
@michaelsaah
Copy link
Contributor Author

@johngmyers @M00nF1sh just bumping this, it's an ongoing operational issue for us (Twilio) on EKS. any help appreciated.

@michaelsaah
Copy link
Contributor Author

just another bump, any eyes appreciated

@M00nF1sh
Copy link
Collaborator

M00nF1sh commented Aug 4, 2023

@michaelsaah

Thanks for this contribution. I agree with @johngmyers that the error cannot be ignored without retry. Since such SG modification errors can be transient errors such as EC2 api throttle and shall be retried to avoid issues in security group settings.

How about below change:

  1. inside reconcileWithIngressPermissionsPerSG, when reconcile for each SG(aggregatedIngressPermissionsPerSG), we don't fail upon error but aggregate all errors into a single error and return it. (e.g. use errors.Join)
  2. in
    if err := m.networkingManager.ReconcileForPodEndpoints(ctx, tgb, endpoints); err != nil {
    , if ReconcileForPodEndpoints failed with error, we don't return the error immediately, instead we continue target registration/deregistration and return runtime.NewRequeueNeeded("networking reconciliation") if the ReconcileForPodEndpoints returned a error before.
  3. don't emit the event inside reconcileWithIngressPermissionsPerSG, emit the event during inside targetgroupbinding/resource_manager.go instead, so there is only one event if multiple SG reconcillation failed.

@michaelsaah
Copy link
Contributor Author

thanks for the review @M00nF1sh, addressed your feedback. have a good weekend!

@michaelsaah
Copy link
Contributor Author

just bumping this for a re-review, thanks

@michaelsaah
Copy link
Contributor Author

morning, just a monday review bump, thanks

Copy link
Contributor

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor style nit

/lgtm

pkg/targetgroupbinding/networking_manager.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 19, 2023
@johngmyers
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 19, 2023
Co-authored-by: John Gardiner Myers <[email protected]>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 21, 2023
@michaelsaah
Copy link
Contributor Author

thanks for the re-review @johngmyers, committed your style suggestion

@johngmyers
Copy link
Contributor

/lgtm
/assign @M00nF1sh

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 21, 2023
@michaelsaah
Copy link
Contributor Author

looks like that test might be flaky: #3289 (comment)

@johngmyers
Copy link
Contributor

/retest

Copy link
Collaborator

@M00nF1sh M00nF1sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late review. This change looks good to me now, thanks a lot for your contribution :D

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: johngmyers, M00nF1sh, michaelsaah

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 29, 2023
@codecov-commenter
Copy link

Codecov Report

Patch coverage has no change and project coverage change: +0.85% 🎉

Comparison is base (d177c89) 54.70% compared to head (4607bb4) 55.56%.
Report is 40 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3296      +/-   ##
==========================================
+ Coverage   54.70%   55.56%   +0.85%     
==========================================
  Files         148      149       +1     
  Lines        8590     8828     +238     
==========================================
+ Hits         4699     4905     +206     
- Misses       3559     3586      +27     
- Partials      332      337       +5     
Files Changed Coverage Δ
pkg/targetgroupbinding/networking_manager.go 33.92% <0.00%> (-0.62%) ⬇️
pkg/targetgroupbinding/resource_manager.go 14.96% <0.00%> (-0.21%) ⬇️

... and 13 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@michaelsaah
Copy link
Contributor Author

/retest

1 similar comment
@johngmyers
Copy link
Contributor

/retest

@k8s-ci-robot k8s-ci-robot merged commit 4e697f8 into kubernetes-sigs:main Aug 30, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants