Skip to content

Commit

Permalink
Merge pull request #189 from tiraboschi/fix_188
Browse files Browse the repository at this point in the history
Correctly validate crd.spec.versions
  • Loading branch information
kevinrizza authored Jul 20, 2020
2 parents 347ca21 + 6183101 commit fa7b1bf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
56 changes: 50 additions & 6 deletions operatorcourier/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,52 @@ def _crd_validation(self, bundle):
if "group" not in crd['spec']:
self._log_error("crd spec.group 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")
if (
"versions" not in crd['spec'] and
"version" not in crd['spec']
):
self._log_error(
"crd spec.version or spec.versions not defined."
)
valid = False
if "versions" in crd['spec']:
if not len(crd['spec']['versions']) > 0:
self._log_error("crd spec.versions is empty.")
valid = False

else:
for ver in crd['spec']['versions']:
if (
"name" not in ver or
"served" not in ver or
"storage" not in ver
):
self._log_error(
"crd spec.versions contains an invalid "
"CustomResourceDefinitionVersion."
)
valid = False
if "version" in crd['spec']:
if (
"name" in crd['spec']['version'][0] and
crd['spec']['version'][0]['name'] !=
crd['spec']['version']
):
self._log_error(
"crd spec.version and spec.versions are "
"defined but spec.versions[0].name "
"doesn't match spec.version."
)
valid = False
storage_version_list = [
v for v in crd['spec']['versions']
if "storage" in v and v['storage'] is True
]
if len(storage_version_list) != 1:
self._log_error(
"crd spec.version should contain exactly "
"one version flagged as storage version."
)
valid = False
return valid

def _csv_validation(self, bundle):
Expand Down Expand Up @@ -273,8 +314,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'
if csvOwnedCrd['version'] not in [
v['name'] for v in crd['spec']['versions']
if 'name' in v
]:
self._log_error('CSV.spec.crd.owned.version is '
'not in CRD.spec.versions list')
valid = False
if 'version' in crd['spec']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ data:
- packages
type: object
versions:
- v1beta1
- name: v1beta1
served: true
storage: true
- apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,12 @@ data:
- packages
type: object
versions:
- v1alpha1
- v1beta1
- name: v1beta1
served: true
storage: true
- name: v1alpha1
served: true
storage: false
- apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down

0 comments on commit fa7b1bf

Please sign in to comment.