-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
⚠️ Validate controller names are unique #2902
Conversation
/lgtm |
LGTM label has been added. Git tree hash: 88bba7827300bc12364a32520eea18dc109de046
|
/hold |
Otherwise lgtm from my side |
When re-using the same name among multiple controllers, they will report to the same metrics and use the same logger. This can be very confusing, might not be obvious and can happen accidentally. Validate controller names are unique at runtime to avoid all of this.
/hold cancel |
Thx! /lgtm |
LGTM label has been added. Git tree hash: 4f7a6ac50b301922450983aa632b2baaebf1a055
|
[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
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
FWIW, this seems to trigger an error in our AFAUI, the manager gets closed
but the next test returns an error added here.
|
I think it's not a race condition. The problem is that the check is a singleton, but it has to be because the queue metrics are also singletons. What you can do today is to use different controller names for each test run. Just discussed this with @alvaroaleman, we would add an option to controller & manager (the controller option defaults to the one on the manager) to skip the name check.
I assume this would help in your case? |
@mythi @alvaroaleman PR: #2918 |
thanks! I'll give it a try on Tue. |
* Bump `k8s.io/*` deps to v0.31.1 - Bump `k8s.io/*` deps to v0.31.1 - Bump `controller-tools` to v0.16.3 * enable controller SkipNameValidation in test ref kubernetes-sigs/controller-runtime#2902 (comment) * Bump `k8s.io/*` deps to v0.31.1 - Bump `k8s.io/*` deps to v0.31.1 - Bump `controller-tools` to v0.16.3 * Use 1.31 testenv cluster * Make probe agent backoff timeout configurable --------- Co-authored-by: Dmitri Fedotov <[email protected]>
Previous to the version v0.19.0 of controller-runtime it was possible to have the same name for every controller, but in the new version this is not allow anymore by the following PR kubernetes-sigs/controller-runtime#2902 Now we have a specific name for every controller and this may improve the logging process. Closes #5640 Signed-off-by: Jonathan Gonzalez V. <[email protected]>
Previous to the version v0.19.0 of controller-runtime it was possible to have the same name for every controller, but in the new version this is not allow anymore by the following PR kubernetes-sigs/controller-runtime#2902 Now we have a specific name for every controller and this may improve the logging process. Closes #5640 Signed-off-by: Jonathan Gonzalez V. <[email protected]>
Controller-runtime v0.19.0 errors when a controller manager detects multiple controllers with the same name; this is done to improve the clarity of the log messages. This patch adds a name for every controller in the operator, complying with this rule. For more information, see kubernetes-sigs/controller-runtime#2902 Closes #5640 Signed-off-by: Jonathan Gonzalez V. <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]>
Controller-runtime v0.19.0 errors when a controller manager detects multiple controllers with the same name; this is done to improve the clarity of the log messages. This patch adds a name for every controller in the operator, complying with this rule. For more information, see kubernetes-sigs/controller-runtime#2902 Closes #5640 Signed-off-by: Jonathan Gonzalez V. <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit 6e28aa8)
Controller-runtime v0.19.0 errors when a controller manager detects multiple controllers with the same name; this is done to improve the clarity of the log messages. This patch adds a name for every controller in the operator, complying with this rule. For more information, see kubernetes-sigs/controller-runtime#2902 Closes #5640 Signed-off-by: Jonathan Gonzalez V. <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit 6e28aa8)
Controller-runtime v0.19.0 errors when a controller manager detects multiple controllers with the same name; this is done to improve the clarity of the log messages. This patch adds a name for every controller in the operator, complying with this rule. For more information, see kubernetes-sigs/controller-runtime#2902 Closes #5640 Signed-off-by: Jonathan Gonzalez V. <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit 6e28aa8)
As of controller-runtime 0.19.0, it validates that controller names should be unique[1]. In controller tests, we instantiate a controller multiple times, therefore, the validation fails. To avoid it, disable it. [1]: kubernetes-sigs/controller-runtime#2902 Signed-off-by: Toshikuni Fukaya <[email protected]>
As of controller-runtime 0.19.0, it validates that controller names should be unique[1]. In controller tests, we instantiate a controller multiple times, therefore, the validation fails. To avoid it, disable it. [1]: kubernetes-sigs/controller-runtime#2902 Signed-off-by: Toshikuni Fukaya <[email protected]>
) | ||
|
||
var nameLock sync.Mutex | ||
var usedNames sets.Set[string] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @alvaroaleman @sbueringer
Holding controller name with a global variable seems not a good idea, because the variable will be shared between tests in a test suite or in a test package.
To be more specific, see following the test sample below:
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mgr, err := controllerruntime.NewManager(&rest.Config{}, controllerruntime.Options{})
controller := &FooController{}
err = controller.SetupWithManager(mgr)
assert.NoError(t, err) // raise error: Controller names must be unique to avoid multiple controllers reporting to the same metric
// ... others
})
}
Even though each test creates a brand new controller manager, but the usedNamed
is shared unexpected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My two cents:
The used controller names should be stored in a specific manager instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RainbowMango my tests have the following: ctrl.NewManager(cfg, ctrl.Options{Scheme: scheme.Scheme, Metrics: metricsserver.Options{BindAddress: "0"}, Controller: config.Controller{SkipNameValidation: &yes}})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thanks. @mythi
It's not a blocker for me.
I noticed the option as well, but I think it's more like a workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mythi @RainbowMango my 2 cents there as well
I did raise the same question at this issue and I really like the idea of storing controller names within one manager maybe? Or at least provide some mechanism of cleaning this map instead of disabling the check completely
When re-using the same name among multiple controllers, they will report to the same metrics and use the same logger. This can be very confusing, might not be obvious and can happen accidentally.
Validate controller names are unique at runtime to avoid all of this.