-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Discourage usage of nullable on API types #8488
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,6 +27,7 @@ An introduction to using resources with kubectl can be found in [the object mana | |||||
- [Categories](#categories) | ||||||
- [Idempotency](#idempotency) | ||||||
- [Optional vs. Required](#optional-vs-required) | ||||||
- [Nullable](#nullable) | ||||||
- [Defaulting](#defaulting) | ||||||
- [Static Defaults](#static-defaults) | ||||||
- [Admission Controlled Defaults](#admission-controlled-defaults) | ||||||
|
@@ -866,6 +867,17 @@ language client, and any other clients that use corresponding types | |||||
Therefore, we ask that pointers always be used with optional fields that do not | ||||||
have a built-in `nil` value. | ||||||
|
||||||
## Nullable | ||||||
|
||||||
The `+nullable` comment tag allows the json `null` value to be a valid value | ||||||
for a field. The `null` value is serialized only when a field is a pointer | ||||||
in the Go definition, and does not have the `omitempty` json tag. | ||||||
|
||||||
For example, a map field marked with `+nullable` would accept either `foo: null` or `foo: {}`. | ||||||
|
||||||
Usage of `+nullable` is discouraged as it introduces several issues: | ||||||
- It is not compatible with json merge patching. | ||||||
- It is not compatible with generic protobuf. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's also not compatible with server-side apply, but this should be verified (I have a vague memory of SSA using null values as a signal to remove a key, which would make a null value impossible to persist via SSA) |
||||||
## Defaulting | ||||||
|
||||||
|
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.
(from the merge patch RFC: "Null values in the merge patch are given special meaning to indicate the removal of existing values in the target.")