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

tofieldset: Add tests to show it already allow duplicates #249

Merged

Conversation

apelisse
Copy link
Contributor

Continuation of #247.

This uses the pattern that I've generally used to solve the problem, which is to not try to be too smart about duplicate entries, and just record the path element for the whole thing, rather than try to track all the fields within. It's not super relevant because no one should ever be able to apply duplicates, so they wouldn't really have conflicts with sub-fields anyway, we've decided that they should have a conflict with the idea of "duplicates" (de-duplicating is a conflict).

/assign @alexzielenski

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 27, 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 requested a review from jpbetz September 27, 2023 22:19
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 27, 2023
_P("list", _KBF("key", "a", "id", 1), "key"),
_P("list", _KBF("key", "a", "id", 1), "id"),
_P("list", _KBF("key", "a", "id", 1), "nv"),
_P("list", _KBF("key", "a", "id", 2)),
Copy link
Contributor Author

@apelisse apelisse Sep 27, 2023

Choose a reason for hiding this comment

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

cc @jpbetz
This code is mostly irrelevant because we only use ToFieldSet on objects that are applied, and we should never allow apply to have duplicates (now, that being said, I'm curious if this whole change even makes sense?). I still wanted to illustrate that when someone will update with duplicates items, we will just give them ownership of the associative key and that's it, as a way to indicate that they own that key multiple times. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One drawback of this, but I don't know if we can solve it anyway, is that if someone applies one item, and then it gets updated into two items, that item won't be pruned when it's removed from the applied configuration, meaning it can no longer be removed with server-side apply. I think that's reasonable.

Copy link
Contributor

@alexzielenski alexzielenski Oct 6, 2023

Choose a reason for hiding this comment

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

This code is mostly irrelevant because we only use ToFieldSet on objects that are applied, and we should never allow apply to have duplicates (now, that being said, I'm curious if this whole change even makes sense?)

If apply can never have duplicates why are we making SMD ToFieldSet tolerate duplicates? How do Updates get the list of fields to own if not via ToFieldSet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If apply can never have duplicates why are we making SMD ToFieldSet tolerate duplicates?

Context, we're trying to solve #234

For built-ins, the listType=map is used a little loosely, and we don't have a great way to address that, except for accepting some duplicates. We still can't apply duplicates, but right now you can't apply an objects that has these duplicates.

How do Updates get the list of fields to own if not via ToFieldSet?

By using "Compare", they own the fields that they changed, since we don't know exactly what they intended to own.

Copy link
Contributor

Choose a reason for hiding this comment

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

We still can't apply duplicates, but right now you can't apply an objects that has these duplicates.

Is ToFieldSet invoked on the final merged object, or the partial patch? If it is invoked on the partial patch aren't there no duplicates and this PR has no effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, that's more or less what I said in the PR body:

It's not super relevant because no one should ever be able to apply duplicates

But:

  1. This is for consistency, if we agree that this is how ownership of things that are duplicates, we should probably apply it everywhere, even if it's not relevant here.
  2. This is the first time we use that new pattern in the code so I want to make sure we're fine with it.

@apelisse
Copy link
Contributor Author

/hold

I'm trying a new test with pruning fields that are removed by appliers and this doesn't work, looking into this.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 27, 2023
@apelisse
Copy link
Contributor Author

apelisse commented Oct 5, 2023

/hold cancel

Thought about this further, I think it's fine, unless I forgot the use-case I had in mind ...

@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 5, 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.

Just to clarify, this change makes SMD give ownership of the entire object if there are duplicates in a list map?

I'm having a hard time tracking the "before" behavior and the "after" behavior.

_P("list", _KBF("key", "a", "id", 1), "key"),
_P("list", _KBF("key", "a", "id", 1), "id"),
_P("list", _KBF("key", "a", "id", 1), "nv"),
_P("list", _KBF("key", "a", "id", 2)),
Copy link
Contributor

@alexzielenski alexzielenski Oct 6, 2023

Choose a reason for hiding this comment

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

This code is mostly irrelevant because we only use ToFieldSet on objects that are applied, and we should never allow apply to have duplicates (now, that being said, I'm curious if this whole change even makes sense?)

If apply can never have duplicates why are we making SMD ToFieldSet tolerate duplicates? How do Updates get the list of fields to own if not via ToFieldSet?

_P("list", _KBF("key", "a", "id", 1), "key"),
_P("list", _KBF("key", "a", "id", 1), "id"),
_P("list", _KBF("key", "a", "id", 1), "nv"),
_P("list", _KBF("key", "a", "id", 2)),
Copy link
Contributor

Choose a reason for hiding this comment

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

if someone applies one item, and then it gets updated into two items, that item won't be pruned when it's removed from the applied configuration, meaning it can no longer be removed with server-side apply.

Why wouldn't it be pruned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because when you update to multiple items, it steals the ownership of the whole item and we don't prune things that you don't have ownership over.

Copy link
Contributor

@alexzielenski alexzielenski Oct 6, 2023

Choose a reason for hiding this comment

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

it steals the ownership of the whole item and we don't prune things that you don't have ownership over.

It sounds like you do own it if it steals ownership of the whole item? Do you only have ownership of one copy? Can you share example of the behavior for this. I would expect that you have ownerhsip of the whole duplicated field, and when you submit an UPDATE or PATCH that does not include it, then no one has ownership, and it is pruned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using sets, since it's a little simpler:
Apply, "applier": [1]
Update, "updater": [1, 1] # Updater steals ownership of 1
Apply, "applier": [] # 1 is not pruned because it's owned by updater.
Final object: [1, 1]

Copy link
Contributor

@alexzielenski alexzielenski Oct 6, 2023

Choose a reason for hiding this comment

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

That seems like correct behavior to me. What if it was a map typed list with duplicate keys but unequal objects?

Apply, "applier": [ObjWithKeyA]
Update, "updater": [ObjWithKeyAButSlighlyDifferent, ObjWithKeyAButAlsoDifferent] # Should be three copies of 'A'?
Apply, "applier": [] # is A pruned?
Whats the final object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point.

So first of all, Update replaces the whole list, so if you do

Update, "updater": [ObjWithKeyAButSlighlyDifferent, ObjWithKeyAButAlsoDifferent] # Should be three copies of 'A'?

you end-up with that exact object.

Second, the way this is meant to work, is that if you have duplicate, you own the key and the key only, so here's what happens in your scenario:

Apply, "applier": [ObjWithKeyA] -> applier owns ObjWithKeyA
Update, "updater": [ObjWithKeyAButSlighlyDifferent, ObjWithKeyAButAlsoDifferent] -> duplicates, updater owns just "KeyA" (none of the fields)
Apply, "applier": [] # is A pruned? no
Whats the final object
[ObjWithKeyAButSlighlyDifferent, ObjWithKeyAButAlsoDifferent] with KeyA owned by updater.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think thats reasonable

typed/tofieldset.go Show resolved Hide resolved
@alexzielenski
Copy link
Contributor

LGTM from me. I think you mentioned you wanted @jpbetz input so will defer tag

@k8s-ci-robot
Copy link
Contributor

@alexzielenski: Closed this PR.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot reopened this Oct 6, 2023
@k8s-ci-robot
Copy link
Contributor

@alexzielenski: Reopened this PR.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@alexzielenski
Copy link
Contributor

alexzielenski commented Oct 6, 2023

whoops. brain misfire

/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 6, 2023
@k8s-ci-robot k8s-ci-robot merged commit 52ca48f into kubernetes-sigs:master Oct 6, 2023
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants