Skip to content

Commit 7952ae6

Browse files
committed
validate: add validation for apiservicedefinitions
1 parent 2533643 commit 7952ae6

File tree

4 files changed

+384
-3
lines changed

4 files changed

+384
-3
lines changed

operatorcourier/validate.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ def _csv_spec_validation(self, spec, bundleData):
188188
spec["customresourcedefinitions"], bundleData) is False:
189189
valid = False
190190

191+
if "apiservicedefinitions" in spec:
192+
if self._csv_asd_validation(spec["apiservicedefinitions"]) is False:
193+
valid = False
194+
191195
return valid
192196

193197
def _csv_crd_validation(self, customresourcedefinitions, bundleData):
@@ -307,6 +311,55 @@ def _csv_crd_validation(self, customresourcedefinitions, bundleData):
307311

308312
return valid
309313

314+
def _csv_asd_validation(self, apiservicedefinitions):
315+
valid = True
316+
317+
if "owned" not in apiservicedefinitions:
318+
self._log_error("spec.apiservicedefinitions.owned"
319+
"not defined for csv")
320+
return False
321+
322+
# required attributes of owned apiservicedefinitions
323+
attributeList = ["group", "version", "kind", "name", "deploymentName",
324+
"displayName", "description"]
325+
326+
# validate the owned apiservicedefinitions
327+
def validate_owned(resource, attribute):
328+
if attribute not in resource:
329+
self._log_error(
330+
"%s not defined for item in spec.apiservicedefinitions." % attribute)
331+
return False
332+
elif not resource[attribute]:
333+
self._log_error("%s is empty for item in "
334+
"spec.apiservicedefinitions." % attribute)
335+
return False
336+
return True
337+
338+
for csvOwnedAsd in apiservicedefinitions["owned"]:
339+
for attr in attributeList:
340+
if validate_owned(csvOwnedAsd, attr) is False:
341+
valid = False
342+
343+
if "specDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
344+
if self._csv_descriptors_validation(
345+
csvOwnedAsd["specDescriptors"],
346+
csvOwnedAsd["name"]) is False:
347+
valid = False
348+
349+
if "statusDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
350+
if self._csv_descriptors_validation(
351+
csvOwnedAsd["statusDescriptors"],
352+
csvOwnedAsd["name"]) is False:
353+
valid = False
354+
355+
if "actionDescriptors" in csvOwnedAsd and "name" in csvOwnedAsd:
356+
if self._csv_descriptors_validation(
357+
csvOwnedAsd["actionDescriptors"],
358+
csvOwnedAsd["name"]) is False:
359+
valid = False
360+
361+
return valid
362+
310363
def _csv_spec_install_validation(self, install):
311364
valid = True
312365

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
# CSV.spec.apiservicedefinitions.owned.{kind,deploymentName} and
2+
# CSV.spec.apiservicedefinitions.owned.specDescriptors.{description,displayName}
3+
# are empty in this file
4+
data:
5+
clusterServiceVersions: |
6+
- apiVersion: operators.coreos.com/v1alpha1
7+
kind: ClusterServiceVersion
8+
metadata:
9+
annotations:
10+
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>"}}}]'
11+
categories: openshift required
12+
certified: 'true'
13+
containerImage: quay.io/openshift/origin-operator-marketplace:latest
14+
createdAt: 2019/11/15
15+
description: An operator to run the OpenShift marketplace
16+
healthIndex: B
17+
repository: https://github.com/operator-framework/operator-marketplace
18+
support: Red Hat
19+
name: marketplace-operator.v0.0.1
20+
namespace: placeholder
21+
spec:
22+
apiservicedefinitions:
23+
owned:
24+
- description: Some description
25+
displayName: Some Display Name
26+
kind: SomeKind
27+
name: somename.redhat.com
28+
group: somegroup.redhat.com
29+
version: v1alpha1
30+
deploymentName: some deployment name
31+
- version: v1alpha1
32+
group: somegroup.redhat.com
33+
kind:
34+
description: Some description 2
35+
displayName: Some Display Name 2
36+
name: someothername.redhat.com
37+
specDescriptors:
38+
- path: type
39+
customresourcedefinitions:
40+
owned:
41+
- description: Represents an OperatorSource.
42+
displayName: Operator Source
43+
kind: OperatorSource
44+
name: operatorsources.marketplace.redhat.com
45+
specDescriptors:
46+
- description: The type of the operator source.
47+
displayName: Type
48+
path: type
49+
- description: Points to the remote app registry server from where operator
50+
manifests can be fetched.
51+
displayName: Endpoint
52+
path: endpoint
53+
- description: 'The namespace in app registry.
54+
55+
Only operator manifests under this namespace will be visible.
56+
57+
Please note that this is not a k8s namespace.'
58+
displayName: Registry Namespace
59+
path: registryNamespace
60+
statusDescriptors:
61+
- description: Current status of the CatalogSourceConfig
62+
displayName: Current Phase Name
63+
path: currentPhase.phase.name
64+
- description: Message associated with the current status
65+
displayName: Current Phase Message
66+
path: currentPhase.phase.message
67+
version: v1alpha1
68+
- description: Represents a CatalogSourceConfig object which is used to configure
69+
a CatalogSource.
70+
displayName: Catalog Source Config
71+
kind: CatalogSourceConfig
72+
name: catalogsourceconfigs.marketplace.redhat.com
73+
specDescriptors:
74+
- description: The namespace where the operators will be enabled.
75+
displayName: Target Namespace
76+
path: targetNamespace
77+
- description: List of operator(s) which will be enabled in the target namespace
78+
displayName: Packages
79+
path: packages
80+
statusDescriptors:
81+
- description: Current status of the CatalogSourceConfig
82+
displayName: Current Phase Name
83+
path: currentPhase.phase.name
84+
- description: Message associated with the current status
85+
displayName: Current Phase Message
86+
path: currentPhase.phase.message
87+
version: v1alpha1
88+
description: Marketplace is a gateway for users to consume off-cluster Operators
89+
which will include Red Hat, ISV, optional OpenShift and community content.
90+
displayName: marketplace-operator
91+
install:
92+
spec:
93+
clusterPermissions:
94+
- rules:
95+
- apiGroups:
96+
- marketplace.redhat.com
97+
resources:
98+
- '*'
99+
verbs:
100+
- '*'
101+
- apiGroups:
102+
- ''
103+
resources:
104+
- services
105+
- configmaps
106+
verbs:
107+
- '*'
108+
- apiGroups:
109+
- operators.coreos.com
110+
resources:
111+
- catalogsources
112+
verbs:
113+
- '*'
114+
serviceAccountName: marketplace-operator
115+
deployments:
116+
- name: marketplace-operator
117+
spec:
118+
replicas: 1
119+
selector:
120+
matchLabels:
121+
name: marketplace-operator
122+
template:
123+
metadata:
124+
labels:
125+
name: marketplace-operator
126+
name: marketplace-operator
127+
spec:
128+
containers:
129+
- command:
130+
- marketplace-operator
131+
env:
132+
- name: WATCH_NAMESPACE
133+
valueFrom:
134+
fieldRef:
135+
fieldPath: metadata.namespace
136+
- name: OPERATOR_NAME
137+
value: marketplace-operator
138+
image: quay.io/openshift/origin-operator-marketplace:latest
139+
imagePullPolicy: Always
140+
livenessProbe:
141+
httpGet:
142+
path: /healthz
143+
port: 8080
144+
name: marketplace-operator
145+
ports:
146+
- containerPort: 60000
147+
name: metrics
148+
- containerPort: 8080
149+
name: healthz
150+
readinessProbe:
151+
httpGet:
152+
path: /healthz
153+
port: 8080
154+
serviceAccountName: marketplace-operator
155+
strategy: deployment
156+
installModes:
157+
- supported: true
158+
type: OwnNamespace
159+
- supported: true
160+
type: SingleNamespace
161+
- supported: false
162+
type: MultiNamespace
163+
- supported: true
164+
type: AllNamespaces
165+
keywords:
166+
- marketplace
167+
- catalog
168+
- olm
169+
- admin
170+
labels:
171+
name: marketplace-operator
172+
links:
173+
- name: Markplace Operator Source Code
174+
url: https://github.com/operator-framework/operator-marketplace
175+
maintainers:
176+
177+
name: AOS Marketplace Team
178+
maturity: alpha
179+
provider:
180+
name: Red Hat
181+
selector:
182+
matchLabels:
183+
name: marketplace-operator
184+
version: 0.0.1
185+
customResourceDefinitions: |
186+
- apiVersion: apiextensions.k8s.io/v1beta1
187+
kind: CustomResourceDefinition
188+
metadata:
189+
annotations:
190+
description: Represents a CatalogSourceConfig.
191+
displayName: Catalog Source Config
192+
name: catalogsourceconfigs.marketplace.redhat.com
193+
spec:
194+
additionalPrinterColumns:
195+
- JSONPath: .spec.targetNamespace
196+
description: The namespace where the operators will be enabled
197+
name: TargetNamespace
198+
type: string
199+
- JSONPath: .spec.packages
200+
description: List of operator(s) which will be enabled in the target namespace
201+
name: Packages
202+
type: string
203+
- JSONPath: .status.currentPhase.phase.name
204+
description: Current status of the CatalogSourceConfig
205+
name: Status
206+
type: string
207+
- JSONPath: .status.currentPhase.phase.message
208+
description: Message associated with the current status
209+
name: Message
210+
type: string
211+
- JSONPath: .metadata.creationTimestamp
212+
name: Age
213+
type: date
214+
group: marketplace.redhat.com
215+
names:
216+
kind: CatalogSourceConfig
217+
listKind: CatalogSourceConfigList
218+
plural: catalogsourceconfigs
219+
shortNames:
220+
- csc
221+
singular: catalogsourceconfig
222+
scope: Namespaced
223+
validation:
224+
openAPIV3Schema:
225+
properties:
226+
spec:
227+
description: Spec for a CatalogSourceConfig
228+
properties:
229+
packages:
230+
description: Comma separated list of operator(s) without spaces
231+
which will be enabled in the target namespace
232+
type: string
233+
targetNamespace:
234+
description: The namespace where the operators will be enabled
235+
type: string
236+
required:
237+
- targetNamespace
238+
- packages
239+
type: object
240+
version: v1alpha1
241+
- apiVersion: apiextensions.k8s.io/v1beta1
242+
kind: CustomResourceDefinition
243+
metadata:
244+
annotations:
245+
description: Represents an OperatorSource.
246+
displayName: Operator Source
247+
name: operatorsources.marketplace.redhat.com
248+
spec:
249+
additionalPrinterColumns:
250+
- JSONPath: .spec.type
251+
description: The type of the OperatorSource
252+
name: Type
253+
type: string
254+
- JSONPath: .spec.endpoint
255+
description: The endpoint of the OperatorSource
256+
name: Endpoint
257+
type: string
258+
- JSONPath: .spec.registryNamespace
259+
description: App registry namespace
260+
name: Registry
261+
type: string
262+
- JSONPath: .spec.displayName
263+
description: Display (pretty) name to indicate the OperatorSource's name
264+
name: DisplayName
265+
type: string
266+
- JSONPath: .spec.publisher
267+
description: Publisher of the OperatorSource
268+
name: Publisher
269+
type: string
270+
- JSONPath: .status.currentPhase.phase.name
271+
description: Current status of the OperatorSource
272+
name: Status
273+
type: string
274+
- JSONPath: .status.currentPhase.phase.message
275+
description: Message associated with the current status
276+
name: Message
277+
type: string
278+
- JSONPath: .metadata.creationTimestamp
279+
name: Age
280+
type: date
281+
group: marketplace.redhat.com
282+
names:
283+
kind: OperatorSource
284+
listKind: OperatorSourceList
285+
plural: operatorsources
286+
shortNames:
287+
- opsrc
288+
singular: operatorsource
289+
scope: Namespaced
290+
validation:
291+
openAPIV3Schema:
292+
properties:
293+
spec:
294+
description: Spec for an OperatorSource.
295+
properties:
296+
endpoint:
297+
description: Points to the remote app registry server from where
298+
operator manifests can be fetched.
299+
type: string
300+
registryNamespace:
301+
description: 'The namespace in app registry.
302+
303+
Only operator manifests under this namespace will be visible.
304+
305+
Please note that this is not a k8s namespace.'
306+
type: string
307+
type:
308+
description: The type of the OperatorSource
309+
pattern: appregistry
310+
type: string
311+
required:
312+
- type
313+
- endpoint
314+
- registryNamespace
315+
type: object
316+
version: v1alpha1
317+
packages: |
318+
- channels:
319+
- currentCSV: marketplace-operator.v0.0.1
320+
name: alpha
321+
packageName: marketplace

tests/test_files/yaml_source_dir/valid_yamls_with_single_crd/dynatrace-monitoring.v0.2.0.clusterserviceversion.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ metadata:
3838
name: dynatrace-monitoring.v0.2.0
3939
namespace: "placeholder"
4040
spec:
41-
apiservicedefinitions: {}
41+
apiservicedefinitions:
42+
owned: {}
4243
customresourcedefinitions:
4344
owned:
4445
- description: Dyantrace OneAgent monitoring agent

0 commit comments

Comments
 (0)