Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump cel go to latest version #118339

Merged
merged 2 commits into from
Jun 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions LICENSES/vendor/golang.org/x/exp/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/google/cadvisor v0.47.1
github.com/google/cel-go v0.12.6
github.com/google/cel-go v0.16.0
github.com/google/gnostic v0.5.7-v3refs
github.com/google/go-cmp v0.5.9
github.com/google/gofuzz v1.2.0
Expand Down Expand Up @@ -141,7 +141,7 @@ require (
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
Expand Down Expand Up @@ -230,6 +230,7 @@ require (
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
jpbetz marked this conversation as resolved.
Show resolved Hide resolved
golang.org/x/mod v0.10.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 h1:yL7+Jz0jTC6yykIK/Wh74gnTJnrGr5AyrNMXuA0gves=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand Down Expand Up @@ -351,8 +351,8 @@ github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/cadvisor v0.47.1 h1:YyKnRy/3myRNGOvF1bNF9FFnpjY7Gky5yKi/ZlN+BSo=
github.com/google/cadvisor v0.47.1/go.mod h1:iJdTjcjyKHjLCf7OSTzwP5GxdfrkPusw2x5bwGvuLUw=
github.com/google/cel-go v0.12.6 h1:kjeKudqV0OygrAqA9fX6J55S8gj+Jre2tckIm5RoG4M=
github.com/google/cel-go v0.12.6/go.mod h1:Jk7ljRzLBhkmiAwBoUxB1sZSCVBAzkqPF25olK/iRDw=
github.com/google/cel-go v0.16.0 h1:DG9YQ8nFCFXAs/FDDwBxmL1tpKNrdlGUM9U3537bX/Y=
github.com/google/cel-go v0.16.0/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=
github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -785,6 +785,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
9 changes: 7 additions & 2 deletions hack/unwanted-dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"gopkg.in/fsnotify.v1": "obsolete, use github.com/fsnotify/fsnotify",
"k8s.io/klog": "we have switched to klog v2, so avoid klog v1",
"rsc.io/quote": "refer to #102833",
"rsc.io/sampler": "refer to #102833"
"rsc.io/sampler": "refer to #102833",
"golang.org/x/exp": "This subrepository holds experimental and deprecated packages"
}
},
"status": {
Expand Down Expand Up @@ -168,7 +169,6 @@
"github.com/container-storage-interface/spec",
"github.com/containerd/ttrpc",
"github.com/google/cadvisor",
"github.com/google/cel-go",
"github.com/google/gnostic",
"github.com/googleapis/gax-go/v2",
"github.com/grpc-ecosystem/go-grpc-middleware",
Expand All @@ -182,8 +182,13 @@
"go.opentelemetry.io/otel/exporters/otlp/otlptrace",
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc",
"google.golang.org/api",
"google.golang.org/genproto/googleapis/api",
"google.golang.org/grpc",
"sigs.k8s.io/apiserver-network-proxy/konnectivity-client"
],
"golang.org/x/exp": [
"github.com/google/cel-go",
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
]
}
}
Expand Down
5 changes: 3 additions & 2 deletions staging/src/k8s.io/apiextensions-apiserver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.20
require (
github.com/emicklei/go-restful/v3 v3.9.0
github.com/gogo/protobuf v1.3.2
github.com/google/cel-go v0.12.6
github.com/google/cel-go v0.16.0
github.com/google/gnostic v0.5.7-v3refs
github.com/google/go-cmp v0.5.9
github.com/google/gofuzz v1.2.0
Expand Down Expand Up @@ -39,7 +39,7 @@ require (

require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand Down Expand Up @@ -105,6 +105,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.19.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
Expand Down
11 changes: 7 additions & 4 deletions staging/src/k8s.io/apiextensions-apiserver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,41 @@ func TestCelCostStability(t *testing.T) {
"self.listOfListMap[0].exists(e, e.k3 == '3' && e.v3 == 'i')": 14,
},
},
{name: "optionals",
obj: map[string]interface{}{
"obj": map[string]interface{}{
"field": "a",
},
"m": map[string]interface{}{
"k": "v",
},
"l": []interface{}{
"a",
},
},
schema: objectTypePtr(map[string]schema.Structural{
"obj": objectType(map[string]schema.Structural{
"field": stringType,
"absentField": stringType,
}),
"m": mapType(&stringType),
"l": listType(&stringType),
}),
expectCost: map[string]int64{
"optional.of('a') != optional.of('b')": 3,
"optional.of('a') != optional.none()": 3,
"optional.of('a').hasValue()": 2,
"optional.of('a').or(optional.of('a')).hasValue()": 2, // or() is short-circuited
"optional.none().or(optional.of('a')).hasValue()": 3,
"optional.of('a').optMap(v, v == 'value').hasValue()": 8,
"self.obj.?field == optional.of('a')": 5,
"self.obj.?absentField == optional.none()": 4,
"self.obj.?field.orValue('v') == 'a'": 4,
"self.m[?'k'] == optional.of('v')": 5,
"self.l[?0] == optional.of('a')": 5,
"optional.ofNonZeroValue(1).hasValue()": 2,
},
},
}

