mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Fix apply equality check to allow empty map to be equal to nil for builtin types
This commit is contained in:
parent
89a68be3a9
commit
f8a33e3679
@ -28,6 +28,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/equality"
|
"k8s.io/apimachinery/pkg/api/equality"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/conversion"
|
"k8s.io/apimachinery/pkg/conversion"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apiserver/pkg/endpoints/metrics"
|
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||||
@ -152,14 +153,20 @@ func IgnoreManagedFieldsTimestampsTransformer(
|
|||||||
return newObj, nil
|
return newObj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eqFn := equalities.DeepEqual
|
||||||
|
if _, ok := newObj.(*unstructured.Unstructured); ok {
|
||||||
|
// Use strict equality with unstructured
|
||||||
|
eqFn = equalities.DeepEqualWithNilDifferentFromEmpty
|
||||||
|
}
|
||||||
|
|
||||||
// This condition ensures the managed fields are always compared first. If
|
// This condition ensures the managed fields are always compared first. If
|
||||||
// this check fails, the if statement will short circuit. If the check
|
// this check fails, the if statement will short circuit. If the check
|
||||||
// succeeds the slow path is taken which compares entire objects.
|
// succeeds the slow path is taken which compares entire objects.
|
||||||
if !equalities.DeepEqualWithNilDifferentFromEmpty(oldManagedFields, newManagedFields) {
|
if !eqFn(oldManagedFields, newManagedFields) {
|
||||||
return newObj, nil
|
return newObj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if equalities.DeepEqualWithNilDifferentFromEmpty(newObj, oldObj) {
|
if eqFn(newObj, oldObj) {
|
||||||
// Remove any changed timestamps, so that timestamp is not the only
|
// Remove any changed timestamps, so that timestamp is not the only
|
||||||
// change seen by etcd.
|
// change seen by etcd.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user