Skip to content

feat: configure resource class and name for controller #1781

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
Feb 28, 2023

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Feb 23, 2023

this is mostly needed so we are able to nicely upgrade the spring boot starter to 4.2.x of JOSDK

@csviri csviri self-assigned this Feb 23, 2023
@csviri csviri requested a review from metacosm February 23, 2023 09:58
@csviri
Copy link
Collaborator Author

csviri commented Feb 23, 2023

}

public ControllerConfigurationOverrider<R> withResourceClass(Class<R> resourceClass) {
this.resourceClass = resourceClass;
Copy link
Collaborator

@metacosm metacosm Feb 23, 2023

Choose a reason for hiding this comment

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

It feels weird to override a given controller configuration with a different resource type so I'm not sure about this one…

Copy link
Collaborator Author

@csviri csviri Feb 23, 2023

Choose a reason for hiding this comment

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

I think it was added there if there is some hierarchy or something in reconciler, and cannot be detected as we do now. in that terms it makes sense to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem is that it opens the door for improper usage so I'd rather see this support moved somewhere outside of the overrider. The goal of the overrider is to change the configuration provided by the annotations at runtime, not to create a new configuration from scratch. As such, since the resource type is mandated by the parameter type of the Reconciler implementation, it shouldn't be possible to override it at runtime so the more I think about it, the more against this change I am.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, that is right. The problem is it's not possible to specify it by @ControllerConfiguration. Shall we put it rather there?
Would be a better solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That would be a huge change and a redundant information with the Reconciler implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, I fail to see how things would work if you were to override the resource type and end up with something that doesn't match your Reconciler implementation… If people want to have a hierarchy, the resource type parameter should be propagated along it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

kk, let's remove this option

Copy link
Collaborator Author

@csviri csviri Feb 27, 2023

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically there is no other way to configure this through our public API, just maybe hacking it with some custom config service, what is problematic. So I think we should allow this to be configured and document it, that this is just for framework support.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Basically there is no other way to configure this through our public API, just maybe hacking it with some custom config service, what is problematic. So I think we should allow this to be configured and document it, that this is just for framework support.

That is not true: the current way to do it is to provide your own ControllerConfiguration implementation (or extend the existing ConfigurationService implementations) but I do agree that we could make things easier.

@csviri csviri force-pushed the override-class-controller branch from e7affe1 to fa57cd7 Compare February 27, 2023 09:18
@csviri csviri requested a review from metacosm February 27, 2023 09:18
@metacosm
Copy link
Collaborator

metacosm commented Feb 27, 2023

Note that this is technically a breaking API change.

return (Class<P>) Utils.getFirstTypeArgumentFromSuperClassOrInterface(getClass(),
ControllerConfiguration.class);
}
Class<P> getResourceClass();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should keep a default implementation to avoid breaking the API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, yes, althoug not really the API, it's the implementation. But we should remove it in the future, to make it more explicit that this is not used

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is ok to do ti for next? (I mean a separate PR, wdyt?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, this method should stay as it's needed by some implementations, Quarkus in particular. And it is breaking the API because implementations that were relying on the provided default implementation won't compile anymore with this change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted and commented it for now, but I guess we can adjust also quarkus in the future if it will be removed.

For now fine to have it there IMO.

This PR should be ready now, also the adjusted spring boot part.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that this will change in Quarkus because the resource class is resolved at build time and is therefore fixed then, not resolved at runtime, which is why we need this method to stay as-is.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

65.2% 65.2% Coverage
0.0% 0.0% Duplication

@csviri csviri merged commit a67ba0b into main Feb 28, 2023
@csviri csviri deleted the override-class-controller branch February 28, 2023 09:53
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.

2 participants