Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make CRD order predictable in CSV #524

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/project.yml
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -57,8 +48,8 @@ public class CsvManifestsBuilder extends ManifestsBuilder {
private static final String IMAGE_PNG = "image/png";

private final ClusterServiceVersionBuilder csvBuilder;
private final Set<String> ownedCRs = new HashSet<>();
private final Set<String> requiredCRs = new HashSet<>();
private final SortedSet<String> ownedCRs = new TreeSet<>();
private final SortedSet<String> requiredCRs = new TreeSet<>();
private final Path kubernetesResources;

public CsvManifestsBuilder(CSVMetadataHolder metadata, List<ReconcilerAugmentedClassInfo> controllers,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<? extends HasMetadata> resourceClass) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.quarkiverse</groupId>
<artifactId>quarkiverse-parent</artifactId>
<version>10</version>
<version>12</version>
</parent>
<groupId>io.quarkiverse.operatorsdk</groupId>
<artifactId>quarkus-operator-sdk-parent</artifactId>
Expand Down