diff --git a/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/BundleProcessor.java b/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/BundleProcessor.java index ae7f1e76..350e5c42 100644 --- a/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/BundleProcessor.java +++ b/bundle-generator/deployment/src/main/java/io/quarkiverse/operatorsdk/bundle/deployment/BundleProcessor.java @@ -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>(); ClassUtils.getKnownReconcilers(index, log) @@ -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(), @@ -249,8 +256,9 @@ void generateBundle(ApplicationInfoBuildItem configuration, } } - private Map getSharedMetadataHolders(String name, String version, IndexView index) { - CSVMetadataHolder csvMetadata = new CSVMetadataHolder(name, version, "default"); + private Map 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(sharedMetadataImpls.size() + 1); sharedMetadataImpls.forEach(sharedMetadataImpl -> { 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 256757bc..4fcfc358 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 @@ -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") @@ -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")); diff --git a/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/sources/FirstReconciler.java b/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/sources/FirstReconciler.java index 7260226e..cd176cda 100644 --- a/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/sources/FirstReconciler.java +++ b/bundle-generator/deployment/src/test/java/io/quarkiverse/operatorsdk/bundle/sources/FirstReconciler.java @@ -9,6 +9,7 @@ public class FirstReconciler implements Reconciler { public static final String VERSION = "first-version"; + public static final String REPLACES = "first-replaces"; @Override public UpdateControl reconcile(First request, Context context) { diff --git a/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/BundleGenerationConfiguration.java b/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/BundleGenerationConfiguration.java index 85bf4a99..8ee539dd 100644 --- a/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/BundleGenerationConfiguration.java +++ b/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/BundleGenerationConfiguration.java @@ -32,4 +32,17 @@ public class BundleGenerationConfiguration { @ConfigItem public Optional packageName; + /** + * The replaces value that should be used in the generated CSV. + */ + @ConfigItem + public Optional 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 version; + } diff --git a/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/CSVMetadataHolder.java b/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/CSVMetadataHolder.java index 955daa65..a140c6f5 100644 --- a/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/CSVMetadataHolder.java +++ b/bundle-generator/runtime/src/main/java/io/quarkiverse/operatorsdk/bundle/runtime/CSVMetadataHolder.java @@ -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); }