Skip to content

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

Merged
merged 6 commits into from
Jan 7, 2021

Conversation

metacosm
Copy link
Collaborator

@metacosm metacosm commented Jan 4, 2021

Fixes #279

@metacosm metacosm self-assigned this Jan 4, 2021
@@ -6,6 +6,23 @@

public interface ResourceController<R extends CustomResource> {

static String getDefaultNameFor(ResourceController controller) {
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

@s-soroosh s-soroosh Jan 4, 2021

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@metacosm
Copy link
Collaborator Author

metacosm commented Jan 4, 2021

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 application.yml files as dotted names are interpreted as composite paths instead of simple names. This is why the tests are currently failing with this new version of the code that tries to unify names.

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 getSimpleName) only when there's a conflict so I'd actually be in favor of reverting that change. What do you think @adam-sandor?

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.
@s-soroosh
Copy link
Contributor

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 application.yml files as dotted names are interpreted as composite paths instead of simple names. This is why the tests are currently failing with this new version of the code that tries to unify names.

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 getSimpleName) only when there's a conflict so I'd actually be in favor of reverting that change. What do you think @adam-sandor?

if the key has dots, then you just need to wrap the key with brackets, e.g:

controllers:
  '[io.javaoperatorsdk.operator.springboot.starter.testcontroller]':
    retry:
      maxAttempts: 3
      initialInterval: 1000
      intervalMultiplier: 1.5
      maxInterval: 50000
      maxElapsedTime: 100000

@metacosm
Copy link
Collaborator Author

metacosm commented Jan 5, 2021

Sure but can we expect most people to know that? Personally, I'd rather add a name to my ResourceController annotation than have to remember the syntax and have the risk of a typo in the potentially long package name.

@s-soroosh
Copy link
Contributor

Sure but can we expect most people to know that? Personally, I'd rather add a name to my ResourceController annotation than have to remember the syntax and have the risk of a typo in the potentially long package name.

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 @Controller.name

@metacosm
Copy link
Collaborator Author

metacosm commented Jan 5, 2021

Sure but can we expect most people to know that? Personally, I'd rather add a name to my ResourceController annotation than have to remember the syntax and have the risk of a typo in the potentially long package name.

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 @Controller.name

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?

@s-soroosh
Copy link
Contributor

Sure but can we expect most people to know that? Personally, I'd rather add a name to my ResourceController annotation than have to remember the syntax and have the risk of a typo in the potentially long package name.

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 @Controller.name

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.
it sounds more like concurrency issues, they don't happen so often but we don't really want even those few times it happens, so we need a way to prevent them and at the same time having a predictable behaviour for the user.

@metacosm
Copy link
Collaborator Author

metacosm commented Jan 5, 2021

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.
it sounds more like concurrency issues, they don't happen so often but we don't really want even those few times it happens, so we need a way to prevent them and at the same time having a predictable behaviour for the user.

Yes but I think that the fix should be to tell people to annotate their controller with name in that case, instead of making the default behavior more complex, and, of course, document this… 😄

@s-soroosh
Copy link
Contributor

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.
it sounds more like concurrency issues, they don't happen so often but we don't really want even those few times it happens, so we need a way to prevent them and at the same time having a predictable behaviour for the user.

Yes but I think that the fix should be to tell people to annotate their controller with name in that case, instead of making the default behavior more complex, and, of course, document this… 😄

If we raise compiletime/runtime error in such cases, then it makes sense

@metacosm
Copy link
Collaborator Author

metacosm commented Jan 5, 2021

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?

@adam-sandor
Copy link
Collaborator

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.
@metacosm metacosm force-pushed the controller-name-fix branch from 71f4fe1 to 85475e3 Compare January 5, 2021 17:29
@metacosm metacosm force-pushed the controller-name-fix branch from 85475e3 to cc819e1 Compare January 5, 2021 17:31
@metacosm
Copy link
Collaborator Author

metacosm commented Jan 6, 2021

Ready to merge.

@adam-sandor
Copy link
Collaborator

LGTM

@adam-sandor adam-sandor merged commit 9e5cb13 into master Jan 7, 2021
@metacosm metacosm deleted the controller-name-fix branch January 7, 2021 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change in default controller naming scheme breaks Quarkus extension
3 participants