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

Defaults and Conversions have deep entanglement #6210

Closed
thockin opened this issue Mar 31, 2015 · 9 comments
Closed

Defaults and Conversions have deep entanglement #6210

thockin opened this issue Mar 31, 2015 · 9 comments
Labels
area/apiserver priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.

Comments

@thockin
Copy link
Member

thockin commented Mar 31, 2015

Given

type Foo struct {
   Spec FooSpec
}

If you have a custom conversion for Foo and that func does not explicitly call Convert() on FooSpec, then no conversion function will be called on Spec - not too surprising. HOWEVER - it will also bypass the defaulting function of FooSpec. This is a bit more surprising.

Worse - the tests for defaults run with no custom conversion functions loaded, it seems, so even though things pass the test, they don't actually work.

This needs some thought or AT LEAST some good docs.

@vmarmol vmarmol added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. area/apiserver team/master labels Mar 31, 2015
@yujuhong
Copy link
Contributor

Yes, defaulting is tangled with conversions, and there are some caveats unfortunately. One example is that if you convert an object multiple times between different versions, you may end up having an object populated with default values from multiple versions. I am not sure that this is the intended behavior. We could use more clarity on this, and the example you mentioned.

As for the tests, as far as I know, most custom conversion functions convert versioned objects (e.g. pkg/api/v1beta1) to api objects (pkg/api), or vice versa, which is likely the case you were referring to. The defaults_tests.go in each version tests encoding a versioned object and decoding it into an object of the same version again. Nowhere in that path invokes api <-> versioned conversions. What I can do to improve the tests is to Decode the object into an api object, and then convert it back to the versioned object before verifying the default values. What do you think, @thockin?

@thockin
Copy link
Member Author

thockin commented Mar 31, 2015

I'm not sure this is worth a lot of attention right now. I wanted to file
it so we can think about it for a larger revamp of
conversion/validation/defaulting.

On Tue, Mar 31, 2015 at 11:27 AM, Yu-Ju Hong notifications@github.com
wrote:

Yes, defaulting is tangled with conversions, and there are some caveats
unfortunately. One example is that if you convert an object multiple times
between different versions, you may end up having an object populated with
default values from multiple versions. I am not sure that this is the
intended behavior. We could use more clarity on this, and the example you
mentioned.

As for the tests, as far as I know, most custom conversion functions
convert versioned objects (e.g. pkg/api/v1beta1) to api objects (pkg/api),
or vice versa, which is likely the case you were referring to. The
defaults_tests.go in each version tests encoding a versioned object and
decoding it into an object of the same version again. Nowhere in that path
invokes api <-> versioned conversions. What I can do to improve the tests
is to Decode the object into an api object, and then convert it back to
the versioned object before verifying the default values. What do you
think, @thockin https://github.com/thockin?


Reply to this email directly or view it on GitHub
#6210 (comment)
.

@yujuhong
Copy link
Contributor

Agreed that the entanglement should be addressed in a larger revamp, but the tests should still catch most of the unexpected errors until we have time for the revamp. I submitted a PR #6235.

@yujuhong
Copy link
Contributor

Default tests should be able to catch most problems now that the PR has been merged.

@yujuhong yujuhong added priority/backlog Higher priority than priority/awaiting-more-evidence. and removed priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. labels Mar 31, 2015
@dchen1107
Copy link
Member

  • me on latest update on this.

@lavalamp lavalamp added priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. and removed priority/backlog Higher priority than priority/awaiting-more-evidence. labels Mar 31, 2015
@lavalamp
Copy link
Member

Unfortunately, this is probably a post-1.0 item.

@pmorie
Copy link
Member

pmorie commented Apr 28, 2015

Related: #7337, might be able to be closed as a dupe.

@lavalamp
Copy link
Member

Kicking this can down the road.

@smarterclayton
Copy link
Contributor

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apiserver priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.
Projects
None yet
Development

No branches or pull requests

9 participants