Skip to content

Commit 25a7159

Browse files
authored
chore(constraint): Correct message to failureMessage in olm.constraint schema (#2572)
The correct field for olm.constraint is `failureMessage` instead of `message` as it is currently in the code. This change is to honor the field name that is specified in the original enhancement. Signed-off-by: Vu Dinh <[email protected]>
1 parent 9fd1c3f commit 25a7159

File tree

9 files changed

+49
-22
lines changed

9 files changed

+49
-22
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/onsi/gomega v1.15.0
2525
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
2626
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0
27-
github.com/operator-framework/api v0.11.0
27+
github.com/operator-framework/api v0.11.1
2828
github.com/operator-framework/operator-registry v1.17.5
2929
github.com/otiai10/copy v1.2.0
3030
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 2 additions & 2 deletions
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.11.0 h1:W9V1NNwl3LWPQL9S1pDaFONCarJLl8Xu6gdF9w54hTE=
931-
github.com/operator-framework/api v0.11.0/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
930+
github.com/operator-framework/api v0.11.1 h1:5eNUMplyL/GZrnBgG4SS2csO3+Fl4F79OqXN6POHQyA=
931+
github.com/operator-framework/api v0.11.1/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=

pkg/controller/registry/resolver/cache/predicates.go

Lines changed: 6 additions & 6 deletions
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
}

pkg/controller/registry/resolver/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func (pc *predicateConverter) convertConstraints(constraints ...constraints.Cons
837837
subs, perr := pc.convertConstraints(constraint.None.Constraints...)
838838
preds[i], err = cache.Not(subs...), perr
839839
case constraint.Cel != nil:
840-
preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.Message)
840+
preds[i], err = cache.CreateCelPredicate(pc.celEnv, constraint.Cel.Rule, constraint.FailureMessage)
841841
default:
842842
// Unknown constraint types are handled by constraints.Parse(),
843843
// but parsed constraints may be empty.

pkg/controller/registry/resolver/resolver_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ func TestSolveOperators_OLMConstraint_CompoundAll(t *testing.T) {
903903
catName: csName, catNamespace: namespace,
904904
properties: []*api.Property{{
905905
Type: constraints.OLMConstraintType,
906-
Value: `{"message": "all constraint",
906+
Value: `{"failureMessage": "all constraint",
907907
"all": {"constraints": [
908908
{"package": {"packageName": "foo", "versionRange": ">=1.0.0"}},
909909
{"gvk": {"group": "g1", "version": "v1", "kind": "k1"}},
@@ -985,7 +985,7 @@ func TestSolveOperators_OLMConstraint_CompoundAny(t *testing.T) {
985985
catName: csName, catNamespace: namespace,
986986
properties: []*api.Property{{
987987
Type: constraints.OLMConstraintType,
988-
Value: `{"message": "any constraint",
988+
Value: `{"failureMessage": "any constraint",
989989
"any": {"constraints": [
990990
{"gvk": {"group": "g1", "version": "v1", "kind": "k1"}},
991991
{"gvk": {"group": "g2", "version": "v2", "kind": "k2"}}
@@ -1065,7 +1065,7 @@ func TestSolveOperators_OLMConstraint_CompoundNone(t *testing.T) {
10651065
properties: []*api.Property{
10661066
{
10671067
Type: constraints.OLMConstraintType,
1068-
Value: `{"message": "compound none constraint",
1068+
Value: `{"failureMessage": "compound none constraint",
10691069
"all": {"constraints": [
10701070
{"gvk": {"group": "g0", "version": "v0", "kind": "k0"}},
10711071
{"none": {"constraints": [
@@ -1150,7 +1150,7 @@ func TestSolveOperators_OLMConstraint_Unknown(t *testing.T) {
11501150
catName: csName, catNamespace: namespace,
11511151
properties: []*api.Property{{
11521152
Type: constraints.OLMConstraintType,
1153-
Value: `{"message": "unknown constraint", "unknown": {"foo": "bar"}}`,
1153+
Value: `{"failureMessage": "unknown constraint", "unknown": {"foo": "bar"}}`,
11541154
}},
11551155
}}
11561156

@@ -2489,21 +2489,21 @@ func TestSolveOperators_GenericConstraint(t *testing.T) {
24892489
deps1 := []*api.Dependency{
24902490
{
24912491
Type: "olm.constraint",
2492-
Value: `{"message":"gvk-constraint",
2492+
Value: `{"failureMessage":"gvk-constraint",
24932493
"cel":{"rule":"properties.exists(p, p.type == 'olm.gvk' && p.value == {'group': 'g', 'version': 'v', 'kind': 'k'})"}}`,
24942494
},
24952495
}
24962496
deps2 := []*api.Dependency{
24972497
{
24982498
Type: "olm.constraint",
2499-
Value: `{"message":"gvk2-constraint",
2499+
Value: `{"failureMessage":"gvk2-constraint",
25002500
"cel":{"rule":"properties.exists(p, p.type == 'olm.gvk' && p.value == {'group': 'g2', 'version': 'v', 'kind': 'k'})"}}`,
25012501
},
25022502
}
25032503
deps3 := []*api.Dependency{
25042504
{
25052505
Type: "olm.constraint",
2506-
Value: `{"message":"package-constraint",
2506+
Value: `{"failureMessage":"package-constraint",
25072507
"cel":{"rule":"properties.exists(p, p.type == 'olm.package' && p.value.packageName == 'packageB' && (semver_compare(p.value.version, '1.0.1') == 0))"}}`,
25082508
},
25092509
}

vendor/github.com/operator-framework/api/pkg/constraints/constraint.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/api/pkg/validation/internal/csv.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/api/pkg/validation/internal/good_practices.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ github.com/openshift/client-go/config/informers/externalversions/config
624624
github.com/openshift/client-go/config/informers/externalversions/config/v1
625625
github.com/openshift/client-go/config/informers/externalversions/internalinterfaces
626626
github.com/openshift/client-go/config/listers/config/v1
627-
# github.com/operator-framework/api v0.11.0
627+
# github.com/operator-framework/api v0.11.1
628628
## explicit; go 1.16
629629
github.com/operator-framework/api/crds
630630
github.com/operator-framework/api/pkg/constraints

0 commit comments

Comments
 (0)