File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package predicate
1717import (
1818 "reflect"
1919
20+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2122 "sigs.k8s.io/controller-runtime/pkg/event"
2223 logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -91,6 +92,9 @@ func (DependentPredicate) Update(e event.UpdateEvent) bool {
9192 old .SetResourceVersion ("" )
9293 new .SetResourceVersion ("" )
9394
95+ old .SetManagedFields (removeTimeFromManagedFields (old .GetManagedFields ()))
96+ new .SetManagedFields (removeTimeFromManagedFields (new .GetManagedFields ()))
97+
9498 if reflect .DeepEqual (old .Object , new .Object ) {
9599 return false
96100 }
@@ -99,3 +103,15 @@ func (DependentPredicate) Update(e event.UpdateEvent) bool {
99103 new .GroupVersionKind ().GroupVersion (), "kind" , new .GroupVersionKind ().Kind )
100104 return true
101105}
106+
107+ func removeTimeFromManagedFields (fields []metav1.ManagedFieldsEntry ) []metav1.ManagedFieldsEntry {
108+ if fields == nil {
109+ return nil
110+ }
111+ newFields := []metav1.ManagedFieldsEntry {}
112+ for _ , field := range fields {
113+ field .Time = nil
114+ newFields = append (newFields , field )
115+ }
116+ return newFields
117+ }
Original file line number Diff line number Diff line change 1515package predicate
1616
1717import (
18+ "time"
19+
1820 . "github.com/onsi/ginkgo"
1921 . "github.com/onsi/gomega"
22+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2023 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2124)
2225
@@ -66,6 +69,32 @@ var _ = Describe("DependentPredicate", func() {
6669 Expect (pred .Update (e )).To (BeFalse ())
6770 })
6871 })
72+
73+ When ("except time in managedFields is different" , func () {
74+ BeforeEach (func () {
75+ curTime := time .Now ()
76+ oldTime := metav1 .NewTime (curTime )
77+ oldObj .SetManagedFields ([]metav1.ManagedFieldsEntry {{
78+ Manager : "test" ,
79+ Operation : "Update" ,
80+ APIVersion : "v1" ,
81+ Time : & oldTime ,
82+ }})
83+
84+ duration , _ := time .ParseDuration ("4h" )
85+ newTime := metav1 .NewTime (curTime .Add (duration ))
86+ newObj .SetManagedFields ([]metav1.ManagedFieldsEntry {{
87+ Manager : "test" ,
88+ Operation : "Update" ,
89+ APIVersion : "v1" ,
90+ Time : & newTime ,
91+ }})
92+ })
93+ It ("should return false" , func () {
94+ e := makeUpdateEventFor (oldObj , newObj )
95+ Expect (pred .Update (e )).To (BeFalse ())
96+ })
97+ })
6998 })
7099
71100 When ("objects are different" , func () {
You can’t perform that action at this time.
0 commit comments