feat: add AddReference method to References#415
Open
yordis wants to merge 1 commit intocrossplane:mainfrom
Open
feat: add AddReference method to References#415yordis wants to merge 1 commit intocrossplane:mainfrom
yordis wants to merge 1 commit intocrossplane:mainfrom
Conversation
30b0582 to
3da3f28
Compare
Contributor
Author
|
A few things from this,
|
3da3f28 to
67ef84e
Compare
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
67ef84e to
797d5c9
Compare
3 tasks
mbbush
reviewed
Jun 10, 2024
| // in another object. | ||
| func (r References) AddReference(fieldPath string, ref Reference) error { | ||
| if _, ok := r[fieldPath]; ok { | ||
| return ErrReferenceAlreadyExists |
Contributor
There was a problem hiding this comment.
I don't love returning an error in this situation. My instinct is that the action of setting a reference should be idempotent; as you've implemented it all times it's invoked but the first will fail with an error.
Maybe it's ok because it would happen at generation time, although I don't know if we could guarantee that.
Contributor
Author
There was a problem hiding this comment.
I have no strong opinions; either way it is fine by me
Contributor
Author
There was a problem hiding this comment.
Hey @mbbush, what would be the resolution here? I am not sure if you requested some changes or not
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of your changes
@haarchri was helping at crossplane-contrib/provider-upjet-digitalocean#41 (thank you), and during the code review, I noticed a oversee where he replaced the existing
r.Referencesas follow:I am glad that I saw the diff, but honestly, this is a straightforward thing to miss when they are so much code-generated files noise, or people tend to ignore those.
As @haarchri explained, "That's why I prefer this, for example, https://github.com/crossplane-contrib/provider-upjet-aws/blob/main/config/elbv2/config.go#L13," which is a really common scenario.
I never considered using the existing style. I didn't think much about it. He didn’t try to break things. Still, we ran into the issue. Since we are talking about "style" here, it is really difficult to be objective and define who is more proper.
So, the fix here is to expose an SDK API that avoids such a mistake.
I am not proposing adding getters and setters everywhere either, just reacting to the situation and figuring out how to mitigate the issues in the future; as I usually say, "let the code teach you what to do, not the other way around."
I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested