Proposal: Shift to a library-first architecture for v5 #5277
Replies: 4 comments
-
|
I think the ideas are good. We should improve the API.
|
Beta Was this translation helpful? Give feedback.
-
@camilamacedo86 It seems that the The cmd and hack/docs/utils packages seem to be safe to move to an internal, as they apparently have not been imported by any other project (yet). That being said, I believe the safest path would be to treat all of them as breaking changes and deprecate them before any removal. We could add a |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for putting this together. I agree the library UX and public API could be better (docs, discoverability, clearer what is public). But I’d be very careful about starting a v5 just for cleanup or small improvements. Every major bump adds friction (breaking changes, slower upgrades, and some users staying behind). In the past, v2 → v3 → v4 was mostly forced by upstream/Kubernetes changes. Today v4 feels mature and stable, so honestly I hope we don’t need v5 in the next 2–3 years. My suggestion:
So: +1 to improvements, but v5 only when it really matters (or we’re forced), not for minor cleanup. |
Beta Was this translation helpful? Give feedback.
-
|
Agreed! I'll start working on non-breaking changes that could improve DX and we can discuss them individually in the PRs. I'll also create some issues to keep track of the breaking changes. Thanks for taking the time to analyze this proposal and for your feedback! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I get that Kubebuilder is first and foremost a CLI app and it has notably helped thousands of developers succesfully build their operators throughout the years.
BUT, it is also noticeable that Kubebuilder has seen very little adoption as a library. I can only think of the Operator-SDK as its biggest consumer.
One of the reasons, I think, is that the Kubebuilder API could be better documented as a library. The Kubebuilder Book is an excellent resource for end-users, but lacks the documentation for developers who want to use Kubebuilder as a library.
Talking about the structure, the deeply nested packages results in a not-so-nice developer experience. For example, the yaml package is nested inside pkg/config/store/yaml, so the user needs to import
sigs.k8s.io/kubebuilder/v4/pkg/config/store/yaml, which is bit java-esque.Also, I believe some identifiers were leaked into the public API and very little documentation has been provided for them. For example, the
yamlpackage I just mentioned, which has already been imported by three other projects, as per what pkg.go.dev shows, has a lacking documentation. Some other packages, like the cmd, docs/utils and e2e/utils should not have been exposed in the API, I believe. If they are indeed meant for external usage, their documentation clearly needs improvements.Talking about the docs, of all the thirty packages exposed in
pkg/, only two (cli and go/v4/scaffolds) have a more detailed documentation.Another reason for its low usage as a library is that Kubebuilder is not very discoverable in the most important directory for go packages and modules, pkg.go.dev. And when you do find it on pkg.go.dev, it is shown primarily as a command, not a package.
So, my proposal is:
Why not shift into a library-first architecture for v5? We could cleanup the API, deprecate identifiers that leaked, and improve the developer experience.
We could adopt the "Facade Pattern" and expose a new
kubebuilderpackage to seal the API contract in a single package, similar to what controller-runtime already does, keep all the implementation in internal packages, and keep the CLI app intocmd/kubebuilder/,as it would be the most idiomatic place for the command, as a consumer of the Kubebuilder library.We could move to the following structure:
Or we could be more extreme and put the deprecated API into an internal:
This would help keep the API concise into one package,
kubebuilder, improving maintenance and developer experience. Users of the library then would only have to importsigs.k8s.io/kubebuilderin their packages.As a nice bonus, we would have a better idea of how many projects are actually using Kubebuilder as a library by looking at pkg.go.dev "Imported by" stats.
Would Kubebuilder still be "go-installable"?
Yes, but in a more verbose path. Currently, users type
go install sigs.k8s.io/kubebuilder/v4to install the CLI. If we shift to library first structure, users will have to typego install sigs.k8s.io/kubebuilder/v4/cmd/kubebuilder, which is a bit verbose, but still possible. With that in mind, I have to note that the current documentation doesn't recommend or even mention thego installmethod for installing Kubebuilder. The other installation methods would still work just as fine.Anyway, thanks for reading through this and I look forward to hearing your opinions on this.
3 votes ·
Beta Was this translation helpful? Give feedback.
All reactions