Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Revert "Revert "[ART-4751] update valid-subscription in csv"" (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ximinhan authored Sep 22, 2022
1 parent 7d7e99f commit bc9aa3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
13 changes: 8 additions & 5 deletions doozerlib/olm/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,14 @@ def replace_image_references_by_sha_on_bundle_manifests(self):
contents = self.find_and_replace_image_references_by_sha(f.read())
f.seek(0)
f.truncate()
f.write(contents)
if "clusterserviceversion.yaml" in file:
if not self.valid_subscription_label:
raise ValueError("missing valid-subscription-label in operator config")
yml_content = yaml.safe_load(contents)
yml_content['metadata']['annotations']['operators.openshift.io/valid-subscription'] = self.valid_subscription_label
f.write(yaml.dump(yml_content))
else:
f.write(contents)

def generate_bundle_annotations(self):
"""Create an annotations YAML file for the bundle, using info extracted from operator's
Expand Down Expand Up @@ -570,17 +577,13 @@ def operator_framework_tags(self):
if self.runtime.group_config.operator_channel_stable == 'default':
override_default = stable_channel

if not self.valid_subscription_label:
raise ValueError("missing valid-subscription-label in operator config")

return {
'operators.operatorframework.io.bundle.channel.default.v1': override_default,
'operators.operatorframework.io.bundle.channels.v1': override_channel,
'operators.operatorframework.io.bundle.manifests.v1': 'manifests/',
'operators.operatorframework.io.bundle.mediatype.v1': 'registry+v1',
'operators.operatorframework.io.bundle.metadata.v1': 'metadata/',
'operators.operatorframework.io.bundle.package.v1': self.package,
'operators.openshift.io/valid-subscription': self.valid_subscription_label,
}

@property
Expand Down
18 changes: 0 additions & 18 deletions tests/test_olm_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,3 @@ def test_get_bundle_image_name_no_ose_prefix(self):
def test_get_bundle_image_name_with_ose_prefix(self):
obj = flexmock(OLMBundle(None, dry_run=False, brew_session=MagicMock()), bundle_name='ose-foo')
self.assertEqual(obj.get_bundle_image_name(), 'openshift/ose-foo')

def test_valid_subscription_label_is_present(self):
expected_key = 'operators.openshift.io/valid-subscription'
expected_val = '["My", "Subscription", "Label"]'

# mocking
config = {'update-csv': {'valid-subscription-label': expected_val}}
runtime = flexmock(
group_config=flexmock(operator_channel_stable='default'),
image_map={'myimage': flexmock(config=config)}
)
obj = flexmock(OLMBundle(runtime, dry_run=False, brew_session=MagicMock()), operator_name='myimage')
obj.channel = '...'
obj.package = '...'

self.assertIn(expected_key, obj.operator_framework_tags.keys())
actual_val = obj.operator_framework_tags[expected_key]
self.assertEqual(expected_val, actual_val)

0 comments on commit bc9aa3f

Please sign in to comment.