diff options
| author | Wojciech Tyczynski <wojtekt@google.com> | 2015-05-13 14:36:59 +0200 |
|---|---|---|
| committer | Wojciech Tyczynski <wojtekt@google.com> | 2015-05-13 14:43:48 +0200 |
| commit | c92c7a5d8201e1bb2b74af77f0c3980d6b8c750b (patch) | |
| tree | 0c8f017aa6838710980ad7c101a25677d3f37b16 | |
| parent | 8b6e9102beb4fc7914000c10e0b0ef99b5245fbf (diff) | |
Instructions for generating conversions.
| -rw-r--r-- | api_changes.md | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/api_changes.md b/api_changes.md index f46d2d4e..8b0a0e56 100644 --- a/api_changes.md +++ b/api_changes.md @@ -227,18 +227,32 @@ Thus, we are auto-generating conversion functions that are much more efficient than the generic ones (which are based on reflections and thus are highly inefficient). -The conversion code resides with each versioned API - -`pkg/api/<version>/conversion.go`. To regenerate conversion functions: +The conversion code resides with each versioned API. There are two files: + - `pkg/api/<version>/conversion.go` containing manually written conversion + functions + - `pkg/api/<version>/conversion_generated.go` containing auto-generated + conversion functions + +Since auto-generated conversion functions are using manually written ones, +those manually written should be named with a defined convention, i.e. a function +converting type X in pkg a to type Y in pkg b, should be named: +`convert_a_X_To_b_Y`. + +Also note that you can (and for efficiency reasons should) use auto-generated +conversion functions when writing your conversion functions. + +Once all the necessary manually written conversions are added, you need to +regenerate auto-generated ones. To regenerate them: - run ``` $ go run cmd/kube-conversion/conversion.go -v <version> -f <file1.txt> -n <file2.txt> ``` - - replace all conversion functions (convert\* functions) in the above file - with the contents of \<file1.txt\> - - replace arguments of `newer.Scheme.AddGeneratedConversionFuncs` - with the contents of \<file2.txt\> + - replace all conversion functions (convert\* functions) in the + `pkg/api/<version>/conversion_generated.go` with the contents of \<file1.txt\> + - replace arguments of `newer.Scheme.AddGeneratedConversionFuncs` in the + `pkg/api/<version>/conversion_generated.go` with the contents of \<file2.txt\> -Unsurprisingly, this also requires you to add tests to +Unsurprisingly, adding manually written conversion also requires you to add tests to `pkg/api/<version>/conversion_test.go`. ## Update the fuzzer |
