forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: static KubernetesResource class registration in synthetic bean
Signed-off-by: Marc Nuri <marc@marcnuri.com>
- Loading branch information
Showing
5 changed files
with
89 additions
and
39 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...al/src/main/java/io/quarkus/kubernetes/client/deployment/KubernetesResourceBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.quarkus.kubernetes.client.deployment; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Type; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.arc.deployment.SyntheticBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.kubernetes.client.runtime.KubernetesResources; | ||
import io.quarkus.kubernetes.client.runtime.KubernetesSerializationRecorder; | ||
|
||
public class KubernetesResourceBuildStep { | ||
@BuildStep | ||
@Record(ExecutionTime.STATIC_INIT) | ||
SyntheticBeanBuildItem kubernetesResourceClasses( | ||
KubernetesSerializationRecorder recorder, BuildProducer<AdditionalBeanBuildItem> additionalBeans) { | ||
additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(KubernetesResources.class)); | ||
final var classArray = Type.create(DotName.createSimple(Class[].class.getName()), Type.Kind.ARRAY); | ||
return SyntheticBeanBuildItem | ||
.configure(Object.class).providerType(classArray).addType(classArray) | ||
.scope(Singleton.class) | ||
.qualifiers(AnnotationInstance.builder(KubernetesResources.class).build()) | ||
.runtimeValue(recorder.scanKubernetesResources()) | ||
.done(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...time-internal/src/main/java/io/quarkus/kubernetes/client/runtime/KubernetesResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.kubernetes.client.runtime; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
@Qualifier | ||
@Retention(RUNTIME) | ||
@Target({ METHOD, FIELD, PARAMETER, TYPE }) | ||
public @interface KubernetesResources { | ||
} |
31 changes: 31 additions & 0 deletions
31
...l/src/main/java/io/quarkus/kubernetes/client/runtime/KubernetesSerializationRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.kubernetes.client.runtime; | ||
|
||
import java.util.HashSet; | ||
import java.util.ServiceLoader; | ||
import java.util.Set; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesResource; | ||
import io.fabric8.kubernetes.internal.KubernetesDeserializer; | ||
import io.quarkus.runtime.RuntimeValue; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class KubernetesSerializationRecorder { | ||
|
||
public RuntimeValue<Class<? extends KubernetesResource>[]> scanKubernetesResources() { | ||
final var classLoaders = new ClassLoader[] { | ||
Thread.currentThread().getContextClassLoader(), | ||
KubernetesDeserializer.class.getClassLoader() }; | ||
final Set<Class<? extends KubernetesResource>> resourceClasses = new HashSet<>(); | ||
for (var classLoader : classLoaders) { | ||
if (classLoader == null) { | ||
continue; | ||
} | ||
final var serviceLoader = ServiceLoader.load(KubernetesResource.class, classLoader); | ||
for (var kr : serviceLoader) { | ||
resourceClasses.add(kr.getClass()); | ||
} | ||
} | ||
return new RuntimeValue<>(resourceClasses.<Class<? extends KubernetesResource>> toArray(Class[]::new)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters