typed: Allow duplicates when we merge #253
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/structured-merge-diff/pull/253#" title="Author self-approved">apelisse</a>
The full list of commands accepted by this bot can be found here.
The pull request process is described here
<details >
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":[]} -->
So this is merging the new item with the first occurence, I'm currently thinking we should replace altogether.
This seems equivalent, since we are looking LHS first. Just curious why the change? Is it a noop?
Is this existence check necessary? Is observed a set?
I'm not sure why this case is necessary. It's hard to track the invariants of observedRHS vs mergedRHS without going very deep into the code.
Are the PE's no longer ordered?
This case surprised me. From our prior conversations I would not have expected the merge with one of the duplicates. It doesn't seem like as the author of such a resource I'd be very conscious of which of the duplicates I am merging with.
Is it possible to have two instances of the same value but they are owned by different field managers? In that case I almost would expect "MY" version of the duplicate to be merged; but don't think that'd be worth the effort.
Except for one tests make a lot of sense and very straightforward.
TBH I could not gain deep sense of the code changes without obtaining degree in SMD. This code could benefit a lot from some more inline comments about the invariants of this algorithm.
They are still, but "order" didn't really tell me what they were. I could revert or make it rhsOrderedPEs or something.
Actually, lhs can have multiple times the same PE, so we want to make sure we get the right one (I don't think it's equivalent).
observed is a map from pathelement to the actual value.
the value that ends-up being in the PE is the one we're going to use to merge I think, so if we were to override here, I think we would end-up merging with the last item in the list rather than the first. But since we've decided we might not want to do that, I will probably deal with that differently.
Is it possible to have two instances of the same value but they are owned by different field managers?
No.
This case surprised me. From our prior conversations I would not have expected the merge with one of the duplicates. It doesn't seem like as the author of such a resource I'd be very conscious of which of the duplicates I am merging with.
yeah, I think we just need to replace rather than merge, which means I'll need to know if they are duplicated and replace altogether, I'll update the algorithm.
AI: look for issue reported where someone couldn't update because of managed fields
edit: this was a note to self unrelated to this PR, was https://github.com/kubernetes/kubernetes/issues/90904
comment that lChild will be nil if the LHS had duplicates for pe
comment that we use lhs.AtUsing instead of observedLHS because observedLHS can contain nil if the lhs had duplicates
lChild, _ := observedLHS.Get(pe) // may be nil if not present or LHS duplicated this item
is it possible to only tolerate duplicates making the LHS and keep returning the duplicate error making the RHS?
tests look good, the change was shockingly small.
mostly requests for clearer comments, one request to keep the duplicate-error-returning bit the same when constructing observedRHS
Added a comment for that.
PTAL, I think I've addressed all the commits. Also split the rename of rhsOrder and lhsOrder in a seperate commit to keep the meat of the change isolated.
/lgtm
Thanks, open the k/k PR to update master and ping me for review.
I suspect we'll want to backport this, not sure if that means picking the fix to other smd branches or not.
apelisse
The goal is to ignore duplicates if they are not included in the partial object, and to replace all of the occurences if they are in the partial object.
/assign @liggitt
/cc @alexzielenski