Skip to content

Commit 235dd66

Browse files
committed
More feedback :-)
1 parent 4f37c2f commit 235dd66

File tree

1 file changed

+28
-16
lines changed
  • keps/sig-api-machinery/1929-built-in-default

1 file changed

+28
-16
lines changed

keps/sig-api-machinery/1929-built-in-default/README.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ meaning, they do not "look" the same and are hard to compare for
197197
clients. They are also currently treated differently by Kubernetes for
198198
defaulting purposes.
199199

200-
We propose to start removing fields with a null value, when the openapi
201-
nullable flag is missing or false. We assume that existing APIs that use
202-
nullable are happy with null values. Also, people can remove the
203-
nullable attribute if they want null values to start being removed.
204-
This will help aligning CRDs and built-in types (there are no ways to
205-
set nullable to true for built-in types). If a non-nullable defaulted
206-
field is set to null, the null value will be removed by the apiserver,
207-
and then the default will be applied.
200+
Currently, null values trigger an error when nullable is false and don't
201+
get defaulted if a default is available. We propose to start defaulting
202+
fields with null values if a default is available, or the field will be
203+
removed if no default exists, but only when the openapi nullable flag is
204+
missing or false. We assume that existing APIs that use nullable are
205+
happy with null values. Also, people can remove the nullable attribute
206+
if they want null values to start being removed. This will help
207+
aligning CRDs and built-in types (there are no ways to set nullable to
208+
true for built-in types).
208209

209210
Note that we still consider `{}` (and 0, 0.0, "", false, []) to be
210211
different from `null`, so `{"foo": {}}` is different from `{}` or from
@@ -438,9 +439,9 @@ Object:
438439
invalid:
439440
type: string
440441
default: "default-name"
441-
# This field would only be present for CRDs, for built-in,
442-
# the empty value would be accepted and treated as missing.
443-
minLength: 1
442+
# This field would only be present for CRDs, for built-in,
443+
# the empty value would be accepted and treated as missing.
444+
minLength: 1
444445
defaulted:
445446
type: int
446447
default: false
@@ -457,14 +458,19 @@ Which, for both CRD types and built-in types, would generate the following behav
457458
{"name": "default-name", "number": 0}
458459
```
459460

460-
Note that a simplified version of the generated code for built-ins would look like this:
461+
Note that a simplified, and non-cached version of the generated code for
462+
built-ins would look like this:
461463
```golang
462464
func GenerateDefault(obj *Object) {
463465
if obj.Name == "" {
464-
obj.Name = "default-name"
466+
if err := json.Unmarshal([]byte(`"default-name"`), &obj.Name); err != nil {
467+
panic(err)
468+
}
465469
}
466470
if obj.Number == 0 {
467-
obj.Number = 0
471+
if err := json.Unmarshal([]byte(`0`), &obj.Number); err != nil {
472+
panic(err)
473+
}
468474
}
469475
}
470476
```
@@ -500,8 +506,14 @@ the additional defaulting functions, automatically call them prior to
500506
the existing defaulting functions
501507
2. Update kube-openapi to parse the `+default` marker and include it in
502508
the OpenAPI definition.
503-
3. Implement the new CRD semantics that clears `null` values from
504-
objects when nullable is unset or false.
509+
3. Implement the new CRD semantics for properties with nullable unset or
510+
false (which previously would have resulted in a validation error that
511+
null is not a valid value):
512+
- properties and list items with a default have the default applied,
513+
replacing the explicit null value
514+
- list items without a default let the explicit null value remain,
515+
resulting in a validation error (matches current behavior)
516+
- properties without a default have the explicit null value removed
505517
4. Add additional "default" field to sigs.k8s.io/structured-merge-diff
506518
internal schema, and parse that field from the OpenAPI, use it when the
507519
map key is missing. The code for this already exists in a

0 commit comments

Comments
 (0)