-
Notifications
You must be signed in to change notification settings - Fork 282
Break down rabbitmqcluster_controller.go #418
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
Conversation
- separate according to different k8s/rmq concepts that the Reconcile function is handling - all broken down files have a corresponding *_test.go file which contains its integration tests
I'm really happy we're doing this, the controller codebase was getting difficult to navigate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff. I feel like this queue rebalancing could be done in a more generic way (it doesn't really reconciles anything and it's not clear how another post-deploy command would fit into this). But I'm totally happy to take this PR as-is and worry about that when working on #414, which is another post deploy command (but only executed on fresh deployments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for this Chunyi. This solves some of the navigation issues I had with the controller also. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this refactor!
Note to reviewers: remember to look at the commits in this PR and consider if they can be squashed
Summary Of Changes
This is a refactor PR which separates logics of controllers/rabbitmqcluster_controller.go. I extracted helper functions according to different concepts/objects that the
Reconcile()
is operating on.Each of the file has a corresponding
reconcile_*_test.go
which contains its integration tests. I add an additionalutils.go
which contained general helper functions that were used in multiple of the above files.PodExecutor
interface is extracted to its own file as well.rabbitmqcluster_controller.go
still containers theReconcile()
,SetupWithManager()
, and helper functionaddResourceToIndex
,getRabbitmqCluster
,getChildResources
andlogAndRecordOperationResult
.Pros and Cons
I think the controller logic became easier to navigate with this refactor. When we are modifying
rabbitmqcluster_controller.go
, most of the time we are changing the logic of how theReconcile()
deals with one object/aspects. With this refactor, it should be easier to see where to make changes. Each of these files can grow or shrink themselves without impacting the main controller logic.The obvious cons will be losing history behind the helper function. However, I would argue that we will eventually do a refactor and the earlier we do it, the more history we can preserve.
Next Step
This is "shift and life" PR that does not change any helper function or any test. I think the logical step next will be to refactor all helper reconcile to have the same contract, and to further move certain logic from
Reconcile()
to the helpers. Before I head there, I would like to check in with the team first.Local Testing
Have run unit and integration tests.