|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * operators/understanding/olm/olm-understanding-dependency-resolution.adoc |
| 4 | + |
| 5 | +:_content-type: CONCEPT |
| 6 | +[id="olm-generic-constraints_{context}"] |
| 7 | += Generic constraints |
| 8 | + |
| 9 | +An `olm.constraint` property declares a dependency constraint of a particular type, differentiating non-constraint and constraint properties. Its `value` field is an object containing a `failureMessage` field holding a string-representation of the constraint message. This message is surfaced as an informative comment to users if the constraint is not satisfiable at runtime. |
| 10 | + |
| 11 | +The following keys denote the available constraint types: |
| 12 | + |
| 13 | +`gvk`:: Type whose value and interpretation is identical to the `olm.gvk` type |
| 14 | + |
| 15 | +`package`:: Type whose value and interpretation is identical to the `olm.package` type |
| 16 | + |
| 17 | +`cel`:: A Common Expression Language (CEL) expression evaluated at runtime by the Operator Lifecycle Manager (OLM) resolver over arbitrary bundle properties and cluster information |
| 18 | + |
| 19 | +`all`, `any`, `not`:: Conjunction, disjunction, and negation constraints, respectively, containing one or more concrete constraints, such as `gvk` or a nested compound constraint |
| 20 | + |
| 21 | +[id="olm-cel_{context}"] |
| 22 | +== Common Expression Language (CEL) constraints |
| 23 | + |
| 24 | +The `cel` constraint type supports link:https://github.com/google/cel-go[Common Expression Language (CEL)] as the expression language. The `cel` struct has a `rule` field which contains the CEL expression string that is evaluated against Operator properties at runtime to determine if the Operator satisfies the constraint. |
| 25 | + |
| 26 | +.Example `cel` constraint |
| 27 | +[source,yaml] |
| 28 | +---- |
| 29 | +type: olm.constraint |
| 30 | +value: |
| 31 | + failureMessage: 'require to have "certified"' |
| 32 | + cel: |
| 33 | + rule: 'properties.exists(p, p.type == "certified")' |
| 34 | +---- |
| 35 | + |
| 36 | +The CEL syntax supports a wide range of logical operators, such as `AND` and `OR`. As a result, a single CEL expression can have multiple rules for multiple conditions that are linked together by these logical operators. These rules are evaluated against a dataset of multiple different properties from a bundle or any given source, and the output is solved into a single bundle or Operator that satisfies all of those rules within a single constraint. |
| 37 | + |
| 38 | +.Example `cel` constraint with multiple rules |
| 39 | +[source,yaml] |
| 40 | +---- |
| 41 | +type: olm.constraint |
| 42 | +value: |
| 43 | + failureMessage: 'require to have "certified" and "stable" properties' |
| 44 | + cel: |
| 45 | + rule: 'properties.exists(p, p.type == "certified") && properties.exists(p, p.type == "stable")' |
| 46 | +---- |
| 47 | + |
| 48 | +[id="olm-compound-constraints_{context}"] |
| 49 | +== Compound constraints (all, any, not) |
| 50 | + |
| 51 | +Compound constraint types are evaluated following their logical definitions. |
| 52 | + |
| 53 | +The following is an example of a conjunctive constraint (`all`) of two packages and one GVK. That is, they must all be satisfied by installed bundles: |
| 54 | + |
| 55 | +.Example `all` constraint |
| 56 | +[source,yaml] |
| 57 | +---- |
| 58 | +schema: olm.bundle |
| 59 | +name: red.v1.0.0 |
| 60 | +properties: |
| 61 | +- type: olm.constraint |
| 62 | + value: |
| 63 | + failureMessage: All are required for Red because... |
| 64 | + all: |
| 65 | + constraints: |
| 66 | + - failureMessage: Package blue is needed for... |
| 67 | + package: |
| 68 | + name: blue |
| 69 | + versionRange: '>=1.0.0' |
| 70 | + - failureMessage: GVK Green/v1 is needed for... |
| 71 | + gvk: |
| 72 | + group: greens.example.com |
| 73 | + version: v1 |
| 74 | + kind: Green |
| 75 | +---- |
| 76 | + |
| 77 | +The following is an example of a disjunctive constraint (`any`) of three versions of the same GVK. That is, at least one must be satisfied by installed bundles: |
| 78 | + |
| 79 | +.Example `any` constraint |
| 80 | +[source,yaml] |
| 81 | +---- |
| 82 | +schema: olm.bundle |
| 83 | +name: red.v1.0.0 |
| 84 | +properties: |
| 85 | +- type: olm.constraint |
| 86 | + value: |
| 87 | + failureMessage: Any are required for Red because... |
| 88 | + any: |
| 89 | + constraints: |
| 90 | + - gvk: |
| 91 | + group: blues.example.com |
| 92 | + version: v1beta1 |
| 93 | + kind: Blue |
| 94 | + - gvk: |
| 95 | + group: blues.example.com |
| 96 | + version: v1beta2 |
| 97 | + kind: Blue |
| 98 | + - gvk: |
| 99 | + group: blues.example.com |
| 100 | + version: v1 |
| 101 | + kind: Blue |
| 102 | +---- |
| 103 | + |
| 104 | +The following is an example of a negation constraint (`not`) of one version of a GVK. That is, this GVK cannot be provided by any bundle in the result set: |
| 105 | + |
| 106 | +.Example `not` constraint |
| 107 | +[source,yaml] |
| 108 | +---- |
| 109 | +schema: olm.bundle |
| 110 | +name: red.v1.0.0 |
| 111 | +properties: |
| 112 | +- type: olm.constraint |
| 113 | + value: |
| 114 | + all: |
| 115 | + constraints: |
| 116 | + - failureMessage: Package blue is needed for... |
| 117 | + package: |
| 118 | + name: blue |
| 119 | + versionRange: '>=1.0.0' |
| 120 | + - failureMessage: Cannot be required for Red because... |
| 121 | + not: |
| 122 | + constraints: |
| 123 | + - gvk: |
| 124 | + group: greens.example.com |
| 125 | + version: v1alpha1 |
| 126 | + kind: greens |
| 127 | +---- |
| 128 | + |
| 129 | +The negation semantics might appear unclear in the `not` constraint context. To clarify, the negation is really instructing the resolver to remove any possible solution that includes a particular GVK, package at a version, or satisfies some child compound constraint from the result set. |
| 130 | + |
| 131 | +As a corollary, the `not` compound constraint should only be used within `all` or `any` constraints, because negating without first selecting a possible set of dependencies does not make sense. |
| 132 | + |
| 133 | +[id="olm-nested-compound_{context}"] |
| 134 | +== Nested compound constraints |
| 135 | + |
| 136 | +A nested compound constraint, one that contains at least one child compound constraint along with zero or more simple constraints, is evaluated from the bottom up following the procedures for each previously described constraint type. |
| 137 | + |
| 138 | +The following is an example of a disjunction of conjunctions, where one, the other, or both can satisfy the constraint: |
| 139 | + |
| 140 | +.Example nested compound constraint |
| 141 | +[source,yaml] |
| 142 | +---- |
| 143 | +schema: olm.bundle |
| 144 | +name: red.v1.0.0 |
| 145 | +properties: |
| 146 | +- type: olm.constraint |
| 147 | + value: |
| 148 | + failureMessage: Required for Red because... |
| 149 | + any: |
| 150 | + constraints: |
| 151 | + - all: |
| 152 | + constraints: |
| 153 | + - package: |
| 154 | + name: blue |
| 155 | + versionRange: '>=1.0.0' |
| 156 | + - gvk: |
| 157 | + group: blues.example.com |
| 158 | + version: v1 |
| 159 | + kind: Blue |
| 160 | + - all: |
| 161 | + constraints: |
| 162 | + - package: |
| 163 | + name: blue |
| 164 | + versionRange: '<1.0.0' |
| 165 | + - gvk: |
| 166 | + group: blues.example.com |
| 167 | + version: v1beta1 |
| 168 | + kind: Blue |
| 169 | +---- |
| 170 | + |
| 171 | +[NOTE] |
| 172 | +==== |
| 173 | +The maximum raw size of an `olm.constraint` type is 64KB to limit resource exhaustion attacks. |
| 174 | +==== |
0 commit comments