Skip to content

✨ feat: scope controller name validation to manager instance #3241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jingyih
Copy link

@jingyih jingyih commented Jun 24, 2025

This PR refactors controller name validation to be scoped to each controller manager instance, rather than being enforced globally across the entire process.

Global uniqueness could cause conflicts in test suites where multiple managers are created and destroyed. Since the global list of names is not reset, tests can fail unexpectedly when they try to reuse a controller name in a new manager instance. Related issues:

The new implementation aligns controller name validation with the lifecycle of the manager, which IMO is the correct architectural approach.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jingyih
Once this PR has been reviewed and has the lgtm label, please assign joelanford 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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 24, 2025
@k8s-ci-robot k8s-ci-robot requested review from inteon and JoelSpeed June 24, 2025 03:39
@k8s-ci-robot
Copy link
Contributor

Welcome @jingyih!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. 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/controller-runtime 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
Copy link
Contributor

Hi @jingyih. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 24, 2025
@jingyih jingyih changed the title feat: scope controller name validation to manager instance ✨ feat: scope controller name validation to manager instance Jun 24, 2025
}

if cm.usedControllerNames.Has(name) {
return fmt.Errorf("controller with name %s already exists in this manager. Controller names must be unique within the same controller manager to avoid multiple controllers reporting the same metric. This validation can be disabled via the SkipNameValidation option", name)
Copy link
Contributor

Choose a reason for hiding this comment

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

When you have multiple managers, how do the metrics look? Is there a specific metric label that identifies the manager?

Copy link
Member

Choose a reason for hiding this comment

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

No, there is nothing. The metrics are global and not scoped to the manager, which is why the check is as it is

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback. You've highlighted an important issue regarding metric collisions. I can see that the metrics are global and not scoped to individual manager instances, which is why the original check existed.

The main goal of this PR is to improve the developer experience for the common case of running a single manager per process. The current global validation sometimes require developers to use SkipNameValidation when the test recreating managers, which can mask naming conflicts until runtime. By scoping validation to the manager, these errors can be caught early during testing.

I am aware that this change introduces challenges for the less common scenario of running multiple managers in a single process. In order to improve dev experience for single controller manger use case, this PR requires dev to manually avoid naming conflict when working with multiple controller managers. I see two possible solutions to address this:

  • Use separate Prometheus registries for each manager
  • Add a manager-specific metric label

I'm open to suggestions and looking forward to your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend to disable the name validation in tests

@sbueringer
Copy link
Member

/hold

See: #3241 (comment)

@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 Jun 25, 2025
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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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.

4 participants