Add GraalVM native image support for Fabric8 autoconfig module#2247
Add GraalVM native image support for Fabric8 autoconfig module#2247kamalcis wants to merge 4 commits into
Conversation
d272d9d to
9b6a0eb
Compare
Signed-off-by: Abu Hena Mostafa Kamal <kamalcis@gmail.com>
Add RuntimeHintsRegistrar and @ConstructorBinding fixes to enable Spring Cloud Kubernetes to run as a GraalVM native image. Changes: - Add Fabric8RuntimeHints implementing RuntimeHintsRegistrar with reflection hints for Fabric8 client classes (KubernetesClientImpl, KubernetesClientBuilder, Config, ConfigBuilder), Kubernetes resources (ConfigMap, ConfigMapList, Secret, SecretList, ObjectMeta), and config properties (ConfigMapConfigProperties, SecretsConfigProperties) - Remove @ImportRuntimeHints(Fabric8RuntimeHints.class) from Fabric8AutoConfiguration and register Fabric8RuntimeHints via META-INF/spring/aot.factories instead for proper AOT processing - Add @ConstructorBinding to ConfigMapConfigProperties constructor to ensure correct binding behavior in native AOT mode - Add @ConstructorBinding to SecretsConfigProperties constructor for the same reason - Register KubernetesConfigDataLoader in spring.factories to fix silent config data loading failure in native AOT mode Validated on GraalVM CE 25.0.2 with Spring Boot 4.1.0-SNAPSHOT and Kubernetes 1.34.1 on a live kubeadm cluster (93ms startup time). Fixes: native image startup failure with NoSuchMethodException for ConfigMapConfigProperties and SecretsConfigProperties, and silent config data load skip in AOT mode. Signed-off-by: Abu Hena Mostafa Kamal <kamalcis@gmail.com>
Remove @ConstructorBinding from ConfigMapConfigProperties and SecretsConfigProperties as it is not needed in this case. Register both classes in Fabric8RuntimeHints with INVOKE_DECLARED_CONSTRUCTORS to ensure GraalVM can construct them at runtime. Add unit tests for Fabric8RuntimeHints covering reflection hint registrations for Fabric8 client classes, Kubernetes API resources, and config properties. Signed-off-by: Abu Hena Mostafa Kamal <kamalcis@gmail.com>
Spring Boot AOT engine automatically processes ConfigDataLoader registrations from META-INF/spring/ imports file, making the spring.factories entry unnecessary and redundant. Signed-off-by: Abu Hena Mostafa Kamal <kamalcis@gmail.com>
607b9d6 to
4dd0f5a
Compare
|
Hi @ryanjbaxter, I hope you're well! |
|
Thanks! I think this would be a good feature for our 2026 release which will be sometime towards the end of the year |
Thank you so much for triaging this and adding it to the 2026.0.0-M1 milestone. Please let me know if there's anything you'd like me to address. Looking forward to collaborating on this! |


Problem
Spring Cloud Kubernetes Fabric8 autoconfig module does not support
GraalVM native image compilation. The README explicitly states native
images are unsupported. Native builds fail at runtime with:
java.lang.ClassNotFoundException:
io.fabric8.kubernetes.client.impl.KubernetesClientImpl
Closes #1350
Testing Environment
Tested on:
Reproduce
cd spring-cloud-kubernetes> ./mvnw clean install -DskipTests -Dspring-boot.build-image.skip=true
https://github.com/kamalcis/graalvm-sck-app/blob/main/k8s.yaml ( kubectl apply -f k8s.yaml)
Solution
Add
Fabric8RuntimeHintsimplementingRuntimeHintsRegistrarto register:KubernetesClientImpl,KubernetesClientBuilder,and
ConfigFabric8ProfileEnvironmentPostProcessorNote
User applications must set
spring.main.cloud-platform=kubernetesin their configuration to enable SCK auto-configuration in
native image environments. Auto-detection of the Kubernetes
platform is not yet supported in native images and is a
separate concern from this PR.
Results on Merge:
Deployed the user application image ( containing the SCK library ) into Kubeadm cluster. Pods started successfully, logs were clean, and SCK auto-configuration loaded correctly at runtime. Pods start instantly, logs are clean, and SCK auto-configuration loads correctly at runtime.