mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 07:39:22 +00:00
ratcheting: disable correlation by index
discussion: https://github.com/kubernetes/kubernetes/pull/121118#discussion_r1358865893
This commit is contained in:
parent
d991ed56c2
commit
fb1fc8b4a7
@ -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",
|
||||
|
@ -114,20 +114,16 @@ 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 {
|
||||
// Unrecognized list type. Assume non-correlatable.
|
||||
return nil
|
||||
}
|
||||
|
||||
return oldAsList[index]
|
||||
}
|
||||
}
|
||||
|
||||
// CachedDeepEqual is equivalent to reflect.DeepEqual, but caches the
|
||||
|
@ -142,7 +142,7 @@ 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(`
|
||||
@ -150,8 +150,6 @@ func TestCorrelation(t *testing.T) {
|
||||
type: string
|
||||
`),
|
||||
KeyPath: []interface{}{1},
|
||||
NewValue: "b",
|
||||
OldValue: "b",
|
||||
},
|
||||
{
|
||||
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",
|
||||
@ -201,8 +199,6 @@ func TestCorrelation(t *testing.T) {
|
||||
type: string
|
||||
`),
|
||||
KeyPath: []interface{}{1},
|
||||
NewValue: "b",
|
||||
OldValue: "oldB",
|
||||
},
|
||||
{
|
||||
Name: "Changed Index In Nested Old Object",
|
||||
|
Loading…
Reference in New Issue
Block a user