Skip to content

Commit

Permalink
Merge pull request #198 from kevinrizza/no-crds
Browse files Browse the repository at this point in the history
Allow csv spec.customresourcedefinitions to be null
  • Loading branch information
kevinrizza committed Nov 9, 2020
2 parents 1bff2f1 + f07552c commit 6c692d5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 132 deletions.
133 changes: 65 additions & 68 deletions operatorcourier/validate.py
Expand Up @@ -269,76 +269,73 @@ def _csv_spec_validation(self, spec, 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
if customresourcedefinitions is not None:
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

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 'versions' in crd['spec']:
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']:
validCrdVersions[csvOwnedCrd['name']].append(
csvOwnedCrd['version'] == crd['spec']['version']
)
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 '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
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 'versions' in crd['spec']:
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']:
validCrdVersions[csvOwnedCrd['name']].append(
csvOwnedCrd['version'] == crd['spec']['version']
)

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

for name, validVersions in validCrdVersions.items():
# most likely we will have just one version per CRD; should we
Expand Down

This file was deleted.

Expand Up @@ -136,51 +136,4 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
customresourcedefinitions:
owned:
- name: etcdclusters.etcd.database.coreos.com
version: v1beta2
kind: EtcdCluster
displayName: etcd Cluster
description: Represents a cluster of etcd nodes.
resources:
- kind: Service
version: v1
- kind: Pod
version: v1
specDescriptors:
- description: The desired number of member Pods for the etcd cluster.
displayName: Size
path: size
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:podCount'
statusDescriptors:
- description: The status of each of the member Pods for the etcd cluster.
displayName: Member Status
path: members
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:podStatuses'
- description: The service at which the running etcd cluster can be accessed.
displayName: Service
path: service
x-descriptors:
- 'urn:alm:descriptor:io.kubernetes:Service'
- description: The current size of the etcd cluster.
displayName: Cluster Size
path: size
- description: The current version of the etcd cluster.
displayName: Current Version
path: currentVersion
- description: 'The target version of the etcd cluster, after upgrading.'
displayName: Target Version
path: targetVersion
- description: The current status of the etcd cluster.
displayName: Status
path: phase
x-descriptors:
- 'urn:alm:descriptor:io.kubernetes.phase'
- description: Explanation for the current status of the cluster.
displayName: Status Details
path: reason
x-descriptors:
- 'urn:alm:descriptor:io.kubernetes.phase:reason'
customresourcedefinitions: {}
Expand Up @@ -320,6 +320,7 @@ data:
- key: tls.key
path: apiserver.key
secretName: v1beta1.servicecatalog.k8s.io-cert
customresourcedefinitions:
apiservicedefinitions:
owned:
- group: servicecatalog.k8s.io
Expand Down

0 comments on commit 6c692d5

Please sign in to comment.