diff --git a/go.mod b/go.mod index 3a51a44c89..23f900bac4 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/mikefarah/yq/v3 v3.0.0-20201202084205-8846255d1c37 github.com/onsi/ginkgo v1.16.4 github.com/openshift/api v0.0.0-20200331152225-585af27e34fd - github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a + github.com/operator-framework/api v0.12.0 github.com/operator-framework/operator-lifecycle-manager v0.0.0-00010101000000-000000000000 github.com/operator-framework/operator-registry v1.17.5 github.com/sirupsen/logrus v1.8.1 diff --git a/staging/api/pkg/constraints/constraint.go b/staging/api/pkg/constraints/constraint.go index d59d04542d..f65e8725de 100644 --- a/staging/api/pkg/constraints/constraint.go +++ b/staging/api/pkg/constraints/constraint.go @@ -12,9 +12,9 @@ const OLMConstraintType = "olm.constraint" // Constraint holds parsed, potentially nested dependency constraints. type Constraint struct { - // Constraint message that surfaces in resolution + // Constraint failure message that surfaces in resolution // This field is optional - Message string `json:"message,omitempty" yaml:"message,omitempty"` + FailureMessage string `json:"failureMessage,omitempty" yaml:"failureMessage,omitempty"` // The cel struct that contraints CEL expression Cel *Cel `json:"cel,omitempty" yaml:"cel,omitempty"` @@ -25,14 +25,15 @@ type Constraint struct { // GVK defines a constraint for a GVK. GVK *GVKConstraint `json:"gvk,omitempty" yaml:"gvk,omitempty"` - // All, Any, and None are compound constraints. See this enhancement for details: + // All, Any, and Not are compound constraints. See this enhancement for details: // https://github.com/operator-framework/enhancements/blob/master/enhancements/compound-bundle-constraints.md All *CompoundConstraint `json:"all,omitempty" yaml:"all,omitempty"` Any *CompoundConstraint `json:"any,omitempty" yaml:"any,omitempty"` - // A note on None: this constraint is not particularly useful by itself. + // A note on Not: this constraint isn't particularly useful by itself. // It should be used within an All constraint alongside some other constraint type - // since saying "none of these GVKs/packages/etc." without an alternative doesn't make sense. - None *CompoundConstraint `json:"none,omitempty" yaml:"none,omitempty"` + // since saying "do not use any of these GVKs/packages/etc." without an alternative + // doesn't make sense. + Not *CompoundConstraint `json:"not,omitempty" yaml:"not,omitempty"` } // CompoundConstraint holds a list of potentially nested constraints diff --git a/staging/api/pkg/constraints/constraint_test.go b/staging/api/pkg/constraints/constraint_test.go index b35e36fa0e..a2df76dcae 100644 --- a/staging/api/pkg/constraints/constraint_test.go +++ b/staging/api/pkg/constraints/constraint_test.go @@ -22,28 +22,28 @@ func TestParse(t *testing.T) { name: "Valid/BasicGVK", input: json.RawMessage(inputBasicGVK), expConstraint: Constraint{ - Message: "blah", - GVK: &GVKConstraint{Group: "example.com", Version: "v1", Kind: "Foo"}, + FailureMessage: "blah", + GVK: &GVKConstraint{Group: "example.com", Version: "v1", Kind: "Foo"}, }, }, { name: "Valid/BasicPackage", input: json.RawMessage(inputBasicPackage), expConstraint: Constraint{ - Message: "blah", - Package: &PackageConstraint{PackageName: "foo", VersionRange: ">=1.0.0"}, + FailureMessage: "blah", + Package: &PackageConstraint{PackageName: "foo", VersionRange: ">=1.0.0"}, }, }, { name: "Valid/BasicAll", input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "all")), expConstraint: Constraint{ - Message: "blah", + FailureMessage: "blah", All: &CompoundConstraint{ Constraints: []Constraint{ { - Message: "blah blah", - Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}, + FailureMessage: "blah blah", + Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}, }, }, }, @@ -53,27 +53,27 @@ func TestParse(t *testing.T) { name: "Valid/BasicAny", input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "any")), expConstraint: Constraint{ - Message: "blah", + FailureMessage: "blah", Any: &CompoundConstraint{ Constraints: []Constraint{ { - Message: "blah blah", - Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}, + FailureMessage: "blah blah", + Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}, }, }, }, }, }, { - name: "Valid/BasicNone", - input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "none")), + name: "Valid/BasicNot", + input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "not")), expConstraint: Constraint{ - Message: "blah", - None: &CompoundConstraint{ + FailureMessage: "blah", + Not: &CompoundConstraint{ Constraints: []Constraint{ { - Message: "blah blah", - Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}, + FailureMessage: "blah blah", + Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}, }, }, }, @@ -83,13 +83,13 @@ func TestParse(t *testing.T) { name: "Valid/Complex", input: json.RawMessage(inputComplex), expConstraint: Constraint{ - Message: "blah", + FailureMessage: "blah", All: &CompoundConstraint{ Constraints: []Constraint{ {Package: &PackageConstraint{PackageName: "fuz", VersionRange: ">=1.0.0"}}, {GVK: &GVKConstraint{Group: "fals.example.com", Kind: "Fal", Version: "v1"}}, { - Message: "foo and buf must be stable versions", + FailureMessage: "foo and buf must be stable versions", All: &CompoundConstraint{ Constraints: []Constraint{ {Package: &PackageConstraint{PackageName: "foo", VersionRange: ">=1.0.0"}}, @@ -99,7 +99,7 @@ func TestParse(t *testing.T) { }, }, { - Message: "blah blah", + FailureMessage: "blah blah", Any: &CompoundConstraint{ Constraints: []Constraint{ {GVK: &GVKConstraint{Group: "foos.example.com", Kind: "Foo", Version: "v1beta1"}}, @@ -109,7 +109,7 @@ func TestParse(t *testing.T) { }, }, { - None: &CompoundConstraint{ + Not: &CompoundConstraint{ Constraints: []Constraint{ {GVK: &GVKConstraint{Group: "bazs.example.com", Kind: "Baz", Version: "v1alpha1"}}, }, @@ -132,7 +132,7 @@ func TestParse(t *testing.T) { { name: "Invalid/UnknownField", input: json.RawMessage( - `{"message": "something", "arbitrary": {"key": "value"}}`, + `{"failureMessage": "something", "arbitrary": {"key": "value"}}`, ), expError: `json: unknown field "arbitrary"`, }, @@ -153,7 +153,7 @@ func TestParse(t *testing.T) { const ( inputBasicGVK = `{ - "message": "blah", + "failureMessage": "blah", "gvk": { "group": "example.com", "version": "v1", @@ -162,7 +162,7 @@ const ( }` inputBasicPackage = `{ - "message": "blah", + "failureMessage": "blah", "package": { "packageName": "foo", "versionRange": ">=1.0.0" @@ -170,11 +170,11 @@ const ( }` inputBasicCompoundTmpl = `{ -"message": "blah", +"failureMessage": "blah", "%s": { "constraints": [ { - "message": "blah blah", + "failureMessage": "blah blah", "package": { "packageName": "fuz", "versionRange": ">=1.0.0" @@ -185,7 +185,7 @@ const ( ` inputComplex = `{ -"message": "blah", +"failureMessage": "blah", "all": { "constraints": [ { @@ -202,7 +202,7 @@ const ( } }, { - "message": "foo and buf must be stable versions", + "failureMessage": "foo and buf must be stable versions", "all": { "constraints": [ { @@ -228,7 +228,7 @@ const ( } }, { - "message": "blah blah", + "failureMessage": "blah blah", "any": { "constraints": [ { @@ -256,7 +256,7 @@ const ( } }, { - "none": { + "not": { "constraints": [ { "gvk": { diff --git a/staging/operator-lifecycle-manager/go.mod b/staging/operator-lifecycle-manager/go.mod index cfdb77c548..1c13e7efc9 100644 --- a/staging/operator-lifecycle-manager/go.mod +++ b/staging/operator-lifecycle-manager/go.mod @@ -25,7 +25,7 @@ require ( github.com/onsi/gomega v1.15.0 github.com/openshift/api v0.0.0-20200331152225-585af27e34fd github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 - github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a + github.com/operator-framework/api v0.12.0 github.com/operator-framework/operator-registry v1.17.5 github.com/otiai10/copy v1.2.0 github.com/pkg/errors v0.9.1 diff --git a/staging/operator-lifecycle-manager/go.sum b/staging/operator-lifecycle-manager/go.sum index cabfccd98f..3748e2a012 100644 --- a/staging/operator-lifecycle-manager/go.sum +++ b/staging/operator-lifecycle-manager/go.sum @@ -927,8 +927,8 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/operator-framework/api v0.7.1/go.mod h1:L7IvLd/ckxJEJg/t4oTTlnHKAJIP/p51AvEslW3wYdY= -github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a h1:tX+zUHdTkn7NfLt9Y8zjsfmSeZkE+sKQEZRqYkVdHYo= -github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA= +github.com/operator-framework/api v0.12.0 h1:aHxHk50/Y1J4Ogdk2J6tYofgX+GEqyBPCMyun+JFqV4= +github.com/operator-framework/api v0.12.0/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA= github.com/operator-framework/operator-registry v1.17.5 h1:LR8m1rFz5Gcyje8WK6iYt+gIhtzqo52zMRALdmTYHT0= github.com/operator-framework/operator-registry v1.17.5/go.mod h1:sRQIgDMZZdUcmHltzyCnM6RUoDF+WS8Arj1BQIARDS8= github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k= diff --git a/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go b/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go index 2ce6231529..037af4207d 100644 --- a/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go +++ b/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go @@ -358,9 +358,9 @@ func CountingPredicate(p Predicate, n *int) Predicate { } type celPredicate struct { - program constraints.CelProgram - rule string - message string + program constraints.CelProgram + rule string + failureMessage string } func (cp *celPredicate) Test(entry *Entry) bool { @@ -383,14 +383,14 @@ func (cp *celPredicate) Test(entry *Entry) bool { return ok } -func CreateCelPredicate(env *constraints.CelEnvironment, rule string, message string) (Predicate, error) { +func CreateCelPredicate(env *constraints.CelEnvironment, rule string, failureMessage string) (Predicate, error) { prog, err := env.Validate(rule) if err != nil { return nil, err } - return &celPredicate{program: prog, rule: rule, message: message}, nil + return &celPredicate{program: prog, rule: rule, failureMessage: failureMessage}, nil } func (cp *celPredicate) String() string { - return fmt.Sprintf("with constraint: %q and message: %q", cp.rule, cp.message) + return fmt.Sprintf("with constraint: %q and message: %q", cp.rule, cp.failureMessage) } diff --git a/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go b/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go index f1b5d42a0f..4905aa3765 100644 --- a/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go +++ b/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go @@ -815,11 +815,11 @@ func (pc *predicateConverter) convertConstraints(constraints ...constraints.Cons case constraint.Any != nil: subs, perr := pc.convertConstraints(constraint.Any.Constraints...) preds[i], err = cache.Or(subs...), perr - case constraint.None != nil: - subs, perr := pc.convertConstraints(constraint.None.Constraints...) + case constraint.Not != nil: + subs, perr := pc.convertConstraints(constraint.Not.Constraints...) preds[i], err = cache.Not(subs...), perr case constraint.Cel != nil: - preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.Message) + preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.FailureMessage) default: // Unknown constraint types are handled by constraints.Parse(), // but parsed constraints may be empty. diff --git a/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver_test.go b/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver_test.go index 776f88e6df..0002c35522 100644 --- a/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver_test.go +++ b/staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver_test.go @@ -803,7 +803,7 @@ func TestSolveOperators_OLMConstraint_CompoundAll(t *testing.T) { catName: csName, catNamespace: namespace, properties: []*api.Property{{ Type: constraints.OLMConstraintType, - Value: `{"message": "all constraint", + Value: `{"failureMessage": "all constraint", "all": {"constraints": [ {"package": {"packageName": "foo", "versionRange": ">=1.0.0"}}, {"gvk": {"group": "g1", "version": "v1", "kind": "k1"}}, @@ -885,7 +885,7 @@ func TestSolveOperators_OLMConstraint_CompoundAny(t *testing.T) { catName: csName, catNamespace: namespace, properties: []*api.Property{{ Type: constraints.OLMConstraintType, - Value: `{"message": "any constraint", + Value: `{"failureMessage": "any constraint", "any": {"constraints": [ {"gvk": {"group": "g1", "version": "v1", "kind": "k1"}}, {"gvk": {"group": "g2", "version": "v2", "kind": "k2"}} @@ -953,7 +953,7 @@ func TestSolveOperators_OLMConstraint_CompoundAny(t *testing.T) { } } -func TestSolveOperators_OLMConstraint_CompoundNone(t *testing.T) { +func TestSolveOperators_OLMConstraint_CompoundNot(t *testing.T) { namespace := "olm" csName := "community" catalog := cache.SourceKey{Name: csName, Namespace: namespace} @@ -965,10 +965,10 @@ func TestSolveOperators_OLMConstraint_CompoundNone(t *testing.T) { properties: []*api.Property{ { Type: constraints.OLMConstraintType, - Value: `{"message": "compound none constraint", + Value: `{"failureMessage": "compound not constraint", "all": {"constraints": [ {"gvk": {"group": "g0", "version": "v0", "kind": "k0"}}, - {"none": {"constraints": [ + {"not": {"constraints": [ {"gvk": {"group": "g1", "version": "v1", "kind": "k1"}}, {"gvk": {"group": "g2", "version": "v2", "kind": "k2"}} ]}} @@ -1050,7 +1050,7 @@ func TestSolveOperators_OLMConstraint_Unknown(t *testing.T) { catName: csName, catNamespace: namespace, properties: []*api.Property{{ Type: constraints.OLMConstraintType, - Value: `{"message": "unknown constraint", "unknown": {"foo": "bar"}}`, + Value: `{"failureMessage": "unknown constraint", "unknown": {"foo": "bar"}}`, }}, }} @@ -2389,21 +2389,21 @@ func TestSolveOperators_GenericConstraint(t *testing.T) { deps1 := []*api.Dependency{ { Type: "olm.constraint", - Value: `{"message":"gvk-constraint", + Value: `{"failureMessage":"gvk-constraint", "cel":{"rule":"properties.exists(p, p.type == 'olm.gvk' && p.value == {'group': 'g', 'version': 'v', 'kind': 'k'})"}}`, }, } deps2 := []*api.Dependency{ { Type: "olm.constraint", - Value: `{"message":"gvk2-constraint", + Value: `{"failureMessage":"gvk2-constraint", "cel":{"rule":"properties.exists(p, p.type == 'olm.gvk' && p.value == {'group': 'g2', 'version': 'v', 'kind': 'k'})"}}`, }, } deps3 := []*api.Dependency{ { Type: "olm.constraint", - Value: `{"message":"package-constraint", + Value: `{"failureMessage":"package-constraint", "cel":{"rule":"properties.exists(p, p.type == 'olm.package' && p.value.packageName == 'packageB' && (semver_compare(p.value.version, '1.0.1') == 0))"}}`, }, } diff --git a/staging/operator-registry/bundles/etcd.0.9.2/metadata/dependencies.yaml b/staging/operator-registry/bundles/etcd.0.9.2/metadata/dependencies.yaml index a4d95d4d9c..41903694a0 100644 --- a/staging/operator-registry/bundles/etcd.0.9.2/metadata/dependencies.yaml +++ b/staging/operator-registry/bundles/etcd.0.9.2/metadata/dependencies.yaml @@ -4,3 +4,8 @@ dependencies: group: testapi.coreos.com kind: testapi version: v1 +- type: olm.constraint + value: + failureMessage: 'require to have "certified"' + cel: + rule: 'properties.exists(p, p.type == "certified")' diff --git a/staging/operator-registry/go.mod b/staging/operator-registry/go.mod index f2c5b49678..b1e82f13d5 100644 --- a/staging/operator-registry/go.mod +++ b/staging/operator-registry/go.mod @@ -36,7 +36,7 @@ require ( github.com/onsi/gomega v1.15.0 github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6 - github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce + github.com/operator-framework/api v0.12.0 github.com/otiai10/copy v1.2.0 github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 github.com/pkg/errors v0.9.1 diff --git a/staging/operator-registry/go.sum b/staging/operator-registry/go.sum index 26c5c94954..10900d0923 100644 --- a/staging/operator-registry/go.sum +++ b/staging/operator-registry/go.sum @@ -645,8 +645,8 @@ github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:e github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= -github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce h1:+zEJrt6Kw4SnN115WzleIpmw5jAgscrWb9K0WgvjhOc= -github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA= +github.com/operator-framework/api v0.12.0 h1:aHxHk50/Y1J4Ogdk2J6tYofgX+GEqyBPCMyun+JFqV4= +github.com/operator-framework/api v0.12.0/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA= github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= diff --git a/staging/operator-registry/pkg/registry/populator_test.go b/staging/operator-registry/pkg/registry/populator_test.go index d6f7533749..1666f58632 100644 --- a/staging/operator-registry/pkg/registry/populator_test.go +++ b/staging/operator-registry/pkg/registry/populator_test.go @@ -151,6 +151,10 @@ func TestQuerierForImage(t *testing.T) { Type: "olm.gvk", Value: `{"group":"etcd.database.coreos.com","kind":"EtcdCluster","version":"v1beta2"}`, }, + { + Type: "olm.constraint", + Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`, + }, }, Properties: []*api.Property{ { @@ -572,6 +576,10 @@ func TestQuerierForDependencies(t *testing.T) { Type: "olm.gvk", Value: `{"group":"testprometheus.coreos.com","kind":"testtestprometheus","version":"v1"}`, }, + { + Type: "olm.constraint", + Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`, + }, } type operatorbundle struct { @@ -635,6 +643,14 @@ func TestListBundles(t *testing.T) { Type: "olm.gvk", Value: `{"group":"etcd.database.coreos.com","kind":"EtcdCluster","version":"v1beta2"}`, }, + { + Type: "olm.constraint", + Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`, + }, + { + Type: "olm.constraint", + Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`, + }, } dependencies := []*api.Dependency{} diff --git a/staging/operator-registry/pkg/registry/registry_to_model.go b/staging/operator-registry/pkg/registry/registry_to_model.go index b45fdf8828..14b6e7b004 100644 --- a/staging/operator-registry/pkg/registry/registry_to_model.go +++ b/staging/operator-registry/pkg/registry/registry_to_model.go @@ -55,6 +55,11 @@ func ObjectsAndPropertiesFromBundle(b *Bundle) ([]string, []property.Property, e return nil, nil, property.ParseError{Idx: i, Typ: p.Type, Err: err} } packageRequiredProps = append(packageRequiredProps, property.MustBuildPackageRequired(v.PackageName, v.Version)) + default: + otherProps = append(otherProps, property.Property{ + Type: p.Type, + Value: p.Value, + }) } } diff --git a/staging/operator-registry/pkg/registry/registry_to_model_test.go b/staging/operator-registry/pkg/registry/registry_to_model_test.go index 14e370d726..8d9f7dcb95 100644 --- a/staging/operator-registry/pkg/registry/registry_to_model_test.go +++ b/staging/operator-registry/pkg/registry/registry_to_model_test.go @@ -1,6 +1,7 @@ package registry import ( + "encoding/json" "testing" "github.com/stretchr/testify/assert" @@ -44,7 +45,12 @@ func testExpectedProperties() []property.Property { property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdCluster"), property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdBackup"), property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdRestore"), + property.Property{ + Type: "olm.constraint", + Value: json.RawMessage(`{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`), + }, } + for _, obj := range testExpectedObjects() { props = append(props, property.MustBuildBundleObjectData([]byte(obj))) } diff --git a/vendor/github.com/operator-framework/api/pkg/constraints/constraint.go b/vendor/github.com/operator-framework/api/pkg/constraints/constraint.go index d59d04542d..f65e8725de 100644 --- a/vendor/github.com/operator-framework/api/pkg/constraints/constraint.go +++ b/vendor/github.com/operator-framework/api/pkg/constraints/constraint.go @@ -12,9 +12,9 @@ const OLMConstraintType = "olm.constraint" // Constraint holds parsed, potentially nested dependency constraints. type Constraint struct { - // Constraint message that surfaces in resolution + // Constraint failure message that surfaces in resolution // This field is optional - Message string `json:"message,omitempty" yaml:"message,omitempty"` + FailureMessage string `json:"failureMessage,omitempty" yaml:"failureMessage,omitempty"` // The cel struct that contraints CEL expression Cel *Cel `json:"cel,omitempty" yaml:"cel,omitempty"` @@ -25,14 +25,15 @@ type Constraint struct { // GVK defines a constraint for a GVK. GVK *GVKConstraint `json:"gvk,omitempty" yaml:"gvk,omitempty"` - // All, Any, and None are compound constraints. See this enhancement for details: + // All, Any, and Not are compound constraints. See this enhancement for details: // https://github.com/operator-framework/enhancements/blob/master/enhancements/compound-bundle-constraints.md All *CompoundConstraint `json:"all,omitempty" yaml:"all,omitempty"` Any *CompoundConstraint `json:"any,omitempty" yaml:"any,omitempty"` - // A note on None: this constraint is not particularly useful by itself. + // A note on Not: this constraint isn't particularly useful by itself. // It should be used within an All constraint alongside some other constraint type - // since saying "none of these GVKs/packages/etc." without an alternative doesn't make sense. - None *CompoundConstraint `json:"none,omitempty" yaml:"none,omitempty"` + // since saying "do not use any of these GVKs/packages/etc." without an alternative + // doesn't make sense. + Not *CompoundConstraint `json:"not,omitempty" yaml:"not,omitempty"` } // CompoundConstraint holds a list of potentially nested constraints diff --git a/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go b/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go index 2ce6231529..037af4207d 100644 --- a/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go +++ b/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache/predicates.go @@ -358,9 +358,9 @@ func CountingPredicate(p Predicate, n *int) Predicate { } type celPredicate struct { - program constraints.CelProgram - rule string - message string + program constraints.CelProgram + rule string + failureMessage string } func (cp *celPredicate) Test(entry *Entry) bool { @@ -383,14 +383,14 @@ func (cp *celPredicate) Test(entry *Entry) bool { return ok } -func CreateCelPredicate(env *constraints.CelEnvironment, rule string, message string) (Predicate, error) { +func CreateCelPredicate(env *constraints.CelEnvironment, rule string, failureMessage string) (Predicate, error) { prog, err := env.Validate(rule) if err != nil { return nil, err } - return &celPredicate{program: prog, rule: rule, message: message}, nil + return &celPredicate{program: prog, rule: rule, failureMessage: failureMessage}, nil } func (cp *celPredicate) String() string { - return fmt.Sprintf("with constraint: %q and message: %q", cp.rule, cp.message) + return fmt.Sprintf("with constraint: %q and message: %q", cp.rule, cp.failureMessage) } diff --git a/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go b/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go index f1b5d42a0f..4905aa3765 100644 --- a/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go +++ b/vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go @@ -815,11 +815,11 @@ func (pc *predicateConverter) convertConstraints(constraints ...constraints.Cons case constraint.Any != nil: subs, perr := pc.convertConstraints(constraint.Any.Constraints...) preds[i], err = cache.Or(subs...), perr - case constraint.None != nil: - subs, perr := pc.convertConstraints(constraint.None.Constraints...) + case constraint.Not != nil: + subs, perr := pc.convertConstraints(constraint.Not.Constraints...) preds[i], err = cache.Not(subs...), perr case constraint.Cel != nil: - preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.Message) + preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.FailureMessage) default: // Unknown constraint types are handled by constraints.Parse(), // but parsed constraints may be empty. diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/registry/registry_to_model.go b/vendor/github.com/operator-framework/operator-registry/pkg/registry/registry_to_model.go index b45fdf8828..14b6e7b004 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/registry/registry_to_model.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/registry/registry_to_model.go @@ -55,6 +55,11 @@ func ObjectsAndPropertiesFromBundle(b *Bundle) ([]string, []property.Property, e return nil, nil, property.ParseError{Idx: i, Typ: p.Type, Err: err} } packageRequiredProps = append(packageRequiredProps, property.MustBuildPackageRequired(v.PackageName, v.Version)) + default: + otherProps = append(otherProps, property.Property{ + Type: p.Type, + Value: p.Value, + }) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index e2004212de..55a56718ac 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -497,7 +497,7 @@ github.com/openshift/client-go/config/informers/externalversions/config github.com/openshift/client-go/config/informers/externalversions/config/v1 github.com/openshift/client-go/config/informers/externalversions/internalinterfaces github.com/openshift/client-go/config/listers/config/v1 -# github.com/operator-framework/api v0.10.8-0.20211210205029-40cb9fd4036a => ./staging/api +# github.com/operator-framework/api v0.12.0 => ./staging/api ## explicit github.com/operator-framework/api/crds github.com/operator-framework/api/pkg/constraints