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

Prevent kafka controller from running into NodePort service deletion and re-creation cycles indefinitely #928

Merged
merged 11 commits into from Feb 16, 2023

Conversation

panyuenlau
Copy link
Member

@panyuenlau panyuenlau commented Feb 9, 2023

Q A
Bug fix? yes
New feature? no
API breaks? no
Deprecations? no
Related tickets fixes #922
License Apache 2.0

What's in this PR?

To fix #922

Why?

When using NodePort as the service type for external listeners, the corresponding NodePort services get into deletion-recreation cycles indefinitely

Additional context

Also refactor the relevant logic - moving the headless service related logic from pkg/resources/kafka/allBrokerService.go to pkg/resources/kafka/headlessService.go along with additional unit tests

Checklist

  • Implementation tested
  • Error handling code meets the guideline
  • Logging code meets the guideline
    - [x] User guide and development docs updated (if needed)

@panyuenlau panyuenlau self-assigned this Feb 10, 2023
@panyuenlau panyuenlau marked this pull request as ready for review February 10, 2023 20:40
@panyuenlau panyuenlau requested a review from a team as a code owner February 10, 2023 20:40
@panyuenlau
Copy link
Member Author

panyuenlau commented Feb 10, 2023

Found another minor issue during development - if the external listeners were set to Loadbalancer and then changed to Nodeport, the operator doesn't remove the unused loadbalancer service

Will open another PR to address this issue since it's not part of #922

Copy link
Member

@pregnor pregnor left a comment

Choose a reason for hiding this comment

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

Don't be discouraged by the comments, as those are just recommendations and optional stuff, I would be okay approving the PR as is, I just feel like we could still add some worthwhile improvements at relatively low cost.

Also I don't keep my suggestions in me, rather write it out even if it is just a personal practice (some optionals), but if you disagree with anything - that is not arequired change of which there is non right now - I'm not attached to these and am ready to drop those.

pkg/resources/kafka/headlessService.go Outdated Show resolved Hide resolved
pkg/resources/kafka/headlessService.go Show resolved Hide resolved
pkg/resources/kafka/headlessService.go Outdated Show resolved Hide resolved
pkg/resources/kafka/headlessService.go Outdated Show resolved Hide resolved
pkg/resources/kafka/headlessService.go Outdated Show resolved Hide resolved
pkg/resources/kafka/headlessService_test.go Outdated Show resolved Hide resolved
pkg/resources/kafka/headlessService_test.go Outdated Show resolved Hide resolved
pkg/resources/kafka/headlessService_test.go Outdated Show resolved Hide resolved
pkg/resources/kafka/headlessService_test.go Show resolved Hide resolved
pkg/resources/kafka/headlessService_test.go Show resolved Hide resolved
Kuvesz
Kuvesz previously approved these changes Feb 14, 2023
Copy link
Contributor

@Kuvesz Kuvesz left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for also adding tests!


// if NodePort is used for any of the external listeners, the corresponding services need to remain
// so that clients from outside the Kubernetes cluster can reach the brokers
filteredSvcsToDelete := services
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we dont have to use another variable for this.
we can use the services all way long.
later: services = nonNodePortServices(services)
...

Copy link
Member Author

Choose a reason for hiding this comment

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

yea...but having this little extra variable named filteredSvcsToDelete would make the implementation more readable

Copy link
Contributor

Choose a reason for hiding this comment

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

It is clear enough to me services = nonNodePortServices(services).
It is just my opinion and a suggestion. Your solution is ok for me.

Copy link
Contributor

@bartam1 bartam1 Feb 15, 2023

Choose a reason for hiding this comment

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

We can also use here (

var services corev1.ServiceList
) name like: filteredSvcsToDelete
and filteredSvcsToDelete = nonNodePortBrokerServices(filteredSvcsToDelete).

This

filteredSvcsToDelete := services

"services" already filtered by label selector so it is equal filteredSvcsToDelete

Copy link
Member Author

Choose a reason for hiding this comment

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

"services" already filtered by label selector so it is equal filteredSvcsToDelete

I guess I have a slightly different interpretation - we use the label selectors to query all of the services that match the labels (and they are stored in the services variable), then we filter them based on the external listener configuration, which results in filteredSvcsToDelete and these are the services that we will actually remove at the end

Using a different variable with a more declarative name would make it more understandable to people that are not familiar with the existing codebase IMO - so I' d prefer to keep it as it is

Copy link
Member

@pregnor pregnor left a comment

Choose a reason for hiding this comment

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

LGTM at a glance

@panyuenlau panyuenlau merged commit c470369 into master Feb 16, 2023
@panyuenlau panyuenlau deleted the deletion/non-headless/svc branch February 16, 2023 12:26
bartam1 pushed a commit that referenced this pull request Feb 17, 2023
…and re-creation cycles indefinitely (#928)

* Prevent kafka controller from running into NodePort service deletion and re-creation cycles indefinitely

* Rename variable

* Refactor existing implementation to improve readability

* Fix unintended change

* Update logs and comments to reduce confusion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

External NodePort services got killed and recreated for every several seconds.
4 participants