Skip to content

Commit f8a33e3

Browse files
committed
Fix apply equality check to allow empty map to be equal to nil for builtin types
1 parent 89a68be commit f8a33e3

File tree

1 file changed

+9
-2
lines changed
  • staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager

1 file changed

+9
-2
lines changed

staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/equality.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/apimachinery/pkg/api/equality"
2929
"k8s.io/apimachinery/pkg/api/meta"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3132
"k8s.io/apimachinery/pkg/conversion"
3233
"k8s.io/apimachinery/pkg/runtime"
3334
"k8s.io/apiserver/pkg/endpoints/metrics"
@@ -152,14 +153,20 @@ func IgnoreManagedFieldsTimestampsTransformer(
152153
return newObj, nil
153154
}
154155

156+
eqFn := equalities.DeepEqual
157+
if _, ok := newObj.(*unstructured.Unstructured); ok {
158+
// Use strict equality with unstructured
159+
eqFn = equalities.DeepEqualWithNilDifferentFromEmpty
160+
}
161+
155162
// This condition ensures the managed fields are always compared first. If
156163
// this check fails, the if statement will short circuit. If the check
157164
// succeeds the slow path is taken which compares entire objects.
158-
if !equalities.DeepEqualWithNilDifferentFromEmpty(oldManagedFields, newManagedFields) {
165+
if !eqFn(oldManagedFields, newManagedFields) {
159166
return newObj, nil
160167
}
161168

162-
if equalities.DeepEqualWithNilDifferentFromEmpty(newObj, oldObj) {
169+
if eqFn(newObj, oldObj) {
163170
// Remove any changed timestamps, so that timestamp is not the only
164171
// change seen by etcd.
165172
//

0 commit comments

Comments
 (0)