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: Update compare algorithm to handle duplicates #251

Merged
merged 2 commits into from
Oct 12, 2023

Conversation

apelisse
Copy link
Contributor

@apelisse apelisse commented Oct 9, 2023

Same strategy as #249, still trying to address #234. Algorithm goes as follow:

  1. Duplicates are treated as separate from non-duplicates items
  2. Adding a duplicate to an existing item means we will remove the existing (counted as removed) and added as a duplicate (added).
  3. Removing does the opposite
  4. If any of the duplicated value changes, key will be counted as "modified".

Rewording:

In compare, treat duplicate keys in associative lists/sets as a separate atomic list, marked by owning just the duplicated key.

/assign @alexzielenski
/cc @jpbetz

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 9, 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 9, 2023
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.

I'm still not super familiar with this part of SMD yet so I asked a lot of questions, sorry :)

typed/compare.go Outdated
continue

if v, found := lValues.Get(pe); found {
list := v.Unstructured().([]value.Value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be preferable to avoid unstructured conversion for the comparison? This kinda makes me sad

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I dont understand how this line works. Shouldn't Unstructured return a []interface{}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's because I'm abusing the PathElementValueMap here. I don't insert a valid value in there, I cast a []value.Value into a value and then retrieve it, and it just works. I don't know if we want to introduce generics code in here just yet, so I can't really make the map take whatever type of parameter type I want.

typed/compare.go Show resolved Hide resolved
typed/compare.go Show resolved Hide resolved
if len(rList) != 0 {
rValue = rList[0]
}
errs = append(errs, w.compareListItem(t, pe, lValue, rValue)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm reading this correctly, this is the "no duplicates" case and should be semantically identical to the old code?

@apelisse
Copy link
Contributor Author

OK, I've added comments to explain what happens, hopefully that helps.

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.

lgtm except for that comment about unstructured

typed/compare.go Outdated
continue

if v, found := lValues.Get(pe); found {
list := v.Unstructured().([]value.Value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I dont understand how this line works. Shouldn't Unstructured return a []interface{}?

@apelisse
Copy link
Contributor Author

OK I've added a new commit to create a new map of PEs to interface{}, and then updated the other commit to use it instead of value, which simplifies the code a tiny bit since we don't have to create the new valueinterface thingy.

@alexzielenski
Copy link
Contributor

/lgtm
/hold

in case you wanted to change anything else

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Oct 12, 2023
@apelisse
Copy link
Contributor Author

/hold

I'm good thanks!

@apelisse
Copy link
Contributor Author

I meant
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 12, 2023
@k8s-ci-robot k8s-ci-robot merged commit 1233172 into kubernetes-sigs:master Oct 12, 2023
5 checks passed
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

3 participants