Skip to content

Commit d272d9d

Browse files
committed
Add GraalVM native image support for Fabric8 autoconfig module
1 parent 5f1e613 commit d272d9d

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8AutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
3333
import org.springframework.context.annotation.Bean;
3434
import org.springframework.context.annotation.Configuration;
35+
import org.springframework.context.annotation.ImportRuntimeHints;
3536
import org.springframework.core.env.Environment;
3637

3738
/**
@@ -41,6 +42,7 @@
4142
* @author Eddú Meléndez
4243
* @author Tim Ysewyn
4344
*/
45+
@ImportRuntimeHints(Fabric8RuntimeHints.class)
4446
@Configuration(proxyBeanMethods = false)
4547
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
4648
@AutoConfigureAfter(KubernetesCommonsAutoConfiguration.class)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2013-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.fabric8;
18+
19+
import io.fabric8.kubernetes.client.Config;
20+
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
21+
import io.fabric8.kubernetes.client.impl.KubernetesClientImpl;
22+
23+
import org.springframework.aot.hint.MemberCategory;
24+
import org.springframework.aot.hint.RuntimeHints;
25+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
26+
import org.springframework.aot.hint.TypeReference;
27+
28+
/**
29+
* {@link RuntimeHintsRegistrar} for Spring Cloud Kubernetes Fabric8 native image support.
30+
*
31+
* Registers reflection, resource, and proxy hints required for GraalVM native image
32+
* compilation when using the Fabric8 Kubernetes client with Spring Cloud Kubernetes.
33+
*
34+
* @author Abu Hena Mostafa Kamal
35+
*/
36+
public class Fabric8RuntimeHints implements RuntimeHintsRegistrar {
37+
38+
@Override
39+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
40+
// Fabric8 client impl - loaded reflectively via KubernetesClientBuilder
41+
hints.reflection()
42+
.registerType(TypeReference.of(KubernetesClientImpl.class), MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
43+
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.ACCESS_DECLARED_FIELDS);
44+
45+
// KubernetesClientBuilder - used in Fabric8AutoConfiguration
46+
hints.reflection()
47+
.registerType(TypeReference.of(KubernetesClientBuilder.class), MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
48+
MemberCategory.INVOKE_DECLARED_METHODS);
49+
50+
// Fabric8 Config - used in Fabric8AutoConfiguration
51+
hints.reflection()
52+
.registerType(TypeReference.of(Config.class), MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
53+
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.ACCESS_DECLARED_FIELDS);
54+
55+
// EnvironmentPostProcessor loaded via spring.factories
56+
hints.reflection()
57+
.registerType(TypeReference.of(Fabric8ProfileEnvironmentPostProcessor.class),
58+
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
59+
60+
// Kubernetes service account and kubeconfig resources
61+
hints.resources().registerPattern(".kube/config");
62+
hints.resources().registerPattern("var/run/secrets/kubernetes.io/serviceaccount/token");
63+
hints.resources().registerPattern("var/run/secrets/kubernetes.io/serviceaccount/ca.crt");
64+
hints.resources().registerPattern("var/run/secrets/kubernetes.io/serviceaccount/namespace");
65+
66+
}
67+
68+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
org.springframework.cloud.kubernetes.fabric8.Fabric8RuntimeHints

0 commit comments

Comments
 (0)