diff --git a/docs/users/fbc_autorelease.md b/docs/users/fbc_autorelease.md index 638356b4f..f18d78096 100644 --- a/docs/users/fbc_autorelease.md +++ b/docs/users/fbc_autorelease.md @@ -46,6 +46,7 @@ catalog_templates: replaces: aqua.0.0.1 - template_name: semver.yaml channels: [Fast, Stable] + defaultChannel: Stable ``` The example above shows a release configuration where operator bundle is going to be released to the `my-channel` channel in the `basic.yaml` catalog template and to the @@ -54,6 +55,9 @@ released to the `my-channel` channel in the `basic.yaml` catalog template and to The `replaces` field is optional and it specifies the bundle that the new bundle replaces in the update graph. +The `defaultChannel` field is optional and it specifies which channel should be +the default for installing an operator. + ### File structure The schema of the file is available here: [release-config.yaml schema](https://github.com/redhat-openshift-ecosystem/operator-pipelines/blob/main/operatorcert/schemas/release-config-schema.json). The schema is validated automatically in the pipeline and the PR will fail with explanations if the file is not valid. @@ -65,6 +69,7 @@ Here is a summary of the file structure: * `template_name` - the name of the catalog template file in the `catalog-templates` directory. * `channels` - a list of channels where the bundle should be released. * In case of using `SemVer` a user can pick from allowed values: `Fast`, `Stable` and `Candidate`. + * `defaultChannel` - the default channel for the operator package (**Optional**). If not specified, defaults to the first channel listed in the channels list. * `replaces` - the bundle that the new bundle replaces in the update graph. (**Optional**, only for the basic templates) * `skips` - a list of bundles that should be skipped in the update graph. (**Optional**, only for the basic templates) * `skipRange` - a range of bundles that should be skipped in the update graph. (**Optional**, only for the basic templates) diff --git a/operatorcert/entrypoints/add_bundle_to_fbc.py b/operatorcert/entrypoints/add_bundle_to_fbc.py index dbfa349e2..07223adfe 100644 --- a/operatorcert/entrypoints/add_bundle_to_fbc.py +++ b/operatorcert/entrypoints/add_bundle_to_fbc.py @@ -299,7 +299,7 @@ def create( package = { "schema": "olm.package", "name": self.operator.operator_name, - "defaultChannel": channels[0]["name"], + "defaultChannel": release_config.get("defaultChannel", channels[0]["name"]), } bundle_obj = {"schema": "olm.bundle", "image": bundle_pullspec} @@ -466,6 +466,13 @@ def release_bundle_to_fbc(args: argparse.Namespace, bundle: Bundle) -> None: for release_config_template in bundle.release_config["catalog_templates"]: template_name = release_config_template["template_name"] template_mapping = get_catalog_mapping(bundle.operator.config, template_name) + default_channel = release_config_template.get("defaultChannel") + template_channels = release_config_template["channels"] + if default_channel and default_channel not in template_channels: + raise ValueError( + f"defaultChannel '{default_channel}' not found in '{template_name}'. " + f"Available channels: {template_channels}" + ) if not template_mapping: raise ValueError( f"Template mapping not found for '{template_name}' in ci.yaml." diff --git a/operatorcert/schemas/release-config-schema.json b/operatorcert/schemas/release-config-schema.json index 143fd15a9..4bfbaca42 100644 --- a/operatorcert/schemas/release-config-schema.json +++ b/operatorcert/schemas/release-config-schema.json @@ -27,6 +27,10 @@ "minItems": 1, "uniqueItems": true }, + "defaultChannel": { + "description": "default channel for this template (optional, defaults to first channel)", + "type": "string" + }, "replaces": { "description": "operator version which this PR replaces (optional)", "type": "string" diff --git a/tests/entrypoints/test_add_bundle_to_fbc.py b/tests/entrypoints/test_add_bundle_to_fbc.py index 3cf62fa77..c2f533b38 100644 --- a/tests/entrypoints/test_add_bundle_to_fbc.py +++ b/tests/entrypoints/test_add_bundle_to_fbc.py @@ -416,7 +416,9 @@ def test_release_bundle_to_fbc( add_bundle_to_fbc.release_bundle_to_fbc(args, bundle) bundle.release_config = { - "catalog_templates": [{"template_name": "fake-template.yaml"}] + "catalog_templates": [ + {"template_name": "fake-template.yaml", "channels": ["alpha"]}, + ] } mock_catalog_mapping.return_value = None with pytest.raises(ValueError): @@ -434,8 +436,27 @@ def test_release_bundle_to_fbc( bundle.release_config = { "catalog_templates": [ - {"template_name": "fake-basic.yaml"}, - {"template_name": "fake-semver.yaml"}, + { + "template_name": "fake-template.yaml", + "channels": ["alpha"], + "defaultChannel": "stable", + }, + ] + } + mock_catalog_mapping.side_effect = [ + { + "template_name": "fake-template.yaml", + "catalog_names": ["v4.12-fake"], + "type": "olm.template.basic", + } + ] + with pytest.raises(ValueError, match="defaultChannel 'stable' not found"): + add_bundle_to_fbc.release_bundle_to_fbc(args, bundle) + + bundle.release_config = { + "catalog_templates": [ + {"template_name": "fake-basic.yaml", "channels": ["alpha"]}, + {"template_name": "fake-semver.yaml", "channels": ["Fast", "Candidate"]}, ] } mock_catalog_mapping.side_effect = [