for _, tt := range cases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ func TestValidationExpressions(t *testing.T) {
errors: map[string]string{
// Invalid regex with a string constant regex pattern is compile time error
"self.val1.matches(')')": "compile error: program instantiation failed: error parsing regexp: unexpected ): `)`",
// strings version 0 does not have format or join
// TODO: Replace this error test with valid tests when the string version is bumped.
"'%s %i'.format('a', 1) == 'a 1'": "undeclared reference to 'format'",
},
},
{name: "escaped strings",
Expand Down Expand Up @@ -1842,6 +1845,88 @@ func TestValidationExpressions(t *testing.T) {
"authorizer.path('/healthz').check('get').allowed()": "undeclared reference to 'authorizer'",
},
},
{name: "optionals", // https://github.com/google/cel-spec/wiki/proposal-246
jpbetz marked this conversation as resolved.
Show resolved Hide resolved
obj: map[string]interface{}{
"presentObj": map[string]interface{}{
"presentStr": "value",
},
"m": map[string]interface{}{"k": "v"},
"l": []interface{}{"a"},
},
schema: objectTypePtr(map[string]schema.Structural{
"presentObj": objectType(map[string]schema.Structural{
"presentStr": stringType,
}),
"absentObj": objectType(map[string]schema.Structural{
"absentStr": stringType,
}),
"m": mapType(&stringType),
"l": listType(&stringType),
}),
valid: []string{
"self.?presentObj.?presentStr == optional.of('value')",
"self.presentObj.?presentStr == optional.of('value')",
"self.presentObj.?presentStr.or(optional.of('nope')) == optional.of('value')",
"self.presentObj.?presentStr.orValue('') == 'value'",
"self.presentObj.?presentStr.hasValue() == true",
"self.presentObj.?presentStr.optMap(v, v == 'value').hasValue()",
"self.?absentObj.?absentStr == optional.none()",
"self.?absentObj.?absentStr.or(optional.of('nope')) == optional.of('nope')",
"self.?absentObj.?absentStr.orValue('nope') == 'nope'",
"self.?absentObj.?absentStr.hasValue() == false",
"self.?absentObj.?absentStr.optMap(v, v == 'value').hasValue() == false",

"self.m[?'k'] == optional.of('v')",
"self.m[?'k'].or(optional.of('nope')) == optional.of('v')",
"self.m[?'k'].orValue('') == 'v'",
"self.m[?'k'].hasValue() == true",
"self.m[?'k'].optMap(v, v == 'v').hasValue()",
"self.m[?'x'] == optional.none()",
"self.m[?'x'].or(optional.of('nope')) == optional.of('nope')",
"self.m[?'x'].orValue('nope') == 'nope'",
"self.m[?'x'].hasValue() == false",
"self.m[?'x'].hasValue() == false",

"self.l[?0] == optional.of('a')",
"self.l[?1] == optional.none()",
"self.l[?0].orValue('') == 'a'",
"self.l[?0].hasValue() == true",
"self.l[?0].optMap(v, v == 'a').hasValue()",
"self.l[?1] == optional.none()",
"self.l[?1].or(optional.of('nope')) == optional.of('nope')",
"self.l[?1].orValue('nope') == 'nope'",
"self.l[?1].hasValue() == false",
"self.l[?1].hasValue() == false",

"optional.ofNonZeroValue(1).hasValue()",
"optional.ofNonZeroValue(uint(1)).hasValue()",
"optional.ofNonZeroValue(1.1).hasValue()",
"optional.ofNonZeroValue('a').hasValue()",
"optional.ofNonZeroValue(true).hasValue()",
"optional.ofNonZeroValue(['a']).hasValue()",
"optional.ofNonZeroValue({'k': 'v'}).hasValue()",
"optional.ofNonZeroValue(timestamp('2011-08-18T00:00:00.000+01:00')).hasValue()",
"optional.ofNonZeroValue(duration('19h3m37s10ms')).hasValue()",
"optional.ofNonZeroValue(null) == optional.none()",
"optional.ofNonZeroValue(0) == optional.none()",
"optional.ofNonZeroValue(uint(0)) == optional.none()",
"optional.ofNonZeroValue(0.0) == optional.none()",
"optional.ofNonZeroValue('') == optional.none()",
"optional.ofNonZeroValue(false) == optional.none()",
"optional.ofNonZeroValue([]) == optional.none()",
"optional.ofNonZeroValue({}) == optional.none()",
"optional.ofNonZeroValue(timestamp('0001-01-01T00:00:00.000+00:00')) == optional.none()",
"optional.ofNonZeroValue(duration('0s')) == optional.none()",

"{?'k': optional.none(), 'k2': 'v2'} == {'k2': 'v2'}",
"{?'k': optional.of('v'), 'k2': 'v2'} == {'k': 'v', 'k2': 'v2'}",
"['a', ?optional.none(), 'c'] == ['a', 'c']",
"['a', ?optional.of('v'), 'c'] == ['a', 'v', 'c']",
},
errors: map[string]string{
"self.absentObj.?absentStr == optional.none()": "no such key: absentObj", // missing ?. operator on first deref is an error
},
},
}

