Skip to content

🌱 Deprecate the scheme builder#3461

Open
alvaroaleman wants to merge 1 commit intokubernetes-sigs:mainfrom
alvaroaleman:deprecate-scheme
Open

🌱 Deprecate the scheme builder#3461
alvaroaleman wants to merge 1 commit intokubernetes-sigs:mainfrom
alvaroaleman:deprecate-scheme

Conversation

@alvaroaleman
Copy link
Member

Controller-Runtime should never be imported into api packages and the scheme builder is only useful in those, so deprecate it.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 25, 2026
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 25, 2026
alias.go Outdated
// SchemeBuilder builds a new Scheme for mapping go types to Kubernetes GroupVersionKinds.
type SchemeBuilder = scheme.Builder
//
// Deprecated: Controller-Runtime should not be imported in api packages and this
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also word this stronger and mention that api packages should not import anything other than other api packages and apimachinery

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me. Or we phrase it more generically and write that folks should be extremely careful with any dependency they add to their API (packages).

E.g. having dependencies on corev1.ObjectReference is an extremely bad idea. Similarly embeddeding any external API types into an API needs careful consideration as it couples APIs (somewhat fine with k/k v1 APIs, but even then there are non-trivial trade-offs in my opinion like inheriting all changes that are made to these APIs elsewhere)

@JoelSpeed Do you have some input for how we should phrase this?
I think this is deprecation warning is a good place to share some guidance. I wouldn't go into too much detail but some high-level points could be good here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we phrase it more generically and write that folks should be extremely careful with any dependency they add to their API (packages).

This sounds like a good way to frame it

I would target this message to APIs should import minimal dependencies. Maybe something along the lines of:

// API Packages should import minimal dependencies, typically including only k8s.io/apimachinery sub-packages and standard library packages.
// Importing additional packages affects consumers of your API and adds complexity to their dependency management.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworded it mostly based on Joels suggestion with the addition that importing other API packages is also fine, let me know what you think

Copy link
Member

@sbueringer sbueringer Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way you phrased it sounds good to me.

I had my share of problems with importing API packages in API packages so now I'm extremely careful with those.

Problems there can be:

  • Importing types that don't actually fit the use case, example metav1.ObjectReference (that one even has a godoc comment that it should not be used)
  • Inheriting changes of the imported types including schema changes
  • Making it necessary to cut a new apiVersion because the referenced apiVersion was bumped to avoid breaking changes (e.g. if a v1beta1 type is embedded into another API and then that type is bumped to v1beta2)

So at that point I only consider it safe to embed external API types if:

  • the lifecycles align (e.g. some k/k v1 type or something that is bumped in lock step with the API the type is embedded in)
  • the use case perfectly fits (that means the fields, godoc and schema validation perfectly fits any one of those might diverge already or might diverge over time)

All that being said, I'm fine with the current wording. We don't have to be too detailed here :) (just sharing some context)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that comment really just tries to explain what is okay to have as a dependency. If it actually makes sense to depend on other apis is yet another question that IMHO we shouldn't try to answer here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an API review perspective, we only generally allow importing other API packages if you are "passing through" the data. E.g. you have a type with an embedded pod spec and you then just copy that directly onto another type

Stefan's write up is detailed enough that I don't need to add anymore, but I am fine with the current wording

@troy0820
Copy link
Member

/lgtm

I know this isn't the removal yet, but we may want to allow @camilamacedo86 to be aware of the changes if they wish to get in front of this with kubebuilder.

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 25, 2026
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 25, 2026
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

DetailsGit tree hash: e675826794effe86010581339f6382e8bcf9a074

alias.go Outdated
// SchemeBuilder builds a new Scheme for mapping go types to Kubernetes GroupVersionKinds.
type SchemeBuilder = scheme.Builder
//
// Deprecated: Controller-Runtime should not be imported in api packages and this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me. Or we phrase it more generically and write that folks should be extremely careful with any dependency they add to their API (packages).

E.g. having dependencies on corev1.ObjectReference is an extremely bad idea. Similarly embeddeding any external API types into an API needs careful consideration as it couples APIs (somewhat fine with k/k v1 APIs, but even then there are non-trivial trade-offs in my opinion like inheriting all changes that are made to these APIs elsewhere)

@JoelSpeed Do you have some input for how we should phrase this?
I think this is deprecation warning is a good place to share some guidance. I wouldn't go into too much detail but some high-level points could be good here

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 3, 2026
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 4, 2026
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last nit

Controller-Runtime should never be imported into api packages and the
scheme builder is only useful in those, so deprecate it.
@k8s-ci-robot
Copy link
Contributor

@alvaroaleman: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-runtime-apidiff 5257194 link false /test pull-controller-runtime-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@sbueringer
Copy link
Member

Thx!

/lgtm
/approve

Keeping the hold so @JoelSpeed can take another look

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 5, 2026
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

DetailsGit tree hash: 3ebffa234fe07f7a11cfd93cdabcff21067c5ee7

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, sbueringer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [alvaroaleman,sbueringer]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants