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 c31b345f..c6edbb38 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 @@ -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>(); ClassUtils.getKnownReconcilers(index, log) @@ -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(), @@ -244,8 +251,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 cab91b1f..5cc65edb 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 @@ -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 @@ -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); 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); }