mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #121577 from cici37/celFixPick
Bump cel-go to v0.17.7 and introduce set ext library with new options
This commit is contained in:
commit
d1113c9a00
2
go.mod
2
go.mod
@ -39,7 +39,7 @@ require (
|
|||||||
github.com/golang/mock v1.6.0
|
github.com/golang/mock v1.6.0
|
||||||
github.com/golang/protobuf v1.5.3
|
github.com/golang/protobuf v1.5.3
|
||||||
github.com/google/cadvisor v0.47.3
|
github.com/google/cadvisor v0.47.3
|
||||||
github.com/google/cel-go v0.17.6
|
github.com/google/cel-go v0.17.7
|
||||||
github.com/google/gnostic-models v0.6.8
|
github.com/google/gnostic-models v0.6.8
|
||||||
github.com/google/go-cmp v0.6.0
|
github.com/google/go-cmp v0.6.0
|
||||||
github.com/google/gofuzz v1.2.0
|
github.com/google/gofuzz v1.2.0
|
||||||
|
4
go.sum
4
go.sum
@ -480,8 +480,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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cadvisor v0.47.3 h1:5XKTHBduWlBjmgw07uwEiC+Xa/FRd0MZI37oqlTagO0=
|
github.com/google/cadvisor v0.47.3 h1:5XKTHBduWlBjmgw07uwEiC+Xa/FRd0MZI37oqlTagO0=
|
||||||
github.com/google/cadvisor v0.47.3/go.mod h1:iJdTjcjyKHjLCf7OSTzwP5GxdfrkPusw2x5bwGvuLUw=
|
github.com/google/cadvisor v0.47.3/go.mod h1:iJdTjcjyKHjLCf7OSTzwP5GxdfrkPusw2x5bwGvuLUw=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
@ -8,7 +8,7 @@ require (
|
|||||||
github.com/emicklei/go-restful/v3 v3.11.0
|
github.com/emicklei/go-restful/v3 v3.11.0
|
||||||
github.com/evanphx/json-patch v4.12.0+incompatible
|
github.com/evanphx/json-patch v4.12.0+incompatible
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
github.com/google/cel-go v0.17.6
|
github.com/google/cel-go v0.17.7
|
||||||
github.com/google/gnostic-models v0.6.8
|
github.com/google/gnostic-models v0.6.8
|
||||||
github.com/google/go-cmp v0.6.0
|
github.com/google/go-cmp v0.6.0
|
||||||
github.com/google/gofuzz v1.2.0
|
github.com/google/gofuzz v1.2.0
|
||||||
|
@ -223,8 +223,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
|||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
@ -230,8 +230,8 @@ func TestCelCostStability(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{name: "listSets",
|
{name: "listSets",
|
||||||
obj: objs([]interface{}{"a", "b", "c"}, []interface{}{"a", "c", "b"}),
|
obj: objs([]interface{}{"a", "b", "c"}, []interface{}{"a", "c", "b"}, buildLargeArray(1000)),
|
||||||
schema: schemas(listSetType(&stringType), listSetType(&stringType)),
|
schema: schemas(listSetType(&stringType), listSetType(&stringType), listSetType(&integerType)),
|
||||||
expectCost: map[string]int64{
|
expectCost: map[string]int64{
|
||||||
// equal even though order is different
|
// equal even though order is different
|
||||||
"self.val1 == ['c', 'b', 'a']": 3,
|
"self.val1 == ['c', 'b', 'a']": 3,
|
||||||
@ -241,6 +241,12 @@ func TestCelCostStability(t *testing.T) {
|
|||||||
"!('x' in self.val1)": 6,
|
"!('x' in self.val1)": 6,
|
||||||
"self.val1 + self.val2 == ['a', 'b', 'c']": 6,
|
"self.val1 + self.val2 == ['a', 'b', 'c']": 6,
|
||||||
"self.val1 + ['c', 'd'] == ['a', 'b', 'c', 'd']": 4,
|
"self.val1 + ['c', 'd'] == ['a', 'b', 'c', 'd']": 4,
|
||||||
|
"sets.contains(self.val1, ['a'])": 6,
|
||||||
|
"sets.equivalent(self.val1, ['a', 'b', 'c'])": 21,
|
||||||
|
"sets.intersects(self.val1, ['a'])": 6,
|
||||||
|
"sets.contains(self.val3, [1])": 1003,
|
||||||
|
"!sets.equivalent(self.val3, [1, 2, 3])": 6004,
|
||||||
|
"sets.intersects(self.val3, [1])": 1003,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{name: "listMaps",
|
{name: "listMaps",
|
||||||
@ -1157,6 +1163,14 @@ func TestCelCostStability(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildLargeArray(size int) []interface{} {
|
||||||
|
lArray := make([]interface{}, size)
|
||||||
|
for i := 0; i < len(lArray); i++ {
|
||||||
|
lArray[i] = i
|
||||||
|
}
|
||||||
|
return lArray
|
||||||
|
}
|
||||||
|
|
||||||
func TestCelEstimatedCostStability(t *testing.T) {
|
func TestCelEstimatedCostStability(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -11,7 +11,7 @@ require (
|
|||||||
github.com/evanphx/json-patch v4.12.0+incompatible
|
github.com/evanphx/json-patch v4.12.0+incompatible
|
||||||
github.com/fsnotify/fsnotify v1.7.0
|
github.com/fsnotify/fsnotify v1.7.0
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
github.com/google/cel-go v0.17.6
|
github.com/google/cel-go v0.17.7
|
||||||
github.com/google/gnostic-models v0.6.8
|
github.com/google/gnostic-models v0.6.8
|
||||||
github.com/google/go-cmp v0.6.0
|
github.com/google/go-cmp v0.6.0
|
||||||
github.com/google/gofuzz v1.2.0
|
github.com/google/gofuzz v1.2.0
|
||||||
|
4
staging/src/k8s.io/apiserver/go.sum
generated
4
staging/src/k8s.io/apiserver/go.sum
generated
@ -223,8 +223,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
|||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
@ -22,7 +22,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/google/cel-go/cel"
|
"github.com/google/cel-go/cel"
|
||||||
|
"github.com/google/cel-go/checker"
|
||||||
"github.com/google/cel-go/ext"
|
"github.com/google/cel-go/ext"
|
||||||
|
"github.com/google/cel-go/interpreter"
|
||||||
"golang.org/x/sync/singleflight"
|
"golang.org/x/sync/singleflight"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/version"
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
@ -106,6 +108,21 @@ var baseOpts = []VersionedOptions{
|
|||||||
ext.Strings(ext.StringsVersion(2)),
|
ext.Strings(ext.StringsVersion(2)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// Set library
|
||||||
|
{
|
||||||
|
IntroducedVersion: version.MajorMinor(1, 29),
|
||||||
|
EnvOptions: []cel.EnvOption{
|
||||||
|
ext.Sets(),
|
||||||
|
// cel-go v0.17.7 introduced CostEstimatorOptions.
|
||||||
|
// Previous the presence has a cost of 0 but cel fixed it to 1. We still set to 0 here to avoid breaking changes.
|
||||||
|
cel.CostEstimatorOptions(checker.PresenceTestHasCost(false)),
|
||||||
|
},
|
||||||
|
ProgramOptions: []cel.ProgramOption{
|
||||||
|
// cel-go v0.17.7 introduced CostTrackerOptions.
|
||||||
|
// Previous the presence has a cost of 0 but cel fixed it to 1. We still set to 0 here to avoid breaking changes.
|
||||||
|
cel.CostTrackerOptions(interpreter.PresenceTestHasCost(false)),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustBaseEnvSet returns the common CEL base environments for Kubernetes for Version, or panics
|
// MustBaseEnvSet returns the common CEL base environments for Kubernetes for Version, or panics
|
||||||
|
@ -527,6 +527,236 @@ func TestQuantityCost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetsCost(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
expr string
|
||||||
|
expectEstimatedCost checker.CostEstimate
|
||||||
|
expectRuntimeCost uint64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "sets",
|
||||||
|
expr: `sets.contains([], [])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 21, Max: 21},
|
||||||
|
expectRuntimeCost: 21,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1], [])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 21, Max: 21},
|
||||||
|
expectRuntimeCost: 21,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 22, Max: 22},
|
||||||
|
expectRuntimeCost: 22,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1], [1, 1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1, 1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([2, 1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1, 2, 3, 4], [2, 3])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 29, Max: 29},
|
||||||
|
expectRuntimeCost: 29,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1], [1.0, 1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1, 2], [2u, 2.0])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 25, Max: 25},
|
||||||
|
expectRuntimeCost: 25,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1, 2u], [2, 2.0])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 25, Max: 25},
|
||||||
|
expectRuntimeCost: 25,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([1, 2.0, 3u], [1.0, 2u, 3])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 30, Max: 30},
|
||||||
|
expectRuntimeCost: 30,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.contains([[1], [2, 3]], [[2, 3.0]])`,
|
||||||
|
// 10 for each list creation, top-level list sizes are 2, 1
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 53, Max: 53},
|
||||||
|
expectRuntimeCost: 53,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.contains([1], [2])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.contains([1], [1, 2])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 24, Max: 24},
|
||||||
|
expectRuntimeCost: 24,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.contains([1], ["1", 1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 24, Max: 24},
|
||||||
|
expectRuntimeCost: 24,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.contains([1], [1.1, 1u])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 24, Max: 24},
|
||||||
|
expectRuntimeCost: 24,
|
||||||
|
},
|
||||||
|
|
||||||
|
// set equivalence (note the cost factor is higher as it's basically two contains checks)
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([], [])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 21, Max: 21},
|
||||||
|
expectRuntimeCost: 21,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([1], [1, 1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 25, Max: 25},
|
||||||
|
expectRuntimeCost: 25,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([1, 1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 25, Max: 25},
|
||||||
|
expectRuntimeCost: 25,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([1], [1u, 1.0])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 25, Max: 25},
|
||||||
|
expectRuntimeCost: 25,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([1], [1u, 1.0])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 25, Max: 25},
|
||||||
|
expectRuntimeCost: 25,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([1, 2, 3], [3u, 2.0, 1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 39, Max: 39},
|
||||||
|
expectRuntimeCost: 39,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.equivalent([[1.0], [2, 3]], [[1], [2, 3.0]])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 69, Max: 69},
|
||||||
|
expectRuntimeCost: 69,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.equivalent([2, 1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 26, Max: 26},
|
||||||
|
expectRuntimeCost: 26,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.equivalent([1], [1, 2])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 26, Max: 26},
|
||||||
|
expectRuntimeCost: 26,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.equivalent([1, 2], [2u, 2, 2.0])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 34, Max: 34},
|
||||||
|
expectRuntimeCost: 34,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.equivalent([1, 2], [1u, 2, 2.3])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 34, Max: 34},
|
||||||
|
expectRuntimeCost: 34,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 22, Max: 22},
|
||||||
|
expectRuntimeCost: 22,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([1], [1, 1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([1, 1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([2, 1], [1])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([1], [1, 2])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([1], [1.0, 2])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([1, 2], [2u, 2, 2.0])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 27, Max: 27},
|
||||||
|
expectRuntimeCost: 27,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([1, 2], [1u, 2, 2.3])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 27, Max: 27},
|
||||||
|
expectRuntimeCost: 27,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `sets.intersects([[1], [2, 3]], [[1, 2], [2, 3.0]])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 65, Max: 65},
|
||||||
|
expectRuntimeCost: 65,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.intersects([], [])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 22, Max: 22},
|
||||||
|
expectRuntimeCost: 22,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.intersects([1], [])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 22, Max: 22},
|
||||||
|
expectRuntimeCost: 22,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.intersects([1], [2])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 23, Max: 23},
|
||||||
|
expectRuntimeCost: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.intersects([1], ["1", 2])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 24, Max: 24},
|
||||||
|
expectRuntimeCost: 24,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
expr: `!sets.intersects([1], [1.1, 2u])`,
|
||||||
|
expectEstimatedCost: checker.CostEstimate{Min: 24, Max: 24},
|
||||||
|
expectRuntimeCost: 24,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
testCost(t, tc.expr, tc.expectEstimatedCost, tc.expectRuntimeCost)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCost(t *testing.T, expr string, expectEsimatedCost checker.CostEstimate, expectRuntimeCost uint64) {
|
func testCost(t *testing.T, expr string, expectEsimatedCost checker.CostEstimate, expectRuntimeCost uint64) {
|
||||||
est := &CostEstimator{SizeEstimator: &testCostEstimator{}}
|
est := &CostEstimator{SizeEstimator: &testCostEstimator{}}
|
||||||
env, err := cel.NewEnv(
|
env, err := cel.NewEnv(
|
||||||
@ -536,6 +766,10 @@ func testCost(t *testing.T, expr string, expectEsimatedCost checker.CostEstimate
|
|||||||
Lists(),
|
Lists(),
|
||||||
Authz(),
|
Authz(),
|
||||||
Quantity(),
|
Quantity(),
|
||||||
|
ext.Sets(),
|
||||||
|
// cel-go v0.17.7 introduced CostEstimatorOptions.
|
||||||
|
// Previous the presence has a cost of 0 but cel fixed it to 1. We still set to 0 here to avoid breaking changes.
|
||||||
|
cel.CostEstimatorOptions(checker.PresenceTestHasCost(false)),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%v", err)
|
t.Fatalf("%v", err)
|
||||||
|
@ -45,7 +45,7 @@ require (
|
|||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/cel-go v0.17.6 // indirect
|
github.com/google/cel-go v0.17.7 // indirect
|
||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
4
staging/src/k8s.io/cloud-provider/go.sum
generated
4
staging/src/k8s.io/cloud-provider/go.sum
generated
@ -203,8 +203,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
|||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
@ -40,7 +40,7 @@ require (
|
|||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/cel-go v0.17.6 // indirect
|
github.com/google/cel-go v0.17.7 // indirect
|
||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
|
4
staging/src/k8s.io/controller-manager/go.sum
generated
4
staging/src/k8s.io/controller-manager/go.sum
generated
@ -200,8 +200,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
|||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
@ -46,7 +46,7 @@ require (
|
|||||||
github.com/go-openapi/swag v0.22.3 // indirect
|
github.com/go-openapi/swag v0.22.3 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/cel-go v0.17.6 // indirect
|
github.com/google/cel-go v0.17.7 // indirect
|
||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
4
staging/src/k8s.io/kube-aggregator/go.sum
generated
4
staging/src/k8s.io/kube-aggregator/go.sum
generated
@ -202,8 +202,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
|||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
@ -30,7 +30,7 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
|||||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
2
staging/src/k8s.io/kubelet/go.sum
generated
2
staging/src/k8s.io/kubelet/go.sum
generated
@ -59,7 +59,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
|
|||||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
2
staging/src/k8s.io/legacy-cloud-providers/go.sum
generated
2
staging/src/k8s.io/legacy-cloud-providers/go.sum
generated
@ -196,7 +196,7 @@ github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
|
|||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
@ -43,7 +43,7 @@ require (
|
|||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/cel-go v0.17.6 // indirect
|
github.com/google/cel-go v0.17.7 // indirect
|
||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
4
staging/src/k8s.io/pod-security-admission/go.sum
generated
4
staging/src/k8s.io/pod-security-admission/go.sum
generated
@ -200,8 +200,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
|||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
@ -40,7 +40,7 @@ require (
|
|||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/cel-go v0.17.6 // indirect
|
github.com/google/cel-go v0.17.7 // indirect
|
||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
4
staging/src/k8s.io/sample-apiserver/go.sum
generated
4
staging/src/k8s.io/sample-apiserver/go.sum
generated
@ -201,8 +201,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
|
|||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
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/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||||
github.com/google/cel-go v0.17.6 h1:QDvHTIJunIsbgN8yVukx0HGnsqVLSY6xGqo+17IjIyM=
|
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
|
||||||
github.com/google/cel-go v0.17.6/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
|
||||||
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
|
||||||
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
10
vendor/github.com/google/cel-go/cel/env.go
generated
vendored
10
vendor/github.com/google/cel-go/cel/env.go
generated
vendored
@ -119,6 +119,7 @@ type Env struct {
|
|||||||
appliedFeatures map[int]bool
|
appliedFeatures map[int]bool
|
||||||
libraries map[string]bool
|
libraries map[string]bool
|
||||||
validators []ASTValidator
|
validators []ASTValidator
|
||||||
|
costOptions []checker.CostOption
|
||||||
|
|
||||||
// Internal parser representation
|
// Internal parser representation
|
||||||
prsr *parser.Parser
|
prsr *parser.Parser
|
||||||
@ -181,6 +182,7 @@ func NewCustomEnv(opts ...EnvOption) (*Env, error) {
|
|||||||
libraries: map[string]bool{},
|
libraries: map[string]bool{},
|
||||||
validators: []ASTValidator{},
|
validators: []ASTValidator{},
|
||||||
progOpts: []ProgramOption{},
|
progOpts: []ProgramOption{},
|
||||||
|
costOptions: []checker.CostOption{},
|
||||||
}).configure(opts)
|
}).configure(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,6 +358,8 @@ func (e *Env) Extend(opts ...EnvOption) (*Env, error) {
|
|||||||
}
|
}
|
||||||
validatorsCopy := make([]ASTValidator, len(e.validators))
|
validatorsCopy := make([]ASTValidator, len(e.validators))
|
||||||
copy(validatorsCopy, e.validators)
|
copy(validatorsCopy, e.validators)
|
||||||
|
costOptsCopy := make([]checker.CostOption, len(e.costOptions))
|
||||||
|
copy(costOptsCopy, e.costOptions)
|
||||||
|
|
||||||
ext := &Env{
|
ext := &Env{
|
||||||
Container: e.Container,
|
Container: e.Container,
|
||||||
@ -371,6 +375,7 @@ func (e *Env) Extend(opts ...EnvOption) (*Env, error) {
|
|||||||
provider: provider,
|
provider: provider,
|
||||||
chkOpts: chkOptsCopy,
|
chkOpts: chkOptsCopy,
|
||||||
prsrOpts: prsrOptsCopy,
|
prsrOpts: prsrOptsCopy,
|
||||||
|
costOptions: costOptsCopy,
|
||||||
}
|
}
|
||||||
return ext.configure(opts)
|
return ext.configure(opts)
|
||||||
}
|
}
|
||||||
@ -557,7 +562,10 @@ func (e *Env) EstimateCost(ast *Ast, estimator checker.CostEstimator, opts ...ch
|
|||||||
TypeMap: ast.typeMap,
|
TypeMap: ast.typeMap,
|
||||||
ReferenceMap: ast.refMap,
|
ReferenceMap: ast.refMap,
|
||||||
}
|
}
|
||||||
return checker.Cost(checked, estimator, opts...)
|
extendedOpts := make([]checker.CostOption, 0, len(e.costOptions))
|
||||||
|
extendedOpts = append(extendedOpts, opts...)
|
||||||
|
extendedOpts = append(extendedOpts, e.costOptions...)
|
||||||
|
return checker.Cost(checked, estimator, extendedOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure applies a series of EnvOptions to the current environment.
|
// configure applies a series of EnvOptions to the current environment.
|
||||||
|
19
vendor/github.com/google/cel-go/cel/options.go
generated
vendored
19
vendor/github.com/google/cel-go/cel/options.go
generated
vendored
@ -23,6 +23,7 @@ import (
|
|||||||
"google.golang.org/protobuf/reflect/protoregistry"
|
"google.golang.org/protobuf/reflect/protoregistry"
|
||||||
"google.golang.org/protobuf/types/dynamicpb"
|
"google.golang.org/protobuf/types/dynamicpb"
|
||||||
|
|
||||||
|
"github.com/google/cel-go/checker"
|
||||||
"github.com/google/cel-go/common/containers"
|
"github.com/google/cel-go/common/containers"
|
||||||
"github.com/google/cel-go/common/functions"
|
"github.com/google/cel-go/common/functions"
|
||||||
"github.com/google/cel-go/common/types"
|
"github.com/google/cel-go/common/types"
|
||||||
@ -469,6 +470,24 @@ func InterruptCheckFrequency(checkFrequency uint) ProgramOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CostEstimatorOptions configure type-check time options for estimating expression cost.
|
||||||
|
func CostEstimatorOptions(costOpts ...checker.CostOption) EnvOption {
|
||||||
|
return func(e *Env) (*Env, error) {
|
||||||
|
e.costOptions = append(e.costOptions, costOpts...)
|
||||||
|
return e, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostTrackerOptions configures a set of options for cost-tracking.
|
||||||
|
//
|
||||||
|
// Note, CostTrackerOptions is a no-op unless CostTracking is also enabled.
|
||||||
|
func CostTrackerOptions(costOpts ...interpreter.CostTrackerOption) ProgramOption {
|
||||||
|
return func(p *prog) (*prog, error) {
|
||||||
|
p.costOptions = append(p.costOptions, costOpts...)
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CostTracking enables cost tracking and registers a ActualCostEstimator that can optionally provide a runtime cost estimate for any function calls.
|
// CostTracking enables cost tracking and registers a ActualCostEstimator that can optionally provide a runtime cost estimate for any function calls.
|
||||||
func CostTracking(costEstimator interpreter.ActualCostEstimator) ProgramOption {
|
func CostTracking(costEstimator interpreter.ActualCostEstimator) ProgramOption {
|
||||||
return func(p *prog) (*prog, error) {
|
return func(p *prog) (*prog, error) {
|
||||||
|
35
vendor/github.com/google/cel-go/cel/program.go
generated
vendored
35
vendor/github.com/google/cel-go/cel/program.go
generated
vendored
@ -106,7 +106,7 @@ func (ed *EvalDetails) State() interpreter.EvalState {
|
|||||||
// ActualCost returns the tracked cost through the course of execution when `CostTracking` is enabled.
|
// ActualCost returns the tracked cost through the course of execution when `CostTracking` is enabled.
|
||||||
// Otherwise, returns nil if the cost was not enabled.
|
// Otherwise, returns nil if the cost was not enabled.
|
||||||
func (ed *EvalDetails) ActualCost() *uint64 {
|
func (ed *EvalDetails) ActualCost() *uint64 {
|
||||||
if ed.costTracker == nil {
|
if ed == nil || ed.costTracker == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cost := ed.costTracker.ActualCost()
|
cost := ed.costTracker.ActualCost()
|
||||||
@ -130,10 +130,14 @@ type prog struct {
|
|||||||
// Interpretable configured from an Ast and aggregate decorator set based on program options.
|
// Interpretable configured from an Ast and aggregate decorator set based on program options.
|
||||||
interpretable interpreter.Interpretable
|
interpretable interpreter.Interpretable
|
||||||
callCostEstimator interpreter.ActualCostEstimator
|
callCostEstimator interpreter.ActualCostEstimator
|
||||||
|
costOptions []interpreter.CostTrackerOption
|
||||||
costLimit *uint64
|
costLimit *uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *prog) clone() *prog {
|
func (p *prog) clone() *prog {
|
||||||
|
costOptsCopy := make([]interpreter.CostTrackerOption, len(p.costOptions))
|
||||||
|
copy(costOptsCopy, p.costOptions)
|
||||||
|
|
||||||
return &prog{
|
return &prog{
|
||||||
Env: p.Env,
|
Env: p.Env,
|
||||||
evalOpts: p.evalOpts,
|
evalOpts: p.evalOpts,
|
||||||
@ -155,9 +159,10 @@ func newProgram(e *Env, ast *Ast, opts []ProgramOption) (Program, error) {
|
|||||||
// Ensure the default attribute factory is set after the adapter and provider are
|
// Ensure the default attribute factory is set after the adapter and provider are
|
||||||
// configured.
|
// configured.
|
||||||
p := &prog{
|
p := &prog{
|
||||||
Env: e,
|
Env: e,
|
||||||
decorators: []interpreter.InterpretableDecorator{},
|
decorators: []interpreter.InterpretableDecorator{},
|
||||||
dispatcher: disp,
|
dispatcher: disp,
|
||||||
|
costOptions: []interpreter.CostTrackerOption{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the program via the ProgramOption values.
|
// Configure the program via the ProgramOption values.
|
||||||
@ -242,6 +247,12 @@ func newProgram(e *Env, ast *Ast, opts []ProgramOption) (Program, error) {
|
|||||||
factory := func(state interpreter.EvalState, costTracker *interpreter.CostTracker) (Program, error) {
|
factory := func(state interpreter.EvalState, costTracker *interpreter.CostTracker) (Program, error) {
|
||||||
costTracker.Estimator = p.callCostEstimator
|
costTracker.Estimator = p.callCostEstimator
|
||||||
costTracker.Limit = p.costLimit
|
costTracker.Limit = p.costLimit
|
||||||
|
for _, costOpt := range p.costOptions {
|
||||||
|
err := costOpt(costTracker)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
// Limit capacity to guarantee a reallocation when calling 'append(decs, ...)' below. This
|
// Limit capacity to guarantee a reallocation when calling 'append(decs, ...)' below. This
|
||||||
// prevents the underlying memory from being shared between factory function calls causing
|
// prevents the underlying memory from being shared between factory function calls causing
|
||||||
// undesired mutations.
|
// undesired mutations.
|
||||||
@ -371,7 +382,11 @@ type progGen struct {
|
|||||||
// the test is successful.
|
// the test is successful.
|
||||||
func newProgGen(factory progFactory) (Program, error) {
|
func newProgGen(factory progFactory) (Program, error) {
|
||||||
// Test the factory to make sure that configuration errors are spotted at config
|
// Test the factory to make sure that configuration errors are spotted at config
|
||||||
_, err := factory(interpreter.NewEvalState(), &interpreter.CostTracker{})
|
tracker, err := interpreter.NewCostTracker(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = factory(interpreter.NewEvalState(), tracker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -384,7 +399,10 @@ func (gen *progGen) Eval(input any) (ref.Val, *EvalDetails, error) {
|
|||||||
// new EvalState instance for each call to ensure that unique evaluations yield unique stateful
|
// new EvalState instance for each call to ensure that unique evaluations yield unique stateful
|
||||||
// results.
|
// results.
|
||||||
state := interpreter.NewEvalState()
|
state := interpreter.NewEvalState()
|
||||||
costTracker := &interpreter.CostTracker{}
|
costTracker, err := interpreter.NewCostTracker(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
det := &EvalDetails{state: state, costTracker: costTracker}
|
det := &EvalDetails{state: state, costTracker: costTracker}
|
||||||
|
|
||||||
// Generate a new instance of the interpretable using the factory configured during the call to
|
// Generate a new instance of the interpretable using the factory configured during the call to
|
||||||
@ -412,7 +430,10 @@ func (gen *progGen) ContextEval(ctx context.Context, input any) (ref.Val, *EvalD
|
|||||||
// new EvalState instance for each call to ensure that unique evaluations yield unique stateful
|
// new EvalState instance for each call to ensure that unique evaluations yield unique stateful
|
||||||
// results.
|
// results.
|
||||||
state := interpreter.NewEvalState()
|
state := interpreter.NewEvalState()
|
||||||
costTracker := &interpreter.CostTracker{}
|
costTracker, err := interpreter.NewCostTracker(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
det := &EvalDetails{state: state, costTracker: costTracker}
|
det := &EvalDetails{state: state, costTracker: costTracker}
|
||||||
|
|
||||||
// Generate a new instance of the interpretable using the factory configured during the call to
|
// Generate a new instance of the interpretable using the factory configured during the call to
|
||||||
|
56
vendor/github.com/google/cel-go/checker/cost.go
generated
vendored
56
vendor/github.com/google/cel-go/checker/cost.go
generated
vendored
@ -230,7 +230,7 @@ func addUint64NoOverflow(x, y uint64) uint64 {
|
|||||||
// multiplyUint64NoOverflow multiplies non-negative ints. If the result is exceeds math.MaxUint64, math.MaxUint64
|
// multiplyUint64NoOverflow multiplies non-negative ints. If the result is exceeds math.MaxUint64, math.MaxUint64
|
||||||
// is returned.
|
// is returned.
|
||||||
func multiplyUint64NoOverflow(x, y uint64) uint64 {
|
func multiplyUint64NoOverflow(x, y uint64) uint64 {
|
||||||
if x > 0 && y > 0 && x > math.MaxUint64/y {
|
if y != 0 && x > math.MaxUint64/y {
|
||||||
return math.MaxUint64
|
return math.MaxUint64
|
||||||
}
|
}
|
||||||
return x * y
|
return x * y
|
||||||
@ -242,7 +242,11 @@ func multiplyByCostFactor(x uint64, y float64) uint64 {
|
|||||||
if xFloat > 0 && y > 0 && xFloat > math.MaxUint64/y {
|
if xFloat > 0 && y > 0 && xFloat > math.MaxUint64/y {
|
||||||
return math.MaxUint64
|
return math.MaxUint64
|
||||||
}
|
}
|
||||||
return uint64(math.Ceil(xFloat * y))
|
ceil := math.Ceil(xFloat * y)
|
||||||
|
if ceil >= doubleTwoTo64 {
|
||||||
|
return math.MaxUint64
|
||||||
|
}
|
||||||
|
return uint64(ceil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -260,9 +264,10 @@ type coster struct {
|
|||||||
// iterRanges tracks the iterRange of each iterVar.
|
// iterRanges tracks the iterRange of each iterVar.
|
||||||
iterRanges iterRangeScopes
|
iterRanges iterRangeScopes
|
||||||
// computedSizes tracks the computed sizes of call results.
|
// computedSizes tracks the computed sizes of call results.
|
||||||
computedSizes map[int64]SizeEstimate
|
computedSizes map[int64]SizeEstimate
|
||||||
checkedAST *ast.CheckedAST
|
checkedAST *ast.CheckedAST
|
||||||
estimator CostEstimator
|
estimator CostEstimator
|
||||||
|
overloadEstimators map[string]FunctionEstimator
|
||||||
// presenceTestCost will either be a zero or one based on whether has() macros count against cost computations.
|
// presenceTestCost will either be a zero or one based on whether has() macros count against cost computations.
|
||||||
presenceTestCost CostEstimate
|
presenceTestCost CostEstimate
|
||||||
}
|
}
|
||||||
@ -291,6 +296,7 @@ func (vs iterRangeScopes) peek(varName string) (int64, bool) {
|
|||||||
type CostOption func(*coster) error
|
type CostOption func(*coster) error
|
||||||
|
|
||||||
// PresenceTestHasCost determines whether presence testing has a cost of one or zero.
|
// PresenceTestHasCost determines whether presence testing has a cost of one or zero.
|
||||||
|
//
|
||||||
// Defaults to presence test has a cost of one.
|
// Defaults to presence test has a cost of one.
|
||||||
func PresenceTestHasCost(hasCost bool) CostOption {
|
func PresenceTestHasCost(hasCost bool) CostOption {
|
||||||
return func(c *coster) error {
|
return func(c *coster) error {
|
||||||
@ -303,15 +309,30 @@ func PresenceTestHasCost(hasCost bool) CostOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FunctionEstimator provides a CallEstimate given the target and arguments for a specific function, overload pair.
|
||||||
|
type FunctionEstimator func(estimator CostEstimator, target *AstNode, args []AstNode) *CallEstimate
|
||||||
|
|
||||||
|
// OverloadCostEstimate binds a FunctionCoster to a specific function overload ID.
|
||||||
|
//
|
||||||
|
// When a OverloadCostEstimate is provided, it will override the cost calculation of the CostEstimator provided to
|
||||||
|
// the Cost() call.
|
||||||
|
func OverloadCostEstimate(overloadID string, functionCoster FunctionEstimator) CostOption {
|
||||||
|
return func(c *coster) error {
|
||||||
|
c.overloadEstimators[overloadID] = functionCoster
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cost estimates the cost of the parsed and type checked CEL expression.
|
// Cost estimates the cost of the parsed and type checked CEL expression.
|
||||||
func Cost(checker *ast.CheckedAST, estimator CostEstimator, opts ...CostOption) (CostEstimate, error) {
|
func Cost(checker *ast.CheckedAST, estimator CostEstimator, opts ...CostOption) (CostEstimate, error) {
|
||||||
c := &coster{
|
c := &coster{
|
||||||
checkedAST: checker,
|
checkedAST: checker,
|
||||||
estimator: estimator,
|
estimator: estimator,
|
||||||
exprPath: map[int64][]string{},
|
overloadEstimators: map[string]FunctionEstimator{},
|
||||||
iterRanges: map[string][]int64{},
|
exprPath: map[int64][]string{},
|
||||||
computedSizes: map[int64]SizeEstimate{},
|
iterRanges: map[string][]int64{},
|
||||||
presenceTestCost: CostEstimate{Min: 1, Max: 1},
|
computedSizes: map[int64]SizeEstimate{},
|
||||||
|
presenceTestCost: CostEstimate{Min: 1, Max: 1},
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
err := opt(c)
|
err := opt(c)
|
||||||
@ -532,7 +553,14 @@ func (c *coster) functionCost(function, overloadID string, target *AstNode, args
|
|||||||
}
|
}
|
||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
if len(c.overloadEstimators) != 0 {
|
||||||
|
if estimator, found := c.overloadEstimators[overloadID]; found {
|
||||||
|
if est := estimator(c.estimator, target, args); est != nil {
|
||||||
|
callEst := *est
|
||||||
|
return CallEstimate{CostEstimate: callEst.Add(argCostSum()), ResultSize: est.ResultSize}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if est := c.estimator.EstimateCallCost(function, overloadID, target, args); est != nil {
|
if est := c.estimator.EstimateCallCost(function, overloadID, target, args); est != nil {
|
||||||
callEst := *est
|
callEst := *est
|
||||||
return CallEstimate{CostEstimate: callEst.Add(argCostSum()), ResultSize: est.ResultSize}
|
return CallEstimate{CostEstimate: callEst.Add(argCostSum()), ResultSize: est.ResultSize}
|
||||||
@ -682,3 +710,7 @@ func isScalar(t *types.Type) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
doubleTwoTo64 = math.Ldexp(1.0, 64)
|
||||||
|
)
|
||||||
|
1
vendor/github.com/google/cel-go/ext/BUILD.bazel
generated
vendored
1
vendor/github.com/google/cel-go/ext/BUILD.bazel
generated
vendored
@ -20,6 +20,7 @@ go_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//cel:go_default_library",
|
"//cel:go_default_library",
|
||||||
|
"//checker:go_default_library",
|
||||||
"//checker/decls:go_default_library",
|
"//checker/decls:go_default_library",
|
||||||
"//common/overloads:go_default_library",
|
"//common/overloads:go_default_library",
|
||||||
"//common/types:go_default_library",
|
"//common/types:go_default_library",
|
||||||
|
61
vendor/github.com/google/cel-go/ext/sets.go
generated
vendored
61
vendor/github.com/google/cel-go/ext/sets.go
generated
vendored
@ -15,10 +15,14 @@
|
|||||||
package ext
|
package ext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/google/cel-go/cel"
|
"github.com/google/cel-go/cel"
|
||||||
|
"github.com/google/cel-go/checker"
|
||||||
"github.com/google/cel-go/common/types"
|
"github.com/google/cel-go/common/types"
|
||||||
"github.com/google/cel-go/common/types/ref"
|
"github.com/google/cel-go/common/types/ref"
|
||||||
"github.com/google/cel-go/common/types/traits"
|
"github.com/google/cel-go/common/types/traits"
|
||||||
|
"github.com/google/cel-go/interpreter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sets returns a cel.EnvOption to configure namespaced set relationship
|
// Sets returns a cel.EnvOption to configure namespaced set relationship
|
||||||
@ -95,12 +99,24 @@ func (setsLib) CompileOptions() []cel.EnvOption {
|
|||||||
cel.Function("sets.intersects",
|
cel.Function("sets.intersects",
|
||||||
cel.Overload("list_sets_intersects_list", []*cel.Type{listType, listType}, cel.BoolType,
|
cel.Overload("list_sets_intersects_list", []*cel.Type{listType, listType}, cel.BoolType,
|
||||||
cel.BinaryBinding(setsIntersects))),
|
cel.BinaryBinding(setsIntersects))),
|
||||||
|
cel.CostEstimatorOptions(
|
||||||
|
checker.OverloadCostEstimate("list_sets_contains_list", estimateSetsCost(1)),
|
||||||
|
checker.OverloadCostEstimate("list_sets_intersects_list", estimateSetsCost(1)),
|
||||||
|
// equivalence requires potentially two m*n comparisons to ensure each list is contained by the other
|
||||||
|
checker.OverloadCostEstimate("list_sets_equivalent_list", estimateSetsCost(2)),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProgramOptions implements the Library interface method.
|
// ProgramOptions implements the Library interface method.
|
||||||
func (setsLib) ProgramOptions() []cel.ProgramOption {
|
func (setsLib) ProgramOptions() []cel.ProgramOption {
|
||||||
return []cel.ProgramOption{}
|
return []cel.ProgramOption{
|
||||||
|
cel.CostTrackerOptions(
|
||||||
|
interpreter.OverloadCostTracker("list_sets_contains_list", trackSetsCost(1)),
|
||||||
|
interpreter.OverloadCostTracker("list_sets_intersects_list", trackSetsCost(1)),
|
||||||
|
interpreter.OverloadCostTracker("list_sets_equivalent_list", trackSetsCost(2)),
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setsIntersects(listA, listB ref.Val) ref.Val {
|
func setsIntersects(listA, listB ref.Val) ref.Val {
|
||||||
@ -136,3 +152,46 @@ func setsEquivalent(listA, listB ref.Val) ref.Val {
|
|||||||
}
|
}
|
||||||
return setsContains(listB, listA)
|
return setsContains(listB, listA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func estimateSetsCost(costFactor float64) checker.FunctionEstimator {
|
||||||
|
return func(estimator checker.CostEstimator, target *checker.AstNode, args []checker.AstNode) *checker.CallEstimate {
|
||||||
|
if len(args) == 2 {
|
||||||
|
arg0Size := estimateSize(estimator, args[0])
|
||||||
|
arg1Size := estimateSize(estimator, args[1])
|
||||||
|
costEstimate := arg0Size.Multiply(arg1Size).MultiplyByCostFactor(costFactor).Add(callCostEstimate)
|
||||||
|
return &checker.CallEstimate{CostEstimate: costEstimate}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func estimateSize(estimator checker.CostEstimator, node checker.AstNode) checker.SizeEstimate {
|
||||||
|
if l := node.ComputedSize(); l != nil {
|
||||||
|
return *l
|
||||||
|
}
|
||||||
|
if l := estimator.EstimateSize(node); l != nil {
|
||||||
|
return *l
|
||||||
|
}
|
||||||
|
return checker.SizeEstimate{Min: 0, Max: math.MaxUint64}
|
||||||
|
}
|
||||||
|
|
||||||
|
func trackSetsCost(costFactor float64) interpreter.FunctionTracker {
|
||||||
|
return func(args []ref.Val, _ ref.Val) *uint64 {
|
||||||
|
lhsSize := actualSize(args[0])
|
||||||
|
rhsSize := actualSize(args[1])
|
||||||
|
cost := callCost + uint64(float64(lhsSize*rhsSize)*costFactor)
|
||||||
|
return &cost
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func actualSize(value ref.Val) uint64 {
|
||||||
|
if sz, ok := value.(traits.Sizer); ok {
|
||||||
|
return uint64(sz.Size().(types.Int))
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
callCostEstimate = checker.CostEstimate{Min: 1, Max: 1}
|
||||||
|
callCost = uint64(1)
|
||||||
|
)
|
||||||
|
47
vendor/github.com/google/cel-go/interpreter/runtimecost.go
generated
vendored
47
vendor/github.com/google/cel-go/interpreter/runtimecost.go
generated
vendored
@ -133,6 +133,7 @@ func PresenceTestHasCost(hasCost bool) CostTrackerOption {
|
|||||||
func NewCostTracker(estimator ActualCostEstimator, opts ...CostTrackerOption) (*CostTracker, error) {
|
func NewCostTracker(estimator ActualCostEstimator, opts ...CostTrackerOption) (*CostTracker, error) {
|
||||||
tracker := &CostTracker{
|
tracker := &CostTracker{
|
||||||
Estimator: estimator,
|
Estimator: estimator,
|
||||||
|
overloadTrackers: map[string]FunctionTracker{},
|
||||||
presenceTestHasCost: true,
|
presenceTestHasCost: true,
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -144,9 +145,24 @@ func NewCostTracker(estimator ActualCostEstimator, opts ...CostTrackerOption) (*
|
|||||||
return tracker, nil
|
return tracker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OverloadCostTracker binds an overload ID to a runtime FunctionTracker implementation.
|
||||||
|
//
|
||||||
|
// OverloadCostTracker instances augment or override ActualCostEstimator decisions, allowing for versioned and/or
|
||||||
|
// optional cost tracking changes.
|
||||||
|
func OverloadCostTracker(overloadID string, fnTracker FunctionTracker) CostTrackerOption {
|
||||||
|
return func(tracker *CostTracker) error {
|
||||||
|
tracker.overloadTrackers[overloadID] = fnTracker
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FunctionTracker computes the actual cost of evaluating the functions with the given arguments and result.
|
||||||
|
type FunctionTracker func(args []ref.Val, result ref.Val) *uint64
|
||||||
|
|
||||||
// CostTracker represents the information needed for tracking runtime cost.
|
// CostTracker represents the information needed for tracking runtime cost.
|
||||||
type CostTracker struct {
|
type CostTracker struct {
|
||||||
Estimator ActualCostEstimator
|
Estimator ActualCostEstimator
|
||||||
|
overloadTrackers map[string]FunctionTracker
|
||||||
Limit *uint64
|
Limit *uint64
|
||||||
presenceTestHasCost bool
|
presenceTestHasCost bool
|
||||||
|
|
||||||
@ -159,10 +175,19 @@ func (c *CostTracker) ActualCost() uint64 {
|
|||||||
return c.cost
|
return c.cost
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CostTracker) costCall(call InterpretableCall, argValues []ref.Val, result ref.Val) uint64 {
|
func (c *CostTracker) costCall(call InterpretableCall, args []ref.Val, result ref.Val) uint64 {
|
||||||
var cost uint64
|
var cost uint64
|
||||||
|
if len(c.overloadTrackers) != 0 {
|
||||||
|
if tracker, found := c.overloadTrackers[call.OverloadID()]; found {
|
||||||
|
callCost := tracker(args, result)
|
||||||
|
if callCost != nil {
|
||||||
|
cost += *callCost
|
||||||
|
return cost
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if c.Estimator != nil {
|
if c.Estimator != nil {
|
||||||
callCost := c.Estimator.CallCost(call.Function(), call.OverloadID(), argValues, result)
|
callCost := c.Estimator.CallCost(call.Function(), call.OverloadID(), args, result)
|
||||||
if callCost != nil {
|
if callCost != nil {
|
||||||
cost += *callCost
|
cost += *callCost
|
||||||
return cost
|
return cost
|
||||||
@ -173,11 +198,11 @@ func (c *CostTracker) costCall(call InterpretableCall, argValues []ref.Val, resu
|
|||||||
switch call.OverloadID() {
|
switch call.OverloadID() {
|
||||||
// O(n) functions
|
// O(n) functions
|
||||||
case overloads.StartsWithString, overloads.EndsWithString, overloads.StringToBytes, overloads.BytesToString, overloads.ExtQuoteString, overloads.ExtFormatString:
|
case overloads.StartsWithString, overloads.EndsWithString, overloads.StringToBytes, overloads.BytesToString, overloads.ExtQuoteString, overloads.ExtFormatString:
|
||||||
cost += uint64(math.Ceil(float64(c.actualSize(argValues[0])) * common.StringTraversalCostFactor))
|
cost += uint64(math.Ceil(float64(c.actualSize(args[0])) * common.StringTraversalCostFactor))
|
||||||
case overloads.InList:
|
case overloads.InList:
|
||||||
// If a list is composed entirely of constant values this is O(1), but we don't account for that here.
|
// If a list is composed entirely of constant values this is O(1), but we don't account for that here.
|
||||||
// We just assume all list containment checks are O(n).
|
// We just assume all list containment checks are O(n).
|
||||||
cost += c.actualSize(argValues[1])
|
cost += c.actualSize(args[1])
|
||||||
// O(min(m, n)) functions
|
// O(min(m, n)) functions
|
||||||
case overloads.LessString, overloads.GreaterString, overloads.LessEqualsString, overloads.GreaterEqualsString,
|
case overloads.LessString, overloads.GreaterString, overloads.LessEqualsString, overloads.GreaterEqualsString,
|
||||||
overloads.LessBytes, overloads.GreaterBytes, overloads.LessEqualsBytes, overloads.GreaterEqualsBytes,
|
overloads.LessBytes, overloads.GreaterBytes, overloads.LessEqualsBytes, overloads.GreaterEqualsBytes,
|
||||||
@ -185,8 +210,8 @@ func (c *CostTracker) costCall(call InterpretableCall, argValues []ref.Val, resu
|
|||||||
// When we check the equality of 2 scalar values (e.g. 2 integers, 2 floating-point numbers, 2 booleans etc.),
|
// When we check the equality of 2 scalar values (e.g. 2 integers, 2 floating-point numbers, 2 booleans etc.),
|
||||||
// the CostTracker.actualSize() function by definition returns 1 for each operand, resulting in an overall cost
|
// the CostTracker.actualSize() function by definition returns 1 for each operand, resulting in an overall cost
|
||||||
// of 1.
|
// of 1.
|
||||||
lhsSize := c.actualSize(argValues[0])
|
lhsSize := c.actualSize(args[0])
|
||||||
rhsSize := c.actualSize(argValues[1])
|
rhsSize := c.actualSize(args[1])
|
||||||
minSize := lhsSize
|
minSize := lhsSize
|
||||||
if rhsSize < minSize {
|
if rhsSize < minSize {
|
||||||
minSize = rhsSize
|
minSize = rhsSize
|
||||||
@ -195,23 +220,23 @@ func (c *CostTracker) costCall(call InterpretableCall, argValues []ref.Val, resu
|
|||||||
// O(m+n) functions
|
// O(m+n) functions
|
||||||
case overloads.AddString, overloads.AddBytes:
|
case overloads.AddString, overloads.AddBytes:
|
||||||
// In the worst case scenario, we would need to reallocate a new backing store and copy both operands over.
|
// In the worst case scenario, we would need to reallocate a new backing store and copy both operands over.
|
||||||
cost += uint64(math.Ceil(float64(c.actualSize(argValues[0])+c.actualSize(argValues[1])) * common.StringTraversalCostFactor))
|
cost += uint64(math.Ceil(float64(c.actualSize(args[0])+c.actualSize(args[1])) * common.StringTraversalCostFactor))
|
||||||
// O(nm) functions
|
// O(nm) functions
|
||||||
case overloads.MatchesString:
|
case overloads.MatchesString:
|
||||||
// https://swtch.com/~rsc/regexp/regexp1.html applies to RE2 implementation supported by CEL
|
// https://swtch.com/~rsc/regexp/regexp1.html applies to RE2 implementation supported by CEL
|
||||||
// Add one to string length for purposes of cost calculation to prevent product of string and regex to be 0
|
// Add one to string length for purposes of cost calculation to prevent product of string and regex to be 0
|
||||||
// in case where string is empty but regex is still expensive.
|
// in case where string is empty but regex is still expensive.
|
||||||
strCost := uint64(math.Ceil((1.0 + float64(c.actualSize(argValues[0]))) * common.StringTraversalCostFactor))
|
strCost := uint64(math.Ceil((1.0 + float64(c.actualSize(args[0]))) * common.StringTraversalCostFactor))
|
||||||
// We don't know how many expressions are in the regex, just the string length (a huge
|
// We don't know how many expressions are in the regex, just the string length (a huge
|
||||||
// improvement here would be to somehow get a count the number of expressions in the regex or
|
// improvement here would be to somehow get a count the number of expressions in the regex or
|
||||||
// how many states are in the regex state machine and use that to measure regex cost).
|
// how many states are in the regex state machine and use that to measure regex cost).
|
||||||
// For now, we're making a guess that each expression in a regex is typically at least 4 chars
|
// For now, we're making a guess that each expression in a regex is typically at least 4 chars
|
||||||
// in length.
|
// in length.
|
||||||
regexCost := uint64(math.Ceil(float64(c.actualSize(argValues[1])) * common.RegexStringLengthCostFactor))
|
regexCost := uint64(math.Ceil(float64(c.actualSize(args[1])) * common.RegexStringLengthCostFactor))
|
||||||
cost += strCost * regexCost
|
cost += strCost * regexCost
|
||||||
case overloads.ContainsString:
|
case overloads.ContainsString:
|
||||||
strCost := uint64(math.Ceil(float64(c.actualSize(argValues[0])) * common.StringTraversalCostFactor))
|
strCost := uint64(math.Ceil(float64(c.actualSize(args[0])) * common.StringTraversalCostFactor))
|
||||||
substrCost := uint64(math.Ceil(float64(c.actualSize(argValues[1])) * common.StringTraversalCostFactor))
|
substrCost := uint64(math.Ceil(float64(c.actualSize(args[1])) * common.StringTraversalCostFactor))
|
||||||
cost += strCost * substrCost
|
cost += strCost * substrCost
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -353,7 +353,7 @@ github.com/google/cadvisor/utils/sysfs
|
|||||||
github.com/google/cadvisor/utils/sysinfo
|
github.com/google/cadvisor/utils/sysinfo
|
||||||
github.com/google/cadvisor/version
|
github.com/google/cadvisor/version
|
||||||
github.com/google/cadvisor/watcher
|
github.com/google/cadvisor/watcher
|
||||||
# github.com/google/cel-go v0.17.6
|
# github.com/google/cel-go v0.17.7
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/google/cel-go/cel
|
github.com/google/cel-go/cel
|
||||||
github.com/google/cel-go/checker
|
github.com/google/cel-go/checker
|
||||||
|
Loading…
Reference in New Issue
Block a user