diff --git a/staging/src/k8s.io/apiextensions-apiserver/test/integration/ratcheting_test.go b/staging/src/k8s.io/apiextensions-apiserver/test/integration/ratcheting_test.go index cc88e1d8114..d0f850e97cc 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/test/integration/ratcheting_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/test/integration/ratcheting_test.go @@ -1175,7 +1175,7 @@ func TestRatchetingFunctionality(t *testing.T) { }, }, { - Name: "ArrayItems correlate by index", + Name: "ArrayItems do not correlate by index", Operations: []ratchetingTestOperation{ updateMyCRDV1Beta1Schema{&apiextensionsv1.JSONSchemaProps{ Type: "object", @@ -1246,9 +1246,9 @@ func TestRatchetingFunctionality(t *testing.T) { }, "otherField": "hello world", }}, - // (This test shows an array can be correlated by index with its old value) - applyPatchOperation{ - "add new, valid fields to elements of the array, ratcheting unchanged old fields within the array elements by correlating by index", + // (This test shows an array cannpt be correlated by index with its old value) + expectError{applyPatchOperation{ + "add new, valid fields to elements of the array, failing to ratchet unchanged old fields within the array elements by correlating by index due to atomic list", myCRDV1Beta1, myCRDInstanceName, map[string]interface{}{ "values": []interface{}{ map[string]interface{}{ @@ -1261,7 +1261,7 @@ func TestRatchetingFunctionality(t *testing.T) { "key2": "valid value", }, }, - }}, + }}}, expectError{ applyPatchOperation{ "reorder the array, preventing index correlation", diff --git a/staging/src/k8s.io/apiserver/pkg/cel/common/equality.go b/staging/src/k8s.io/apiserver/pkg/cel/common/equality.go index 3046880bb5b..a271cae795e 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/common/equality.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/common/equality.go @@ -114,19 +114,15 @@ func (r *CorrelatedObject) correlateOldValueForChildAtNewIndex(index int) interf // of value // (would allow you to add/remove items from sets with ratcheting but not change them) return nil + case "": + fallthrough case "atomic": - // Atomic lists are not correlatable by item + // Atomic lists are the default are not correlatable by item // Ratcheting is not available on a per-index basis return nil default: - // Correlate by-index by default. - // - // Cannot correlate an out-of-bounds index - if len(oldAsList) <= index { - return nil - } - - return oldAsList[index] + // Unrecognized list type. Assume non-correlatable. + return nil } } diff --git a/staging/src/k8s.io/apiserver/pkg/cel/common/equality_test.go b/staging/src/k8s.io/apiserver/pkg/cel/common/equality_test.go index 8300d0a7f74..50c5146ae45 100644 --- a/staging/src/k8s.io/apiserver/pkg/cel/common/equality_test.go +++ b/staging/src/k8s.io/apiserver/pkg/cel/common/equality_test.go @@ -142,16 +142,14 @@ func TestCorrelation(t *testing.T) { OldValue: "b", }, { - Name: "Basic Index", + Name: "Atomic Array not correlatable", RootObject: mustUnstructured(`[a, b]`), RootOldObject: mustUnstructured(`[a, b]`), Schema: mustSchema(` items: type: string `), - KeyPath: []interface{}{1}, - NewValue: "b", - OldValue: "b", + KeyPath: []interface{}{1}, }, { Name: "Added Key Not In Old Object", @@ -187,7 +185,7 @@ func TestCorrelation(t *testing.T) { KeyPath: []interface{}{2}, }, { - Name: "Changed Index In Old Object", + Name: "Changed Index In Old Object not correlatable", RootObject: []interface{}{ "a", "b", @@ -200,9 +198,7 @@ func TestCorrelation(t *testing.T) { items: type: string `), - KeyPath: []interface{}{1}, - NewValue: "b", - OldValue: "oldB", + KeyPath: []interface{}{1}, }, { Name: "Changed Index In Nested Old Object",