Skip to content

Commit f14ac67

Browse files
Merge pull request #122369 from cici37/automated-cherry-pick-of-#122193-upstream-release-1.29
Automated cherry pick of #122193: Keep presence cost to 0 to ensure backward compatibility. Kubernetes-commit: 2991f6e2165003c6fe50fb46a95d7215f9e65179
2 parents eccd921 + 510e9f2 commit f14ac67

File tree

3 files changed

+46
-44
lines changed

3 files changed

+46
-44
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
gopkg.in/yaml.v2 v2.4.0
2727
k8s.io/api v0.0.0-20240110173429-a48c0a49b1dc
2828
k8s.io/apimachinery v0.0.0-20240110172605-dc7e034c8647
29-
k8s.io/apiserver v0.0.0-20240110183326-0065398a1f50
29+
k8s.io/apiserver v0.0.0-20240112174207-e9b57224a279
3030
k8s.io/client-go v0.0.0-20240110175813-baea19d6e81c
3131
k8s.io/code-generator v0.0.0-20240110171822-07ba7365408a
3232
k8s.io/component-base v0.0.0-20240110180938-aca7dbbf0e34
@@ -130,7 +130,7 @@ require (
130130
replace (
131131
k8s.io/api => k8s.io/api v0.0.0-20240110173429-a48c0a49b1dc
132132
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20240110172605-dc7e034c8647
133-
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20240110183326-0065398a1f50
133+
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20240112174207-e9b57224a279
134134
k8s.io/client-go => k8s.io/client-go v0.0.0-20240110175813-baea19d6e81c
135135
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20240110171822-07ba7365408a
136136
k8s.io/component-base => k8s.io/component-base v0.0.0-20240110180938-aca7dbbf0e34

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ k8s.io/api v0.0.0-20240110173429-a48c0a49b1dc h1:z2Ii/wAgmsfREj444+Z0jFzHslm+Ep/
401401
k8s.io/api v0.0.0-20240110173429-a48c0a49b1dc/go.mod h1:JS1rn0RBc46vCh2T2+zcnx+oNtvh+pDndpURdiWnHNc=
402402
k8s.io/apimachinery v0.0.0-20240110172605-dc7e034c8647 h1:SfqmT8ezTnkZc9G0t8b4s6+Z6zT/rMKhZm9yQq5wG+U=
403403
k8s.io/apimachinery v0.0.0-20240110172605-dc7e034c8647/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTKU=
404-
k8s.io/apiserver v0.0.0-20240110183326-0065398a1f50 h1:KbsB4DdFRRfy+IhExFpSTnI0Ecgex+fTu2inrZQCYSo=
405-
k8s.io/apiserver v0.0.0-20240110183326-0065398a1f50/go.mod h1:weQQ7wKBVb/AYWnaASQaNsMgkfHRCxQjKguUO/byLF0=
404+
k8s.io/apiserver v0.0.0-20240112174207-e9b57224a279 h1:CJnOKCne7o6k5P218dmddJ7uwNGieDx7cWXmWUKzplA=
405+
k8s.io/apiserver v0.0.0-20240112174207-e9b57224a279/go.mod h1:weQQ7wKBVb/AYWnaASQaNsMgkfHRCxQjKguUO/byLF0=
406406
k8s.io/client-go v0.0.0-20240110175813-baea19d6e81c h1:S8iocBcKfLfrC9VQy38QMJeChfF3B5QwJKsNrA9MI0Q=
407407
k8s.io/client-go v0.0.0-20240110175813-baea19d6e81c/go.mod h1:6kNfSLAoK7xQAWeKaZ62IQvDSLEls0B+w4UQJccyOeA=
408408
k8s.io/code-generator v0.0.0-20240110171822-07ba7365408a h1:oXW+lLK1hzfnWwkh4O9H6h/7Bxk2XDiN0+cFfw5JwzQ=

pkg/apiserver/schema/cel/celcoststability_test.go

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ func TestCelCostStability(t *testing.T) {
227227
"!(0 in self.val1)": 6,
228228
"self.val1 + self.val2 == [1, 2, 3, 1, 2, 3]": 6,
229229
"self.val1 + [4, 5] == [1, 2, 3, 4, 5]": 4,
230+
"has(self.val1)": 1,
231+
"has(self.val1) && has(self.val2)": 2,
230232
},
231233
},
232234
{name: "listSets",
@@ -1344,9 +1346,9 @@ func TestCelEstimatedCostStability(t *testing.T) {
13441346
"!(0 in self.val1)": 1572866,
13451347
"self.val1 + self.val2 == [1, 2, 3, 1, 2, 3]": 16,
13461348
"self.val1 + [4, 5] == [1, 2, 3, 4, 5]": 24,
1347-
"has(self.val1)": 2,
1348-
"has(self.val1) && has(self.val2)": 4,
1349-
"!has(self.val1)": 3,
1349+
"has(self.val1)": 1,
1350+
"has(self.val1) && has(self.val2)": 2,
1351+
"!has(self.val1)": 2,
13501352
"self.val1.all(k, size(self.val1) > 0)": 11010044,
13511353
"self.val1.exists_one(k, self.val1 == [2])": 23592949,
13521354
"!self.val1.exists_one(k, size(self.val1) > 0)": 9437183,
@@ -1365,9 +1367,9 @@ func TestCelEstimatedCostStability(t *testing.T) {
13651367
"!('x' in self.val1)": 1048578,
13661368
"self.val1 + self.val2 == ['a', 'b', 'c']": 16,
13671369
"self.val1 + ['c', 'd'] == ['a', 'b', 'c', 'd']": 24,
1368-
"has(self.val1)": 2,
1369-
"has(self.val1) && has(self.val2)": 4,
1370-
"!has(self.val1)": 3,
1370+
"has(self.val1)": 1,
1371+
"has(self.val1) && has(self.val2)": 2,
1372+
"!has(self.val1)": 2,
13711373
"self.val1.all(k, size(self.val1) > 0)": 7340028,
13721374
"self.val1.exists_one(k, self.val1 == ['a'])": 15728629,
13731375
"!self.val1.exists_one(k, size(self.val1) > 0)": 6291455,
@@ -1392,9 +1394,9 @@ func TestCelEstimatedCostStability(t *testing.T) {
13921394

13931395
"self.objs[2] + [self.objs[0][0], self.objs[0][1]] == self.objs[0]": 104883, // concat against a declared list
13941396
"size(self.objs[0] + [self.objs[3][0]]) == 3": 20,
1395-
"has(self.objs)": 2,
1396-
"has(self.objs) && has(self.objs)": 4,
1397-
"!has(self.objs)": 3,
1397+
"has(self.objs)": 1,
1398+
"has(self.objs) && has(self.objs)": 2,
1399+
"!has(self.objs)": 2,
13981400
"self.objs[0].all(k, size(self.objs[0]) > 0)": 8388604,
13991401
"self.objs[0].exists_one(k, size(self.objs[0]) > 0)": 7340030,
14001402
"!self.objs[0].exists_one(k, size(self.objs[0]) > 0)": 7340031,
@@ -1409,9 +1411,9 @@ func TestCelEstimatedCostStability(t *testing.T) {
14091411
"'k1' in self.val1": 3,
14101412
"!('k3' in self.val1)": 4,
14111413
"self.val1 == {'k1': 'a', 'k2': 'b'}": 33,
1412-
"has(self.val1)": 2,
1413-
"has(self.val1) && has(self.val2)": 4,
1414-
"!has(self.val1)": 3,
1414+
"has(self.val1)": 1,
1415+
"has(self.val1) && has(self.val2)": 2,
1416+
"!has(self.val1)": 2,
14151417
"self.val1.all(k, size(self.val1) > 0)": 2752508,
14161418
"self.val1.exists_one(k, size(self.val1) > 0)": 2359294,
14171419
"!self.val1.exists_one(k, size(self.val1) > 0)": 2359295,
@@ -1448,13 +1450,13 @@ func TestCelEstimatedCostStability(t *testing.T) {
14481450
}),
14491451
// https://github.com/google/cel-spec/blob/master/doc/langdef.md#field-selection
14501452
expectCost: map[string]uint64{
1451-
"has(self.a.b)": 3,
1452-
"has(self.a1.b1.c1)": 4,
1453-
"!(has(self.a1.d2) && has(self.a1.d2.e2))": 8, // must check intermediate optional fields (see below no such key error for d2)
1454-
"!has(self.a1.d2)": 4,
1455-
"has(self.a)": 2,
1456-
"has(self.a) && has(self.a1)": 4,
1457-
"!has(self.a)": 3,
1453+
"has(self.a.b)": 2,
1454+
"has(self.a1.b1.c1)": 3,
1455+
"!(has(self.a1.d2) && has(self.a1.d2.e2))": 6, // must check intermediate optional fields (see below no such key error for d2)
1456+
"!has(self.a1.d2)": 3,
1457+
"has(self.a)": 1,
1458+
"has(self.a) && has(self.a1)": 2,
1459+
"!has(self.a)": 2,
14581460
},
14591461
},
14601462
{name: "map access",
@@ -1468,10 +1470,10 @@ func TestCelEstimatedCostStability(t *testing.T) {
14681470
"!('c' in self.val)": 4,
14691471
"'d' in self.val": 3,
14701472
// field selection also possible if map key is a valid CEL identifier
1471-
"!has(self.val.a)": 4,
1472-
"has(self.val.b)": 3,
1473-
"!has(self.val.c)": 4,
1474-
"has(self.val.d)": 3,
1473+
"!has(self.val.a)": 3,
1474+
"has(self.val.b)": 2,
1475+
"!has(self.val.c)": 3,
1476+
"has(self.val.d)": 2,
14751477
"self.val.all(k, self.val[k] > 0)": 3595115,
14761478
"self.val.exists_one(k, self.val[k] == 2)": 2696338,
14771479
"!self.val.exists_one(k, self.val[k] > 0)": 3145728,
@@ -1488,9 +1490,9 @@ func TestCelEstimatedCostStability(t *testing.T) {
14881490
})),
14891491
}),
14901492
expectCost: map[string]uint64{
1491-
"has(self.listMap[0].v)": 4,
1493+
"has(self.listMap[0].v)": 3,
14921494
"self.listMap.all(m, m.k.startsWith('a'))": 6291453,
1493-
"self.listMap.all(m, !has(m.v2) || m.v2 == 'z')": 9437178,
1495+
"self.listMap.all(m, !has(m.v2) || m.v2 == 'z')": 8388603,
14941496
"self.listMap.exists(m, m.k.endsWith('1'))": 7340028,
14951497
"self.listMap.exists_one(m, m.k == 'a3')": 5242879,
14961498
"!self.listMap.all(m, m.k.endsWith('1'))": 6291454,
@@ -1503,12 +1505,12 @@ func TestCelEstimatedCostStability(t *testing.T) {
15031505
// test comprehensions where the field used in predicates is unset on all but one of the elements:
15041506
// - with has checks:
15051507

1506-
"self.listMap.exists(m, has(m.v2) && m.v2 == 'z')": 9437178,
1507-
"!self.listMap.all(m, has(m.v2) && m.v2 != 'z')": 8388604,
1508-
"self.listMap.exists_one(m, has(m.v2) && m.v2 == 'z')": 7340029,
1509-
"self.listMap.filter(m, has(m.v2) && m.v2 == 'z').size() == 1": 18874365,
1508+
"self.listMap.exists(m, has(m.v2) && m.v2 == 'z')": 8388603,
1509+
"!self.listMap.all(m, has(m.v2) && m.v2 != 'z')": 7340029,
1510+
"self.listMap.exists_one(m, has(m.v2) && m.v2 == 'z')": 6291454,
1511+
"self.listMap.filter(m, has(m.v2) && m.v2 == 'z').size() == 1": 17825790,
15101512
// undocumented overload of map that takes a filter argument. This is the same as .filter().map()
1511-
"self.listMap.map(m, has(m.v2) && m.v2 == 'z', m.v2).size() == 1": 19922940,
1513+
"self.listMap.map(m, has(m.v2) && m.v2 == 'z', m.v2).size() == 1": 18874365,
15121514
"self.listMap.filter(m, has(m.v2) && m.v2 == 'z').map(m, m.v2).size() == 1": uint64(18446744073709551615),
15131515
// - without has checks:
15141516

@@ -1639,7 +1641,7 @@ func TestCelEstimatedCostStability(t *testing.T) {
16391641
"self.embedded.metadata.generateName == 'pickItForMe'": 6,
16401642

16411643
// the object exists
1642-
"has(self.embedded)": 2,
1644+
"has(self.embedded)": 1,
16431645
},
16441646
},
16451647
{name: "string in intOrString",
@@ -1691,7 +1693,7 @@ func TestCelEstimatedCostStability(t *testing.T) {
16911693
"something": withNullable(true, intOrStringType()),
16921694
}),
16931695
expectCost: map[string]uint64{
1694-
"!has(self.something)": 3,
1696+
"!has(self.something)": 2,
16951697
},
16961698
},
16971699
{name: "percent comparison using intOrString",
@@ -1753,7 +1755,7 @@ func TestCelEstimatedCostStability(t *testing.T) {
17531755
},
17541756
}),
17551757
expectCost: map[string]uint64{
1756-
"has(self.withUnknown)": 2,
1758+
"has(self.withUnknown)": 1,
17571759
"self.withUnknownList.size() == 5": 4,
17581760
// fields that are unknown because they were not specified on the object schema are included in equality checks
17591761
"self.withUnknownList[0] != self.withUnknownList[1]": 6,
@@ -1818,19 +1820,19 @@ func TestCelEstimatedCostStability(t *testing.T) {
18181820
"setToNullNullableStr": withNullable(true, stringType),
18191821
}),
18201822
expectCost: map[string]uint64{
1821-
"!has(self.unsetPlainStr)": 3,
1822-
"has(self.unsetDefaultedStr) && self.unsetDefaultedStr == 'default value'": 6,
1823-
"!has(self.unsetNullableStr)": 3,
1823+
"!has(self.unsetPlainStr)": 2,
1824+
"has(self.unsetDefaultedStr) && self.unsetDefaultedStr == 'default value'": 5,
1825+
"!has(self.unsetNullableStr)": 2,
18241826

1825-
"has(self.setPlainStr) && self.setPlainStr == 'v1'": 5,
1826-
"has(self.setDefaultedStr) && self.setDefaultedStr == 'v2'": 5,
1827-
"has(self.setNullableStr) && self.setNullableStr == 'v3'": 5,
1827+
"has(self.setPlainStr) && self.setPlainStr == 'v1'": 4,
1828+
"has(self.setDefaultedStr) && self.setDefaultedStr == 'v2'": 4,
1829+
"has(self.setNullableStr) && self.setNullableStr == 'v3'": 4,
18281830
// We treat null fields as absent fields, not as null valued fields.
18291831
// Note that this is different than how we treat nullable list items or map values.
18301832
"type(self.setNullableStr) != null_type": 4,
18311833

18321834
// a field that is set to null is treated the same as an absent field in validation rules
1833-
"!has(self.setToNullNullableStr)": 3,
1835+
"!has(self.setToNullNullableStr)": 2,
18341836
},
18351837
},
18361838
{name: "null values in container types",

0 commit comments

Comments
 (0)