-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 <[email protected]>
Showing
5 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...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,52 @@ | ||
package io.quarkus.kubernetes.client.deployment; | ||
|
||
import java.util.HashSet; | ||
import java.util.ServiceLoader; | ||
import java.util.Set; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Type; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesResource; | ||
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; | ||
import io.quarkus.kubernetes.client.spi.KubernetesResourcesBuildItem; | ||
|
||
public class KubernetesResourceBuildStep { | ||
|
||
@BuildStep | ||
void scanKubernetesResourceClasses(BuildProducer<KubernetesResourcesBuildItem> kubernetesResourcesBuildItemBuildProducer) { | ||
final Set<Class<? extends KubernetesResource>> resourceClasses = new HashSet<>(); | ||
final var serviceLoader = ServiceLoader.load(KubernetesResource.class); | ||
for (var kr : serviceLoader) { | ||
resourceClasses.add(kr.getClass()); | ||
} | ||
kubernetesResourcesBuildItemBuildProducer.produce( | ||
new KubernetesResourcesBuildItem(resourceClasses.<Class<? extends KubernetesResource>> toArray(Class[]::new))); | ||
} | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.STATIC_INIT) | ||
SyntheticBeanBuildItem kubernetesResourceClasses( | ||
KubernetesSerializationRecorder recorder, | ||
KubernetesResourcesBuildItem kubernetesResourcesBuildItem, | ||
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.initKubernetesResources(kubernetesResourcesBuildItem.getResourceClasses())) | ||
.done(); | ||
} | ||
} |
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 { | ||
} |
14 changes: 14 additions & 0 deletions
14
...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,14 @@ | ||
package io.quarkus.kubernetes.client.runtime; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesResource; | ||
import io.quarkus.runtime.RuntimeValue; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class KubernetesSerializationRecorder { | ||
|
||
public RuntimeValue<Class<? extends KubernetesResource>[]> initKubernetesResources( | ||
Class<? extends KubernetesResource>[] resources) { | ||
return new RuntimeValue<>(resources); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...ient/spi/src/main/java/io/quarkus/kubernetes/client/spi/KubernetesResourcesBuildItem.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,17 @@ | ||
package io.quarkus.kubernetes.client.spi; | ||
|
||
import io.fabric8.kubernetes.api.model.KubernetesResource; | ||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class KubernetesResourcesBuildItem extends SimpleBuildItem { | ||
|
||
private final Class<? extends KubernetesResource>[] resourceClasses; | ||
|
||
public KubernetesResourcesBuildItem(Class<? extends KubernetesResource>[] resourceClasses) { | ||
this.resourceClasses = resourceClasses; | ||
} | ||
|
||
public Class<? extends KubernetesResource>[] getResourceClasses() { | ||
return resourceClasses; | ||
} | ||
} |