Skip to content

Commit efb98fd

Browse files
Merge pull request #119807 from jpbetz/automated-cherry-pick-of-#119800-origin-release-1.28
Automated cherry pick of #119800: Fixes CEL estimated cost to propagate result sizes correctly Kubernetes-commit: ab3cebfdb2cd1054f34f4287a757755810ede009
2 parents 6087aeb + 4d28f48 commit efb98fd

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/emicklei/go-restful/v3 v3.9.0
99
github.com/evanphx/json-patch v4.12.0+incompatible
1010
github.com/gogo/protobuf v1.3.2
11-
github.com/google/cel-go v0.16.0
11+
github.com/google/cel-go v0.16.1
1212
github.com/google/gnostic-models v0.6.8
1313
github.com/google/go-cmp v0.5.9
1414
github.com/google/gofuzz v1.2.0
@@ -26,7 +26,7 @@ require (
2626
gopkg.in/yaml.v2 v2.4.0
2727
k8s.io/api v0.0.0-20230904104028-546e4253e738
2828
k8s.io/apimachinery v0.0.0-20230904102823-bc548d1d2406
29-
k8s.io/apiserver v0.0.0-20230904114607-bf038b7f385e
29+
k8s.io/apiserver v0.0.0-20230906193730-7e09bf350908
3030
k8s.io/client-go v0.0.0-20230904110526-745513ad7b37
3131
k8s.io/code-generator v0.0.0-20230807201159-791c213a776b
3232
k8s.io/component-base v0.0.0-20230904111932-ef6aa9891ad3
@@ -129,7 +129,7 @@ require (
129129
replace (
130130
k8s.io/api => k8s.io/api v0.0.0-20230904104028-546e4253e738
131131
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230904102823-bc548d1d2406
132-
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20230904114607-bf038b7f385e
132+
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20230906193730-7e09bf350908
133133
k8s.io/client-go => k8s.io/client-go v0.0.0-20230904110526-745513ad7b37
134134
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20230807201159-791c213a776b
135135
k8s.io/component-base => k8s.io/component-base v0.0.0-20230904111932-ef6aa9891ad3

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
159159
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
160160
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
161161
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
162-
github.com/google/cel-go v0.16.0 h1:DG9YQ8nFCFXAs/FDDwBxmL1tpKNrdlGUM9U3537bX/Y=
163-
github.com/google/cel-go v0.16.0/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
162+
github.com/google/cel-go v0.16.1 h1:3hZfSNiAU3KOiNtxuFXVp5WFy4hf/Ly3Sa4/7F8SXNo=
163+
github.com/google/cel-go v0.16.1/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
164164
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
165165
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
166166
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -673,8 +673,8 @@ k8s.io/api v0.0.0-20230904104028-546e4253e738 h1:0PmEjeZX6g4bLgztHHEVVj0XrMQ+F8u
673673
k8s.io/api v0.0.0-20230904104028-546e4253e738/go.mod h1:4GpdFbUbYEFNj6e44T5yz6hE7p8yAn4+dYvmqTPVuOs=
674674
k8s.io/apimachinery v0.0.0-20230904102823-bc548d1d2406 h1:/YP5PLKVrV5WDzScq2agCBHPP0FCLVrU/4d9+j8uEFs=
675675
k8s.io/apimachinery v0.0.0-20230904102823-bc548d1d2406/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU=
676-
k8s.io/apiserver v0.0.0-20230904114607-bf038b7f385e h1:J1HaAqOL9irju2bXc34G3Z2UTXZVnE+GLOfSD1NTwRg=
677-
k8s.io/apiserver v0.0.0-20230904114607-bf038b7f385e/go.mod h1:CjTNnDKEDMQHdsr2dzFdIFuoZxfXISlPuT7BSOa3YQw=
676+
k8s.io/apiserver v0.0.0-20230906193730-7e09bf350908 h1:HVeQjJRMlaVBcjY4ujcNXpta+aLDa7QXz5K1y38r43E=
677+
k8s.io/apiserver v0.0.0-20230906193730-7e09bf350908/go.mod h1:CZwPGvyqJFPbGm/wL283IZM52p6VcGic+gXoOP7wy+4=
678678
k8s.io/client-go v0.0.0-20230904110526-745513ad7b37 h1:+SF0CtBoQI6Eso+8poN4i55d4oUahClerZwALYSz6Tw=
679679
k8s.io/client-go v0.0.0-20230904110526-745513ad7b37/go.mod h1:9oac6LWqvfKcphw6P69YH6Ns8xgf4S3ciKrBfqXxq3c=
680680
k8s.io/code-generator v0.0.0-20230807201159-791c213a776b h1:SQbgU/KO+8dA4z1FG2Miatu7XYb3oDc7tzbycneiyDY=

pkg/apis/apiextensions/validation/validation_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9315,6 +9315,32 @@ func TestValidateCustomResourceDefinitionValidation(t *testing.T) {
93159315
forbidden("spec.validation.openAPIV3Schema.properties[f].x-kubernetes-validations[0].messageExpression"),
93169316
},
93179317
},
9318+
{
9319+
name: "x-kubernetes-validations rule with lowerAscii check should be within estimated cost limit",
9320+
opts: validationOptions{requireStructuralSchema: true},
9321+
input: apiextensions.CustomResourceValidation{
9322+
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
9323+
Type: "object",
9324+
Properties: map[string]apiextensions.JSONSchemaProps{
9325+
"f": {
9326+
Type: "array",
9327+
MaxItems: pointer.Int64(5),
9328+
Items: &apiextensions.JSONSchemaPropsOrArray{
9329+
Schema: &apiextensions.JSONSchemaProps{
9330+
Type: "string",
9331+
MaxLength: pointer.Int64(5),
9332+
},
9333+
},
9334+
XValidations: apiextensions.ValidationRules{
9335+
{
9336+
Rule: "self.all(x, self.exists_one(y, x.lowerAscii() == y.lowerAscii()))",
9337+
},
9338+
},
9339+
},
9340+
},
9341+
},
9342+
},
9343+
},
93189344
{
93199345
name: "x-kubernetes-validations rule invalidated by messageExpression exceeding per-CRD estimated cost limit",
93209346
opts: validationOptions{requireStructuralSchema: true},

pkg/apiserver/schema/cel/celcoststability_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func TestCelCostStability(t *testing.T) {
115115
"self.val1.substring(4, 10).trim() == 'takes'": 6,
116116
"self.val1.upperAscii() == 'ROOK TAKES 👑'": 6,
117117
"self.val1.lowerAscii() == 'rook takes 👑'": 6,
118+
"self.val1.lowerAscii() == self.val1.lowerAscii()": 10,
118119
},
119120
},
120121
{name: "escaped strings",

pkg/apiserver/schema/cel/compilation_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,17 +1683,19 @@ func TestCostEstimation(t *testing.T) {
16831683
name: "extended library replace",
16841684
schemaGenerator: func(max *int64) *schema.Structural {
16851685
strType := withMaxLength(primitiveType("string", ""), max)
1686+
beforeLen := int64(2)
1687+
afterLen := int64(4)
16861688
objType := objectType(map[string]schema.Structural{
16871689
"str": strType,
1688-
"before": strType,
1689-
"after": strType,
1690+
"before": withMaxLength(primitiveType("string", ""), &beforeLen),
1691+
"after": withMaxLength(primitiveType("string", ""), &afterLen),
16901692
})
16911693
objType = withRule(objType, "self.str.replace(self.before, self.after) == 'does not matter'")
16921694
return &objType
16931695
},
1694-
expectedCalcCost: 629154,
1695-
setMaxElements: 10,
1696-
expectedSetCost: 16,
1696+
expectedCalcCost: 629154, // cost is based on the result size of the replace() call
1697+
setMaxElements: 4,
1698+
expectedSetCost: 12,
16971699
},
16981700
{
16991701
name: "extended library split",

0 commit comments

Comments
 (0)