From c8f4fd4f41a2e090f8234b386800162ce3eab970 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 22 Mar 2023 15:21:36 +0100 Subject: [PATCH] fix: make CRD order predictable in CSV (#524) * fix: make CRD order predictable in CSV Fixes #523 * chore: release 4.0.8 * chore: update quarkiverse-parent to version 12 --- .github/project.yml | 4 +-- .../builders/CsvManifestsBuilder.java | 15 +++-------- .../bundle/MultipleOperatorsBundleTest.java | 25 +++++-------------- pom.xml | 2 +- 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/.github/project.yml b/.github/project.yml index abe0fa0d..fb15da1c 100644 --- a/.github/project.yml +++ b/.github/project.yml @@ -1,5 +1,5 @@ name: Java Operator SDK Extension release: - current-version: 4.0.7 - next-version: 4.0.8-SNAPSHOT + current-version: 4.0.8 + next-version: 4.0.9-SNAPSHOT diff --git a/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/builders/CsvManifestsBuilder.java b/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/builders/CsvManifestsBuilder.java index 852dc4e0..aa8b7dcf 100644 --- a/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/builders/CsvManifestsBuilder.java +++ b/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/builders/CsvManifestsBuilder.java @@ -5,16 +5,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Path; -import java.util.Arrays; -import java.util.Base64; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; @@ -57,8 +48,8 @@ public class CsvManifestsBuilder extends ManifestsBuilder { private static final String IMAGE_PNG = "image/png"; private final ClusterServiceVersionBuilder csvBuilder; - private final Set ownedCRs = new HashSet<>(); - private final Set requiredCRs = new HashSet<>(); + private final SortedSet ownedCRs = new TreeSet<>(); + private final SortedSet requiredCRs = new TreeSet<>(); private final Path kubernetesResources; public CsvManifestsBuilder(CSVMetadataHolder metadata, List controllers, diff --git a/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/MultipleOperatorsBundleTest.java b/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/MultipleOperatorsBundleTest.java index e5329368..1ba7c8f2 100644 --- a/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/MultipleOperatorsBundleTest.java +++ b/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/MultipleOperatorsBundleTest.java @@ -1,7 +1,6 @@ package io.quarkiverse.operatorsdk.bundle; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.file.Files; @@ -14,15 +13,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion; -import io.quarkiverse.operatorsdk.bundle.sources.External; -import io.quarkiverse.operatorsdk.bundle.sources.ExternalDependentResource; -import io.quarkiverse.operatorsdk.bundle.sources.First; -import io.quarkiverse.operatorsdk.bundle.sources.FirstReconciler; -import io.quarkiverse.operatorsdk.bundle.sources.Second; -import io.quarkiverse.operatorsdk.bundle.sources.SecondExternal; -import io.quarkiverse.operatorsdk.bundle.sources.SecondReconciler; -import io.quarkiverse.operatorsdk.bundle.sources.Third; -import io.quarkiverse.operatorsdk.bundle.sources.ThirdReconciler; +import io.quarkiverse.operatorsdk.bundle.sources.*; import io.quarkus.test.ProdBuildResults; import io.quarkus.test.ProdModeTestResults; import io.quarkus.test.QuarkusProdModeTest; @@ -55,15 +46,11 @@ public void shouldWriteBundleForTheOperators() throws IOException { assertFileExistsIn(thirdManifests.resolve(getCRDNameFor(External.class)), thirdManifests); final var csvAsString = Files.readString(thirdManifests.resolve("third-operator.clusterserviceversion.yaml")); final var csv = Serialization.unmarshal(csvAsString, ClusterServiceVersion.class); - assertEquals(HasMetadata.getFullResourceName(Third.class), - csv.getSpec().getCustomresourcedefinitions().getOwned().get(0).getName()); - assertTrue(csvSpecHasRequired(csv, HasMetadata.getFullResourceName(External.class))); - assertTrue(csvSpecHasRequired(csv, HasMetadata.getFullResourceName(SecondExternal.class))); - } - - private static boolean csvSpecHasRequired(ClusterServiceVersion csv, String externalName) { - return csv.getSpec().getCustomresourcedefinitions().getRequired().stream() - .anyMatch(desc -> externalName.equals(desc.getName())); + final var crds = csv.getSpec().getCustomresourcedefinitions(); + assertEquals(HasMetadata.getFullResourceName(Third.class), crds.getOwned().get(0).getName()); + // CRDs should be alphabetically ordered + assertEquals(HasMetadata.getFullResourceName(External.class), crds.getRequired().get(0).getName()); + assertEquals(HasMetadata.getFullResourceName(SecondExternal.class), crds.getRequired().get(1).getName()); } private void checkBundleFor(Path bundle, String operatorName, Class resourceClass) { diff --git a/pom.xml b/pom.xml index 2d4ab672..2c15b365 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.quarkiverse quarkiverse-parent - 10 + 12 io.quarkiverse.operatorsdk quarkus-operator-sdk-parent