Skip to content

Commit

Permalink
feat: enable setting version/replaces field from properties
Browse files Browse the repository at this point in the history
Fixes #713

Signed-off-by: Chris Laprun <claprun@redhat.com>
  • Loading branch information
metacosm committed Sep 20, 2023
1 parent b563961 commit 497f5a9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ CSVMetadataBuildItem gatherCSVMetadata(ApplicationInfoBuildItem configuration,
CombinedIndexBuildItem combinedIndexBuildItem) {
final var index = combinedIndexBuildItem.getIndex();
final var defaultName = bundleConfiguration.packageName.orElse(configuration.getName());

// note that version, replaces, etc. should probably be settable at the reconciler level
// use version specified in bundle configuration, if not use the one extracted from the project, if available
final var version = configuration.getVersion();
final var defaultVersion = ApplicationInfoBuildItem.UNSET_VALUE.equals(version) ? null : version;
final var sharedMetadataHolders = getSharedMetadataHolders(defaultName, defaultVersion, index);
final var defaultVersion = bundleConfiguration.version
.orElse(ApplicationInfoBuildItem.UNSET_VALUE.equals(version) ? null : version);

final var defaultReplaces = bundleConfiguration.replaces.orElse(null);

final var sharedMetadataHolders = getSharedMetadataHolders(defaultName, defaultVersion, defaultReplaces, index);
final var csvGroups = new HashMap<CSVMetadataHolder, List<ReconcilerAugmentedClassInfo>>();

ClassUtils.getKnownReconcilers(index, log)
Expand Down Expand Up @@ -104,7 +111,7 @@ CSVMetadataBuildItem gatherCSVMetadata(ApplicationInfoBuildItem configuration,
}
}
csvMetadata = createMetadataHolder(csvMetadataAnnotation,
new CSVMetadataHolder(csvMetadataName, defaultVersion, origin));
new CSVMetadataHolder(csvMetadataName, defaultVersion, defaultReplaces, origin));
}
log.infov("Assigning ''{0}'' reconciler to {1}",
reconcilerInfo.nameOrFailIfUnset(),
Expand Down Expand Up @@ -244,8 +251,9 @@ void generateBundle(ApplicationInfoBuildItem configuration,
}
}

private Map<String, CSVMetadataHolder> getSharedMetadataHolders(String name, String version, IndexView index) {
CSVMetadataHolder csvMetadata = new CSVMetadataHolder(name, version, "default");
private Map<String, CSVMetadataHolder> getSharedMetadataHolders(String name, String version, String defaultReplaces,
IndexView index) {
CSVMetadataHolder csvMetadata = new CSVMetadataHolder(name, version, defaultReplaces, "default");
final var sharedMetadataImpls = index.getAllKnownImplementors(SHARED_CSV_METADATA);
final var result = new HashMap<String, CSVMetadataHolder>(sharedMetadataImpls.size() + 1);
sharedMetadataImpls.forEach(sharedMetadataImpl -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class MultipleOperatorsBundleTest {
Second.class, SecondReconciler.class,
Third.class, External.class, SecondExternal.class, ThirdReconciler.class,
ExternalDependentResource.class, PodDependentResource.class))
.overrideConfigKey("quarkus.operator-sdk.crd.generate-all", "true");
.overrideConfigKey("quarkus.operator-sdk.crd.generate-all", "true")
.overrideConfigKey("quarkus.operator-sdk.bundle.replaces", FirstReconciler.REPLACES);

@SuppressWarnings("unused")
@ProdBuildResults
Expand All @@ -39,6 +40,7 @@ public void shouldWriteBundleForTheOperators() throws IOException {
// check that version is properly overridden
var csv = getCSVFor(bundle, "first-operator");
assertEquals(FirstReconciler.VERSION, csv.getSpec().getVersion());
assertEquals(FirstReconciler.REPLACES, csv.getSpec().getReplaces());

checkBundleFor(bundle, "second-operator", Second.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class FirstReconciler implements Reconciler<First> {

public static final String VERSION = "first-version";
public static final String REPLACES = "first-replaces";

@Override
public UpdateControl<First> reconcile(First request, Context<First> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ public class BundleGenerationConfiguration {
@ConfigItem
public Optional<String> packageName;

/**
* The replaces value that should be used in the generated CSV.
*/
@ConfigItem
public Optional<String> replaces;

/**
* The version value that should be used in the generated CSV instead of the automatically detected one extracted from the
* project information.
*/
@ConfigItem
public Optional<String> version;

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public RequiredCRD(String kind, String name, String version) {

}

public CSVMetadataHolder(String name, String version, String origin) {
this(name, null, null, null, null, null, null, null, null, version, null, null, null, null, null, null, null, null,
public CSVMetadataHolder(String name, String version, String replaces, String origin) {
this(name, null, null, null, null, null, null, replaces, null, version, null, null, null, null, null, null, null, null,
origin);
}

Expand Down

0 comments on commit 497f5a9

Please sign in to comment.