You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: enhancements/generic-constraints.md
+88-4Lines changed: 88 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ reviewers:
8
8
approvers:
9
9
- "@kevinrizza"
10
10
creation-date: 2021-08-26
11
-
last-updated: 2020-10-08
11
+
last-updated: 2020-11-04
12
12
status: provisional
13
13
---
14
14
@@ -41,9 +41,12 @@ Both types are specifically handled by the resolver in OLM and cannot be changed
41
41
* 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.
42
42
43
43
### Goals
44
+
44
45
- Provide specification and guideline to specify a constraint that contains declarative requirements/rules.
45
46
- Support the compound constraint (the constraint with mutliple requirements that is resolved into a single operator).
47
+
46
48
### Non-Goals
49
+
47
50
- Eliminate the existing built-in constraints.
48
51
- Support multiple expression languages other than CEL (though the syntax may allow the support for other languages for future use).
49
52
- 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:
93
96
94
97
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`.
95
98
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 dynatically 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
+
```
97
107
98
108
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.
99
109
100
110
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.
101
111
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
+
```
103
120
104
121
#### Compound Constraint
105
122
@@ -162,7 +179,74 @@ Besides CEL, there are other languages that can be used such as:
162
179
163
180
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.
164
181
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'
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
166
250
167
251
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
0 commit comments