kubernetes-sigs / cluster-api-provider-openstack

Cluster API implementation for OpenStack
https://cluster-api-openstack.sigs.k8s.io/
Apache License 2.0
292 stars 253 forks source link

🌱 Reduce cyclomatic complexity of ReconcileLoadBalancer #1904

Closed mdbooth closed 7 months ago

mdbooth commented 7 months ago

This function had become genuinely too complex over time, to the point that even the linter was starting to complain about it when making almost any change.

This change refactors ReconcileLoadBalancer into several smaller logical functions which are much easier to read and reason about. It also revealed some trivial optimisations:

Apart from just the code cleanup, this has the benefit of not requiring these changes to be mixed into other PRs when the complexity exceeds the linter's threshold.

/hold

k8s-ci-robot commented 7 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mdbooth

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: - ~~[OWNERS](https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/main/OWNERS)~~ [mdbooth] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
netlify[bot] commented 7 months ago

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
Latest commit e8ccd212952cebf768171982b2d0cbaf7c59fe6b
Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/65de485fd2f4b0000862af65
Deploy Preview https://deploy-preview-1904--kubernetes-sigs-cluster-api-openstack.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

mdbooth commented 7 months ago

/cc @MaysaMacedo as this touches some of your code.

mdbooth commented 7 months ago

I 100% agree about unit test coverage. However, this is basically just code motion so I can separate these changes from the other changes I'm making to the same code without triggering the gocyclo linter. IOW this is just yak shaving for me right now.

If you fancied taking the yak shears and writing some good unit tests while I get back to the API stuff I'd add to the beers I owe you.

EmilienM commented 7 months ago

/lgtm I'll let another reviewer take a look.

mdbooth commented 7 months ago

/hold cancel

MaysaMacedo commented 7 months ago

/hold

@mdbooth holding just to give a chance for you to check my comments, feel free to unhold once you checked them

MaysaMacedo commented 7 months ago

/lgtm

EmilienM commented 7 months ago

Restoring Maysa's LGTM, fixing unit tests and removing /hold. /lgtm /hold cancel