-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
What steps did you take and what happened?
Create a simple program, as below and run go mod tidy
:
package main
import (
"fmt"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
func main() {
myCluster := &capiv1beta1.Cluster{}
fmt.Printf("My Cluster: %+v\n", myCluster)
}
This results in a go.mod with 56 dependencies. Included in this list is controller-runtime
which, is also imported by a lot of consumers of the API types. controller-runtime
has evolved a lot over time and, because it is being imported by the APIs currently, means that any project consuming the API types must also import the same controller-runtime as the rest of CAPI.
There are use cases where, building a consumer, I do not need to use any of the code (defaulting, validation etc) from CAPI and as such, do not need such a restriction on my controller-runtime
version.
If we modify the way the SchemeBuilder
works and move the webhooks to a separate package, then we can reduce the required imports for the API package down to just 31 dependencies, and, these dependencies do not include controller-runtime
or other fast moving/changing packages. There are still obviously a good number of deps in there from K8s paths, but these are mostly API machinery related and have pretty stable APIs.
I think if we can separate the webhooks out in this way (I notice Cluster and ClusterClass already are?) then I think this would make consuming these API types in other projects a lot easier.
Note how k8s.io/api
does not include much code with the API types for this reason as well.
The alternative solution for consumers is to copy/paste the types out to their own repos which is less ideal.
What did you expect to happen?
API types should not be tied to many dependencies, especially not controller-runtime.
Cluster API version
main branch
Kubernetes version
N/A
Anything else you would like to add?
No response
Label(s) to be applied
/kind bug
One or more /area label. See https://github.com/kubernetes-sigs/cluster-api/labels?q=area for the list of labels.
TODO
- Update schemebuilder in
./api
(🌱 Remove reliance on controller-runtime scheme builder #9045) - Update schemebuilder in
./controlplane/kubeadm/api
(🌱 Remove reliance on controller-runtime scheme builder for remaining API groups #9266) - Update schemebuilder in
./bootstrap/kubeadm/api
(🌱 Remove reliance on controller-runtime scheme builder for remaining API groups #9266) - Update schemebuilder in
./exp/api
(🌱 Remove reliance on controller-runtime scheme builder for experimental APIs #9185) - Update schemebuilder in
./exp/addons/api
(🌱 Remove reliance on controller-runtime scheme builder for experimental APIs #9185) - Update schemebuilder in
./exp/ipam/api
(🌱 Remove reliance on controller-runtime scheme builder for experimental APIs #9185) - Update schemebuilder in
./exp/runtime/api
(🌱 Remove reliance on controller-runtime scheme builder for experimental APIs #9185) - Update schemebuilder in
./cmd/clusterctl/api
(🌱 Remove reliance on controller-runtime scheme builder for remaining API groups #9266) - Update schemebuilder in
./test/infrastructure/docker/api
(🌱 Remove reliance on controller-runtime scheme builder for remaining API groups #9266) - Update schemebuilder in
./test/infrastructure/docker/exp/api
(🌱 Remove reliance on controller-runtime scheme builder for remaining API groups #9266) - Update schemebuilder in
./test/infrastructure/inmemory/api
(🌱 Remove reliance on controller-runtime scheme builder for remaining API groups #9266) - Move webhooks for
./api
(🌱 Move API v1beta1 webhooks to a separate package #9047) - Move webhooks for
./controlplane/kubeadm/api
(🌱 Move Kubeadm API v1beta1 webhooks to separate package #9410) - Move webhooks for
./bootstrap/kubeadm/api
(🌱 Move Kubeadm API v1beta1 webhooks to separate package #9410) - Move webhooks for
./exp/api
(🌱 Move experimental API v1beta1 webhooks to separate package #9417) - Move webhooks for
./exp/addons/api
(🌱 Move experimental addons API v1beta1 webhooks to separate package #9438) [ ] Move webhooks for(N/A)./exp/ipam/api
[ ] Move webhooks for(N/A)./exp/runtime/api
[ ] Move webhooks for(N/A)./cmd/clusterctl/api
- Move webhooks for
./test/infrastructure/docker/api
(🌱 Move docker infrastructure API v1beta1 webhooks to separate package #9458) - Move webhooks for
./test/infrastructure/docker/exp/api
(🌱 Move docker infrastructure experimental API v1beta1 webhooks to separate package #9460) - Move webhooks for
./test/infrastructure/inmemory/api
(🌱 Move inmemory infrastructure API v1beta1 webhooks to separate package #9459) - Add verification to avoid regressions (e.g. 🌱 Remove the dependency on cluster-api/utils from addons API #9482 (comment))
- Ensure docs for provider implementation explain schemebuilder conventions
- Ensure docs for provider implementation explain separate webhooks conventions
- Add import-boss to prevent regressions
-
./api
🌱 Add verify-import-restrictions to enforce import restrictions #9407 - enforce the restrictions in all packages (as soon as we can) (@Ankitasw) 🌱 Enforce import restrictions in all API packages #9461
-