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
Removing generated ResourceHandlers #3327
Conversation
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.
I like where this is going.
This will reduce the size of the client.
If we manage to completely eliminate the use of velocity transformations we will further reduce the number of transitives too.
The tricky part seemed to be the handling of custom impls, which you seem to handle already with the static block.
+1
@@ -132,6 +127,21 @@ | |||
* It is thread safe. | |||
*/ | |||
public abstract class BaseKubernetesClient<C extends Client> extends BaseClient implements GenericKubernetesClient<C> { | |||
|
|||
static { | |||
Handlers.register(Pod.class, PodOperationsImpl::new); |
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.
Perhaps the Handlers
class could be generated during the build process so that we don't need to manually register new ones?
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.
There are a couple of approaches to be weighed:
- something generated - but that will need the some templating mechanism, which we should otherwise be able to remove
- just a reflective association by convention similar to List and Builder classes - bit it seemed more involved to determine the package name, so I didn't take that approach yet. There is some validation logic in my next commit thought that could easily determine if an OperationsImpl is not being picked up by the Handler system that would be applicable here.
- more logic around the initialization - this is what I've started to added in the next commit. If the *ExtensionAdapter class uses references the *Client then that can trigger the static block to register the handlers. Alternatively that registration logic could be moved onto the *ExtensionAdapter (which is probably a better option than the former).
This next commit rationalizes the SharedInformerFactory logic and updates the ServiceCatalog client to the new approach. The DefaultSharedIndexInformerTest.testCustomResourceInformerWithDifferentVersions is not working yet because the direct usage of the OperationContext means that I'll need to add logic to override the ResourceDefinitionContext. |
Can one of the admins verify this patch? |
I've combined the last two commits and updated things mentioned in the last couple of comments to where this now compiles and runs through the kubernetes-tests |
2fd9243
to
201487d
Compare
@rohanKanojia @manusa this now should be pretty representative of these changes - it should build without error not withstanding the latest unsuccessful run. With this only the SharedInformerFactory.sharedIndexInformerFor(Class apiTypeClass, long resyncPeriodInMillis) is not deprecated. |
I haven't deeply reviewed it, but I really like what's going on. |
Same here, though I see several Todos in different spots… Are these expected to be addressed in subsequent PRs or is this PR still a work in progress? |
@metacosm @manusa I've resolved the TODOs that seem important for now. The ones that remain are a reminder about KubernetesDeserializer type registration and a reminder to remove some of the remaining overlap between the SharedInformerFactory and BaseOperation wrt creating informers. I can change those comments if needed. |
- deprecated methods dealing with CustomResources, and added resources methods where appropriate. This means that nearly every method on sharedinformerfactory is now deprecated - replaced CustomResourceDefinitionContext with ResourceDefinitionContext in the api where appropriate - what were generated handlers are now obtained through Handlers methods - passing the type/listType to the base HasMetadataOperation to validate that the operation is registered - moved OperationImpl registration onto the ExtensionAdapters
Took a pass through to rebase and cleanup the import changes.
There's nothing special about the CustomResource base class after these changes, so methods dealing with CustomResources have been deprecated, and similar methods involving "resources" were added. This means that nearly every method on sharedinformerfactory is now deprecated
Does that seem like a good classname?
|
@manusa I'm afraid that keeping this up-to-date will become a full-time job. If possible let's come up with a plan for inclusion to minimize conflicts. |
cr_refinement # Conflicts: # kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseKubernetesClient.java # kubernetes-client/src/main/java/io/fabric8/kubernetes/client/V1AdmissionRegistrationAPIGroupClient.java # kubernetes-client/src/main/java/io/fabric8/kubernetes/client/V1beta1AdmissionRegistrationAPIGroupClient.java
...talog/client/src/main/java/io/fabric8/servicecatalog/client/DefaultServiceCatalogClient.java
Show resolved
Hide resolved
} | ||
|
||
@Override | ||
public NonNamespaceOperation<ClusterTask, ClusterTaskList, Resource<ClusterTask>> clusterTasks() { | ||
return new ClusterTaskOperationsImpl(this.getHttpClient(), this.getConfiguration()); | ||
return Handlers.getOperation(ClusterTask.class, ClusterTaskList.class, this.getHttpClient(), this.getConfiguration()); |
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.
I'm confused now. I assumed this was possible until I saw the code in the linked comment. Now I don't get why in those lines we can follow the same procedure.
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.
You could. ClusterServiceBrokerOperationsImpl will be registered so you can get it through Handlers. However I was attempting to create the minimal changes at first, which would just be to remove the usage of the generated ones.
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.
Captured as #3357
...nt/src/main/java/io/fabric8/kubernetes/client/dsl/internal/KubernetesListOperationsImpl.java
Outdated
Show resolved
Hide resolved
...t/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/ServiceOperationsImpl.java
Show resolved
Hide resolved
Initial tests look positive though, surprisingly, for the same app, the native binary size is larger now than it previously was… For comparison, the same code went from 122 MB with 5.4.1 to 138MB with 5.6 to 140MB with 5.7-SNAPSHOT and this PR, which is quite surprising to me. :( |
It is surprising but indicates that the native compilation is very efficient. So the takeaway is that the jar sizes should go down, but the native doesn't really change. |
SonarCloud Quality Gate failed. |
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.
Description
Before I go too far down this path, I wanted to solicit some feedback. The initial changes to just refine the usage of CustomResource (the first two commits - which had not yet rationalized the SharedInformerFactory) made me want to see what things would look like without any generated ResourceHandlers. This pr has that work mostly completed for the kubernetes/openshift client modules - there are more validations and tests that should be added, but the kubernetes-tests run cleanly.
The idea is to replace the generated classes with ResourceHandlerImpl and ResourceOperationsImpl (which is also used by the resources/customResources dsl entry points). This means that any HasMetadata that is properly annotated can be used as a Resource - whether it's custom, built-in, or from a different client version provided HasMetadata and the annotations are compatible. Some of the SharedInformerFactory logic could be re-targeted to this as well.
The downsides to this approach:
Not really related to these changes it appears that OpenShiftNamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl is not being used.
I'm also thinking it would be good to have more guardrails on KubernetesDeserializer.registerCustomKind given its static nature.
Type of change
test, version modification, documentation, etc.)
Checklist