Skip to content

Commit ce2b3b0

Browse files
authored
Merge pull request #194 from fromanirh/bz1869525
courier: fix validation with multiple CRD versions
2 parents 79098c6 + 9c475e6 commit ce2b3b0

File tree

3 files changed

+394
-5
lines changed

3 files changed

+394
-5
lines changed

operatorcourier/validate.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import collections
12
import logging
23
import json
34
import semver
@@ -238,7 +239,7 @@ def _csv_validation(self, bundle):
238239

239240
def _csv_spec_validation(self, spec, bundleData):
240241
valid = True
241-
242+
validCrdVersions = collections.defaultdict(list)
242243
warnSpecList = ["displayName", "description", "icon",
243244
"version", "provider", "maturity"]
244245

@@ -322,10 +323,9 @@ def _csv_spec_validation(self, spec, bundleData):
322323
'not in CRD.spec.versions list')
323324
valid = False
324325
if 'version' in crd['spec']:
325-
if csvOwnedCrd['version'] != crd['spec']['version']:
326-
self._log_error('CRD.spec.version does not match '
327-
'CSV.spec.crd.owned.version')
328-
valid = False
326+
validCrdVersions[csvOwnedCrd['name']].append(
327+
csvOwnedCrd['version'] == crd['spec']['version']
328+
)
329329

330330
if 'name' in csvOwnedCrd:
331331
if 'spec' in crd:
@@ -339,6 +339,15 @@ def _csv_spec_validation(self, spec, bundleData):
339339
"match "
340340
"CSV.spec.crd.owned.name")
341341
valid = False
342+
343+
for name, validVersions in validCrdVersions.items():
344+
# most likely we will have just one version per CRD; should we
345+
# have more than one single version, it is sufficient that just
346+
# one, usually the latest, matches.
347+
if not any(validVersions):
348+
self._log_error('CRD.spec.version does not match '
349+
'CSV.spec.crd.owned.version')
350+
valid = False
342351
return valid
343352

344353
def _csv_spec_install_validation(self, install):

0 commit comments

Comments
 (0)