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

typed: Allow duplicates when we merge #253

Merged
merged 3 commits into from Oct 20, 2023

Conversation

apelisse
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 13, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 13, 2023
typed/merge_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

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.

typed/merge.go Show resolved Hide resolved
errs = append(errs, errorf("duplicate entries for key %v", pe.String())...)
continue
if _, found := observed.Get(pe); !found {
observed.Insert(pe, child)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this existence check necessary? Is observed a set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

mergeOut, errs := w.mergeListItem(t, pe, lChild, nil)
errs = append(errs, errs...)
if mergeOut != nil {
out = append(out, *mergeOut)
}
lI++
continue
} else if _, ok := mergedRHS.Get(pe); ok {
// we've already merged it with RHS, we don't want to duplicate it, skip it.
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

typed/merge.go Outdated
@@ -180,14 +180,18 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
}
out := make([]interface{}, 0, outLen)

rhsOrder, observedRHS, rhsErrs := w.indexListPathElements(t, rhs)
rhsPEs, observedRHS, rhsErrs := w.indexListPathElements(t, rhs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the PE's no longer ordered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are still, but "order" didn't really tell me what they were. I could revert or make it rhsOrderedPEs or something.

typed/merge_test.go Outdated Show resolved Hide resolved
Copy link

@liggitt liggitt left a comment

Choose a reason for hiding this comment

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

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

typed/merge.go Show resolved Hide resolved
typed/merge.go Outdated Show resolved Hide resolved
typed/merge.go Outdated Show resolved Hide resolved
typed/merge.go Outdated Show resolved Hide resolved
typed/merge.go Outdated Show resolved Hide resolved
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.
@apelisse
Copy link
Contributor Author

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.

@liggitt
Copy link

liggitt commented Oct 20, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 20, 2023
@k8s-ci-robot k8s-ci-robot merged commit 9c99f49 into kubernetes-sigs:master Oct 20, 2023
5 checks passed
@liggitt
Copy link

liggitt commented Oct 20, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants