Skip to content

Commit 983e781

Browse files
committed
Remove owned requirement
1 parent 07c881a commit 983e781

File tree

2 files changed

+127
-135
lines changed

2 files changed

+127
-135
lines changed

operatorcourier/validate.py

Lines changed: 126 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -207,158 +207,151 @@ def _csv_crd_validation(self, customresourcedefinitions, bundleData):
207207
except KeyError:
208208
pass
209209

210-
if "owned" not in customresourcedefinitions:
211-
self._log_error("spec.customresourcedefinitions.owned"
212-
"not defined for csv")
213-
return False
214-
215-
for csvOwnedCrd in customresourcedefinitions["owned"]:
216-
if "name" not in csvOwnedCrd:
217-
self._log_error("name not defined for item in "
218-
"spec.customresourcedefinitions.")
219-
valid = False
220-
elif csvOwnedCrd["name"] not in crdList:
221-
self._log_error("custom resource definition %s referenced in csv "
222-
"not defined in root list of crds",
223-
csvOwnedCrd["name"])
224-
valid = False
225-
226-
if "kind" not in csvOwnedCrd:
227-
self._log_error("kind not defined for item in "
228-
"spec.customresourcedefinitions.")
229-
valid = False
230-
if "version" not in csvOwnedCrd:
231-
self._log_error("version not defined for item in "
232-
"spec.customresourcedefinitions.")
233-
valid = False
234-
235-
# Values of name, version and kind above are compared with their
236-
# values in the associated CRD files later. Empty string check
237-
# is not needed.
238-
# displayName and description should be checked for empty
239-
# strings.
240-
if "displayName" not in csvOwnedCrd:
241-
self._log_error("displayName not defined for item in "
242-
"spec.customresourcedefinitions.")
243-
valid = False
244-
elif not csvOwnedCrd["displayName"]:
245-
self._log_error("displayName is empty for item in "
246-
"spec.customresourcedefinitions.")
247-
valid = False
248-
if "description" not in csvOwnedCrd:
249-
self._log_error("description not defined for item in "
250-
"spec.customresourcedefinitions.")
251-
valid = False
252-
elif not csvOwnedCrd["description"]:
253-
self._log_error("description is empty for item in "
254-
"spec.customresourcedefinitions.")
255-
valid = False
256-
257-
if "specDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
258-
if self._csv_descriptors_validation(
259-
csvOwnedCrd["specDescriptors"],
260-
csvOwnedCrd["name"]) is False:
210+
if "owned" in customresourcedefinitions:
211+
for csvOwnedCrd in customresourcedefinitions["owned"]:
212+
if "name" not in csvOwnedCrd:
213+
self._log_error("name not defined for item in "
214+
"spec.customresourcedefinitions.")
215+
valid = False
216+
elif csvOwnedCrd["name"] not in crdList:
217+
self._log_error("custom resource definition %s referenced in csv "
218+
"not defined in root list of crds",
219+
csvOwnedCrd["name"])
261220
valid = False
262221

263-
if "statusDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
264-
if self._csv_descriptors_validation(
265-
csvOwnedCrd["statusDescriptors"],
266-
csvOwnedCrd["name"]) is False:
222+
if "kind" not in csvOwnedCrd:
223+
self._log_error("kind not defined for item in "
224+
"spec.customresourcedefinitions.")
225+
valid = False
226+
if "version" not in csvOwnedCrd:
227+
self._log_error("version not defined for item in "
228+
"spec.customresourcedefinitions.")
267229
valid = False
268230

269-
if "actionDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
270-
if self._csv_descriptors_validation(
271-
csvOwnedCrd["actionDescriptors"],
272-
csvOwnedCrd["name"]) is False:
231+
# Values of name, version and kind above are compared with their
232+
# values in the associated CRD files later. Empty string check
233+
# is not needed.
234+
# displayName and description should be checked for empty
235+
# strings.
236+
if "displayName" not in csvOwnedCrd:
237+
self._log_error("displayName not defined for item in "
238+
"spec.customresourcedefinitions.")
239+
valid = False
240+
elif not csvOwnedCrd["displayName"]:
241+
self._log_error("displayName is empty for item in "
242+
"spec.customresourcedefinitions.")
243+
valid = False
244+
if "description" not in csvOwnedCrd:
245+
self._log_error("description not defined for item in "
246+
"spec.customresourcedefinitions.")
247+
valid = False
248+
elif not csvOwnedCrd["description"]:
249+
self._log_error("description is empty for item in "
250+
"spec.customresourcedefinitions.")
273251
valid = False
274252

275-
for crd in bundleData[self.crdKey]:
276-
if 'name' not in csvOwnedCrd:
277-
continue
278-
if 'metadata' not in crd or 'name' not in crd['metadata']:
279-
continue
280-
if csvOwnedCrd['name'] != crd['metadata']['name']:
281-
continue
282-
283-
if 'kind' in csvOwnedCrd:
284-
if 'spec' in crd:
285-
if 'names' in crd['spec']:
286-
if 'kind' in crd['spec']['names']:
287-
if csvOwnedCrd['kind'] != \
288-
crd['spec']['names']['kind']:
289-
self._log_error('CRD.spec.names.kind does not '
290-
'match CSV.spec.crd.owned.kind')
291-
valid = False
253+
if "specDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
254+
if self._csv_descriptors_validation(
255+
csvOwnedCrd["specDescriptors"],
256+
csvOwnedCrd["name"]) is False:
257+
valid = False
292258

293-
if 'version' in csvOwnedCrd:
294-
if 'spec' in crd:
295-
if 'version' in crd['spec']:
296-
if csvOwnedCrd['version'] != crd['spec']['version']:
297-
self._log_error('CRD.spec.version does not match '
298-
'CSV.spec.crd.owned.version')
299-
valid = False
259+
if "statusDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
260+
if self._csv_descriptors_validation(
261+
csvOwnedCrd["statusDescriptors"],
262+
csvOwnedCrd["name"]) is False:
263+
valid = False
264+
265+
if "actionDescriptors" in csvOwnedCrd and "name" in csvOwnedCrd:
266+
if self._csv_descriptors_validation(
267+
csvOwnedCrd["actionDescriptors"],
268+
csvOwnedCrd["name"]) is False:
269+
valid = False
300270

301-
if 'name' in csvOwnedCrd:
302-
if 'spec' in crd:
303-
if 'names' in crd['spec'] and 'group' in crd['spec']:
304-
if 'plural' in crd['spec']['names']:
305-
if csvOwnedCrd['name'] != \
306-
crd['spec']['names']['plural'] + '.' + \
307-
crd['spec']['group']:
308-
self._log_error("`CRD.spec.names.plural`."
309-
"`CRD.spec.group` does not "
310-
"match "
311-
"CSV.spec.crd.owned.name")
271+
for crd in bundleData[self.crdKey]:
272+
if 'name' not in csvOwnedCrd:
273+
continue
274+
if 'metadata' not in crd or 'name' not in crd['metadata']:
275+
continue
276+
if csvOwnedCrd['name'] != crd['metadata']['name']:
277+
continue
278+
279+
if 'kind' in csvOwnedCrd:
280+
if 'spec' in crd:
281+
if 'names' in crd['spec']:
282+
if 'kind' in crd['spec']['names']:
283+
if csvOwnedCrd['kind'] != \
284+
crd['spec']['names']['kind']:
285+
self._log_error('CRD.spec.names.kind does not '
286+
'match CSV.spec.crd.owned.kind')
287+
valid = False
288+
289+
if 'version' in csvOwnedCrd:
290+
if 'spec' in crd:
291+
if 'version' in crd['spec']:
292+
if csvOwnedCrd['version'] != crd['spec']['version']:
293+
self._log_error('CRD.spec.version does not match '
294+
'CSV.spec.crd.owned.version')
312295
valid = False
313296

297+
if 'name' in csvOwnedCrd:
298+
if 'spec' in crd:
299+
if 'names' in crd['spec'] and 'group' in crd['spec']:
300+
if 'plural' in crd['spec']['names']:
301+
if csvOwnedCrd['name'] != \
302+
crd['spec']['names']['plural'] + '.' + \
303+
crd['spec']['group']:
304+
self._log_error("`CRD.spec.names.plural`."
305+
"`CRD.spec.group` does not "
306+
"match "
307+
"CSV.spec.crd.owned.name")
308+
valid = False
309+
314310
return valid
315311

316312
def _csv_asd_validation(self, apiservicedefinitions):
317313
valid = True
318314

319-
if "owned" not in apiservicedefinitions:
320-
self._log_error("spec.apiservicedefinitions.owned"
321-
"not defined for csv")
322-
return False
323-
324-
# required attributes of owned apiservicedefinitions
325-
attributeList = ["group", "version", "kind", "name", "deploymentName",
326-
"displayName", "description"]
327-
328-
# validate the owned apiservicedefinitions
329-
def validate_owned(resource, attribute):
330-
if attribute not in resource:
331-
self._log_error(
332-
"%s not defined for item in spec.apiservicedefinitions." % attribute)
333-
return False
334-
elif not resource[attribute]:
335-
self._log_error("%s is empty for item in "
336-
"spec.apiservicedefinitions." % attribute)
337-
return False
338-
return True
315+
if "owned" in apiservicedefinitions:
316+
# required attributes of owned apiservicedefinitions
317+
attributeList = ["group", "version", "kind", "name", "deploymentName",
318+
"displayName", "description"]
339319

340-
for csvOwnedAsd in apiservicedefinitions["owned"]:
341-
for attr in attributeList:
342-
if validate_owned(csvOwnedAsd, attr) is False:
343-
valid = False
320+
# validate the owned apiservicedefinitions
321+
def validate_owned(resource, attribute):
322+
if attribute not in resource:
323+
self._log_error(
324+
"%s not defined for item in spec.apiservicedefinitions."
325+
% attribute)
326+
return False
327+
elif not resource[attribute]:
328+
self._log_error("%s is empty for item in "
329+
"spec.apiservicedefinitions." % attribute)
330+
return False
331+
return True
332+
333+
for csvOwnedAsd in apiservicedefinitions["owned"]:
334+
for attr in attributeList:
335+
if validate_owned(csvOwnedAsd, attr) is False:
336+
valid = False
344337

345-
if "specDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
346-
if self._csv_descriptors_validation(
347-
csvOwnedAsd["specDescriptors"],
348-
csvOwnedAsd["name"]) is False:
349-
valid = False
338+
if "specDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
339+
if self._csv_descriptors_validation(
340+
csvOwnedAsd["specDescriptors"],
341+
csvOwnedAsd["name"]) is False:
342+
valid = False
350343

351-
if "statusDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
352-
if self._csv_descriptors_validation(
353-
csvOwnedAsd["statusDescriptors"],
354-
csvOwnedAsd["name"]) is False:
355-
valid = False
344+
if "statusDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
345+
if self._csv_descriptors_validation(
346+
csvOwnedAsd["statusDescriptors"],
347+
csvOwnedAsd["name"]) is False:
348+
valid = False
356349

357-
if "actionDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
358-
if self._csv_descriptors_validation(
359-
csvOwnedAsd["actionDescriptors"],
360-
csvOwnedAsd["name"]) is False:
361-
valid = False
350+
if "actionDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
351+
if self._csv_descriptors_validation(
352+
csvOwnedAsd["actionDescriptors"],
353+
csvOwnedAsd["name"]) is False:
354+
valid = False
362355

363356
return valid
364357

tests/test_files/yaml_source_dir/valid_yamls_with_single_crd/dynatrace-monitoring.v0.2.0.clusterserviceversion.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ metadata:
3838
name: dynatrace-monitoring.v0.2.0
3939
namespace: "placeholder"
4040
spec:
41-
apiservicedefinitions:
42-
owned: {}
41+
apiservicedefinitions: {}
4342
customresourcedefinitions:
4443
owned:
4544
- description: Dyantrace OneAgent monitoring agent

0 commit comments

Comments
 (0)