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

Gateway resources consolidation #2602

Merged
merged 1 commit into from
Jul 11, 2022

Conversation

mlavacca
Copy link
Member

@mlavacca mlavacca commented Jun 23, 2022

What this PR does / why we need it:
This PR aims at consolidating and factorizing the gatewayClass and Gateway resources across all the integration tests, to remove duplicated code and improve code quality.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #2461

Special notes for your reviewer:
You can find the PR's change list below:

  • All the explicit instantiation of GatewayClass and Gateway objects, followed by the respective GatewayV1alpha2().GatewayClasses().Create() and GatewayV1alpha2().Gateway().Create() function calls have been replaced by a helper call. These helpers are in the helpers_test.go file.
  • Each function that needed a gatewayClass, created it at the beginning and deleted it at the end of the test (via a deferred function). Since about 90% of these objects were copypasta from one test function to another, a unique shared GatewayClass is now created at environment setup time; this object creation is in the suite_test.go file. Each needed GatewayClass different from the default one is created through the aforementioned helper.
  • The files tlsroute_test.go, tcproute_test.go, httproute_test.go, and udproute_test.go used specific helpers to check the linking or unlinking of the routes from the Gateway. They were copypasta one from another. They have been deleted and factorized in a unique function with two additional parameters:
    • protocolType: to specify the protocol to check
    • ensureLinked: to specify whether to check the linking or the unlinking
  • The cleanup in each test case has been made uniform by using the utility suggested in the comment below. NOTE: only the files under refactoring have been subjected to this change.
  • Minor name refactoring throughout the touched files.

PR Readiness Checklist:

Complete these before marking the PR as ready to review:

  • the CHANGELOG.md release notes have been updated to reflect any significant (and particularly user-facing) changes introduced by this PR

@mlavacca mlavacca force-pushed the gateway-resource-consolidation branch from f71b031 to bedd261 Compare June 23, 2022 15:09
@shaneutt
Copy link
Contributor

While you're in here refactoring tests @mlavacca, I wanted to mention that in recent weeks KTF has gotten a new cluster cleanup utility:

https://github.com/Kong/kubernetes-testing-framework/blob/main/pkg/clusters/cleanup.go#L27

There are some examples of its use in the GWO:

Not saying this is required as part of this work you're doing so don't consider it a blocker by any stretch of the imagination, but since you're already in here doing some test cleanup if you would like to clean up some of the myriad defer functions which clean up individual items this could be employed to do so.

@mlavacca mlavacca force-pushed the gateway-resource-consolidation branch 8 times, most recently from b70b334 to ce3a7da Compare June 30, 2022 08:54
@mlavacca mlavacca marked this pull request as ready for review June 30, 2022 09:27
@mlavacca mlavacca requested a review from a team as a code owner June 30, 2022 09:27
@pmalek
Copy link
Member

pmalek commented Jun 30, 2022

Would it be too much to ask for If I'd suggest to put a summary of what were the goals of this refactoring? e.g. what were the functions/methods/structs/interfaces added/removed? 🙏

Given +650 −1,269 and the fact that it touches many files it's a bit hard to review reliably.

@mlavacca
Copy link
Member Author

mlavacca commented Jun 30, 2022

Would it be too much to ask for If I'd suggest to put a summary of what were the goals of this refactoring? e.g. what were the functions/methods/structs/interfaces added/removed? 🙏

Given +650 −1,269 and the fact that it touches many files it's a bit hard to review reliably.

@pmalek I updated the PR description to summarize the changes.

Copy link
Member

@pmalek pmalek left a comment

Choose a reason for hiding this comment

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

Minor nits but 🎖️ overall

@mlavacca mlavacca force-pushed the gateway-resource-consolidation branch from ce3a7da to e692a8b Compare June 30, 2022 13:24
@mlavacca mlavacca requested a review from pmalek June 30, 2022 13:24
pmalek
pmalek previously approved these changes Jun 30, 2022
Copy link
Member

@pmalek pmalek left a comment

Choose a reason for hiding this comment

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

🚢

Copy link
Contributor

@shaneutt shaneutt left a comment

Choose a reason for hiding this comment

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

Looking good, I really do appreciate the emphasis on cleaning up some of our test code, and I particularly like that we're switching over to the KTF cluster.Cleaner for cleanup because that saves a lot of space (don't forget to resolve #2618 if this does indeed update that for all cases).

I do have a few comments to share, take a look and let me know your thoughts.

@Kong Kong deleted a comment from mlavacca Jun 30, 2022
@shaneutt shaneutt dismissed their stale review June 30, 2022 15:31

