Given an object that wishes to have a top level defaulter, traverse the object looking for nested fields that have defaulters and generate a single function for that type that invokes all defaulters. The function will have the name `SetObjectDefaults_NAME`. Types use `// +k8s:defaulter-gen=true` to indicate they wish a defaulter generated. If a function already exists with the desired name `SetObjectDefaults_NAME` then no generation will occur. At a package level, authors can bulk select the types to generate by setting the value of the comment to the name of a field - all objects with that field name without `// +k8s:defaulter-gen=false` defined on the type will get a defaulter. Because the defaulting behavior from conversions happens recursively, all defaulters are expected to be invoked. We call these defaulters "non-covering" (other defaulters may be invoked beneath them). The defaulters we generate, by comparison, are "covering" - no nested defaulters should be invoked. To distinguish between these two types, we introduce the `// +k8s:defaulter-gen=covers` comment on a defaulter function which will instruct the generator that the function should terminate recursion. This sets the stage for future defaulter generation from comments by subsuming our existing generators
2.4 KiB
2.4 KiB