-
Notifications
You must be signed in to change notification settings - Fork 220
fix: clean up controller default name generation #282
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
Conversation
@@ -6,6 +6,23 @@ | |||
|
|||
public interface ResourceController<R extends CustomResource> { | |||
|
|||
static String getDefaultNameFor(ResourceController controller) { |
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.
Wonder why these methods are needed to be here. Let's keep the interfaces as clean and relevant as possible!
I still believe the getName also should be pulled out from this interface, I think it's been missed in the main PR wrt quarkus extension.
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.
We don't need to put these methods there, it just that it made sense to me to move them here since they pertain to ResourceControllers
instead of adding them to a util class that's less discoverable.
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.
@psycho-ir why do you think the getName
method should be pulled? It's needed to be able to configure controllers individually.
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.
It let the user set the controller name in 2 different ways, @Controller.name & overriding the getName
method and that's what we should strive to avoid.
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.
Ah yes, didn't think of that but I assume that someone would need to know what they're doing if they override the default getName
method… since we provide a default implementation. And if they provide their own implementation, then I guess that's the one that would be used and the annotation would be ignored anyway. I don't think that's something that would be an issue in practice.
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.
Well, API design is mainly about the things we let users do and the reason behind them.
The getName method has been implemented for internal use and is effectively final (no reason to be overridden by the client).
Having that in the interface as the method will lead to other questions like why finalizerName
, crdName
, generationAwareEventProcessing
and so on don't have getter method in interface accordingly if there is a getter method with default implementation why @controller annotation is getting the name
field too? and several similar questions.
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.
The name is not internal: to be able to configure a controller, you need to be able to identify it. That's the name's purpose. While there are no obvious reasons that I can think of to override the default naming scheme, some people might still want to provide their own way to name a controller independently of what we provide (because for example, they're not using annotations and don't want to incur that impact at runtime). As such, it makes sense (at least to me) that it lives on the ResourceController
interface.
The other methods, on the other hand, are part of the controller's configuration, which, again, you can't retrieve without first knowing the name of the controller. These values are not part of what is essential to the controller.
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.
In comment, I was talking about the getName and not name, ofc name is not an internal thing, thus the user can set it via @Controller.name.
getName for sure can be added later on (it's backward compatible change) to the interface if it's been decided to get controller essential configuration from anywhere other than the controller annotation, AFAIK it's not currently the case and annotation + its crdName property is required.
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.
Fixed.
The change to use the fully-qualified name of the controller implementations is actually problematic and only works currently because of the fact that names are not being used consistently in all places. In particular, using FQNs doesn't work in This means that if we want to be able to configure a controller via a properties file, you need to add a name to the controller which doesn't seem like a good default behavior to me. It seems like it would make more sense to require changing the default name as it was previously generated (i.e. using |
The new naming algorithm makes it impossible to use the default name for to identify a controller in application.yaml files because FQNs are interpreted as composite paths instead of single names. This makes things more cumbersome, imo.
if the key has dots, then you just need to wrap the key with brackets, e.g:
|
Sure but can we expect most people to know that? Personally, I'd rather add a name to my |
we need examples to illustrate how the controller can be configured via config files anyway, if one prefer to have shorter name for controller for sure it can be overridden with |
Right but my point is that the default behavior should be as simple as possible. Right now, with this change, I feel we're making the default case more complex than it needs to be: how often will people have several controllers with the exact same simple name in their operators? |
I can't really say how often that can happen. however, it's already happening in the tests the SDK itself has. |
Yes but I think that the fix should be to tell people to annotate their controller with |
If we raise compiletime/runtime error in such cases, then it makes sense |
I agree completely and I was planning on looking at implementing something to that effect. Just wanted to make sure we were on the same page regarding the default behavior first. What do you think @adam-sandor @csviri? |
I would be happy to keep the simple name if that's possible to implement |
This allows to have consistent handling of duplicated controller names.
71f4fe1
to
85475e3
Compare
85475e3
to
cc819e1
Compare
Ready to merge. |
LGTM |
Fixes #279