Dismissing my own review to make sure it doesn't block the PR in my absence.

@mlavacca
Copy link
Member Author

mlavacca commented Jul 1, 2022

Looking good, I really do appreciate the emphasis on cleaning up some of our test code, and I particularly like that we're switching over to the KTF cluster.Cleaner for cleanup because that saves a lot of space (don't forget to resolve #2618 if this does indeed update that for all cases).

I used that cleaner only in the files touched by this refactoring. There are many other tests that still use the old cleaning approach.

@mlavacca mlavacca requested review from pmalek, shaneutt and jrsmroz July 1, 2022 10:43
@mlavacca mlavacca force-pushed the gateway-resource-consolidation branch from aee4da5 to 516e7c8 Compare July 1, 2022 11:50
@mlavacca
Copy link
Member Author

mlavacca commented Jul 1, 2022

@pmalek If you don't pass the variable testing.T to the function, you end up in a situation in which you are not able to log anything related to the test (unless we start using another logger): you just return false, and the callback is retried after a while. In this scenario, Whenever a GET fails, it's hard to spot the reason.

For what concern retrying a prior all the GETs, in a real environment I would definitely agree with you, but during tests, I'm not sure it is relevant. Given my thought, I have no problem in replacing the require.NoError(t, err) with t.Log() and return false afterward. But the point raised by Shane was to not pass the testing.T instance at all, and if we follow this approach, we are not able neither to break the test because of the error nor to log the error.

@mlavacca mlavacca requested a review from pmalek July 1, 2022 13:00
@pmalek
Copy link
Member

pmalek commented Jul 1, 2022

@pmalek If you don't pass the variable testing.T to the function, you end up in a situation in which you are not able to log anything related to the test (unless we start using another logger): you just return false, and the callback is retried after a while. ...

... the point raised by Shane was to not pass the testing.T instance at all, and if we follow this approach, we are not able neither to break the test because of the error nor to log the error.

I somehow got fixated on the logging part of it and dismissed (in my head) Shane's concerns.

So, I do agree with what was brought up (w.r.t. passing testing.T) and having an unexpected assertion fail the test and abort it (from a distance), I also believe that not having relevant logs in case of a failure are a sever debugging hindrance.

(Perhaps there's a better way to approach this but) I'd suggest to do pass the testing.T to the helper, but use it mostly for logging and make the eventuallyGatewayIsLinked return bool so that it can be used in .Eventually().

If need be we can create an issue and revisit passing the t into that helper.

@pmalek
Copy link
Member

pmalek commented Jul 1, 2022

OMG, instead of commenting I edited your comment @mlavacca 😠 sorry for that. Should be reverted already now.

@mlavacca mlavacca force-pushed the gateway-resource-consolidation branch 3 times, most recently from 2934626 to ef4223c Compare July 1, 2022 15:57
@mlavacca
Copy link
Member Author

mlavacca commented Jul 1, 2022

(Perhaps there's a better way to approach this but) I'd suggest to do pass the testing.T to the helper, but use it mostly for logging and make the eventuallyGatewayIsLinked return bool so that it can be used in .Eventually().

If need be we can create an issue and revisit passing the t into that helper.

@pmalek I followed this approach: the testing.T instance is passed to the function only for logging purposes. Furthermore, I added a callback builder to follow Shane's idea. This concern should be completely addressed, I don't think we need to create a follow-up issue.

All the gateway and gatewayClass object explicit creations scattered
around the test integration files have been cleaned up and factorized. A
set of helper functions have been created to fulfill this need and to
allow further usage when other new tests will be added.

Signed-off-by: Mattia Lavacca <[email protected]>
@mlavacca mlavacca force-pushed the gateway-resource-consolidation branch from ef4223c to fd20232 Compare July 1, 2022 18:05
@mlavacca mlavacca requested a review from pmalek July 1, 2022 18:06
Copy link
Member

@pmalek pmalek left a comment

Choose a reason for hiding this comment

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

One nit and I think this is good to get merged

@pmalek
Copy link
Member

pmalek commented Jul 1, 2022

Ideally, I'd like Shane to resolve his reservations

@mlavacca mlavacca added the do not merge let the author merge this, don't merge for them. label Jul 1, 2022
@mlavacca
Copy link
Member Author

mlavacca commented Jul 1, 2022

Ideally, I'd like Shane to resolve his reservations

Ok, let's wait for Shane's feedback. I have put the do-not-merge label.
@shaneutt

@mlavacca mlavacca merged commit 95ee4e5 into Kong:main Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge let the author merge this, don't merge for them.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consolidate Gateway resources and helpers used in tests
4 participants