Skip to content

Commit ef33126

Browse files
authored
Merge pull request kubernetes#92897 from MikeSpreitzer/fix92895
Fix description of conversion generator
2 parents 89fdf5e + ced8d95 commit ef33126

File tree

1 file changed

+26
-14
lines changed
  • staging/src/k8s.io/code-generator/cmd/conversion-gen

1 file changed

+26
-14
lines changed

staging/src/k8s.io/code-generator/cmd/conversion-gen/main.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,33 @@ limitations under the License.
3030
// ones named
3131
// autoConvert_<pkg1>_<type>_To_<pkg2>_<type>
3232
// for each such pair of types --- both with (pkg1,pkg2) =
33-
// (internal,external) and (pkg1,pkg2) = (external,internal).
34-
// Additionally: if the destination package does not contain one in a
35-
// non-generated file then a function named
33+
// (internal,external) and (pkg1,pkg2) = (external,internal). The
34+
// generated conversion functions recurse on the structure of the data
35+
// types. For structs, source and destination fields are matched up
36+
// according to name; if a source field has no corresponding
37+
// destination or there is a fundamental mismatch in the type of the
38+
// field then the generated autoConvert_... function has just a
39+
// warning comment about that field. The generated conversion
40+
// functions use standard value assignment wherever possible. For
41+
// compound types, the generated conversion functions call the
42+
// `Convert...` functions for the subsidiary types.
43+
//
44+
// For each pair of types `conversion-gen` will also generate a
45+
// function named
3646
// Convert_<pkg1>_<type>_To_<pkg2>_<type>
37-
// is also generated and it simply calls the `autoConvert...`
38-
// function. The generated conversion functions use standard value
39-
// assignment wherever possible. For compound types, the generated
40-
// conversion functions call the `Convert...` functions for the
41-
// subsidiary types. Thus developers can override the behavior for
42-
// selected types. For a top-level object type (i.e., the type of an
43-
// object that will be input to an apiserver), for such an override to
44-
// be used by the apiserver the developer-maintained conversion
45-
// functions must also be registered by invoking the
46-
// `AddConversionFunc`/`AddGeneratedConversionFunc` method of the
47-
// relevant `Scheme` object from k8s.io/apimachinery/pkg/runtime.
47+
// if both of two conditions are met: (1) the destination package does
48+
// not contain a function of that name in a non-generated file and (2)
49+
// the generation of the corresponding autoConvert_... function did
50+
// not run into trouble with a missing or fundamentally differently
51+
// typed field. A generated Convert_... function simply calls the
52+
// corresponding `autoConvert...` function. `conversion_gen` also
53+
// generates a function that updates a given `runtime.Scheme` by
54+
// registering all the Convert_... functions found and generated.
55+
// Thus developers can override the generated behavior for selected
56+
// type pairs by putting the desired Convert_... functions in
57+
// non-generated files. Further, developers are practically required
58+
// to override the generated behavior when there are missing or
59+
// fundamentally differently typed fields.
4860
//
4961
// `conversion-gen` will scan its `--input-dirs`, looking at the
5062
// package defined in each of those directories for comment tags that

0 commit comments

Comments
 (0)