for i := range tests {
Expand Down Expand Up @@ -2262,7 +2347,7 @@ func TestCELValidationContextCancellation(t *testing.T) {

// This is the most recursive operations we expect to be able to include in an expression.
// This number could get larger with more improvements in the grammar or ANTLR stack, but should *never* decrease or previously valid expressions could be treated as invalid.
const maxValidDepth = 243
const maxValidDepth = 250
jpbetz marked this conversation as resolved.
Show resolved Hide resolved

// TestCELMaxRecursionDepth tests CEL setting for maxRecursionDepth.
func TestCELMaxRecursionDepth(t *testing.T) {
Expand Down Expand Up @@ -2397,15 +2482,15 @@ func TestMessageExpression(t *testing.T) {
message: "message not messageExpression",
messageExpression: `"str1 " + ["a", "b", "c", "d"][4]`,
costBudget: 50,
expectedLogErr: "messageExpression evaluation failed due to: index '4' out of range in list size '4'",
expectedLogErr: "messageExpression evaluation failed due to: index out of bounds: 4",
expectedValidationErr: "message not messageExpression",
expectedRemainingBudget: 47,
},
{
name: "runtime cost preserved if messageExpression fails during evaluation (no message set)",
messageExpression: `"str1 " + ["a", "b", "c", "d"][4]`,
costBudget: 50,
expectedLogErr: "messageExpression evaluation failed due to: index '4' out of range in list size '4'",
expectedLogErr: "messageExpression evaluation failed due to: index out of bounds: 4",
expectedValidationErr: "failed rule",
expectedRemainingBudget: 47,
},
Expand Down