Skip to content

Commit b8d7985

Browse files
committed
fix: workaround quarkusio/quarkus#38657, register full hierarchies
Fixes #824 Previously, we were only registering the class itself for reflection, we now register the full hierarchy instead. Signed-off-by: Chris Laprun <[email protected]>
1 parent 30fff93 commit b8d7985

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/OperatorSDKProcessor.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import jakarta.inject.Singleton;
1414

1515
import org.jboss.jandex.DotName;
16+
import org.jboss.jandex.Type;
1617
import org.jboss.logging.Logger;
1718

1819
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
@@ -34,7 +35,7 @@
3435
import io.quarkus.deployment.annotations.Record;
3536
import io.quarkus.deployment.builditem.*;
3637
import io.quarkus.deployment.builditem.nativeimage.ForceNonWeakReflectiveClassBuildItem;
37-
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
38+
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
3839
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
3940
import io.quarkus.gizmo.AssignableResultHandle;
4041
import io.quarkus.gizmo.MethodCreator;
@@ -180,10 +181,34 @@ AnnotationConfigurablesBuildItem gatherAnnotationConfigurables(
180181
return new AnnotationConfigurablesBuildItem(configurableInfos);
181182
}
182183

184+
/**
185+
* Gathers the CustomResource implementations that are not part of the application index because they are part of an
186+
* external, reusable module for example.
187+
*
188+
* Note that this will be obsolete once <a href="https://github.com/quarkusio/quarkus/pull/38586">Quarkus #38586</a> is
189+
* usable
190+
*
191+
* @param combinedIndexBuildItem
192+
* @param applicationIndexBuildItem
193+
* @param reflectiveClassProducer
194+
*/
195+
@BuildStep
196+
void gatherOutOfAppCustomResourceImplementations(CombinedIndexBuildItem combinedIndexBuildItem,
197+
ApplicationIndexBuildItem applicationIndexBuildItem,
198+
BuildProducer<QOSDKReflectiveClassBuildItem> reflectiveClassProducer) {
199+
final var combinedIndex = combinedIndexBuildItem.getIndex();
200+
final var appIndex = applicationIndexBuildItem.getIndex();
201+
202+
// only add the CRs found in the combined index that were not already in the application one since Quarkus should already handle these
203+
final var crsFromCombined = combinedIndex.getAllKnownSubclasses(Constants.CUSTOM_RESOURCE);
204+
crsFromCombined.removeAll(appIndex.getAllKnownSubclasses(Constants.CUSTOM_RESOURCE));
205+
crsFromCombined.forEach(ci -> reflectiveClassProducer.produce(new QOSDKReflectiveClassBuildItem(ci.name().toString())));
206+
}
207+
183208
@BuildStep
184209
void registerClassesForReflection(
185210
List<QOSDKReflectiveClassBuildItem> toRegister,
186-
BuildProducer<ReflectiveClassBuildItem> reflectionClasses,
211+
BuildProducer<ReflectiveHierarchyBuildItem> reflectionClasses,
187212
BuildProducer<ForceNonWeakReflectiveClassBuildItem> forcedReflectionClasses) {
188213
final var toRegisterSet = toRegister.stream()
189214
.flatMap(QOSDKReflectiveClassBuildItem::classNamesToRegisterForReflectionStream)
@@ -236,11 +261,13 @@ void initializeRuntimeNamespacesFromBuildTimeValues(
236261

237262
}
238263

239-
private void registerAssociatedClassesForReflection(BuildProducer<ReflectiveClassBuildItem> reflectionClasses,
264+
private void registerAssociatedClassesForReflection(BuildProducer<ReflectiveHierarchyBuildItem> reflectionClasses,
240265
BuildProducer<ForceNonWeakReflectiveClassBuildItem> forcedReflectionClasses,
241266
Set<String> classNamesToRegister) {
267+
// todo: use builder API when/if https://github.com/quarkusio/quarkus/pull/38679 is available
242268
classNamesToRegister.forEach(cn -> {
243-
reflectionClasses.produce(ReflectiveClassBuildItem.builder(cn).methods().fields().build());
269+
reflectionClasses.produce(new ReflectiveHierarchyBuildItem.Builder()
270+
.type(Type.create(DotName.createSimple(cn), Type.Kind.CLASS)).build());
244271
forcedReflectionClasses.produce(
245272
new ForceNonWeakReflectiveClassBuildItem(cn));
246273
log.infov("Registered ''{0}'' for reflection", cn);

0 commit comments

Comments
 (0)