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

First refactoring work, decouple wireguard from clustering #41

Merged
merged 37 commits into from
May 13, 2020

Conversation

kaiyou
Copy link
Contributor

@kaiyou kaiyou commented May 6, 2020

This first PR is still a WIP awaiting feedback.

The overall work is split into mostly consistent commits for easier incremental review, attempting to:

  • remove the use of wireguard objects in cluster.go by handling metadata in a separate node.go and generating the overlay address in main.go
  • stop passing the config object around and use function arguments directly
  • lower the complexity of newCluster by moving pre-computations to separate functions

At this point, end to end tests run fine, I have not added any logic yet, and am waiting for the first refactoring work to be (hopefully) merged before actually adding features.

fixes #37

kaiyou added 8 commits May 6, 2020 18:55
Move the computation of clusterKey and bindAddress
to separate functions.
The cornerstone for exchanging data is the node
structure and associated metadata. Moving it to a
separate file (maybe later a separate module) will help
decoupling.
The wireguard is mostly used to compute metadata.
Metadata is now computed by main.go and encoded in
node.go, the cluster only receives a function generating
the binary metadata.
Decouple the config structure from the cluster management and
stop passing the config object around.
Move the calls for metadata decoding from the cluster
membership management loop to the main loop. This task
was not directly related to the cluster, and was adding
complexity, including the need for multierr structures.
@kaiyou
Copy link
Contributor Author

kaiyou commented May 6, 2020

Also, this is directly related to #37

Copy link
Owner

@costela costela left a comment

Choose a reason for hiding this comment

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

Thanks for the work! 👍

I like the direction this is going. Can you take a look at my comments and we'll iterate from there?

cluster.go Outdated Show resolved Hide resolved
cluster.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
node.go Outdated Show resolved Hide resolved
node.go Outdated Show resolved Hide resolved
@costela costela self-assigned this May 6, 2020
@costela costela added the techdebt This may hamper further development label May 6, 2020
@costela costela added this to the v0.3.0 milestone May 6, 2020
@kaiyou
Copy link
Contributor Author

kaiyou commented May 7, 2020

I have a commit on the way for splitting things into modules. Should I wait for us to settle the current issues before pushing further bits into this PR maybe?

@kaiyou
Copy link
Contributor Author

kaiyou commented May 7, 2020

Thanks again for the feedback. I just pushed most requested changes, hope this is still in the right direction. Waiting for your input before I push anything about splitting into modules.

config.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
Copy link
Owner

@costela costela left a comment

Choose a reason for hiding this comment

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

Sorry for the slow review. I'm currently pretty swamped on all sides.

PTAL at my comments and then we can move to the splitting.

Thanks! 👍

@kaiyou
Copy link
Contributor Author

kaiyou commented May 9, 2020

Thanks for the feedback, and no problem about the delays.

After a second thought, passing a Node instance to the cluster as the local node is implemented on top of many changes for splitting the code into packages, and I fear the number of conflicts that will arise. Would you mind if I updated the PR with these changes?

@costela
Copy link
Owner

costela commented May 9, 2020

Would you mind if I updated the PR with these changes?

Not at all! Could just mean I'll need a bit more time to review them, but that's not a deal-breaker.

kaiyou added 5 commits May 9, 2020 16:35
Splitting into modules will help keep concerns separate,
at the cost of a slightly more verbose code.
This means nodeMeta can be private again, and also makes it
easier to pass a Node object to the cluster for local meta,
instead of a generic byte[] function.

For later updating, that node is passed using Update() instead
of New().
kaiyou added 7 commits May 9, 2020 16:35
Currently unit tests only succeed if the state path
is writeable, since it is hardcoded.
Instead of using a trivial function, simply generate the
local node from main.go, manually assign fields from the
nodeMeta struct.
This also caused renaming local variables to avoid
conflicting with the wg package name itself.
Implementing on Node makes a bit more sense than implementing on Cluster
even if the difference in code is insignificant.
@kaiyou
Copy link
Contributor Author

kaiyou commented May 9, 2020

Just pushed the remaining changes. I hope this is not too much for review.

I tried implementing the delegate interface on the Node type by subtyping in the cluster package. I honestly am not sure this improves readability or maintainability. It does make more sense I agree. Up to you I guess, it is all in the latest commit, so pretty easy to revert if needed :)

Copy link
Owner

@costela costela left a comment

Choose a reason for hiding this comment

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

Thanks again for the work! This refactoring is a big improvement!

I have a couple more comments, a few typo-corrections and some bikeshedding, but in general I think we're almost done.

cluster/delegate.go Outdated Show resolved Hide resolved
cluster/delegate.go Outdated Show resolved Hide resolved
cluster/delegate.go Outdated Show resolved Hide resolved
cluster/delegate.go Outdated Show resolved Hide resolved
cluster/delegate.go Outdated Show resolved Hide resolved
common/node.go Show resolved Hide resolved
common/node.go Outdated Show resolved Hide resolved
common/node.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
kaiyou and others added 7 commits May 10, 2020 16:38
Review suggestions in the documentation

Co-authored-by: Leo Antunes <[email protected]>
Also rename setupDelegate to SetLocalNode, so that
main can call SetLocalNode then Update().
EncodeMeta and DecodeMeta are more explicit.
Instead, the overlay address is assigned upon creation.
Also, the wireguard state is responsible for populating
the local node object.
Copy link
Owner

@costela costela left a comment

Choose a reason for hiding this comment

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

Thanks once again for all the work!
I noticed one last problem, basically caused by one of my suggestions that I didn't quite think through. PTAL.

Also, the tests seem to be failing because of the unexporting of AssignOverlayAddr. Should be a quick fix.

main.go Outdated Show resolved Hide resolved
This makes for more straightforward calls. Also, generate
the localNode directly in wg.New.
@kaiyou
Copy link
Contributor Author

kaiyou commented May 12, 2020

Thank you again for the review. I have tried and implemented your suggestions. I will wait for the build. The state test will possibly fail depending on permissions on the builder.

Copy link
Owner

@costela costela left a comment

Choose a reason for hiding this comment

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

Hopefully just the last little fix for the tests, then we're good to go! 👍

cluster/state_test.go Outdated Show resolved Hide resolved
kaiyou and others added 2 commits May 13, 2020 10:42
This is a temporary fix until the state path is made
configurable.
@kaiyou kaiyou changed the title WIP: first refactoring work, decouple wireguard from clustering First refactoring work, decouple wireguard from clustering May 13, 2020
@kaiyou
Copy link
Contributor Author

kaiyou commented May 13, 2020

Pushed these last details and fixed the tests. Also, I removed the WIP from the title since I feel confident about this. Thanks for guiding the work :)

@costela
Copy link
Owner

costela commented May 13, 2020

Nice! This is a definite improvement and will make further work easier!

Thanks again! 👍

@costela costela merged commit 49c0d7f into costela:master May 13, 2020
@kaiyou kaiyou deleted the refactor-decoupling branch June 16, 2020 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
techdebt This may hamper further development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some refactoring ideas
2 participants