Skip to content

Commit 5863540

Browse files
Merge pull request #248 from tylerslaton/sync-constraint-changes
Bug 2034319: Sync constraint changes
2 parents d795a1d + fbfd54e commit 5863540

File tree

19 files changed

+115
-76
lines changed

19 files changed

+115
-76
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/mikefarah/yq/v3 v3.0.0-20201202084205-8846255d1c37
1313
github.com/onsi/ginkgo v1.16.4
1414
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
15-
github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a
15+
github.com/operator-framework/api v0.12.0
1616
github.com/operator-framework/operator-lifecycle-manager v0.0.0-00010101000000-000000000000
1717
github.com/operator-framework/operator-registry v1.17.5
1818
github.com/sirupsen/logrus v1.8.1

staging/api/pkg/constraints/constraint.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const OLMConstraintType = "olm.constraint"
1212

1313
// Constraint holds parsed, potentially nested dependency constraints.
1414
type Constraint struct {
15-
// Constraint message that surfaces in resolution
15+
// Constraint failure message that surfaces in resolution
1616
// This field is optional
17-
Message string `json:"message,omitempty" yaml:"message,omitempty"`
17+
FailureMessage string `json:"failureMessage,omitempty" yaml:"failureMessage,omitempty"`
1818

1919
// The cel struct that contraints CEL expression
2020
Cel *Cel `json:"cel,omitempty" yaml:"cel,omitempty"`
@@ -25,14 +25,15 @@ type Constraint struct {
2525
// GVK defines a constraint for a GVK.
2626
GVK *GVKConstraint `json:"gvk,omitempty" yaml:"gvk,omitempty"`
2727

28-
// All, Any, and None are compound constraints. See this enhancement for details:
28+
// All, Any, and Not are compound constraints. See this enhancement for details:
2929
// https://github.com/operator-framework/enhancements/blob/master/enhancements/compound-bundle-constraints.md
3030
All *CompoundConstraint `json:"all,omitempty" yaml:"all,omitempty"`
3131
Any *CompoundConstraint `json:"any,omitempty" yaml:"any,omitempty"`
32-
// A note on None: this constraint is not particularly useful by itself.
32+
// A note on Not: this constraint isn't particularly useful by itself.
3333
// It should be used within an All constraint alongside some other constraint type
34-
// since saying "none of these GVKs/packages/etc." without an alternative doesn't make sense.
35-
None *CompoundConstraint `json:"none,omitempty" yaml:"none,omitempty"`
34+
// since saying "do not use any of these GVKs/packages/etc." without an alternative
35+
// doesn't make sense.
36+
Not *CompoundConstraint `json:"not,omitempty" yaml:"not,omitempty"`
3637
}
3738

3839
// CompoundConstraint holds a list of potentially nested constraints

staging/api/pkg/constraints/constraint_test.go

+29-29
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ func TestParse(t *testing.T) {
2222
name: "Valid/BasicGVK",
2323
input: json.RawMessage(inputBasicGVK),
2424
expConstraint: Constraint{
25-
Message: "blah",
26-
GVK: &GVKConstraint{Group: "example.com", Version: "v1", Kind: "Foo"},
25+
FailureMessage: "blah",
26+
GVK: &GVKConstraint{Group: "example.com", Version: "v1", Kind: "Foo"},
2727
},
2828
},
2929
{
3030
name: "Valid/BasicPackage",
3131
input: json.RawMessage(inputBasicPackage),
3232
expConstraint: Constraint{
33-
Message: "blah",
34-
Package: &PackageConstraint{PackageName: "foo", VersionRange: ">=1.0.0"},
33+
FailureMessage: "blah",
34+
Package: &PackageConstraint{PackageName: "foo", VersionRange: ">=1.0.0"},
3535
},
3636
},
3737
{
3838
name: "Valid/BasicAll",
3939
input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "all")),
4040
expConstraint: Constraint{
41-
Message: "blah",
41+
FailureMessage: "blah",
4242
All: &CompoundConstraint{
4343
Constraints: []Constraint{
4444
{
45-
Message: "blah blah",
46-
Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"},
45+
FailureMessage: "blah blah",
46+
Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"},
4747
},
4848
},
4949
},
@@ -53,27 +53,27 @@ func TestParse(t *testing.T) {
5353
name: "Valid/BasicAny",
5454
input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "any")),
5555
expConstraint: Constraint{
56-
Message: "blah",
56+
FailureMessage: "blah",
5757
Any: &CompoundConstraint{
5858
Constraints: []Constraint{
5959
{
60-
Message: "blah blah",
61-
Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"},
60+
FailureMessage: "blah blah",
61+
Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"},
6262
},
6363
},
6464
},
6565
},
6666
},
6767
{
68-
name: "Valid/BasicNone",
69-
input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "none")),
68+
name: "Valid/BasicNot",
69+
input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "not")),
7070
expConstraint: Constraint{
71-
Message: "blah",
72-
None: &CompoundConstraint{
71+
FailureMessage: "blah",
72+
Not: &CompoundConstraint{
7373
Constraints: []Constraint{
7474
{
75-
Message: "blah blah",
76-
Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"},
75+
FailureMessage: "blah blah",
76+
Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"},
7777
},
7878
},
7979
},
@@ -83,13 +83,13 @@ func TestParse(t *testing.T) {
8383
name: "Valid/Complex",
8484
input: json.RawMessage(inputComplex),
8585
expConstraint: Constraint{
86-
Message: "blah",
86+
FailureMessage: "blah",
8787
All: &CompoundConstraint{
8888
Constraints: []Constraint{
8989
{Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}},
9090
{GVK: &GVKConstraint{Group: "fals.example.com", Kind: "Fal", Version: "v1"}},
9191
{
92-
Message: "foo and buf must be stable versions",
92+
FailureMessage: "foo and buf must be stable versions",
9393
All: &CompoundConstraint{
9494
Constraints: []Constraint{
9595
{Package: &PackageConstraint{PackageName: "foo", VersionRange: ">=1.0.0"}},
@@ -99,7 +99,7 @@ func TestParse(t *testing.T) {
9999
},
100100
},
101101
{
102-
Message: "blah blah",
102+
FailureMessage: "blah blah",
103103
Any: &CompoundConstraint{
104104
Constraints: []Constraint{
105105
{GVK: &GVKConstraint{Group: "foos.example.com", Kind: "Foo", Version: "v1beta1"}},
@@ -109,7 +109,7 @@ func TestParse(t *testing.T) {
109109
},
110110
},
111111
{
112-
None: &CompoundConstraint{
112+
Not: &CompoundConstraint{
113113
Constraints: []Constraint{
114114
{GVK: &GVKConstraint{Group: "bazs.example.com", Kind: "Baz", Version: "v1alpha1"}},
115115
},
@@ -132,7 +132,7 @@ func TestParse(t *testing.T) {
132132
{
133133
name: "Invalid/UnknownField",
134134
input: json.RawMessage(
135-
`{"message": "something", "arbitrary": {"key": "value"}}`,
135+
`{"failureMessage": "something", "arbitrary": {"key": "value"}}`,
136136
),
137137
expError: `json: unknown field "arbitrary"`,
138138
},
@@ -153,7 +153,7 @@ func TestParse(t *testing.T) {
153153

154154
const (
155155
inputBasicGVK = `{
156-
"message": "blah",
156+
"failureMessage": "blah",
157157
"gvk": {
158158
"group": "example.com",
159159
"version": "v1",
@@ -162,19 +162,19 @@ const (
162162
}`
163163

164164
inputBasicPackage = `{
165-
"message": "blah",
165+
"failureMessage": "blah",
166166
"package": {
167167
"packageName": "foo",
168168
"versionRange": ">=1.0.0"
169169
}
170170
}`
171171

172172
inputBasicCompoundTmpl = `{
173-
"message": "blah",
173+
"failureMessage": "blah",
174174
"%s": {
175175
"constraints": [
176176
{
177-
"message": "blah blah",
177+
"failureMessage": "blah blah",
178178
"package": {
179179
"packageName": "fuz",
180180
"versionRange": ">=1.0.0"
@@ -185,7 +185,7 @@ const (
185185
`
186186

187187
inputComplex = `{
188-
"message": "blah",
188+
"failureMessage": "blah",
189189
"all": {
190190
"constraints": [
191191
{
@@ -202,7 +202,7 @@ const (
202202
}
203203
},
204204
{
205-
"message": "foo and buf must be stable versions",
205+
"failureMessage": "foo and buf must be stable versions",
206206
"all": {
207207
"constraints": [
208208
{
@@ -228,7 +228,7 @@ const (
228228
}
229229
},
230230
{
231-
"message": "blah blah",
231+
"failureMessage": "blah blah",
232232
"any": {
233233
"constraints": [
234234
{
@@ -256,7 +256,7 @@ const (
256256
}
257257
},
258258
{
259-
"none": {
259+
"not": {
260260
"constraints": [
261261
{
262262
"gvk": {

staging/operator-lifecycle-manager/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/onsi/gomega v1.15.0
2626
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
2727
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0
28-
github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a
28+
github.com/operator-framework/api v0.12.0
2929
github.com/operator-framework/operator-registry v1.17.5
3030
github.com/otiai10/copy v1.2.0
3131
github.com/pkg/errors v0.9.1

staging/operator-lifecycle-manager/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,8 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
927927
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
928928
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
929929
github.com/operator-framework/api v0.7.1/go.mod h1:L7IvLd/ckxJEJg/t4oTTlnHKAJIP/p51AvEslW3wYdY=
930-
github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a h1:tX+zUHdTkn7NfLt9Y8zjsfmSeZkE+sKQEZRqYkVdHYo=
931-
github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
930+
github.com/operator-framework/api v0.12.0 h1:aHxHk50/Y1J4Ogdk2J6tYofgX+GEqyBPCMyun+JFqV4=
931+
github.com/operator-framework/api v0.12.0/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
932932
github.com/operator-framework/operator-registry v1.17.5 h1:LR8m1rFz5Gcyje8WK6iYt+gIhtzqo52zMRALdmTYHT0=
933933
github.com/operator-framework/operator-registry v1.17.5/go.mod h1:sRQIgDMZZdUcmHltzyCnM6RUoDF+WS8Arj1BQIARDS8=
934934
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=

staging/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ func CountingPredicate(p Predicate, n *int) Predicate {
358358
}
359359

360360
type celPredicate struct {
361-
program constraints.CelProgram
362-
rule string
363-
message string
361+
program constraints.CelProgram
362+
rule string
363+
failureMessage string
364364
}
365365

366366
func (cp *celPredicate) Test(entry *Entry) bool {
@@ -383,14 +383,14 @@ func (cp *celPredicate) Test(entry *Entry) bool {
383383
return ok
384384
}
385385

386-
func CreateCelPredicate(env *constraints.CelEnvironment, rule string, message string) (Predicate, error) {
386+
func CreateCelPredicate(env *constraints.CelEnvironment, rule string, failureMessage string) (Predicate, error) {
387387
prog, err := env.Validate(rule)
388388
if err != nil {
389389
return nil, err
390390
}
391-
return &celPredicate{program: prog, rule: rule, message: message}, nil
391+
return &celPredicate{program: prog, rule: rule, failureMessage: failureMessage}, nil
392392
}
393393

394394
func (cp *celPredicate) String() string {
395-
return fmt.Sprintf("with constraint: %q and message: %q", cp.rule, cp.message)
395+
return fmt.Sprintf("with constraint: %q and message: %q", cp.rule, cp.failureMessage)
396396
}

staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,11 @@ func (pc *predicateConverter) convertConstraints(constraints ...constraints.Cons
815815
case constraint.Any != nil:
816816
subs, perr := pc.convertConstraints(constraint.Any.Constraints...)
817817
preds[i], err = cache.Or(subs...), perr
818-
case constraint.None != nil:
819-
subs, perr := pc.convertConstraints(constraint.None.Constraints...)
818+
case constraint.Not != nil:
819+
subs, perr := pc.convertConstraints(constraint.Not.Constraints...)
820820
preds[i], err = cache.Not(subs...), perr
821821
case constraint.Cel != nil:
822-
preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.Message)
822+
preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.FailureMessage)
823823
default:
824824
// Unknown constraint types are handled by constraints.Parse(),
825825
// but parsed constraints may be empty.

staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ func TestSolveOperators_OLMConstraint_CompoundAll(t *testing.T) {
803803
catName: csName, catNamespace: namespace,
804804
properties: []*api.Property{{
805805
Type: constraints.OLMConstraintType,
806-
Value: `{"message": "all constraint",
806+
Value: `{"failureMessage": "all constraint",
807807
"all": {"constraints": [
808808
{"package": {"packageName": "foo", "versionRange": ">=1.0.0"}},
809809
{"gvk": {"group": "g1", "version": "v1", "kind": "k1"}},
@@ -885,7 +885,7 @@ func TestSolveOperators_OLMConstraint_CompoundAny(t *testing.T) {
885885
catName: csName, catNamespace: namespace,
886886
properties: []*api.Property{{
887887
Type: constraints.OLMConstraintType,
888-
Value: `{"message": "any constraint",
888+
Value: `{"failureMessage": "any constraint",
889889
"any": {"constraints": [
890890
{"gvk": {"group": "g1", "version": "v1", "kind": "k1"}},
891891
{"gvk": {"group": "g2", "version": "v2", "kind": "k2"}}
@@ -953,7 +953,7 @@ func TestSolveOperators_OLMConstraint_CompoundAny(t *testing.T) {
953953
}
954954
}
955955

956-
func TestSolveOperators_OLMConstraint_CompoundNone(t *testing.T) {
956+
func TestSolveOperators_OLMConstraint_CompoundNot(t *testing.T) {
957957
namespace := "olm"
958958
csName := "community"
959959
catalog := cache.SourceKey{Name: csName, Namespace: namespace}
@@ -965,10 +965,10 @@ func TestSolveOperators_OLMConstraint_CompoundNone(t *testing.T) {
965965
properties: []*api.Property{
966966
{
967967
Type: constraints.OLMConstraintType,
968-
Value: `{"message": "compound none constraint",
968+
Value: `{"failureMessage": "compound not constraint",
969969
"all": {"constraints": [
970970
{"gvk": {"group": "g0", "version": "v0", "kind": "k0"}},
971-
{"none": {"constraints": [
971+
{"not": {"constraints": [
972972
{"gvk": {"group": "g1", "version": "v1", "kind": "k1"}},
973973
{"gvk": {"group": "g2", "version": "v2", "kind": "k2"}}
974974
]}}
@@ -1050,7 +1050,7 @@ func TestSolveOperators_OLMConstraint_Unknown(t *testing.T) {
10501050
catName: csName, catNamespace: namespace,
10511051
properties: []*api.Property{{
10521052
Type: constraints.OLMConstraintType,
1053-
Value: `{"message": "unknown constraint", "unknown": {"foo": "bar"}}`,
1053+
Value: `{"failureMessage": "unknown constraint", "unknown": {"foo": "bar"}}`,
10541054
}},
10551055
}}
10561056

@@ -2389,21 +2389,21 @@ func TestSolveOperators_GenericConstraint(t *testing.T) {
23892389
deps1 := []*api.Dependency{
23902390
{
23912391
Type: "olm.constraint",
2392-
Value: `{"message":"gvk-constraint",
2392+
Value: `{"failureMessage":"gvk-constraint",
23932393
"cel":{"rule":"properties.exists(p, p.type == 'olm.gvk' && p.value == {'group': 'g', 'version': 'v', 'kind': 'k'})"}}`,
23942394
},
23952395
}
23962396
deps2 := []*api.Dependency{
23972397
{
23982398
Type: "olm.constraint",
2399-
Value: `{"message":"gvk2-constraint",
2399+
Value: `{"failureMessage":"gvk2-constraint",
24002400
"cel":{"rule":"properties.exists(p, p.type == 'olm.gvk' && p.value == {'group': 'g2', 'version': 'v', 'kind': 'k'})"}}`,
24012401
},
24022402
}
24032403
deps3 := []*api.Dependency{
24042404
{
24052405
Type: "olm.constraint",
2406-
Value: `{"message":"package-constraint",
2406+
Value: `{"failureMessage":"package-constraint",
24072407
"cel":{"rule":"properties.exists(p, p.type == 'olm.package' && p.value.packageName == 'packageB' && (semver_compare(p.value.version, '1.0.1') == 0))"}}`,
24082408
},
24092409
}

staging/operator-registry/bundles/etcd.0.9.2/metadata/dependencies.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ dependencies:
44
group: testapi.coreos.com
55
kind: testapi
66
version: v1
7+
- type: olm.constraint
8+
value:
9+
failureMessage: 'require to have "certified"'
10+
cel:
11+
rule: 'properties.exists(p, p.type == "certified")'

staging/operator-registry/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/onsi/gomega v1.15.0
3737
github.com/opencontainers/go-digest v1.0.0
3838
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
39-
github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce
39+
github.com/operator-framework/api v0.12.0
4040
github.com/otiai10/copy v1.2.0
4141
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
4242
github.com/pkg/errors v0.9.1

staging/operator-registry/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:e
645645
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
646646
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
647647
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
648-
github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce h1:+zEJrt6Kw4SnN115WzleIpmw5jAgscrWb9K0WgvjhOc=
649-
github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
648+
github.com/operator-framework/api v0.12.0 h1:aHxHk50/Y1J4Ogdk2J6tYofgX+GEqyBPCMyun+JFqV4=
649+
github.com/operator-framework/api v0.12.0/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
650650
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
651651
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
652652
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=

0 commit comments

Comments
 (0)