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

refactor: Easier to read driver seed #411

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

jonstacks
Copy link
Collaborator

What

There are a some places where I think we can use generics and other methods to make the code easier to read, maintain, and test. The initial seed was one of those places that can benefit from this. I think we can also re-use the new internal/util package in more places too.

How

  • Adds a generic function which can takes []T, where *T implements client.Object, and returns []client.Object
  • Adds a function that can fetch all items of a particular type and return them as []client.Object
  • refactors the driver Seed so we can easily see all the types we are seeding

This is slightly less memory efficient as rather than getting a pointer for each item before we call the store to update it, we pre-compute a slice with all pointers. This seemed like an acceptable trade-off for making the code easier to read and manage.

Breaking Changes

No

@jonstacks jonstacks self-assigned this Aug 15, 2024
@jonstacks jonstacks requested a review from a team as a code owner August 15, 2024 13:31
@github-actions github-actions bot added the area/controller Issues dealing with the controller label Aug 15, 2024
go 1.21

toolchain go1.21.5
go 1.22
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While we are using go 1.22 to build, because we had go 1.21 declared in our go.mod, we were not opted into this fix for loop vars.

@jonstacks jonstacks merged commit 9380339 into ngrok:main Aug 15, 2024
7 checks passed
@jonstacks jonstacks added this to the controller 0.12.2 milestone Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/controller Issues dealing with the controller
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants