• Kubernetes Submit Queue's avatar
    Merge pull request #33352 from smarterclayton/unified_defaulters · 2ea4e1f0
    Kubernetes Submit Queue authored
    Automatic merge from submit-queue
    
    Split conversion and defaulting
    
    Separate conversion and defaulting.   Defaulting occurs mixed with conversion today - change the server so that the `VersioningCodec` performs defaulting on the external type during decoding.  
    
    * Add a new method to `Scheme` - `func (*runtime.Scheme) Default(runtime.Object)` - that takes an object and performs defaulting.  
    * Call `Default` during decoding and at static initialization time
    * Use the new `defaulter-gen` to generate top level object defaulters (`v1.Pod`) at build time for any type that needs to perform defaulting.  
    * Add tests and alter the existing code to adapt as necessary
    * Fix a few bugs in conversions that depended on defaulting behavior
    
    ---
    
    Step 1 of decoupling conversion and defaulting. The generator will assist in creating top level defaulters that in a single method invoke all nested defaulters, preventing the need to recurse via reflection or conversion. These top level defaulters will be registered in the scheme and invoked instead of the nested recursion path. This will set the stage for a future generator, capable of creating defaulters from embedded struct tags on external types. However, we must gradually switch these over.
    
    The immediate goal here is to split defaulting and conversion so that the unsafe convertor can be used to maximum potential (we would be able to use direct memory conversion for any identical nested struct, even those that must be defaulted).
    
    The generator uses `k8s:defaulter-gen=TypeMeta` on most public packages to flag any top level type that has defaulters to get a `SetObjectDefaults_NAME` function created (types that don't have defaulters won't have functions).  This also creates a `RegisterDefaults` method that applies a default to an interface{} and returns true if the object was handled.  Existing defaults are left as is.
    
    Add a test to verify old and new path generate the same outcomes.  Defaulter will move to gengo before this is merged, and subsequent PRs will remove defaulting during conversion and have the VersioningCodec apply defaults.
    2ea4e1f0
Name
Last commit
Last update
..
annotations Loading commit data...
endpoints Loading commit data...
errors Loading commit data...
events Loading commit data...
install Loading commit data...
meta Loading commit data...
pod Loading commit data...
resource Loading commit data...
rest Loading commit data...
service Loading commit data...
testapi Loading commit data...
testing Loading commit data...
unversioned Loading commit data...
util Loading commit data...
v1 Loading commit data...
validation Loading commit data...
OWNERS Loading commit data...
context.go Loading commit data...
context_test.go Loading commit data...
conversion.go Loading commit data...
conversion_test.go Loading commit data...
copy_test.go Loading commit data...
deep_copy_test.go Loading commit data...
defaulting_test.go Loading commit data...
defaults.go Loading commit data...
doc.go Loading commit data...
field_constants.go Loading commit data...
generate.go Loading commit data...
generate_test.go Loading commit data...
helpers.go Loading commit data...
helpers_test.go Loading commit data...
mapper.go Loading commit data...
meta.go Loading commit data...
meta_test.go Loading commit data...
node_example.json Loading commit data...
ref.go Loading commit data...
ref_test.go Loading commit data...
register.go Loading commit data...
replication_controller_example.json Loading commit data...
requestcontext.go Loading commit data...
resource_helpers.go Loading commit data...
resource_helpers_test.go Loading commit data...
serialization_proto_test.go Loading commit data...
serialization_test.go Loading commit data...
types.generated.go Loading commit data...
types.go Loading commit data...
zz_generated.deepcopy.go Loading commit data...