From 25af109b1a25a74ab805e489be9981ee413ada9a Mon Sep 17 00:00:00 2001 From: Wenlin Huang Date: Tue, 12 Mar 2019 11:49:50 -0400 Subject: [PATCH] Check presence and match of fields in CRD and CSV in bundle - Check if the following fields in CRD matches that in CSV in bundle - `CRD.spec.names.plural`.`CRD.spec.group` == `CSV.spec.crd.owned.name` - `CRD.spec.names.kind` == `CSV.spec.crd.owned.kind` - `CRD.spec.version` == `CSV.spec.crd.owned.version` - Check the presence of all above fields in the bundle --- operatorcourier/validate.py | 102 ++++-- .../crdmissingkindfield.invalid.bundle.yaml | 301 +++++++++++++++++ .../crdmissingpluralfield.invalid.bundle.yaml | 301 +++++++++++++++++ ...crdmissingversionfield.invalid.bundle.yaml | 301 +++++++++++++++++ .../csvcrdfieldmismatch1.invalid.bundle.yaml | 302 +++++++++++++++++ .../csvcrdfieldmismatch2.invalid.bundle.yaml | 302 +++++++++++++++++ .../csvcrdfieldmismatch3.invalid.bundle.yaml | 303 ++++++++++++++++++ .../csvmissingkindfield.invalid.bundle.yaml | 301 +++++++++++++++++ .../csvmissingnamefield.invalid.bundle.yaml | 301 +++++++++++++++++ ...csvmissingversionfield.invalid.bundle.yaml | 301 +++++++++++++++++ tests/test_validate.py | 56 ++++ 11 files changed, 2840 insertions(+), 31 deletions(-) create mode 100644 tests/test_files/bundles/verification/crdmissingkindfield.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/crdmissingpluralfield.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/crdmissingversionfield.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/csvcrdfieldmismatch1.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/csvcrdfieldmismatch2.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/csvcrdfieldmismatch3.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/csvmissingkindfield.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/csvmissingnamefield.invalid.bundle.yaml create mode 100644 tests/test_files/bundles/verification/csvmissingversionfield.invalid.bundle.yaml diff --git a/operatorcourier/validate.py b/operatorcourier/validate.py index 49b9145..c3d0589 100644 --- a/operatorcourier/validate.py +++ b/operatorcourier/validate.py @@ -18,6 +18,14 @@ class ValidateCmd(): crdKey = "customResourceDefinitions" csvKey = "clusterServiceVersions" pkgsKey = "packages" + crd_required_nested_fields = [ + 'metadata.name', + 'apiVersion', + 'spec.names.kind', + 'spec.names.plural', + 'spec.group', + 'spec.version', + ] def __init__(self, ui_validate_io=False): self.ui_validate_io = ui_validate_io @@ -85,30 +93,27 @@ def _bundle_validation(self, bundle): def _crd_validation(self, bundleData): logger.info("Validating custom resource definitions.") - valid = True - crds = bundleData[self.crdKey] + valid = True for crd in crds: - if "metadata" in crd: - if "name" in crd["metadata"]: - logger.info("Evaluating crd %s", crd["metadata"]["name"]) - else: - self._log_error("crd metadata.name not defined.") - valid = False - else: - self._log_error("crd metadata not defined.") - valid = False - - if "apiVersion" not in crd: - self._log_error("crd apiVersion not defined.") - valid = False + for crd_required_nested_field in self.crd_required_nested_fields: + valid = valid and self._crd_fields_validation( + crd_required_nested_field.split('.'), crd, "") + return valid - if "spec" not in crd: - self._log_error("crd spec not defined.") - valid = False + def _crd_fields_validation(self, fields, yaml_dict, prefix): + if len(fields) == 0: + return True + root_field, subfields = fields[0], fields[1:] + field_string = root_field if prefix == "" else prefix + "." + root_field - return valid + if root_field == 'metadata' and 'name' in yaml_dict['metadata']: + logging.info("Evaluating crd %s", yaml_dict['metadata']['name']) + if root_field not in yaml_dict: + self._log_error("crd field %s not defined.", field_string) + return False + return self._crd_fields_validation(subfields, yaml_dict[root_field], field_string) def _csv_validation(self, bundleData): valid = True @@ -167,20 +172,55 @@ def _csv_spec_validation(self, spec, bundleData): pass if "owned" not in customresourcedefinitions: - self._log_error("spec.customresourcedefinitions.owned" + self._log_error("spec.customresourcedefinitions.owned " "not defined for csv") - valid = False - else: - for crd in customresourcedefinitions["owned"]: - if "name" not in crd: - self._log_error("name not defined for item in " - "spec.customresourcedefinitions.") - valid = False - else: - if crd["name"] not in crdList: - self._log_error("custom resource definition referenced " - "in csv not defined in root list of crds") + 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 + + for crd in bundleData[self.crdKey]: + if 'name' not in csvOwnedCrd or not \ + self._crd_fields_validation(['metadata', 'name'], crd, '') \ + or csvOwnedCrd['name'] != crd['metadata']['name']: + continue + if 'kind' in csvOwnedCrd and \ + self._crd_fields_validation(['spec', 'names', 'kind'], crd, '') \ + and 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 and \ + self._crd_fields_validation(['spec', 'version'], crd, '') and \ + 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 and \ + self._crd_fields_validation(['spec', 'names', 'plural'], crd, '')\ + and self._crd_fields_validation(['spec', 'group'], crd, '') \ + and 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_metadata_validation(self, metadata): diff --git a/tests/test_files/bundles/verification/crdmissingkindfield.invalid.bundle.yaml b/tests/test_files/bundles/verification/crdmissingkindfield.invalid.bundle.yaml new file mode 100644 index 0000000..fe01fd6 --- /dev/null +++ b/tests/test_files/bundles/verification/crdmissingkindfield.invalid.bundle.yaml @@ -0,0 +1,301 @@ +# CRD.spec.names.kind in one of the CRDs is missing in this file +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha1 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/crdmissingpluralfield.invalid.bundle.yaml b/tests/test_files/bundles/verification/crdmissingpluralfield.invalid.bundle.yaml new file mode 100644 index 0000000..2594c61 --- /dev/null +++ b/tests/test_files/bundles/verification/crdmissingpluralfield.invalid.bundle.yaml @@ -0,0 +1,301 @@ +# CRD.spec.names.plural in one of the CRDs is missing in this file +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha1 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/crdmissingversionfield.invalid.bundle.yaml b/tests/test_files/bundles/verification/crdmissingversionfield.invalid.bundle.yaml new file mode 100644 index 0000000..d01b1b5 --- /dev/null +++ b/tests/test_files/bundles/verification/crdmissingversionfield.invalid.bundle.yaml @@ -0,0 +1,301 @@ +# CRD.spec.version in one of the CRDs is missing in this file +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/csvcrdfieldmismatch1.invalid.bundle.yaml b/tests/test_files/bundles/verification/csvcrdfieldmismatch1.invalid.bundle.yaml new file mode 100644 index 0000000..383af5a --- /dev/null +++ b/tests/test_files/bundles/verification/csvcrdfieldmismatch1.invalid.bundle.yaml @@ -0,0 +1,302 @@ +# CSV.spec.crd.owned.kind (OperatorSource) does not match the corresponding CRD.spec.names.kind (OperatorSourceXXX) +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSourceXXX + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha1 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/csvcrdfieldmismatch2.invalid.bundle.yaml b/tests/test_files/bundles/verification/csvcrdfieldmismatch2.invalid.bundle.yaml new file mode 100644 index 0000000..158be3a --- /dev/null +++ b/tests/test_files/bundles/verification/csvcrdfieldmismatch2.invalid.bundle.yaml @@ -0,0 +1,302 @@ +# In OperatorSource, the CSV.spec.crd.owned.version (v1alpha1) does not match CRD.spec.names.version (v1alpha2) +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha2 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/csvcrdfieldmismatch3.invalid.bundle.yaml b/tests/test_files/bundles/verification/csvcrdfieldmismatch3.invalid.bundle.yaml new file mode 100644 index 0000000..913fda3 --- /dev/null +++ b/tests/test_files/bundles/verification/csvcrdfieldmismatch3.invalid.bundle.yaml @@ -0,0 +1,303 @@ +# In OperatorSourceConfig, `CRD.spec.names.plural`.`CRD.spec.group` (catalogsourceconfigsX.marketplace.redhat.com) +# does not match CSV.spec.crd.owned.name (catalogsourceconfigs.marketplace.redhat.com) +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigsX + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha1 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/csvmissingkindfield.invalid.bundle.yaml b/tests/test_files/bundles/verification/csvmissingkindfield.invalid.bundle.yaml new file mode 100644 index 0000000..dab3c24 --- /dev/null +++ b/tests/test_files/bundles/verification/csvmissingkindfield.invalid.bundle.yaml @@ -0,0 +1,301 @@ +# CSV.spec.crd.owned.kind in one of the owned CRDs is missing in this file +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha1 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/csvmissingnamefield.invalid.bundle.yaml b/tests/test_files/bundles/verification/csvmissingnamefield.invalid.bundle.yaml new file mode 100644 index 0000000..2e4f643 --- /dev/null +++ b/tests/test_files/bundles/verification/csvmissingnamefield.invalid.bundle.yaml @@ -0,0 +1,301 @@ +# CSV.spec.crd.owned.name in one of the owned CRDs is missing in this file +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha1 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_files/bundles/verification/csvmissingversionfield.invalid.bundle.yaml b/tests/test_files/bundles/verification/csvmissingversionfield.invalid.bundle.yaml new file mode 100644 index 0000000..90539d7 --- /dev/null +++ b/tests/test_files/bundles/verification/csvmissingversionfield.invalid.bundle.yaml @@ -0,0 +1,301 @@ +# CSV.spec.crd.owned.version in one of the owned CRDs is missing in this file +data: + clusterServiceVersions: | + - apiVersion: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + metadata: + annotations: + alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"","awsSecret":""}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":[""],"storageType":"S3","s3":{"path":"","awsSecret":""}}}]' + categories: openshift required + certified: 'true' + containerImage: quay.io/openshift/origin-operator-marketplace:latest + createdAt: 2019/11/15 + description: An operator to run the OpenShift marketplace + healthIndex: B + repository: https://github.com/operator-framework/operator-marketplace + support: Red Hat + name: marketplace-operator.v0.0.1 + namespace: placeholder + spec: + customresourcedefinitions: + owned: + - description: Represents an OperatorSource. + displayName: Operator Source + kind: OperatorSource + name: operatorsources.marketplace.redhat.com + specDescriptors: + - description: The type of the operator source. + displayName: Type + path: type + - description: Points to the remote app registry server from where operator + manifests can be fetched. + displayName: Endpoint + path: endpoint + - description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + displayName: Registry Namespace + path: registryNamespace + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + - description: Represents a CatalogSourceConfig object which is used to configure + a CatalogSource. + displayName: Catalog Source Config + kind: CatalogSourceConfig + name: catalogsourceconfigs.marketplace.redhat.com + specDescriptors: + - description: The namespace where the operators will be enabled. + displayName: Target Namespace + path: targetNamespace + - description: List of operator(s) which will be enabled in the target namespace + displayName: Packages + path: packages + statusDescriptors: + - description: Current status of the CatalogSourceConfig + displayName: Current Phase Name + path: currentPhase.phase.name + - description: Message associated with the current status + displayName: Current Phase Message + path: currentPhase.phase.message + version: v1alpha1 + description: Marketplace is a gateway for users to consume off-cluster Operators + which will include Red Hat, ISV, optional OpenShift and community content. + displayName: marketplace-operator + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - marketplace.redhat.com + resources: + - '*' + verbs: + - '*' + - apiGroups: + - '' + resources: + - services + - configmaps + verbs: + - '*' + - apiGroups: + - operators.coreos.com + resources: + - catalogsources + verbs: + - '*' + serviceAccountName: marketplace-operator + deployments: + - name: marketplace-operator + spec: + replicas: 1 + selector: + matchLabels: + name: marketplace-operator + template: + metadata: + labels: + name: marketplace-operator + name: marketplace-operator + spec: + containers: + - command: + - marketplace-operator + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: OPERATOR_NAME + value: marketplace-operator + image: quay.io/openshift/origin-operator-marketplace:latest + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /healthz + port: 8080 + name: marketplace-operator + ports: + - containerPort: 60000 + name: metrics + - containerPort: 8080 + name: healthz + readinessProbe: + httpGet: + path: /healthz + port: 8080 + serviceAccountName: marketplace-operator + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - marketplace + - catalog + - olm + - admin + labels: + name: marketplace-operator + links: + - name: Markplace Operator Source Code + url: https://github.com/operator-framework/operator-marketplace + maintainers: + - email: aos-marketplace@redhat.com + name: AOS Marketplace Team + maturity: alpha + provider: + name: Red Hat + selector: + matchLabels: + name: marketplace-operator + version: 0.0.1 + customResourceDefinitions: | + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents a CatalogSourceConfig. + displayName: Catalog Source Config + name: catalogsourceconfigs.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.targetNamespace + description: The namespace where the operators will be enabled + name: TargetNamespace + type: string + - JSONPath: .spec.packages + description: List of operator(s) which will be enabled in the target namespace + name: Packages + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the CatalogSourceConfig + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: CatalogSourceConfig + listKind: CatalogSourceConfigList + plural: catalogsourceconfigs + shortNames: + - csc + singular: catalogsourceconfig + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for a CatalogSourceConfig + properties: + packages: + description: Comma separated list of operator(s) without spaces + which will be enabled in the target namespace + type: string + targetNamespace: + description: The namespace where the operators will be enabled + type: string + required: + - targetNamespace + - packages + type: object + version: v1alpha1 + - apiVersion: apiextensions.k8s.io/v1beta1 + kind: CustomResourceDefinition + metadata: + annotations: + description: Represents an OperatorSource. + displayName: Operator Source + name: operatorsources.marketplace.redhat.com + spec: + additionalPrinterColumns: + - JSONPath: .spec.type + description: The type of the OperatorSource + name: Type + type: string + - JSONPath: .spec.endpoint + description: The endpoint of the OperatorSource + name: Endpoint + type: string + - JSONPath: .spec.registryNamespace + description: App registry namespace + name: Registry + type: string + - JSONPath: .spec.displayName + description: Display (pretty) name to indicate the OperatorSource's name + name: DisplayName + type: string + - JSONPath: .spec.publisher + description: Publisher of the OperatorSource + name: Publisher + type: string + - JSONPath: .status.currentPhase.phase.name + description: Current status of the OperatorSource + name: Status + type: string + - JSONPath: .status.currentPhase.phase.message + description: Message associated with the current status + name: Message + type: string + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: marketplace.redhat.com + names: + kind: OperatorSource + listKind: OperatorSourceList + plural: operatorsources + shortNames: + - opsrc + singular: operatorsource + scope: Namespaced + validation: + openAPIV3Schema: + properties: + spec: + description: Spec for an OperatorSource. + properties: + endpoint: + description: Points to the remote app registry server from where + operator manifests can be fetched. + type: string + registryNamespace: + description: 'The namespace in app registry. + + Only operator manifests under this namespace will be visible. + + Please note that this is not a k8s namespace.' + type: string + type: + description: The type of the OperatorSource + pattern: appregistry + type: string + required: + - type + - endpoint + - registryNamespace + type: object + version: v1alpha1 + packages: | + - channels: + - currentCSV: marketplace-operator.v0.0.1 + name: alpha + packageName: marketplace diff --git a/tests/test_validate.py b/tests/test_validate.py index 4212dca..f40fa71 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -2,6 +2,7 @@ import pytest from operatorcourier.validate import ValidateCmd from operatorcourier.format import unformat_bundle +from testfixtures import LogCapture @pytest.mark.parametrize('bundle,expected_validation_results_dict', [ @@ -55,3 +56,58 @@ def get_bundle(bundle): with open(bundle) as f: bundle = yaml.safe_load(f) return unformat_bundle(bundle) + + +@pytest.mark.parametrize('bundleFile,logInfo', [ + ('tests/test_files/bundles/verification/nopkg.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', 'Bundle does not contain any packages.')), + + ('tests/test_files/bundles/verification/crdmissingkindfield.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', 'crd field spec.names.kind not defined.')), + ('tests/test_files/bundles/verification/crdmissingpluralfield.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', 'crd field spec.names.plural not defined.')), + ('tests/test_files/bundles/verification/crdmissingversionfield.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', 'crd field spec.version not defined.')), + + ('tests/test_files/bundles/verification/csvmissingkindfield.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', + 'kind not defined for item in spec.customresourcedefinitions.')), + ('tests/test_files/bundles/verification/csvmissingnamefield.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', + 'name not defined for item in spec.customresourcedefinitions.')), + ('tests/test_files/bundles/verification/csvmissingversionfield.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', + 'version not defined for item in spec.customresourcedefinitions.')), +]) +def test_invalid_bundle_missing_fields(bundleFile, logInfo): + _test_invalid_bundle_with_log(bundleFile, logInfo) + + +@pytest.mark.parametrize('bundleFile,logInfo', [ + ('tests/test_files/bundles/verification/csvcrdfieldmismatch1.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', + 'CRD.spec.names.kind does not match CSV.spec.crd.owned.kind')), + ('tests/test_files/bundles/verification/csvcrdfieldmismatch2.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', + 'CRD.spec.version does not match CSV.spec.crd.owned.version')), + ('tests/test_files/bundles/verification/csvcrdfieldmismatch3.invalid.bundle.yaml', + ('operatorcourier.validate', 'ERROR', + '`CRD.spec.names.plural`.`CRD.spec.group` does not match CSV.spec.crd.owned.name')), +]) +def test_invalid_bundle_crd_csv_fields_mismatch(bundleFile, logInfo): + _test_invalid_bundle_with_log(bundleFile, logInfo) + + +def _test_invalid_bundle_with_log(bundleFile, logInfo): + with open(bundleFile) as f: + bundle = yaml.safe_load(f) + bundle = unformat_bundle(bundle) + module, level, message = logInfo[0], logInfo[1], logInfo[2] + with LogCapture() as logs: + valid, _ = ValidateCmd().validate(bundle) + assert not valid + + # check if the input log info is present among all logs captured + logs.check_present( + (module, level, message), + )