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

Check presence and match of fields in CRD and CSV in bundle #41

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
87 changes: 76 additions & 11 deletions operatorcourier/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ def _crd_validation(self, bundleData):
if "spec" not in crd:
self._log_error("crd spec not defined.")
valid = False
else:
if "names" not in crd['spec']:
self._log_error("crd spec.names not defined.")
valid = False
else:
if "kind" not in crd['spec']['names']:
self._log_error("crd spec.names.kind not defined.")
valid = False
if "plural" not in crd['spec']['names']:
self._log_error("crd spec.names.plural not defined.")
valid = False
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

return valid

Expand Down Expand Up @@ -169,18 +186,66 @@ def _csv_spec_validation(self, spec, bundleData):
if "owned" not in customresourcedefinitions:
self._log_error("spec.customresourcedefinitions.owned"
"not defined for csv")
valid = False
else:
for crd in customresourcedefinitions["owned"]:
if "name" not in crd:
self._log_error("name not defined for item in "
"spec.customresourcedefinitions.")
valid = False
else:
if crd["name"] not in crdList:
self._log_error("custom resource definition referenced "
"in csv not defined in root list of crds")
return False

for csvOwnedCrd in customresourcedefinitions["owned"]:
SamiSousa marked this conversation as resolved.
Show resolved Hide resolved
if "name" not in csvOwnedCrd:
jeremy-wl marked this conversation as resolved.
Show resolved Hide resolved
self._log_error("name not defined for item in "
"spec.customresourcedefinitions.")
valid = False
elif csvOwnedCrd["name"] not in crdList:
self._log_error("custom resource definition %s referenced in csv "
"not defined in root list of crds",
csvOwnedCrd["name"])
valid = False

if "kind" not in csvOwnedCrd:
self._log_error("kind not defined for item in "
"spec.customresourcedefinitions.")
valid = False
if "version" not in csvOwnedCrd:
self._log_error("version not defined for item in "
"spec.customresourcedefinitions.")
valid = False

for crd in bundleData[self.crdKey]:
if 'name' not in csvOwnedCrd:
continue
if 'metadata' not in crd or 'name' not in crd['metadata']:
continue
if csvOwnedCrd['name'] != crd['metadata']['name']:
continue

if 'kind' in csvOwnedCrd:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much easier to read. 🤓

if 'spec' in crd:
if 'names' in crd['spec']:
if 'kind' in crd['spec']['names']:
if csvOwnedCrd['kind'] != \
crd['spec']['names']['kind']:
self._log_error('CRD.spec.names.kind does not '
'match CSV.spec.crd.owned.kind')
valid = False

if 'version' in csvOwnedCrd:
if 'spec' in crd:
if 'version' in crd['spec']:
if csvOwnedCrd['version'] != crd['spec']['version']:
self._log_error('CRD.spec.version does not match '
'CSV.spec.crd.owned.version')
valid = False

if 'name' in csvOwnedCrd:
if 'spec' in crd:
if 'names' in crd['spec'] and 'group' in crd['spec']:
if 'plural' in crd['spec']['names']:
if csvOwnedCrd['name'] != \
crd['spec']['names']['plural'] + '.' + \
crd['spec']['group']:
self._log_error("`CRD.spec.names.plural`."
"`CRD.spec.group` does not "
"match "
"CSV.spec.crd.owned.name")
valid = False
return valid

def _csv_metadata_validation(self, metadata):
Expand Down
Loading