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

using jandex for kubernetesdeserializer #4024

Closed
wants to merge 1 commit into from

Conversation

shawkins
Copy link
Contributor

@shawkins shawkins commented Mar 30, 2022

Description

Addresses #3923

The classes will be discovered by the jandex index rather than by package.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@shawkins
Copy link
Contributor Author

shawkins commented Apr 4, 2022

My guess at ways forward here are:

  • at some place in the osgi feature make the models explicit requirements
  • leave in a serviceloader based mechanism, such that class discovery delegated to that service's classloader.

@iocanel
Copy link
Member

iocanel commented Apr 4, 2022

Caused by: org.apache.felix.resolver.reason.ReasonException: Unable to resolve io.fabric8.kubernetes-model-core/6.0.0.SNAPSHOT: missing requirement [io.fabric8.kubernetes-model-core/6.0.0.SNAPSHOT] osgi.wiring.package; filter:="(&(osgi.wiring.package=org.jboss.jandex)(version>=2.4.0)(!(version>=3.0.0)))"

It seems that kubernetes-model-core requires org.jboss.jandex. If jandex is needed at runtime then you just need to added to the feature. If not the kubernetes-mode-core should not import it (maybe add it to the ignore list).

TBH, I am not a big fan of introducing jandex as a runtime dependency. So, if this is the case I think we might want to reconsider.

@shawkins
Copy link
Contributor Author

shawkins commented Apr 4, 2022

TBH, I am not a big fan of introducing jandex as a runtime dependency. So, if this is the case I think we might want to reconsider.

This is something that we talked about in the last call. It makes sense to use jandex as the indexes are already being built. Requiring the manual creation of a class that registers all of the type classes is not desirable.

@shawkins
Copy link
Contributor Author

shawkins commented Apr 4, 2022

It seems that kubernetes-model-core requires org.jboss.jandex

Right I had assumed that was taken care of automatically. The next issue is that we are including the jandex files in the bundles at META-INF/jandex.idx - however that is only for use within the bundle and there doesn't seem to be a simple way to export that.

@iocanel
Copy link
Member

iocanel commented Apr 5, 2022

TBH, I am not a big fan of introducing jandex as a runtime dependency. So, if this is the case I think we might want to reconsider.

This is something that we talked about in the last call. It makes sense to use jandex as the indexes are already being built. Requiring the manual creation of a class that registers all of the type classes is not desirable.

Why not use the SPI ?

@shawkins
Copy link
Contributor Author

shawkins commented Apr 5, 2022

Separated the resolving changes into #4039 - once that is committed we'll revisit this for the usage of jandex.

@shawkins shawkins changed the title making apiVersion and kind strict for resolution using jandex for kubernetesdeserializer Apr 7, 2022
@sonarcloud
Copy link

sonarcloud bot commented Apr 27, 2022

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

81.0% 81.0% Coverage
0.0% 0.0% Duplication

@shawkins
Copy link
Contributor Author

@iocanel @manusa here's what it looks like now:

  1. the KubernetesDeserializer and the thread context classloader will be scanned for jandex.index files, any that are found will be processed - this is sufficient in any flat classloading environment to find everything. However in OSGI we'll see only the index for the kuberentes-model-core.

  2. For OSGI to handle extensions we service load KubernetesMappingResourceProvider off of those same classloaders to obtain the respective classloader for the module to look for the jandex index, and to call the KubernetesMappingResourceProvider method to directly supply classes (not currently used).

  3. For OSGI to find classes in built-in modules, like kubernetes-model-apps, there is a list of classes (not packages) in the KubernetesDeserializer to serve as a way to get the classloader for a given module so that we can find the jandex index. This revision is kind of an in-between solution. Obviously you could take these changes further to introduce a KubernetesMappingResourceProvider into each built-in module - it was just faster for me to get things into this state.

What else is out there:

  • xxx.properties, which is created by manifest.vm. These files seem to match closely to what was in the extension KubernetesMappingResourceProviders. This has the same problem as looking for resource files in general with OSGI - it at least would need to be moved to a package, instead of the root (although I haven't seen that work - even with a valid package exported, I don't see the resources). It would also need a consistent name, instead of the module specific one it currently has. And it is missing types - it does not contain list types (which could be worked around pretty easily by convention) and just a cursory scan there's other things missing as well. For example Binding, Status, and *Options are not listed in core.properties, but all are resolvable via the jandex logic or the legacy logic that matched kind to class name - not that I can think of scenario where wouldn't have wanted to parse DeleteOptions. For those not using the model generator it is harder to use than building a jandex index.

  • kube-shema.json - already included in the bundles for projects built by a generator. Looks to be smaller than the jandex index and can be parsed with just jackson. However even when I export the schema package from a module, this still doesn't seem to be visible to the KubernetesDeserializer class loaders from getResources("schema/kube-schema.json"). For those not using the model generator this is a non-starter.

  • KubeSchema.java - omitted from the bundles. If it were present at a consistent location we could use reflection to infer all top level types.

Copy link
Member

@iocanel iocanel left a comment

Choose a reason for hiding this comment

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

Is there any way to remove the jandex dependency from runtime?

@shawkins
Copy link
Contributor Author

Is there any way to remove the jandex dependency from runtime?

@iocanel unfortunately there is not as we need to read the index to find the classes.

@shawkins
Copy link
Contributor Author

closing in favor of #4511

@shawkins shawkins closed this Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants