Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support crd.versions field #165

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions operatorcourier/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ def _crd_validation(self, bundle):
if "group" not in crd['spec']:
self._log_error("crd spec.group not defined.")
valid = False
if "version" not in crd['spec']:
self._log_error("crd spec.version not defined.")
valid = False
if "versions" not in crd['spec']:
if "version" not in crd['spec']:
self._log_error("crd spec.version or spec.versions not defined")
valid = False

return valid

Expand Down Expand Up @@ -271,6 +272,11 @@ def _csv_spec_validation(self, spec, bundleData):

if 'version' in csvOwnedCrd:
if 'spec' in crd:
if 'versions' in crd['spec']:
if csvOwnedCrd['version'] not in crd['spec']['versions']:
self._log_error('CSV.spec.crd.owned.version is'
'not in CRD.spec.versions list')
valid = False
if 'version' in crd['spec']:
if csvOwnedCrd['version'] != crd['spec']['version']:
self._log_error('CRD.spec.version does not match '
Expand Down
347 changes: 347 additions & 0 deletions tests/test_files/bundles/verification/crdversions.invalid.bundle.yaml

Large diffs are not rendered by default.

348 changes: 348 additions & 0 deletions tests/test_files/bundles/verification/crdversions.valid.bundle.yaml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,27 @@ def _test_invalid_bundle(bundleFile):
unformatted_bundle = unformat_bundle(bundle)
valid, _ = ValidateCmd().validate(unformatted_bundle)
assert not valid


@pytest.mark.parametrize('file_name', [
"tests/test_files/bundles/verification/crdversions.invalid.bundle.yaml",
])
def test_invalid_crd_versions_field(file_name):
with open(file_name) as f:
bundle = yaml.safe_load(f)
bundle = unformat_bundle(bundle)
valid, _ = ValidateCmd().validate(bundle)

assert not valid


@pytest.mark.parametrize('file_name', [
"tests/test_files/bundles/verification/crdversions.valid.bundle.yaml",
])
def test_valid_crd_versions_field(file_name):
with open(file_name) as f:
bundle = yaml.safe_load(f)
bundle = unformat_bundle(bundle)
valid, _ = ValidateCmd().validate(bundle)

assert valid