-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Kubebuilder APIs should import minimal dependencies #4467
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hi @JoelSpeed, What you’re asking about seems to have already been addressed to ensure projects built with
The changes you’re advocating for—a separation of API definitions from webhook and conversion logic—have already been implemented. With the updates in
This approach eliminates the need for downstream projects to import You can confirm these updates by reviewing the three samples under Additionally, the tutorial samples in the documentation provide practical examples of the current scaffold: Given these changes, I believe we can consider this issue resolved as of the 4.3.0 release. However, if I’ve misunderstood or overlooked any aspect of your concern, please let me know! |
I am closing this one since it seems done already. |
@camilamacedo86 No, I don't think this is necessarily fixed, looking at the latest kubebuilder v4, API v2 testdata package If I just import one of the types from that package, the go.mod still relies on controller-runtime, which I think makes the issue still a risk. The conversion elements don't seem to have been moved out of the API packages yet?
|
Discussing with @camilamacedo86 offline, the only two imports from controller-runtime now are Kubebuilder based APIs will continue to rely on these two packages, but, unless controller-runtime introduces a change to either of these interfaces, this should not cause the import and go.mod contention issue described in my original issue. |
Hi @JoelSpeed, We discussed this further, and you made a good point: the Looking at the code, it is still invoked at the following points:
These interfaces haven’t changed for years, but as you mentioned, they could still be modified. Since One potential solution could be to use the API machinery scheme instead of For now, I agree that the issue isn’t fully resolved. While it’s unlikely to occur often, having no dependency at all may not be achievable. A reasonable approach might be to see if That said, if you feel this issue should be re-opened, please feel free to do so. I’m not entirely sure how we could resolve this 100%, but I’m happy to collaborate further. Best regards, |
Found this bug to leave exactly this comment (per discussion with controller-runtime folks)
The dependency on apimachinery is more or less impossible to avoid: it's pulled in by TypeMeta and ObjectMeta in any API resource. In the discussion above, someone suggested me to adapt what CAPI is doing, and it worked well for us. Maybe Kubebuilder can follow it as well? I haven't looked into conversion yet. I wonder if the controller-runtime folks will change how it works similarly to how they treated webhooks (move from API closer to controllers). |
What do you want to happen?
Kubebuilder commonly provides a "standard" layout for controllers and API types across many Kubernetes related projects.
In particular, one of things that Kubebuilder does is generate basic patterns like, containing conversion code or validation webhook code within within the API package.
If you look at repositories like kuberntes/api, you will notice that these packages do not contain additional code. They are clean and only include the types themselves.
Importing an API from k/api, typically results in bringing in the API types itself, and the metav1 package from apimachinery, and dependencies of this.
Importing an API from a kubebuilder based project, typically involves also importing controller-runtime, either for conversion, or for webhook validation code.
By importing controller-runtime within the API packages of projects, this makes consuming APIs from the kubebuilder based projects difficult. Any project that relies on another projects API types, and wants to vendor those, now has to choose a compatible version of controller-runtime based on their upstream projects choice, and not on their own cadence.
Since controller-runtime is fast moving, and things change frequently, this can cause lots of toil, where a project might want to update an API it depends on to make use of a new field, but then has to fix lots of other controller-runtime related issues while doing so.
In the past I've seen projects that rely on multiple different APIs, from multiple kubebuilder based projects, and they could not update as not all of their dependencies had updated to the latest controller-runtime, they were blocked on older versions until their final dependency was updated.
It would be preferable if Kubebuilder could start promotion a pattern of creating conversion code and webhook code in other packages, and keeping the imports for kubebuilder based projects to a minimum, to make it easier and cleaner to consume APIs from other projects, and remove the tie between APIs and specific controller runtime versions.
We went through and made similar changes in the Cluster API community in 2023, but we really should try and promote this wider IMO.
Extra Labels
No response
The text was updated successfully, but these errors were encountered: