From efc1996b7a76eefab6c60e06e8fa2293a47b13b4 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Fri, 8 Nov 2024 10:09:21 +0100 Subject: [PATCH] fix: clarify when id or full resource name is needed Signed-off-by: Chris Laprun --- .../common/ReconciledResourceAugmentedClassInfo.java | 9 ++++++--- .../deployment/CRDGenerationBuildStep.java | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledResourceAugmentedClassInfo.java b/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledResourceAugmentedClassInfo.java index 2754ea06..21a33fe1 100644 --- a/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledResourceAugmentedClassInfo.java +++ b/common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/ReconciledResourceAugmentedClassInfo.java @@ -14,17 +14,20 @@ public class ReconciledResourceAugmentedClassInfo extends public static final String STATUS = "status"; protected boolean hasStatus; - private final String id; + private final Id id; + + public record Id(String fullResourceName, String version) { + } protected ReconciledResourceAugmentedClassInfo(ClassInfo classInfo, DotName extendedOrImplementedClass, int expectedParameterTypesCardinality, String associatedReconcilerName) { super(classInfo, extendedOrImplementedClass, expectedParameterTypesCardinality, associatedReconcilerName); - id = fullResourceName() + version(); + id = new Id(fullResourceName(), version()); } - public String id() { + public Id id() { return id; } diff --git a/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/CRDGenerationBuildStep.java b/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/CRDGenerationBuildStep.java index 01070337..5782fe23 100644 --- a/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/CRDGenerationBuildStep.java +++ b/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/CRDGenerationBuildStep.java @@ -54,7 +54,7 @@ GeneratedCRDInfoBuildItem generateCRDs( final var generate = CRDGeneration.shouldGenerate(crdConfig.generate(), crdConfig.apply(), launchMode); final var storedCRDInfos = stored; final var changedClasses = ConfigurationUtils.getChangedClasses(liveReload); - final var scheduledForGeneration = new HashSet(7); + final var scheduledForGeneration = new HashSet(7); final var excludedResourceClasses = crdConfig.excludeResources().map(Set::copyOf).orElseGet(Collections::emptySet); final var externalCRDs = unownedCRDInfo.getCRDs(); @@ -70,7 +70,7 @@ GeneratedCRDInfoBuildItem generateCRDs( .filter(keepResourcePredicate::apply) .forEach(associatedResource -> { final var crInfo = associatedResource.asResourceTargeting(); - final String crId = crInfo.id(); + final var crId = crInfo.id(); // if the primary resource is unowned, mark it as "scheduled" (i.e. already handled) so that it doesn't get considered if all CRDs generation is requested if (!operatorConfiguration @@ -80,7 +80,7 @@ GeneratedCRDInfoBuildItem generateCRDs( // When we have a live reload, check if we need to regenerate the associated CRD Map crdInfos = Collections.emptyMap(); if (liveReload.isLiveReload()) { - crdInfos = storedCRDInfos.getOrCreateCRDSpecVersionToInfoMapping(crId); + crdInfos = storedCRDInfos.getOrCreateCRDSpecVersionToInfoMapping(crInfo.fullResourceName()); } // schedule the generation of associated primary resource CRD if required @@ -141,11 +141,12 @@ UnownedCRDInfoBuildItem unownedCRDInfo(BuildTimeOperatorConfiguration operatorCo * Exclude all resources that shouldn't be generated because either they've been explicitly excluded or because they're * supposed to be loaded directly from a specified CRD file */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean isExcluded(CustomResourceAugmentedClassInfo crInfo, CRDInfos externalCRDs, - Set excludedResourceClassNames) { + Set excludedResourceClassNames) { final var crClassName = crInfo.classInfo().name().toString(); final var excluded = excludedResourceClassNames.contains(crClassName); - final var external = externalCRDs.contains(crInfo.id()); + final var external = externalCRDs.contains(crInfo.fullResourceName()); if (excluded || external) { log.infov("CRD generation was skipped for ''{0}'' because {1}", crClassName, external ? externalCause : excludedCause);