Skip to content

Commit 260bf1b

Browse files
committed
Update the enhancement with details on syntax and alternative syntax
Signed-off-by: Vu Dinh <vudinh@outlook.com>
1 parent 05be439 commit 260bf1b

File tree

1 file changed

+88
-4
lines changed

1 file changed

+88
-4
lines changed

enhancements/generic-constraints.md

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ reviewers:
88
approvers:
99
- "@kevinrizza"
1010
creation-date: 2021-08-26
11-
last-updated: 2020-10-08
11+
last-updated: 2020-11-04
1212
status: provisional
1313
---
1414

@@ -41,9 +41,12 @@ Both types are specifically handled by the resolver in OLM and cannot be changed
4141
* Note: The current GVK and package constraints are specified in `dependencies.yaml` using `olm.gvk` and `olm.package` type and they are coverted to `olm.gvk.required` or `olm.package.required` property (which is required constraint) to differentiate from the `olm.package` and `olm.gvk` property in the bundle.
4242

4343
### Goals
44+
4445
- Provide specification and guideline to specify a constraint that contains declarative requirements/rules.
4546
- Support the compound constraint (the constraint with mutliple requirements that is resolved into a single operator).
47+
4648
### Non-Goals
49+
4750
- Eliminate the existing built-in constraints.
4851
- Support multiple expression languages other than CEL (though the syntax may allow the support for other languages for future use).
4952
- Provide mechanism to provide cluster constraints. This feature can be addressed in a separate enhancement.
@@ -93,13 +96,27 @@ Each constraint is specified using the following syntax:
9396

9497
The constraint `type` is `olm.constraint` and the `value` is information associated with constraint. The `value` struct has 4 fields: `evaluator`, `rule`, `message` and `action`.
9598

96-
The `evaluator` is a struct with `id` field to represent the language library that will be used to evaluate the expression. At the moment, only CEL expression is supported using `cel` as the identifier.
99+
The `evaluator` is a struct with `id` field to represent the language library that will be used to evaluate the expression. At the moment, only CEL expression is supported using `cel` as the identifier. Given the possibility of supporting other expression languages in the future, the `evaluator` is constructed as a struct so that additional fields can be added without breaking the current syntax. For example, if we support a hypothetical expression language named `lucky` that has ability to dynamically load a package named `bobby` at runtime, a `package` field can be added to `evaluator` struct to support that ability:
100+
101+
```json=
102+
"evaluator":{
103+
"id":"lucky",
104+
"package":"bobby"
105+
},
106+
```
97107

98108
The `rule` field is the string that presents a CEL expression that will be evaluated during resolution against . Only CEL expression is supported in the initial release.
99109

100110
The `message` field is an optional field that is accommodating the rule field to surface information regarding what this CEL rule is about. The message will be surfaced in resolution output when the rule evaluates to false.
101111

102-
Finally, the `action` field is a struct with the `id` field to indicate the resolution action that this constraint will behave. For example, for `require` action, there must be at least one candidate that satisfies this constraint. This action can be used to indicate optional constraint in the future. For the initial release, `require` action is supported.
112+
Finally, the `action` field is a struct with the `id` field to indicate the resolution action that this constraint will behave. For example, for `require` action, there must be at least one candidate that satisfies this constraint. This action can be used to indicate optional constraint in the future adding a new field `optional` such as:
113+
114+
```json=
115+
"action":{
116+
"id":"require"
117+
"optional":true
118+
},
119+
```
103120

104121
#### Compound Constraint
105122

@@ -162,7 +179,74 @@ Besides CEL, there are other languages that can be used such as:
162179

163180
All of these languages can be supported in constraint type. The `evaluator` field is designed to support multiple evaluators/languages if needed. However, intrducing a new language to the constraint type should be evaluated carefully to ensure there is a real need for it. Providing the support for multiple languages can be overwhelming and potentially creates a fragmented user experiences and unnecessary maintainance effort in a long run.
164181

165-
### Simplified constraint type
182+
### Alternative constraint syntax
183+
184+
#### Custom constraint type syntax
185+
186+
The current proposed constraint syntax is designed to support other expression languages in the future. The current `evaluator` struct is designed to suppport additional fields to falicitate additional information that new expression languague may require. Additionally, other goals of this EP to support potentual custom constraints which may not use expression language and have additional fields without having to introduce a new constraint type. The complexity of using `evaluator` struct as an identifier and depending on identifier, more fields are required in the `value` struct can potentually be confusing as fields become intermingled. The alternative syntax is to shift cel constraint type into its own struct under `value` struct.
187+
188+
```yaml=
189+
type: olm.constraint
190+
value:
191+
message: 'require to have "certified" and "stable" properties'
192+
CEL:
193+
rule: 'properties.exists(p, p.type == "certified") && properties.exists(p, p.type == "stable")'
194+
action:
195+
id: "require"
196+
optional: true
197+
```
198+
199+
```
200+
type CEL struct {
201+
Rule string
202+
}
203+
```
204+
205+
If there is a new custom type introduced, a new go struct will be added:
206+
207+
```
208+
type CEL struct {
209+
Rule string
210+
Action string
211+
}
212+
213+
type PropertyEquals struct {
214+
Name string
215+
Value string
216+
}
217+
```
218+
219+
The overall construct struct in go:
220+
221+
```
222+
type Constraint struct {
223+
Message string
224+
Action Action
225+
CEL *CEL
226+
PropertyEquals *PropertyEquals
227+
}
228+
229+
type Action struct {
230+
id string
231+
optional bool
232+
}
233+
```
234+
235+
The constraint syntax in YAML for the new `PropertyEquals` type is:
236+
237+
```yaml=
238+
type: olm.constraint
239+
value:
240+
message: 'require to have "certified" and "stable" properties'
241+
propertyEquals:
242+
name: "olm.maxOCPVersion"
243+
value: "4.9"
244+
action:
245+
id: "require"
246+
optional: false
247+
```
248+
249+
#### Simplified CEL constraint type
166250

167251
The current proposed constraint syntax has most of information nested under `value` field. The complexity of a struct with nested fields can create a bad user experience. It is possible to introduce a constraint type that is specified for CEL
168252

0 commit comments

Comments
 (0)