Skip to content
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

mergeFromPatch does not consider the zero value as part of the patch #703

Closed
enxebre opened this issue Dec 2, 2019 · 6 comments
Closed
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@enxebre
Copy link
Member

enxebre commented Dec 2, 2019

A CRD has a status sub-resource with a required integer field: status.IntField
When trying to patch the status for the first time with status.IntField=0 the diff given by patch.Data(obj) does not consider the zero value as part of the patch to be applied and the request via mergeFromPatch client.Status().Patch fails with is invalid: status.IntField: Required value
Is the only way to go to make IntField a pointer?

@DirectXMan12
Copy link
Contributor

/kind bug
/priority backlog

Do you want zero to be a valid value? Or is that considered unset?

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence. labels Dec 2, 2019
@enxebre
Copy link
Member Author

enxebre commented Dec 3, 2019

Do you want zero to be a valid value? Or is that considered unset?

A valid value.

@DirectXMan12
Copy link
Contributor

is this a structural schema or a non-structural one? I wonder if // +default=0 would work.

@enxebre
Copy link
Member Author

enxebre commented Dec 9, 2019

yeh I wanted to do that unfortunately this is non-structural yet

@DirectXMan12
Copy link
Contributor

hmm... I don't think there's a good way for MergePatchFrom to know that the field changed -- it basically just serializes both instances and then does a diff of the raw JSON, and a field is either omitempty or it isn't, but in either case the value doesn't change from an empty object. You might have to write your own patch generator that knows how to handle the case of "object doesn't exist yet" or something, or just do different behavior if the status is unset initially.

@enxebre
Copy link
Member Author

enxebre commented Dec 10, 2019

Thanks for the ideas Solly, I think we can close this. I'll go by using a pointer for now and would use //+default=0 for a structural schema

@enxebre enxebre closed this as completed Dec 10, 2019
DirectXMan12 pushed a commit that referenced this issue Jan 31, 2020
⚠️ Switch default project version to v2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

No branches or pull requests

3 participants