You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -144,8 +141,6 @@ discriminator should continue to not need a discriminator)
144
141
In order to support unions in a backward compatible way in kubernetes, we're
145
142
proposing the following changes.
146
143
147
-
Note that this proposes unions to be "at most one of". Whether exactly one is
148
-
supported or not should be implemented by the validation logic.
149
144
150
145
### User Stories (Optional)
151
146
@@ -206,6 +201,41 @@ Consider including folks who also work outside the SIG or subproject.
206
201
207
202
## Design Details
208
203
204
+
### Discriminator Field
205
+
206
+
We propose that all new unions maintain a "discriminator". This is a field that
207
+
points to which of the other "union member" fields is to be respected as the
208
+
truly desired union field in the case that there are any conflicts.
209
+
210
+
In order to demonstrate the need for the discriminator, we developed an
211
+
extensive [test matrix](https://docs.google.com/spreadsheets/d/1dIOOqgrgvMI9b2412eVuRSydEaOxhYOoqk6bUjZOY9c/edit?resourcekey=0-wlOfJTC_EX-qpU680STHMA#gid=3601413) that looks at various configurations of the performing
212
+
REST operations on a union where the client or server is unaware of a newly
213
+
added field to the union (due to version skew).
214
+
215
+
We present a [guide doc](https://docs.google.com/document/d/1Wruosjo0ELLl1yxauzpsUjgH2fK9KdgXDmOdJ5sG7Kg/edit?resourcekey=0-8Pwzx6EvsFR7VQoXzCTY4Q) on how to interpret the test matrix, but the major
216
+
conclusions are as follows (along with the test case number from the test matrix):
217
+
218
+
* (Case #22 and #27) If an unstructured client is unaware of field on the union, but wants to clear
219
+
the union entirely (assuming the union is optional), it will have no way of doing
220
+
so without a discriminator. With a discriminator, the client can express its
221
+
intention by setting the discriminator to the empty value and the server can
222
+
respects it intentions and clear any fields the client is unaware of.
223
+
* (Case #12 and #16) If a structured client is unaware of a field in the union that is set and it
224
+
just wants to echo back the union it received in a get request (such as when
225
+
updating other parts of the object), a client without a discriminator will
226
+
silently drop the currently set field, while a client with the discriminator
227
+
will not change the discriminator value, indicating to the client that no
228
+
changes are desired in the union.
229
+
* (Case #34 and #39) If a client sets a union field that the server is not aware of, the server
230
+
will silently drop it and attempt to clear the object of the union field. With
231
+
a discriminator, the server will see the unrecognized discriminator value and
232
+
can fail loudly.
233
+
* (Case #23 and #28) When a client goes to set a field it knows of, but a separate field it doesn't
234
+
know about is currently set, the server can simply know to always respect the
235
+
discriminator. Without a discriminator, the server will have to do convoluted
236
+
logic to detect that the previously set field has not been modified and that
237
+
only one of the other union fields has been.
238
+
209
239
### Go tags
210
240
211
241
We're proposing a new type of tags for go types (in-tree types, and also
@@ -339,14 +369,24 @@ currently done for existing union types.
339
369
340
370
Objects must be validated AFTER the normalization process.
341
371
342
-
### Test Plan
372
+
### Open Questions
343
373
344
-
There are mostly 3 aspects to this plan:
345
-
-[x] Core functionality, isolated from all other components: https://github.com/kubernetes-sigs/structured-merge-diff/blob/master/typed/union_test.go
346
-
-[x] Functionality as part of server-side apply: How human and robot interactions work: https://github.com/kubernetes-sigs/structured-merge-diff/blob/master/typed/union_test.go
347
-
-[x] Integration in kubernetes: https://github.com/kubernetes/kubernetes/pull/77370/files#diff-4ac5831d494b1b52c7c7be81e552a458
374
+
A few open questions exist with the design that need to be resolved with SIG API
375
+
Machinery before moving forward.
348
376
349
-
[] I/we understand the owners of the involved components may require updates to
377
+
1. When a server receives an update request with empty data in the member fields
378
+
but a validly set discriminator pointing to the object's union member field
379
+
that was previously set, should the server error and inform the client that
380
+
the field pointed to by the discriminator is currently empty, or should the
381
+
server retain the previous value it knows was set to the field being pointed
382
+
to by the discriminator?
383
+
2. What should the value of the discriminator be when no field in the union is
384
+
to be set. A couple options inclued an empty string, an field common to all
385
+
union (e.g. "NONE"), or a field specified on a per union basis.
386
+
387
+
### Test Plan
388
+
389
+
[x] I/we understand the owners of the involved components may require updates to
350
390
existing tests to make this code solid enough prior to committing the changes necessary
351
391
to implement this enhancement.
352
392
@@ -457,6 +497,9 @@ enhancement:
457
497
cluster required to make on upgrade, in order to make use of the enhancement?
458
498
-->
459
499
500
+
At first, Only new union types will follow the prescribed guinance, so no upgrades/downgrades are possible for types
501
+
that don't exist yet.
502
+
460
503
### Version Skew Strategy
461
504
462
505
<!--
@@ -472,6 +515,10 @@ enhancement:
472
515
CRI or CNI may require updating that component before the kubelet.
473
516
-->
474
517
518
+
See test matrix and commentary about discriminators. It clearly documents how
519
+
the server will use the discriminator to understand the client's intention even
520
+
if the client is not aware of all union fields because of version skew.
0 commit comments