Skip to content

Commit

Permalink
Remove owned requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed May 5, 2019
1 parent 07c881a commit 983e781
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 135 deletions.
259 changes: 126 additions & 133 deletions operatorcourier/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,158 +207,151 @@ def _csv_crd_validation(self, customresourcedefinitions, bundleData):
except KeyError:
pass

if "owned" not in customresourcedefinitions:
self._log_error("spec.customresourcedefinitions.owned"
"not defined for csv")
return False

for csvOwnedCrd in customresourcedefinitions["owned"]:
if "name" not in csvOwnedCrd:
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

# Values of name, version and kind above are compared with their
# values in the associated CRD files later. Empty string check
# is not needed.
# displayName and description should be checked for empty
# strings.
if "displayName" not in csvOwnedCrd:
self._log_error("displayName not defined for item in "
"spec.customresourcedefinitions.")
valid = False
elif not csvOwnedCrd["displayName"]:
self._log_error("displayName is empty for item in "
"spec.customresourcedefinitions.")
valid = False
if "description" not in csvOwnedCrd:
self._log_error("description not defined for item in "
"spec.customresourcedefinitions.")
valid = False
elif not csvOwnedCrd["description"]:
self._log_error("description is empty for item in "
"spec.customresourcedefinitions.")
valid = False

if "specDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
if self._csv_descriptors_validation(
csvOwnedCrd["specDescriptors"],
csvOwnedCrd["name"]) is False:
if "owned" in customresourcedefinitions:
for csvOwnedCrd in customresourcedefinitions["owned"]:
if "name" not in csvOwnedCrd:
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 "statusDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
if self._csv_descriptors_validation(
csvOwnedCrd["statusDescriptors"],
csvOwnedCrd["name"]) is 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

if "actionDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
if self._csv_descriptors_validation(
csvOwnedCrd["actionDescriptors"],
csvOwnedCrd["name"]) is False:
# Values of name, version and kind above are compared with their
# values in the associated CRD files later. Empty string check
# is not needed.
# displayName and description should be checked for empty
# strings.
if "displayName" not in csvOwnedCrd:
self._log_error("displayName not defined for item in "
"spec.customresourcedefinitions.")
valid = False
elif not csvOwnedCrd["displayName"]:
self._log_error("displayName is empty for item in "
"spec.customresourcedefinitions.")
valid = False
if "description" not in csvOwnedCrd:
self._log_error("description not defined for item in "
"spec.customresourcedefinitions.")
valid = False
elif not csvOwnedCrd["description"]:
self._log_error("description is empty 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:
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 "specDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
if self._csv_descriptors_validation(
csvOwnedCrd["specDescriptors"],
csvOwnedCrd["name"]) is False:
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 "statusDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
if self._csv_descriptors_validation(
csvOwnedCrd["statusDescriptors"],
csvOwnedCrd["name"]) is False:
valid = False

if "actionDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
if self._csv_descriptors_validation(
csvOwnedCrd["actionDescriptors"],
csvOwnedCrd["name"]) is False:
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")
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:
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_asd_validation(self, apiservicedefinitions):
valid = True

if "owned" not in apiservicedefinitions:
self._log_error("spec.apiservicedefinitions.owned"
"not defined for csv")
return False

# required attributes of owned apiservicedefinitions
attributeList = ["group", "version", "kind", "name", "deploymentName",
"displayName", "description"]

# validate the owned apiservicedefinitions
def validate_owned(resource, attribute):
if attribute not in resource:
self._log_error(
"%s not defined for item in spec.apiservicedefinitions." % attribute)
return False
elif not resource[attribute]:
self._log_error("%s is empty for item in "
"spec.apiservicedefinitions." % attribute)
return False
return True
if "owned" in apiservicedefinitions:
# required attributes of owned apiservicedefinitions
attributeList = ["group", "version", "kind", "name", "deploymentName",
"displayName", "description"]

for csvOwnedAsd in apiservicedefinitions["owned"]:
for attr in attributeList:
if validate_owned(csvOwnedAsd, attr) is False:
valid = False
# validate the owned apiservicedefinitions
def validate_owned(resource, attribute):
if attribute not in resource:
self._log_error(
"%s not defined for item in spec.apiservicedefinitions."
% attribute)
return False
elif not resource[attribute]:
self._log_error("%s is empty for item in "
"spec.apiservicedefinitions." % attribute)
return False
return True

for csvOwnedAsd in apiservicedefinitions["owned"]:
for attr in attributeList:
if validate_owned(csvOwnedAsd, attr) is False:
valid = False

if "specDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
if self._csv_descriptors_validation(
csvOwnedAsd["specDescriptors"],
csvOwnedAsd["name"]) is False:
valid = False
if "specDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
if self._csv_descriptors_validation(
csvOwnedAsd["specDescriptors"],
csvOwnedAsd["name"]) is False:
valid = False

if "statusDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
if self._csv_descriptors_validation(
csvOwnedAsd["statusDescriptors"],
csvOwnedAsd["name"]) is False:
valid = False
if "statusDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
if self._csv_descriptors_validation(
csvOwnedAsd["statusDescriptors"],
csvOwnedAsd["name"]) is False:
valid = False

if "actionDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
if self._csv_descriptors_validation(
csvOwnedAsd["actionDescriptors"],
csvOwnedAsd["name"]) is False:
valid = False
if "actionDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
if self._csv_descriptors_validation(
csvOwnedAsd["actionDescriptors"],
csvOwnedAsd["name"]) is False:
valid = False

return valid

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ metadata:
name: dynatrace-monitoring.v0.2.0
namespace: "placeholder"
spec:
apiservicedefinitions:
owned: {}
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: Dyantrace OneAgent monitoring agent
Expand Down

0 comments on commit 983e781

Please sign in to comment.