-
Notifications
You must be signed in to change notification settings - Fork 169
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/remove private dns zone #3500
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AldoFusterTurpin
requested review from
jewzaam,
bennerv,
hawkowl,
rogbas,
jharrington22,
cblecker,
cadenmarchese,
UlrichSchlueter,
s-amann,
SudoBrendan,
Shivkumar13,
yjst2012,
jaitaiwan,
anshulvermapatel,
hlipsig,
dofinn and
tiguelu
as code owners
April 4, 2024 12:58
/azp run ci |
Azure Pipelines successfully started running 1 pipeline(s). |
mociarain
previously approved these changes
Apr 4, 2024
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.
This is great. It's much clearer and easier for me (a newbie to Go and the repo as a whole) to follow and understand.
/azp run ci |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run e2e |
Azure Pipelines successfully started running 1 pipeline(s). |
mociarain
added
ready-for-review
go
Pull requests that update Go code
good first issue
Good for newcomers
size-medium
Size medium
labels
Apr 24, 2024
mociarain
force-pushed
the
refactor/remove_private_dns_zone
branch
from
April 25, 2024 08:49
00db880
to
bbf848c
Compare
/azp run ci |
Azure Pipelines successfully started running 1 pipeline(s). |
github-actions
bot
added
needs-rebase
branch needs a rebase
and removed
ready-for-review
labels
Jul 1, 2024
Please rebase pull request. |
AldoFusterTurpin
force-pushed
the
refactor/remove_private_dns_zone
branch
from
July 18, 2024 11:31
bbf848c
to
276e795
Compare
AldoFusterTurpin
requested review from
SrinivasAtmakuri,
kimorris27 and
tsatam
as code owners
July 18, 2024 11:31
AldoFusterTurpin
force-pushed
the
refactor/remove_private_dns_zone
branch
from
July 18, 2024 11:36
276e795
to
04ed05f
Compare
AldoFusterTurpin
force-pushed
the
refactor/remove_private_dns_zone
branch
2 times, most recently
from
July 18, 2024 13:40
28e8ca3
to
18327fa
Compare
AldoFusterTurpin
force-pushed
the
refactor/remove_private_dns_zone
branch
from
July 19, 2024 10:40
18327fa
to
397fe32
Compare
/azp run ci,e2e |
Azure Pipelines successfully started running 2 pipeline(s). |
mociarain
approved these changes
Jul 19, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR was already opened from my fork but we need to use branches directly in the upstream.
Which issue this PR addresses:
This PR corresponds to the task Identify and implement POC of the code to introduce Clean Architecture.
What this PR does / why we need it:
This PR does not represent the direct and exact application of Clean Architecture as it would be very difficult due to the nature and complexity of the project but instead, it moves in the right direction to improve the health of the codebase to have something more similar to Clean Architecture.
I have performed a presentation talking about key topics of these PR changes and about some principles that can help the Design of the project in the long term to have a shape more similar to Clean Architecture improving what we have today.
The other PR is also part of the same task. Using both PRs I presented key topics that move the direction of the design towards Clean Architecture.
This PR contains > 1 commit so it is easier to navigate and understand. The idea is to squash them when merging but right now I want it that way in case I need to refer to a particular step in the presentation.
Test plan for issue:
Unit tests exist and new ones created. I performed small steps in each commit to not mess up things.
Is there any documentation that needs to be updated for this PR?
N/A.
Optional detailed explanation (covered in the demo):
Problems in pkg/cluster/removeprivatednszone.go
First block of code
Second block of code
Third block of code
Fourth block of code
Problems:
Function too large to understand in a single "quick" (overview) read.
Mix of type of work in one single function/component.
Improvement process
After the first refactor commit("refactor: split in narrow functions and remove duplication", commit ID: cbf7):
We have, clusterVersionIsAtLeast4_4 and validateMachineConfigPoolsAndGetCounter which both perform business logic and at the same time write things into a logger entry. We are forced to do that because we don't treat "cluster version < 4.4, not removing private DNS zone" as an error.
If when given the condition if v.Lt(version.NewVersion(4, 4)) { it created an error with the above message, we would be able to treat all the branches inside this function as errors, and we would simply return that error and handle it appropiately outside this function. Doing that, we would be able to move the "write" part outside the function.
The same happens with the function validateMachineConfigPoolsAndGetCounter, the original code doesn't treat as errors the fact that we are entering the "ifs", it simply writes it to the logger. Returning an error with those messages would be a lot better, we would get rid of the logger parameter in the function. The caller would be responsible to handle the error as "it" wants, so we wouldn't force anyone to write anywhere the error message (because now we have conceptually an error, but we don't use the errors capabilities of Go).
Another option would be to pass a Writer interface in the function signature and implement the interface in the manager struct of the cluster to be able to pass it to the function.
We are overloading too much the *manager type of the cluster package. It would be a lot better to break that huge manager struct into multiple structs and move all the DNS/networking thing to a different struct or to an existing component/package. Single Responsibility Principle
After the refactor commit("refactor: move functions from cluster package to net package", commit ID: 89be):
After the last refactor commit("refactor: remove log in parameters and rename functions", commit ID: 0636):
Update:
I needed to update pkg/cluster/removeprivatednszone.go (rebase master) due to this PR.
So the function now returns an error and a boolean. It is curious that in the previous PR we just return one of the errors (cv, err) and for the other one (v, err) we just log it but return nil. Strange, but I want to keep the same behavior in the refactoring.