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.
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.
Off topic/general comment...
CreateK8sCR
seems to do way too many things right? One func to do create, update, patch, taking ownership, doing all sorts of reflection...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.
The purpose was to create and update objects in the same function so that the main reconciliation loop is cleaner. When you create an object, it's when you also specify its ownership, so these should be together anyway.
The inventory controller makes sure the servers exist at all times (so it recreates them if they've been deleted) and that they look as specified in the Inventory CR spec (so it updates/patches if someone edits them directly).
I suppose we could separate the updates from creation in different functions.
What enhancement did you have in mind for this?
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.
Few suggestions:
updateOrPatchObject
createObject
etc etc. And then finally the caller should explicitly check for errors as needed e.g.k8srr.IsAlreadyExists(err)
for createObject
. i.e c.Create(ctx, job) (job being a struct type job). This means more code but idiomatic/in-line with Gowdyt?
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.
What's going to happen if we split it into a
updateOrPatchObject
and acreateObject
is that someone will get tired of seeing that pattern spread throughout the code and will create a wrapper for that flow calledcreateOrUpdateObject
and we're more or less back to this starting point.I do agree that the name could be improved upon, and certainly how we use it will need to be addressed in the future because as of now the 'update' is rather unsophisticated and doesn't handle needing to modify objects very gracefully at all. They all end up being just a bulk replace of the object which is likely causing issues to anyone doing a watch on them (potentially)
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.
I agree that renaming it to smth like
ensureK8sCR
would be a better description of the functionality.I don't really agree that this is violating the SRP principle, especially with the renaming and possibly enhancing the update.
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.
Yeah definitely doing
createObject
would ultimate be wrapped up. Which is why it's better to be explicit (the third point) and pass the exact typed...so instead we should havecreateJob
orcreateDeployment
instead of super generic funcs