Skip to content

Commit e7f9dd8

Browse files
authored
Merge pull request #78 from galletti94/master
Adding categories check
2 parents 387956e + fafdae3 commit e7f9dd8

File tree

8 files changed

+44
-11
lines changed

8 files changed

+44
-11
lines changed

operatorcourier/validate.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,23 @@ def get_alm_kinds(alm_examples):
409409
def is_mediatype(mediatype):
410410
return mediatype in ["image/gif", "image/jpeg", "image/png", "image/svg+xml"]
411411

412+
def is_category(category):
413+
valid_categories = [
414+
"AI/Machine Learning",
415+
"Big Data",
416+
"Cloud Provider",
417+
"Database",
418+
"Integration & Delivery",
419+
"Logging & Tracing",
420+
"Monitoring",
421+
"Networking",
422+
"OpenShift Optional",
423+
"Security",
424+
"Storage",
425+
"Streaming & Messaging"
426+
]
427+
return category in valid_categories
428+
412429
valid = True
413430

414431
spec = csv["spec"]
@@ -518,4 +535,15 @@ def is_mediatype(mediatype):
518535
self._log_error("spec.icon should be a list")
519536
valid = False
520537

538+
# categories check
539+
if "categories" in annotations:
540+
categories = annotations["categories"].split(',')
541+
for category in categories:
542+
if not is_category(category.lstrip()):
543+
self._log_error(
544+
"category %s is not a valid category",
545+
category.lstrip()
546+
)
547+
valid = False
548+
521549
return valid

tests/test_files/bundles/verification/multiplepkgs.invalid.bundle.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ data:
4242
}
4343
4444
]
45-
categories: openshift required
4645
certified: 'true'
4746
containerImage: quay.io/openshift/origin-operator-marketplace:latest
4847
createdAt: 2019/11/15

tests/test_files/bundles/verification/nocrd.valid.bundle.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ data:
99
name: svcat.v0.1.34
1010
namespace: placeholder
1111
annotations:
12-
categories: "openshift optional, service catalog, osb, osbapi, broker, svcat"
12+
categories: "OpenShift Optional"
1313
certified: "false"
1414
description: Service Catalog lets you provision cloud services directly from the comfort of native Kubernetes tooling. This project is in incubation to bring integration with service brokers to the Kubernetes ecosystem via the Open Service Broker API.
1515
containerImage: quay.io/openshift/origin-service-catalog

tests/test_files/bundles/verification/noicon.valid.bundle.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ data:
3939
}
4040
4141
]
42-
categories: openshift required
4342
certified: 'true'
4443
containerImage: quay.io/openshift/origin-operator-marketplace:latest
4544
createdAt: 2019/11/15

tests/test_files/bundles/verification/nopkg.invalid.bundle.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ data:
55
metadata:
66
annotations:
77
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":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
8-
categories: openshift required
98
certified: 'true'
109
containerImage: quay.io/openshift/origin-operator-marketplace:latest
1110
createdAt: 2019/11/15

tests/test_files/bundles/verification/ui.invalid.bundle.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ data:
3939
}
4040
4141
]
42-
categories: openshift required
42+
categories: invalid
4343
certified: 'true'
4444
containerImage: quay.io/openshift/origin-operator-marketplace:latest
4545
createdAt: 2019/11/15
4646
description: An operator to run the OpenShift marketplace
47-
capabilities: Basic Install
47+
capabilities: invalid
4848
repository: https://github.com/operator-framework/operator-marketplace
4949
support: Red Hat
5050
name: marketplace-operator.v0.0.1

tests/test_files/bundles/verification/valid.bundle.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ data:
3939
}
4040
4141
]
42-
categories: openshift required
42+
categories: "Storage, Integration & Delivery"
4343
certified: 'true'
4444
containerImage: quay.io/openshift/origin-operator-marketplace:latest
4545
createdAt: 2019/11/15

tests/test_validate.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
@pytest.mark.parametrize('bundle,expected_validation_results_dict', [
99
("tests/test_files/bundles/verification/noicon.valid.bundle.yaml",
10-
{'errors': [], 'warnings': ['csv spec.icon not defined']}),
10+
{'errors': [], 'warnings': [
11+
'csv metadata.annotations.categories not defined',
12+
'csv spec.icon not defined']}),
1113
("tests/test_files/bundles/verification/nocrd.valid.bundle.yaml",
12-
{'errors': [], 'warnings': ['csv spec.icon not defined',
13-
'csv spec.maturity not defined']}),
14+
{'errors': [], 'warnings': [
15+
'csv spec.icon not defined',
16+
'csv spec.maturity not defined']}),
1417
])
1518
def test_valid_bundles(bundle, expected_validation_results_dict):
1619
valid, validation_results_dict = get_validation_results(bundle)
@@ -21,7 +24,9 @@ def test_valid_bundles(bundle, expected_validation_results_dict):
2124
@pytest.mark.parametrize('bundle,expected_validation_results_dict', [
2225
("tests/test_files/bundles/verification/nopkg.invalid.bundle.yaml",
2326
{'errors': ['Bundle does not contain any packages.'],
24-
'warnings': ['csv spec.icon not defined']}),
27+
'warnings': [
28+
'csv metadata.annotations.categories not defined',
29+
'csv spec.icon not defined']}),
2530
("tests/test_files/bundles/verification/no-data-key.bundle.yaml",
2631
{'errors': ['Bundle does not contain any clusterServiceVersions.',
2732
'Bundle does not contain any packages.'], 'warnings': []}),
@@ -47,9 +52,12 @@ def test_ui_valid_bundle_io(bundle, expected_validation_results_dict):
4752
"csv.spec.links must be a list of name & url pairs.",
4853
"spec.version invalid is not a valid version "
4954
"(example of a valid version is: v1.0.12)",
55+
"metadata.annotations.capabilities invalid "
56+
"is not a valid capabilities level",
5057
"spec.icon[0].mediatype image/invalid is not "
5158
"a valid mediatype. It must be one of \"image/gif\", "
5259
"\"image/jpeg\", \"image/png\", \"image/svg+xml\"",
60+
"category invalid is not a valid category",
5361
"UI validation failed to verify that required fields "
5462
"for operatorhub.io are properly formatted."
5563
],

0 commit comments

Comments
 (0)