|
| 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 | +} |
0 commit comments