-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Migrate API defaulting to a centralized location #3854
Conversation
@bgrant0607 Brian, you were pretty active in the referenced #1502 discussion -- do you have time to review? |
@thockin, this PR will need a rebase to fix all recently modified tests once it is reviewed. |
@alex-mohr Sorry, I had a massive backlog yesterday. I'll look at this today. @smarterclayton May also want a look. |
if util.AllPtrFieldsNil(obj) { | ||
obj.Always = &RestartPolicyAlways{} | ||
} | ||
}, |
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.
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.
These comments apply to all the versioned instances of defaults.go.
Good changes in general. |
// func(in *v1beta1.Pod) { | ||
// // defaulting logic... | ||
// }) | ||
func (c *Converter) RegisterDefaultingFunc(defaultingFunc interface{}) error { |
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.
We need a test explicitly for the new defaulting code. The existing tests were implicitly relying on the ad hoc default approaches that were previously used. Now they're not.
) | ||
|
||
func init() { | ||
Scheme.AddDefaultingFuncs( |
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.
In the spirit of #3914, we shouldn't be adding any defaulting functions here. Let's just eliminate this file.
Overall I am good with this. I do dislike the need to sprinkle default values around the test codebase - if we got rid of the internal defaulting logic, do es that need go away? |
@thockin With this change, validation depends on defaults being set. As we discussed, the "right" thing to do would be to create all of these test objects by decoding versioned objects. As a convenience and optimization, we could create a library of creators of simple objects for common scenarios -- internally we call these "test fixtures". That would be a pretty big change, though. I don't think we should block this PR on it. |
Agree no need to block on the constructors - this is strictly an improvement. |
Currently, the validation logic validates fields in an object and supply default values wherever applies. This change factors out defaulting to a set of defaulting callback functions for decoding (see kubernetes#1502 for more discussion). * This change is based on pull request 2587. * Most defaulting has been migrated to defaults.go where the defaulting functions are added. * validation_test.go and converter_test.go have been adapted to not testing the default values. * Fixed all tests with that create invalid objects with the absence of defaulting logic.
Addressed the comments in the new patch.
This PR has grown bigger and bigger every time I had to rebase. Hopefully we can get it in before another major rebase is required... |
Thanks! LGTM. I'm happy to start with this, then improve it. Did you run e2e? |
I am concerned about yet another deep-something comparator, but we can revisit after we lock this in :) |
@thockin , I understand the concern, and we should definitely iterate on that later. My guess is that many tests are actually redundant, as they test the same logic repeatedly. A major cleanup might make these tests more manageable, and the comparator may no longer required(?). |
One of the test suite in e2e failed:
|
the x509 error is the bane of my job. Nuke your cluster and start over. On Tue, Feb 3, 2015 at 4:40 PM, Yu-Ju Hong notifications@github.com wrote:
|
e2e finally passed. The PR should be ready to merge. |
Great! Re-running travis. |
Travis passed. Shippable is 2 hours behind as usual. Merging. |
Migrate API defaulting to a centralized location
This PR is based on #2587 to fix issue #1502. Most API defaulting in validation.go and conversion.go have been migrated to defaults.go, where the defaulting functions are added to the decoder. The defaulting functions are tied to the specific API version, and will be called during decoding.