diff --git a/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledAugmentedClassInfo.java b/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledAugmentedClassInfo.java index b1cb51d5c..831e651c5 100644 --- a/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledAugmentedClassInfo.java +++ b/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledAugmentedClassInfo.java @@ -62,7 +62,7 @@ public ReconciledResourceAugmentedClassInfo asResourceTargeting() { } @SuppressWarnings("rawtypes") - public static ReconciledAugmentedClassInfo createFor(ClassInfo resourceCI, String reconcilerName, + public static ReconciledAugmentedClassInfo createFor(ClassInfo resourceCI, String name, IndexView index, Logger log, Map context) { var isResource = false; var isCR = false; @@ -79,12 +79,12 @@ public static ReconciledAugmentedClassInfo createFor(ClassInfo resourceCI, Strin ReconciledAugmentedClassInfo reconciledInfo; if (isCR) { - reconciledInfo = new CustomResourceAugmentedClassInfo(resourceCI, reconcilerName); + reconciledInfo = new CustomResourceAugmentedClassInfo(resourceCI, name); } else if (isResource) { reconciledInfo = new ReconciledResourceAugmentedClassInfo<>(resourceCI, HAS_METADATA, 0, - reconcilerName); + name); } else { - reconciledInfo = new ReconciledAugmentedClassInfo<>(resourceCI, OBJECT, 0, reconcilerName); + reconciledInfo = new ReconciledAugmentedClassInfo<>(resourceCI, OBJECT, 0, name); } // make sure the associated resource is properly initialized reconciledInfo.augmentIfKept(index, log, context); diff --git a/common-deployment/src/test/java/io/quarkiverse/operatorsdk/common/ResourceAssociatedAugmentedClassInfoTest.java b/common-deployment/src/test/java/io/quarkiverse/operatorsdk/common/ResourceAssociatedAugmentedClassInfoTest.java new file mode 100644 index 000000000..a05131681 --- /dev/null +++ b/common-deployment/src/test/java/io/quarkiverse/operatorsdk/common/ResourceAssociatedAugmentedClassInfoTest.java @@ -0,0 +1,70 @@ +package io.quarkiverse.operatorsdk.common; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.AbstractMap.SimpleEntry; +import java.util.List; + +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.Index; +import org.junit.jupiter.api.Test; + +import io.fabric8.kubernetes.api.model.ConfigMap; +import io.fabric8.kubernetes.client.CustomResource; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import io.quarkus.test.common.TestClassIndexer; + +class ResourceAssociatedAugmentedClassInfoTest { + + @Test + void getClassNamesToRegisterForReflection() { + final var indexAndInfo = create(ConfigMapReconciler.class); + final var index = indexAndInfo.getKey(); + final var info = indexAndInfo.getValue(); + info.augmentIfKept(index, null, null); + + assertEquals(List.of(ConfigMap.class.getName()), info.getClassNamesToRegisterForReflection()); + } + + private static SimpleEntry getClassInfo(Class> testClass) { + final var index = TestClassIndexer.readIndex(testClass); + return new SimpleEntry<>(index, index.getClassByName(DotName.createSimple(testClass.getName()))); + } + + private static SimpleEntry create(Class> testClass) { + final var indexAndClassInfo = getClassInfo(testClass); + final var classInfo = indexAndClassInfo.getValue(); + return new SimpleEntry<>(indexAndClassInfo.getKey(), + new ResourceAssociatedAugmentedClassInfo(classInfo, Constants.RECONCILER, 1, + ConfigurationUtils.getReconcilerName( + classInfo))); + } + + private static class ConfigMapReconciler implements Reconciler { + + @Override + public UpdateControl reconcile(ConfigMap configMap, Context context) { + return null; + } + } + + private static class TestCRReconciler implements Reconciler { + + @Override + public UpdateControl reconcile(TestCR testCR, Context context) { + return null; + } + } + + private static class TestCR extends CustomResource { + } + + private static class TestCRSpec { + } + + private static class TestCRStatus { + } +}