mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 05:46:16 +00:00
refactor: make CachedDeepEqual independent of validation
before it required running validation first, now it builds the tree as needed
This commit is contained in:
parent
e76aad1813
commit
b321e8bf0d
@ -313,26 +313,20 @@ func (r *CorrelatedObject) CachedDeepEqual() (res bool) {
|
|||||||
} else if oldIsArray {
|
} else if oldIsArray {
|
||||||
if len(oldAsArray) != len(newAsArray) {
|
if len(oldAsArray) != len(newAsArray) {
|
||||||
return false
|
return false
|
||||||
} else if len(r.children) != len(oldAsArray) {
|
|
||||||
// kube-openapi validator is written to always visit all
|
|
||||||
// children of a slice, so this case is only possible if
|
|
||||||
// one of the children could not be correlated. In that case,
|
|
||||||
// we know the objects are not equal.
|
|
||||||
//
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Correctly considers map-type lists due to fact that index here
|
|
||||||
// is only used for numbering. The correlation is stored in the
|
|
||||||
// childInvocation itself
|
|
||||||
//
|
|
||||||
// NOTE: This does not consider sets, since we don't correlate them.
|
|
||||||
for i := range newAsArray {
|
for i := range newAsArray {
|
||||||
// Query for child
|
child := r.Index(i)
|
||||||
child, ok := r.children[i]
|
if child == nil {
|
||||||
if !ok {
|
if r.mapList == nil {
|
||||||
// This should not happen
|
// Treat non-correlatable array as a unit with reflect.DeepEqual
|
||||||
|
return reflect.DeepEqual(oldAsArray, newAsArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If array is correlatable, but old not found. Just short circuit
|
||||||
|
// comparison
|
||||||
return false
|
return false
|
||||||
|
|
||||||
} else if !child.CachedDeepEqual() {
|
} else if !child.CachedDeepEqual() {
|
||||||
// If one child is not equal the entire object is not equal
|
// If one child is not equal the entire object is not equal
|
||||||
return false
|
return false
|
||||||
@ -350,21 +344,12 @@ func (r *CorrelatedObject) CachedDeepEqual() (res bool) {
|
|||||||
} else if oldIsMap {
|
} else if oldIsMap {
|
||||||
if len(oldAsMap) != len(newAsMap) {
|
if len(oldAsMap) != len(newAsMap) {
|
||||||
return false
|
return false
|
||||||
} else if len(oldAsMap) == 0 && len(newAsMap) == 0 {
|
|
||||||
// Both empty
|
|
||||||
return true
|
|
||||||
} else if len(r.children) != len(oldAsMap) {
|
|
||||||
// If we are missing a key it is because the old value could not
|
|
||||||
// be correlated to the new, so the objects are not equal.
|
|
||||||
//
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for k := range oldAsMap {
|
for k := range newAsMap {
|
||||||
// Check to see if this child was explored during validation
|
child := r.Key(k)
|
||||||
child, ok := r.children[k]
|
if child == nil {
|
||||||
if !ok {
|
// Un-correlatable child due to key change.
|
||||||
// Child from old missing in new due to key change
|
|
||||||
// Objects are not equal.
|
// Objects are not equal.
|
||||||
return false
|
return false
|
||||||
} else if !child.CachedDeepEqual() {
|
} else if !child.CachedDeepEqual() {
|
||||||
|
Loading…
Reference in New Issue
Block a user