Skip to content

🌱 Deprecate the scheme builder#3461

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
alvaroaleman:deprecate-scheme
Mar 11, 2026
Merged

🌱 Deprecate the scheme builder#3461
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
alvaroaleman:deprecate-scheme

Conversation

@alvaroaleman

Copy link
Copy Markdown
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
Comment thread 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@sbueringer sbueringer Mar 5, 2026

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: e675826794effe86010581339f6382e8bcf9a074

Comment thread pkg/scheme/scheme.go Outdated
Comment thread 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
Copy Markdown
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

Comment thread examples/crd/pkg/groupversion_info.go
@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

@sbueringer sbueringer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Last nit

Comment thread pkg/scheme/scheme.go
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 3ebffa234fe07f7a11cfd93cdabcff21067c5ee7

@k8s-ci-robot

Copy link
Copy Markdown
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

@sbueringer

Copy link
Copy Markdown
Member

I think we're fine, let's move on

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 11, 2026
@k8s-ci-robot k8s-ci-robot merged commit 37c380b into kubernetes-sigs:main Mar 11, 2026
8 of 9 checks passed
mnencia pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request May 6, 2026
Bump k8s.io/* to v0.36.0. That version preserves API compatibility,
which keeps the migration small
(kubernetes/kubernetes#137298).

controller-runtime v0.24.0 deprecated its SchemeBuilder in favor of the
apimachinery one
(kubernetes-sigs/controller-runtime#3461), so
api/v1 is migrated accordingly.

The Go directive moves to 1.26.0 because controller-runtime v0.24.0
requires it. The k8s.io/streaming migration is test-only. The
regenerated Pooler CRD picks up the upstream PodSpec rename workloadRef
-> schedulingGroup; both shapes are alpha and have no user-visible
impact.

Closes #10592

Signed-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>
cnpg-bot pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request May 6, 2026
Bump k8s.io/* to v0.36.0. That version preserves API compatibility,
which keeps the migration small
(kubernetes/kubernetes#137298).

controller-runtime v0.24.0 deprecated its SchemeBuilder in favor of the
apimachinery one
(kubernetes-sigs/controller-runtime#3461), so
api/v1 is migrated accordingly.

The Go directive moves to 1.26.0 because controller-runtime v0.24.0
requires it. The k8s.io/streaming migration is test-only. The
regenerated Pooler CRD picks up the upstream PodSpec rename workloadRef
-> schedulingGroup; both shapes are alpha and have no user-visible
impact.

Closes #10592

Signed-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>
(cherry picked from commit 490938f)
cnpg-bot pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request May 6, 2026
Bump k8s.io/* to v0.36.0. That version preserves API compatibility,
which keeps the migration small
(kubernetes/kubernetes#137298).

controller-runtime v0.24.0 deprecated its SchemeBuilder in favor of the
apimachinery one
(kubernetes-sigs/controller-runtime#3461), so
api/v1 is migrated accordingly.

The Go directive moves to 1.26.0 because controller-runtime v0.24.0
requires it. The k8s.io/streaming migration is test-only. The
regenerated Pooler CRD picks up the upstream PodSpec rename workloadRef
-> schedulingGroup; both shapes are alpha and have no user-visible
impact.

Closes #10592

Signed-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>
(cherry picked from commit 490938f)
mnencia pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request May 6, 2026
Bump k8s.io/* to v0.36.0. That version preserves API compatibility,
which keeps the migration small
(kubernetes/kubernetes#137298).

controller-runtime v0.24.0 deprecated its SchemeBuilder in favor of the
apimachinery one
(kubernetes-sigs/controller-runtime#3461), so
api/v1 is migrated accordingly.

The Go directive moves to 1.26.0 because controller-runtime v0.24.0
requires it. The k8s.io/streaming migration is test-only. The
regenerated Pooler CRD picks up the upstream PodSpec rename workloadRef
-> schedulingGroup; both shapes are alpha and have no user-visible
impact.

Closes #10592

Signed-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>
(cherry picked from commit 490938f)
cnpg-bot pushed a commit to cloudnative-pg/artifacts that referenced this pull request May 7, 2026
…36.0. That version preserves API compatibility,%0Awhich keeps the migration small%0A(kubernetes/kubernetes#137298 v0.24.0 deprecated its SchemeBuilder in favor of the%0Aapimachinery one%0A(kubernetes-sigs/controller-runtime#3461), so%0Aapi/v1 is migrated accordingly.%0A%0AThe Go directive moves to 1.26.0 because controller-runtime v0.24.0%0Arequires it. The k8s.io/streaming migration is test-only. The%0Aregenerated Pooler CRD picks up the upstream PodSpec rename workloadRef%0A-> schedulingGroup; both shapes are alpha and have no user-visible%0Aimpact.%0A%0ACloses #10592%0A%0ASigned-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>

cloudnative-pg/cloudnative-pg@refs/heads/main
cnpg-bot pushed a commit to cloudnative-pg/artifacts that referenced this pull request May 7, 2026
…36.0. That version preserves API compatibility,%0Awhich keeps the migration small%0A(kubernetes/kubernetes#137298 v0.24.0 deprecated its SchemeBuilder in favor of the%0Aapimachinery one%0A(kubernetes-sigs/controller-runtime#3461), so%0Aapi/v1 is migrated accordingly.%0A%0AThe Go directive moves to 1.26.0 because controller-runtime v0.24.0%0Arequires it. The k8s.io/streaming migration is test-only. The%0Aregenerated Pooler CRD picks up the upstream PodSpec rename workloadRef%0A-> schedulingGroup; both shapes are alpha and have no user-visible%0Aimpact.%0A%0ACloses #10592%0A%0ASigned-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>%0A(cherry picked from commit 490938f9fd7cf688f643eab1098ea36ea1b6e149)

cloudnative-pg/cloudnative-pg@refs/heads/release-1.29
cnpg-bot pushed a commit to cloudnative-pg/artifacts that referenced this pull request May 7, 2026
…36.0. That version preserves API compatibility,%0Awhich keeps the migration small%0A(kubernetes/kubernetes#137298 v0.24.0 deprecated its SchemeBuilder in favor of the%0Aapimachinery one%0A(kubernetes-sigs/controller-runtime#3461), so%0Aapi/v1 is migrated accordingly.%0A%0AThe Go directive moves to 1.26.0 because controller-runtime v0.24.0%0Arequires it. The k8s.io/streaming migration is test-only. The%0Aregenerated Pooler CRD picks up the upstream PodSpec rename workloadRef%0A-> schedulingGroup; both shapes are alpha and have no user-visible%0Aimpact.%0A%0ACloses #10592%0A%0ASigned-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>%0A(cherry picked from commit 490938f9fd7cf688f643eab1098ea36ea1b6e149)

cloudnative-pg/cloudnative-pg@refs/heads/release-1.28
cnpg-bot pushed a commit to cloudnative-pg/artifacts that referenced this pull request May 7, 2026
…36.0. That version preserves API compatibility,%0Awhich keeps the migration small%0A(kubernetes/kubernetes#137298 v0.24.0 deprecated its SchemeBuilder in favor of the%0Aapimachinery one%0A(kubernetes-sigs/controller-runtime#3461), so%0Aapi/v1 is migrated accordingly.%0A%0AThe Go directive moves to 1.26.0 because controller-runtime v0.24.0%0Arequires it. The k8s.io/streaming migration is test-only. The%0Aregenerated Pooler CRD picks up the upstream PodSpec rename workloadRef%0A-> schedulingGroup; both shapes are alpha and have no user-visible%0Aimpact.%0A%0ACloses #10592%0A%0ASigned-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>%0A(cherry picked from commit 490938f9fd7cf688f643eab1098ea36ea1b6e149)

cloudnative-pg/cloudnative-pg@refs/heads/release-1.25
samsimpson1 pushed a commit to alphagov/govuk-job-request-operator that referenced this pull request Jun 3, 2026
Description:
- Dependabot PRs are failing because the latest version of `controller-runtime` has deprecated `scheme.Builder` (https://github.com/alphagov/govuk-job-request-operator/actions/runs/26217422184/job/77143291873?pr=6)
```
Error: api/v1/groupversion_info.go:36:19: SA1019: scheme.Builder is deprecated: This helper is only useful in api packages, but api packages should be easy to import and hence have minimal dependencies. Typically, these dependencies include only the standard library, k8s.io/apimachinery and other api packages. (staticcheck)
```
- kubernetes-sigs/controller-runtime#3461 was used to make the changes
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. 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