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

add support for Spring Framework 6 AOT engine #2402

Closed
wants to merge 4 commits into from

Conversation

joshlong
Copy link
Contributor

@joshlong joshlong commented Oct 1, 2022

Hi

Please find a proof-of-concept introduction of AOT support in Spring Boot 3, per #2398 .

I've tested the proposed changes and they work with both Spring Boot 3 and Spring Boot 2.

Spring Boot 3 is not yet GA, however. So, i've had to add snapshot and milestone repositories. Obviously, this won't do in a library like the Kubernetes Java client which needs to be releasable all the time. I'm not sure how you want to handle this. Maybe we create a separate module that doesn't get released and that has the appropriate repositories? Maybe we just stash this PR until November 24th, when Spring Boot 3 is due to go GA? (maybe a little later than that, who knows...)

Also, for my contribution to work, I need to add a dependency on an external library called Reflections. This is used to capture all the code-generated types for CRDs, for example, in the Kubernetes API and in the user's auto-configured packages in a Spring Boot application. This library is only used at compile time, and only when the user is using Spring Boot 3 AOT compilation. that's not the default. I don't know how to handle that, either. I suppose you could make the package optional and then make sure that the interested developer who wnats to use AOT processing gets a warning or something when they try it without that class on the classpath? I don't like that approach very much. It'd be nice if the library was just there and it worked for anybody who wants to build an AOT/ GraalVM native image, out-of-the-box.

Is there a Maven scope i don't know about that limits the lifetime of the binary explicitly to the time the AOT engine runs?

I tried this new support out on a sample Kubernetes CRD+Controller demo and it works just fine, better than what I was able to do before with Spring Native, actually. From ac consumer's perspective, I didn't have to do anything to make code from the Kubernetes Java client do its magic. I was able to delete code, even.

thanks for your time and consideration

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 1, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: joshlong / name: Josh Long (6f54d63)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Oct 1, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @joshlong!

It looks like this is your first PR to kubernetes-client/java 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/java has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: joshlong
Once this PR has been reviewed and has the lgtm label, please assign brendandburns for approval by writing /assign @brendandburns in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 1, 2022
pom.xml Outdated
@@ -482,49 +487,49 @@
<include>src/test/groovy/**/*.groovy</include>
</includes>

<importOrder> <!-- or a custom ordering -->
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove these whitespace changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i believe this has now been addressed.

pom.xml Outdated
@@ -482,49 +487,49 @@
<include>src/test/groovy/**/*.groovy</include>
</includes>

<importOrder> <!-- or a custom ordering -->
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove these whitespace changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i believe this has now been addressed.

return (generationContext, beanFactoryInitializationCode) -> {
RuntimeHints hints = generationContext.getRuntimeHints();
String[] classNames = new String[]{
"com.google.gson.JsonElement",//
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why there are empty comments after each of these lines?

@brendandburns
Copy link
Contributor

I took a look at the code changes and other than the whitespace changes which need to be reverted, this looks fine to me.

I will let @yue9944882 take a look at the Spring side and comment on how we want to sequence this into the released client.

@joshlong
Copy link
Contributor Author

joshlong commented Oct 2, 2022

Hi, thanks for the quick replies. somehow, the biggest change of my original PR - the fact that it needs a snapshot or milestone (non-Maven central) repository was not in the original pom.xml. Don't ask me how. So I took the code on main, applied it over mine, re-applied the changes without accidentally invoking my IDE's code reformatter, and here we are.

I've updated the PR

@brendandburns
Copy link
Contributor

We already have a spring component (spring-boot-actuator) marked as optional https://github.com/kubernetes-client/java/blob/master/pom.xml#L177 so I think that for the reflections dependency, it makes sense mark it optional also, although I don't feel super strongly about this, but we've definitely gotten feedback about not wanting this library to pull in lots and lots of dependencies.

Regarding the milestone dependency, you're definitely right that we don't want to pull this in until it is released. So it feels like we should leave this PR open until it is released. There's not too much overlap w/ this PR so it shouldn't be too hard to keep it rebased.

@joshlong
Copy link
Contributor Author

joshlong commented Oct 3, 2022

Awesome! Both of those points - delaying until Boot 3 GA and marking Reflections as optional - are reasonable and I appreciate them. I'll follow up sometime after Spring Boot 3 is GA.

Maybe we could do something where, if you try to run the code and do an AOT compilation, it can check that reflections is on the classpath and if it isn't then warn the user to add it to their classpath? That shouldn't be too hard. Spring has a boolean ClassUtils.isPresent (String className, ClassLoader) we can put the warning behind. We'd have to update that one class in my PR.

I'm pretty pleased how far this has come in just a week. Thanks for a great project, and I appreciate the fast turnarounds. Hopefully, people interested in doing so will soon (before 2023, maybe?) be able to build Kubernetes clients and controllers that take 50mb of RAM and startup In no time at all soon enough.

@brendandburns
Copy link
Contributor

Adding that warning seems totally fine to me.

Thanks

@yue9944882
Copy link
Member

Error: COMPILATION ERROR :
Error: /home/runner/work/java/java/spring/src/main/java/io/kubernetes/client/spring/extended/controller/config/KubernetesInformerProperties.java:[17,51] cannot access org.springframework.boot.context.properties.ConfigurationProperties
bad class file: /home/runner/.m2/repository/org/springframework/boot/spring-boot/3.0.0-M5/spring-boot-3.0.0-M5.jar(org/springframework/boot/context/properties/ConfigurationProperties.class)
class file has wrong version 61.0, should be 52.0

@joshlong the idea SGTM, but i noticed the error messages above in the build log. is spring-boot 3 still compatible with java 8? there's still a distinct portion of users actively using java 8, so the compatibility should be preserved as well.

@k8s-ci-robot
Copy link
Contributor

@joshlong: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 22, 2022
@joshlong
Copy link
Contributor Author

joshlong commented Oct 30, 2022

Hi - no, spring boot 3 requires a Java 17 baseline. If we're not willing to insist on java 17 here, could we extract it into a standalone .jar so that people using the Spring Boot starter in boot 2 and 3 get the same jar but those wishing to leverage the new GraalVM AOT support get the new spring boot 3-specific code? That's less than ideal, tho :) we're all gonna have to cut over to 17 eventually

@brendandburns
Copy link
Contributor

I filed an issue so we can discuss how we want to handle Spring 6 and it's dependency on Java 17

#2452

@yue9944882
Copy link
Member

/close

closing it b/c #2457 was merged

@k8s-ci-robot
Copy link
Contributor

@yue9944882: Closed this PR.

In response to this:

/close

closing it b/c #2457 was merged

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@OlgaMaciaszek
Copy link

Hi @brendandburns, when is a release containing these changes scheduled for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants