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

Cleanup finalizer workflow and improve Ingress GC #825

Merged
merged 1 commit into from
Aug 28, 2019

Conversation

skmatti
Copy link
Contributor

@skmatti skmatti commented Aug 13, 2019

This fixes a bug on Ingress resource deletion when Ingress class changes from a GLBC resource to a non-GLBC one. Finalizer of a non-GLBC Ingress resource is removed when GC is invoked on it.

@k8s-ci-robot
Copy link
Contributor

Welcome @skmatti!

It looks like this is your first PR to kubernetes/ingress-gce 🎉. 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/ingress-gce 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

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]

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. I understand the commands that are listed here.

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

Hi @skmatti. Thanks for your PR.

I'm waiting for a kubernetes 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 13, 2019
@MrHohn
Copy link
Member

MrHohn commented Aug 13, 2019

/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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 13, 2019
@skmatti
Copy link
Contributor Author

skmatti commented Aug 13, 2019

/assign @MrHohn

Copy link
Member

@MrHohn MrHohn left a comment

Choose a reason for hiding this comment

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

Thanks, just a few nits.

pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/controller_test.go Show resolved Hide resolved
@bowei
Copy link
Member

bowei commented Aug 14, 2019

/hold

If the Ingress has a finalizer, that means we have potentially allocated resources associated with the previous state of the Ingress. Which means we need to keep the finalizer...

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2019
@rramkumar1
Copy link
Contributor

rramkumar1 commented Aug 14, 2019

@bowei If you look at line 496 of controller.go, you can see that if the class was changed from glbc to non-glbc, then we add the Ingress for garbage collection to ensure we clean stuff up. This was to fix some bug not related to finalizer support.

I think we should add all non-glbc Ingresses for garbage collection always (rather than just when the class is changed) as a sanity check that stuff is getting cleaned up.

@bowei
Copy link
Member

bowei commented Aug 14, 2019

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2019
@bowei
Copy link
Member

bowei commented Aug 14, 2019

Discussed offline -- looks like the finalizer handling is currently incorrect and needs to be fixed.

@bowei
Copy link
Member

bowei commented Aug 14, 2019

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2019
@skmatti skmatti changed the title Remove finalizer on changing Ingress class to non-GLBC wip: Remove finalizer on changing Ingress class to non-GLBC Aug 15, 2019
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 15, 2019
@skmatti skmatti changed the title wip: Remove finalizer on changing Ingress class to non-GLBC WIP: Remove finalizer on changing Ingress class to non-GLBC Aug 15, 2019
@bowei
Copy link
Member

bowei commented Aug 15, 2019

/assign

@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 16, 2019
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 21, 2019
@skmatti skmatti force-pushed the release-1.6 branch 3 times, most recently from c88c5b7 to 45a423c Compare August 22, 2019 07:19
@bowei bowei changed the title Remove finalizer on changing Ingress class to non-GLBC Cleanup finalizer workflow and improve Ingress GC Aug 22, 2019
pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/backends/backends.go Show resolved Hide resolved
pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils_test.go Outdated Show resolved Hide resolved
pkg/utils/utils_test.go Outdated Show resolved Hide resolved
@skmatti skmatti force-pushed the release-1.6 branch 2 times, most recently from 939f0c6 to 3f786ec Compare August 23, 2019 19:48
Copy link
Member

@bowei bowei left a comment

Choose a reason for hiding this comment

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

discussed making the filtering and set of ingresses that the code is operating on more obvious

pkg/backends/backends.go Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Show resolved Hide resolved
pkg/controller/controller.go Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
@skmatti skmatti force-pushed the release-1.6 branch 4 times, most recently from fce6b2f to 348537c Compare August 26, 2019 21:45
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
pkg/controller/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/controller_test.go Show resolved Hide resolved
pkg/controller/controller_test.go Outdated Show resolved Hide resolved
pkg/utils/utils_test.go Show resolved Hide resolved
pkg/utils/utils_test.go Outdated Show resolved Hide resolved
pkg/sync/interfaces.go Outdated Show resolved Hide resolved
pkg/controller/controller.go Outdated Show resolved Hide resolved
@bowei
Copy link
Member

bowei commented Aug 28, 2019

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bowei, MrHohn, skmatti

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

@bowei
Copy link
Member

bowei commented Aug 28, 2019

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 28, 2019
klog.Errorf("Invalid object type: %T", obj)
return
}
if delIng.ObjectMeta.DeletionTimestamp != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Can we have some comments here to explain the reason behind? BTW have we verified that this for sure isn't the case when an Ingress is deleted without finalizer? (I'm still reading through https://github.com/kubernetes/apiserver/blob/master/pkg/registry/generic/registry/store.go...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I tested this behavior. Deletion timestamp is being added only with finalizer enabled. I think I added a comment, but later changed to a log comment below this line.

}
}
// MaybeRemoveFinalizers cleans up Finalizers if needed.
func (lbc *LoadBalancerController) MaybeRemoveFinalizers(state interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

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

Why Maybe?

lbNames []string
svcPorts []utils.ServicePort
// ingressesToCleanup is the list of ingressesToCleanup that needs to be cleaned up during GC.
ingressesToCleanup []*v1beta1.Ingress
Copy link
Member

Choose a reason for hiding this comment

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

I vaguely remember we uses this as a signal for whether we can remove the instance group (if there is no ingresses exist). Has that logic been changed?

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, seems like we look at lbNames instead.

// TODO(ingress#120): Move this to the backend pool so it mirrors creation
if len(gcState.lbNames) == 0 {
igName := lbc.ctx.ClusterNamer.InstanceGroup()
klog.Infof("Deleting instance group %v", igName)
if err := lbc.instancePool.DeleteInstanceGroup(igName); err != err {
return err
}
}

So we need to keep multi-cluster ingress in this case then? :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using lbnames to see if we can delete instance groups.

@k8s-ci-robot k8s-ci-robot merged commit 52428d2 into kubernetes:master Aug 28, 2019
func toLbNames(ings []*v1beta1.Ingress) []string {
lbNames := make([]string, 0, len(ings))
for _, ing := range ings {
lbNames = append(lbNames, utils.IngressKeyFunc(ing))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IngressKeyFunc used here is incorrect. It should be replaced with KeyFunc defined here.

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants