Description
This issue was filed based on this discussion in the #kubebuilder channel from Kubernetes Slack.
👋 I encountered an oddity with controller-gen where I have two types, Fu
, from two packages, ./v1alpha2/subdir
and ./v1alpha3/subdir
, and the signature controller-gen expects for both of the functions is: Convert_subdir_Fu_To_subdir_Fu
. Obviously two functions cannot share the same name in the same package, so this is an issue.
I have tried looking through the GitHub issues, and the closest I can find is #94 (hi @ncdc!), but that only applies to other types that are of type runtime.Object
and are conversion hubs. In my case, Fu
is a data structure shared by different packages in each schema version. For example, ./api/v1alpha2
and ./api/v1alpha2/hello
might both import ./api/v1alpha2/subdir
.
I have experimented with several different approaches, including defining the Convert functions for the parent type that includes Fu
, but I would still receive compileOnError warnings in the generated output about the expected function. The only solution I found is the following:
|-- v1alpha2
|-- conversion
|-- v1alpha2
| |-- fu_conversion.go
|-- v1alpha3
|-- fu_conversion.go
In ./v1alpha2/conversion/v1alpha2/fu_conversion.go
I have one Convert_subdir_Fu_To_subdir_Fu
, and I have the same signature in the other file, with the arg types reversed. With the above, I add the two directories to the --input-dirs
param, and it works.
Is the above solution really the only option?
cc @bryanv