Skip to content
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

feat: use Editable when possible instead of reflection to infer builder #5756

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

Conversation

metacosm
Copy link
Collaborator

  • feat: use Editable when possible instead of reflection to infer builder

@metacosm metacosm self-assigned this Feb 16, 2024
@shawkins
Copy link
Contributor

shawkins commented Feb 16, 2024

I think the only reason this was not done initially is that there's no guarentee that custom resources implement Editable. If a user still wants client logic that interacts with visitors, they will need to make it Editable.

There is also BaseFluent.builderOf that falls back to reflection as well (we could be calling that method here).

Copy link

sonarcloud bot commented Feb 16, 2024

@manusa
Copy link
Member

manusa commented Feb 16, 2024

I think the only reason this was not done initially is that there's no guarentee that custom resources implement Editable. If a user still wants client logic that interacts with visitors, they will need to make it Editable.

For this case maybe we can rely on a fallback?
I can't recall if users had to do additional setup to register the custom resource types for reflection. If that was the case, then this would be compliant with the current behavior, since those builders should need registering too.

@metacosm
Copy link
Collaborator Author

I think the only reason this was not done initially is that there's no guarentee that custom resources implement Editable. If a user still wants client logic that interacts with visitors, they will need to make it Editable.

Indeed, and I think that's a fair assumption to make. The current implementation attempts to locate a builder via reflection even if it doesn't exist, making users explicitly implement Editable will make them create the associated Builder if they want their custom resources to be editable.

There is also BaseFluent.builderOf that falls back to reflection as well (we could be calling that method here).

Yes, but the goal is to remove reflection altogether here.

@metacosm
Copy link
Collaborator Author

I think the only reason this was not done initially is that there's no guarentee that custom resources implement Editable. If a user still wants client logic that interacts with visitors, they will need to make it Editable.

For this case maybe we can rely on a fallback? I can't recall if users had to do additional setup to register the custom resource types for reflection. If that was the case, then this would be compliant with the current behavior, since those builders should need registering too.

Historically, QOSDK was taking care of registering Custom resources associated types for reflection, now the kubernetes client extension does it in a more complete way (though this is currently only in 3.8.0.CR1, iirc).

As far as fallback, I don't really see the point, to be honest, apart from potential backwards compatibility (but that would be in user-provided code since resources provided by the client should already be implemented to support Editable). Either resources have an associated builder and in this case it's trivial to implement Editable or they don't and no fallback will solve the issue. On the other hand, any fallback implementation would require reflection, which we're trying to remove.

For that matter, we might want to consider a Listable interface to provide a way to instantiate the associated list type without requiring reflection as well.

@shawkins
Copy link
Contributor

shawkins commented Feb 16, 2024 via email

@shawkins
Copy link
Contributor

To add more on this the sundio basefluent.builderOf method did not change significantly from the past - it was always using reflection. The change I'm think of was to have the fluent.builder methods call basefluent.builderOf.

So we may not want to change builderOf, and instead introduce a new method that just checks for editable, which would be used by both the fluent builder methods and by the fabric8 client.

@andreaTP
Copy link
Member

Probably, we need to solve #5878 along with this.

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.

4 participants