@@ -17,14 +17,35 @@ issue [40373](https://github.com/kubernetes/kubernetes/issues/40373).
17
17
18
18
## Proposed Change
19
19
20
+ We will use the following notions through the doc.
21
+ Notion:
22
+ list to be merged: same as live list, which is the list current in the server.
23
+ parallel list: the list with ` $setElementOrder ` directive in the patch.
24
+ patch list: the list in the patch that contains the value changes.
25
+
20
26
Changes are all in strategic merge patch package.
21
27
The proposed solution is similar to the solution used for deleting elements from lists of primitives.
22
28
23
29
Add to the current patch, a directive ($setElementOrder) containing a list of element keys -
24
30
either the patch merge key, or for primitives the value. When applying the patch,
25
31
the server ensures that the relative ordering of elements matches the directive.
26
32
27
- Here is an simple example:
33
+ The server will reject the patch if it doesn't satisfy the following 2 requirement.
34
+ - the relative order of any two items in the ` $setElementOrder ` list
35
+ matches that in the patch list if they present.
36
+ - the items in the patch list must be a subset or the same as the ` $setElementOrder ` list if the directive presents.
37
+
38
+ The relative order of two items are determined by the following order:
39
+
40
+ 1 . relative order in the $setElementOrder if both items are present
41
+ 2 . else relative order in the patch if both items are present
42
+ 3 . else relative order in the server-side list if both items are present
43
+ 4 . else append to the end
44
+
45
+ If the relative order of the live config in the server is different from the order of the parallel list,
46
+ the user's patch will always override the order in the server.
47
+
48
+ Here is an simple example of the patch format:
28
49
29
50
Suppose we have a type called list. The patch will look like below.
30
51
The order from the parallel list ($setElementOrder/list) will be respected.
@@ -33,40 +54,32 @@ The order from the parallel list ($setElementOrder/list) will be respected.
33
54
$setElementOrder/list :
34
55
- A
35
56
- B
57
+ - C
36
58
list :
37
- - B
38
59
- A
60
+ - C
39
61
` ` `
40
62
41
- All the items in the server's live list but not in the parallel list will be append to the end of the parallel list.
63
+ All the items in the server's live list but not in the parallel list will be come before the parallel list.
42
64
The relative order between these appended items are kept.
43
- If the relative order of the live config in the server is different from the order of the parallel list,
44
- the user's patch will always override the order in the server.
45
65
46
66
The patched list will look like:
47
67
48
68
` ` `
49
69
mergingList :
70
+ - serverOnlyItem1 \
71
+ ... |===> items in the server's list but not in the parallel list
72
+ - serverOnlyItemM /
50
73
- parallelListItem1 \
51
74
... |===> items from the parallel list
52
75
- parallelListItemN /
53
- - otherItem1 \
54
- ... |===> items in the server's list but not in the parallel list
55
- - otherItemN /
56
76
` ` `
57
77
58
78
### When $setElementOrder is not present and patching a list
59
79
60
80
The new directive $setElementOrder is optional.
61
- The new server applying a patch request without the directive will be
62
- a best-effort operation to keep the order of elements that are already in the list:
63
-
64
- For changes and deletions, the server will just merge the change without sorting them.
65
- So the items in the list will retain the order.
66
-
67
- For additions, the items will be appended to the end of the list.
68
-
69
- So it changes a little from previous releases, but is still fully backward compatible with old clients.
81
+ When the $setElementOrder is missing,
82
+ relative order in the patch list will be respected.
70
83
71
84
Examples where A and C have been changed, B has been deleted and D has been added.
72
85
@@ -75,26 +88,26 @@ Patch:
75
88
` ` ` yaml
76
89
list :
77
90
- A'
78
- - $patch : delete
79
- B
91
+ - B'
80
92
- D
81
93
` ` `
82
94
83
95
Live:
84
96
85
97
` ` ` yaml
86
98
list :
87
- - C
88
99
- B
100
+ - C
89
101
- A
90
102
` ` `
91
103
92
104
Result:
93
105
94
106
` ` ` yaml
95
107
list :
96
- - C
97
- - A
108
+ - C # server-only item comes first
109
+ - A'
110
+ - B'
98
111
- D
99
112
` ` `
100
113
@@ -132,10 +145,12 @@ list:
132
145
# ## When the list to be merged contains elements not found in `$setElementOrder`
133
146
134
147
If the list to be merged contains elements not found in $setElementOrder,
135
- they will come after all elements defined in $setElementOrder, but keep their relative ordering.
148
+ they will come before all elements defined in $setElementOrder, but keep their relative ordering.
136
149
137
150
Example where A & B have been changed :
138
151
152
+ Patch :
153
+
139
154
` ` ` yaml
140
155
$setElementOrder/list:
141
156
- A
@@ -145,6 +160,8 @@ list:
145
160
- B
146
161
` ` `
147
162
163
+ Live :
164
+
148
165
` ` ` yaml
149
166
list:
150
167
- C
@@ -158,11 +175,11 @@ Result:
158
175
159
176
` ` ` yaml
160
177
list:
161
- - A
162
- - B
163
178
- C
164
179
- D
165
180
- E
181
+ - A
182
+ - B
166
183
` ` `
167
184
168
185
# ## When `$setElementOrder` contains elements not found in the list to be merged
@@ -207,7 +224,9 @@ Patch requests without the directive will change a little,
207
224
but still be fully backward compatible.
208
225
209
226
# ## kubectl
210
- If an old kubectl sends a old patch to a new server, the server will not preserve the order which behave as an old server.
227
+ If an old kubectl sends a old patch to a new server,
228
+ the server will honor the order in the list as mentioned above.
229
+ The behavior is a little different from before but is not a breaking change.
211
230
212
231
If a new kubectl sends a new patch to an old server, the server doesn't recognise the parallel list and will drop it.
213
232
So it will behave the same as before.
@@ -284,20 +303,20 @@ env:
284
303
value: new-env
285
304
` ` `
286
305
287
- After server applying the patch :
306
+ After server applying the new patch :
288
307
289
308
` ` ` yaml
290
309
env:
310
+ - name: ENV5
311
+ value: server-added-2
312
+ - name: ENV4
313
+ value: server-added-1
291
314
- name: ENV1
292
315
value: foo
293
316
- name: ENV2
294
317
value: bar
295
318
- name: ENV6
296
319
value: new-env
297
- - name: ENV5
298
- value: server-added-2
299
- - name: ENV4
300
- value: server-added-1
301
320
` ` `
302
321
303
322
# ## List of Primitives
@@ -361,11 +380,11 @@ After server applying the patch:
361
380
362
381
` ` ` yaml
363
382
finalizers:
383
+ - e
384
+ - d
364
385
- a
365
386
- b
366
387
- f
367
- - e
368
- - d
369
388
` ` `
370
389
371
390
0 commit comments