Skip to content

Conversation

@zamai
Copy link

@zamai zamai commented Oct 8, 2025

Description
Many Kubernetes controllers and integration tests rely on AddToScheme helpers to register CRDs. Adding this function to Karpenter simplifies setup, and aligns with standard Kubernetes API patterns.

This PR adds AddToScheme support for Karpenter API types, enabling them to be registered with a runtime.Scheme. This makes it straightforward for external controllers, tests, and tools to use Karpenter’s types with controller-runtime clients, decoders, and webhooks without manual type registration.

Example how currently I register these types:

      // Manually register Karpenter types since it doesn't export AddToScheme
	karpenterGV := schema.GroupVersion{Group: "karpenter.sh", Version: "v1"}
	metav1.AddToGroupVersion(s, karpenterGV)
	s.AddKnownTypes(karpenterGV,
		&karpenterv1.NodePool{},
		&karpenterv1.NodePoolList{},
		&karpenterv1.NodeClaim{},
		&karpenterv1.NodeClaimList{},
	)

After Fix:

	s := runtime.NewScheme()
        karpenterv1.AddToScheme(s)

How was this change tested?
Manually, and I've generated some tests locally, but I feel that they might be unnecessary in the repo.

Please let me know if adding tests for this variable would a requirement, to merge.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 8, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @zamai!

It looks like this is your first PR to kubernetes-sigs/karpenter 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/karpenter has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 8, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @zamai. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 8, 2025
This commit introduces AddToScheme, registers NodePool, NodePoolList, NodeClaim, and NodeClaimList types within the scheme.

add test files

remove test
@zamai zamai force-pushed the add-AddToScheme-function branch from f1202f5 to dc95072 Compare October 9, 2025 09:19
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 9, 2025
@coveralls
Copy link

coveralls commented Oct 9, 2025

Pull Request Test Coverage Report for Build 19195221923

Details

  • 0 of 10 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 81.651%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/apis/v1/register.go 0 10 0.0%
Totals Coverage Status
Change from base Build 19111740812: -0.04%
Covered Lines: 11583
Relevant Lines: 14186

💛 - Coveralls

@zamai
Copy link
Author

zamai commented Oct 10, 2025

/retest

@k8s-ci-robot
Copy link
Contributor

@zamai: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

AddToScheme = SchemeBuilder.AddToScheme
)

func addKnownTypes(s *runtime.Scheme) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: How do you feel about:

Suggested change
func addKnownTypes(s *runtime.Scheme) error {
func (s *runtime.Scheme) addKnownTypes() {

Copy link
Author

Choose a reason for hiding this comment

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

I feel okay about it, but I used runtime.NewSchemeBuilder which accepts function with this signature:

NewSchemeBuilder(funcs ...func(*Scheme) error) SchemeBuilder 

I was following the same pattern I saw other packages implement, example:
https://github.com/argoproj/argo-rollouts/blob/92f4801475175abc888f7a29fee63fd965e15c14/pkg/apis/rollouts/v1alpha1/register.go#L35

Copy link
Contributor

@DerekFrank DerekFrank left a comment

Choose a reason for hiding this comment

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

Do you have any examples of controllers that follow this type of pattern that could be refactored?

GroupVersion = schema.GroupVersion{Group: apis.Group, Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
Copy link
Contributor

Choose a reason for hiding this comment

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

If i'm not mistaken, this includes several different options for adding known types, as you could call:

v1.SchemeBuilder.Build()

as well. Is this intentional?

Copy link
Author

Choose a reason for hiding this comment

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

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: moko-poi, zamai
Once this PR has been reviewed and has the lgtm label, please assign maciekpytel for approval. For more information see the Code Review Process.

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

Needs approval from an approver in each of these files:

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

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants