Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.11.1
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
Expand Down
4 changes: 2 additions & 2 deletions staging/api/pkg/constraints/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
48 changes: 24 additions & 24 deletions staging/api/pkg/constraints/constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
},
Expand All @@ -53,12 +53,12 @@ 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"},
},
},
},
Expand All @@ -68,12 +68,12 @@ func TestParse(t *testing.T) {
name: "Valid/BasicNone",
input: json.RawMessage(fmt.Sprintf(inputBasicCompoundTmpl, "none")),
expConstraint: Constraint{
Message: "blah",
FailureMessage: "blah",
None: &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"},
},
},
},
Expand All @@ -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"}},
Expand All @@ -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"}},
Expand Down Expand Up @@ -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"`,
},
Expand All @@ -153,7 +153,7 @@ func TestParse(t *testing.T) {

const (
inputBasicGVK = `{
"message": "blah",
"failureMessage": "blah",
"gvk": {
"group": "example.com",
"version": "v1",
Expand All @@ -162,19 +162,19 @@ const (
}`

inputBasicPackage = `{
"message": "blah",
"failureMessage": "blah",
"package": {
"packageName": "foo",
"versionRange": ">=1.0.0"
}
}`

inputBasicCompoundTmpl = `{
"message": "blah",
"failureMessage": "blah",
"%s": {
"constraints": [
{
"message": "blah blah",
"failureMessage": "blah blah",
"package": {
"packageName": "fuz",
"versionRange": ">=1.0.0"
Expand All @@ -185,7 +185,7 @@ const (
`

inputComplex = `{
"message": "blah",
"failureMessage": "blah",
"all": {
"constraints": [
{
Expand All @@ -202,7 +202,7 @@ const (
}
},
{
"message": "foo and buf must be stable versions",
"failureMessage": "foo and buf must be stable versions",
"all": {
"constraints": [
{
Expand All @@ -228,7 +228,7 @@ const (
}
},
{
"message": "blah blah",
"failureMessage": "blah blah",
"any": {
"constraints": [
{
Expand Down
2 changes: 1 addition & 1 deletion staging/operator-lifecycle-manager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.11.1
github.com/operator-framework/operator-registry v1.17.5
github.com/otiai10/copy v1.2.0
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions staging/operator-lifecycle-manager/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.11.1 h1:5eNUMplyL/GZrnBgG4SS2csO3+Fl4F79OqXN6POHQyA=
github.com/operator-framework/api v0.11.1/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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ func (pc *predicateConverter) convertConstraints(constraints ...constraints.Cons
subs, perr := pc.convertConstraints(constraint.None.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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down Expand Up @@ -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"}}
Expand Down Expand Up @@ -965,7 +965,7 @@ func TestSolveOperators_OLMConstraint_CompoundNone(t *testing.T) {
properties: []*api.Property{
{
Type: constraints.OLMConstraintType,
Value: `{"message": "compound none constraint",
Value: `{"failureMessage": "compound none constraint",
"all": {"constraints": [
{"gvk": {"group": "g0", "version": "v0", "kind": "k0"}},
{"none": {"constraints": [
Expand Down Expand Up @@ -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"}}`,
}},
}}

Expand Down Expand Up @@ -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))"}}`,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")'
2 changes: 1 addition & 1 deletion staging/operator-registry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.11.1
github.com/otiai10/copy v1.2.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions staging/operator-registry/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.11.1 h1:5eNUMplyL/GZrnBgG4SS2csO3+Fl4F79OqXN6POHQyA=
github.com/operator-framework/api v0.11.1/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=
Expand Down
16 changes: 16 additions & 0 deletions staging/operator-registry/pkg/registry/populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}
Expand Down
5 changes: 5 additions & 0 deletions staging/operator-registry/pkg/registry/registry_to_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}

Expand Down
Loading