Skip to content

Commit

Permalink
feat: enable setting version/replaces field from properties (#716)
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 24, 2023
1 parent a85a79c commit e0e13a8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,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 @@ -106,7 +113,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 @@ -249,8 +256,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 @@ -29,6 +29,7 @@ public class MultipleOperatorsBundleTest {
Third.class, External.class, SecondExternal.class, ThirdReconciler.class,
ExternalDependentResource.class, PodDependentResource.class))
.overrideConfigKey("quarkus.operator-sdk.crd.generate-all", "true")
.overrideConfigKey("quarkus.operator-sdk.bundle.replaces", FirstReconciler.REPLACES)
.overrideConfigKey("quarkus.operator-sdk.bundle.package-name", BUNDLE_PACKAGE);

@SuppressWarnings("unused")
Expand All @@ -42,6 +43,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());
var bundleMeta = getAnnotationFor(bundle, "first-operator");
assertEquals(BUNDLE_PACKAGE, bundleMeta.getAnnotations().get("operators.operatorframework.io.bundle.package.v1"));

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 e0e13a8

Please sign in to comment.