-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
preserve order of list in strategicMergePatch #467
Conversation
@lavalamp Ping |
and list with replace `patchStrategy`, list with merge `patchStrategy`), | ||
we always preserve the order of the list. | ||
|
||
It is obvious that list with replace `patchStrategy` will preserve the order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this sentence. No need to state that the obvious is obvious.
@@ -595,6 +595,16 @@ Strategic Merge Patch also supports special operations as listed below. | |||
|
|||
### List Operations | |||
|
|||
For all lists (including list of maps, list of primitives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't strictly true or possible. What does preserve the order even mean when you merge lists:
- AB
- AC
@@ -595,6 +595,16 @@ Strategic Merge Patch also supports special operations as listed below. | |||
|
|||
### List Operations | |||
|
|||
For all lists (including list of maps, list of primitives | |||
and list with replace `patchStrategy`, list with merge `patchStrategy`), | |||
we always preserve the order of the list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only true if we send the parallel list, which isn't required.
|
||
It is obvious that list with replace `patchStrategy` will preserve the order. | ||
|
||
For list with merge `patchStrategy`, we send a parallel reorder list when there are changes in the list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying element ordering for a strategic merge patch on a list [Alpha]
By default, patching a list using the Strategic Merge strategy will provide no guarantees to the final ordering of elements in the patched list.
As of Kubernetes 1.7, Alpha support exists for explicitly specifying the ordering of elements in a during a Strategic Merge Patch. This can be done by providing a parallel list containing all of the patchMergeKeys of elements that need to be ordered. Any elements missing from the parallel list are guaranteed to appear after elements appearing in the parallel list.
When patching Strategic Merge lists,
kubectl apply
sends a parallel list containing keys for each of the elements in the configuration file.
45687de
to
5d81174
Compare
Updated. |
@apelisse Could you give this a review? |
|
||
By default, patching a list using the Strategic Merge strategy will provide no guarantees to the final ordering of elements in the patched list. | ||
|
||
As of Kubernetes 1.7, Alpha support exists for explicitly specifying the ordering of elements in a during a Strategic Merge Patch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing word "list" ?
Alpha support exists for explicitly specifying the ordering of elements in a LIST during a Strategic Merge Patch.
|
||
As of Kubernetes 1.7, Alpha support exists for explicitly specifying the ordering of elements in a during a Strategic Merge Patch. | ||
This can be done by providing a parallel list containing all of the patchMergeKeys of elements that need to be ordered. | ||
Any elements missing from the parallel list are guaranteed to appear after elements appearing in the parallel list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a relevant use-case, but what happens if the server adds many?
Original:
- A
Server adds B to F:
- A
- B
- C
- D
- E
- F
User applies:
- A
- B
We only guarantee that A and B will keep order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or if the server reorders things in the meantime. Intent gets really muddled here.
Original:
A B C D E
how does a client indicate it want to move A to the end, tolerating any server-side reordering of the other elements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We guaranteed the order from the user's config will always be preserved in the server.
We only guarantee that A and B will keep order?
Yes
how does a client indicate it want to move A to the end, tolerating any server-side reordering of the other elements?
If the server add some items in the list, a client cannot move something to the end without specify the whole list using this approach.
@@ -595,6 +595,16 @@ Strategic Merge Patch also supports special operations as listed below. | |||
|
|||
### List Operations | |||
|
|||
#### Specifying element ordering for a strategic merge patch on a list [Alpha] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is super confusing to put this here. This section of the doc is about when the verb is "list" (i.e., GET on a collection). Please make this part of the strategic merge patch section. Also should we really be editing the doc before it's implemented? I guess I would have expected a proposal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, sorry, I am wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should specify strategic merge patch elsewhere. This is not the right doc to define it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Pulled strategic merge patch doc out.
#535
By default, patching a list using the Strategic Merge strategy will provide no guarantees to the final ordering of elements in the patched list. | ||
|
||
As of Kubernetes 1.7, Alpha support exists for explicitly specifying the ordering of elements in a during a Strategic Merge Patch. | ||
This can be done by providing a parallel list containing all of the patchMergeKeys of elements that need to be ordered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this means. An example would be helpful. Something that explicitly states the syntax of the patch would be best.
value: foo | ||
- name: ENV2 | ||
value: bar | ||
- name: ENV5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that this is a useful feature. It is very complex and I'm not sure why it is necessary, or even why it is an improvement? I can see adding an "append" command.
#### List of Primitives | ||
|
||
We have two patch strategies for lists of primitives: replace and merge. | ||
Replace is the default patch strategy, which will replace the whole list on update and it will preserve the order; | ||
while merge strategy works as an unordered set. In this section, we call a primitive list with merge strategy an unordered set. | ||
while merge strategy works as an ordered set. In this section, we call a primitive list with merge strategy an ordered set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it still be possible to treat these items as an unordered set?
Apologies for delay in looking at this. I am lost in a sea of github notifications, next time chat me up on slack (or internally). Is there a reason why kubernetes/kubernetes#40373 can't just use the replace strategy? We don't have random things mutating the environment variables, I don't think. |
The patch strategy is defined in the go struct tag of the API objects, | ||
e.g. `finalizers` uses `merge` as patch strategy. | ||
```go | ||
Finalizers []string `json:"finalizers,omitempty" patchStrategy:"merge" protobuf:"bytes,14,rep,name=finalizers"` | ||
``` | ||
|
||
##### Unordered Set | ||
##### Ordered Set | ||
|
||
There are 3 operations: add, delete, replace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's truly an ordered set, then there should be more than three operations (or add
should be insert
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we shouldn't get rid of the current unordered set, we should add a way to deal with lists instead.
|
Yeah that's a fair point, we should stop computing these from compiled in
structs. I talked with Phil & Mengqi some yesterday and suggested explicit
inserts, deletes, and moves instead of this ordering suggestion.
…On Mon, Apr 3, 2017 at 9:18 PM, Jordan Liggitt ***@***.***> wrote:
Is there a reason why kubernetes/kubernetes#40373
<kubernetes/kubernetes#40373> can't just use
the replace strategy? We don't have random things mutating the environment
variables, I don't think.
kubectl edit submits a patch computed by CreateTwoWayMergePatch, which
means clients have baked-in structs with merge strategies, so they will
only send the added/deleted items, which means we can't change the strategy
to replace server-side or we'll drop all the envvars they didn't change.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#467 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAnglga6Xg5ddWeAMY61VpSGwh4NpN05ks5rscSNgaJpZM4Mf8vH>
.
|
Move to a proposal PR in #537. PTAL |
* init * cant be in both lists
This is kind of a small proposal of how to preserve the order of list in strategicMergePatch.
Old behavior: we never preserve the order for list with merge
patchStrategy
. Instead we sort them by themergeKey
.Related issue: #40373
cc: @pwittrock @lavalamp