Guide for API conversions
Introduction
The purpose of this document is to help/assist contributors with future API conversions using conversion-gen tool.
Prerequisites
- Create a new API version.
kubebuilder create api --group <group> --version <version> --kind <kind>
- Copy over existing types, and make the required changes.
- Mark a storage version, add marker
+kubebuilder:storageversion
to concerned version package.
NOTE: Refer for more detailed information about prerequisites.
Conversion flow
- In each “spoke” version package, add marker
+k8s:conversion-gen
directive pointing to the “hub” version package. It must be indoc.go
. Refer - In “hub” version package, create
doc.go
file without any marker. Refer - In “spoke” version package, add a var
localSchemeBuilder = &SchemeBuilder.SchemeBuilder
ingroupversion_info.go
so the auto-generated code would compile. Refer - In “hub” version package, create a
conversion.go
to implement the “hub” methods. Refer - Run target
make generate-go-conversions-core
, this will generatezz_generated.conversion.go
in the spoke version package. - In “spoke” version package, update
{kind}_conversion.go
to implement Convertible for each type. Whenconversion-gen
stops generating methods because of incompatibilities or we need to override the behavior, we stick them in this source file. Our “spoke” versions need to implement the Convertible interface. Namely, they’ll need ConvertTo and ConvertFrom methods to convert to/from the hub version. Refer