@@ -22,18 +22,25 @@ import (
2222 "sync"
2323
2424 "github.com/go-logr/logr"
25+ "github.com/google/go-cmp/cmp"
26+ "github.com/google/go-cmp/cmp/cmpopts"
2527 k8serrors "k8s.io/apimachinery/pkg/api/errors"
26- "k8s.io/apimachinery/pkg/types"
28+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+ k8stypes "k8s.io/apimachinery/pkg/types"
2730 "k8s.io/client-go/util/retry"
2831 "sigs.k8s.io/controller-runtime/pkg/client"
32+ gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2933
34+ "github.com/apache/apisix-ingress-controller/api/v1alpha1"
35+ v2 "github.com/apache/apisix-ingress-controller/api/v2"
36+ types "github.com/apache/apisix-ingress-controller/internal/types"
3037 pkgmetrics "github.com/apache/apisix-ingress-controller/pkg/metrics"
3138)
3239
3340const UpdateChannelBufferSize = 1000
3441
3542type Update struct {
36- NamespacedName types .NamespacedName
43+ NamespacedName k8stypes .NamespacedName
3744 Resource client.Object
3845 Mutator Mutator
3946}
@@ -52,6 +59,13 @@ func (m MutatorFunc) Mutate(obj client.Object) client.Object {
5259 return m (obj )
5360}
5461
62+ var cmpIgnoreLastTT = cmp.Options {
63+ cmpopts .IgnoreFields (metav1.Condition {}, "LastTransitionTime" ),
64+ cmpopts .IgnoreMapEntries (func (k string , _ any ) bool {
65+ return k == "lastTransitionTime"
66+ }),
67+ }
68+
5569type UpdateHandler struct {
5670 log logr.Logger
5771 client client.Client
@@ -96,8 +110,20 @@ func (u *UpdateHandler) updateStatus(ctx context.Context, update Update) error {
96110 return nil
97111 }
98112
113+ if statusEqual (obj , newObj , cmpIgnoreLastTT ) {
114+ u .log .V (1 ).Info ("status is equal, skipping update" , "name" , update .NamespacedName .Name ,
115+ "namespace" , update .NamespacedName .Namespace ,
116+ "kind" , types .KindOf (obj ))
117+ return nil
118+ }
119+
99120 newObj .SetUID (obj .GetUID ())
100121
122+ u .log .Info ("updating status" , "name" , update .NamespacedName .Name ,
123+ "namespace" , update .NamespacedName .Namespace ,
124+ "kind" , types .KindOf (newObj ),
125+ )
126+
101127 return u .client .Status ().Update (ctx , newObj )
102128}
103129
@@ -114,8 +140,10 @@ func (u *UpdateHandler) Start(ctx context.Context) error {
114140 case update := <- u .updateChannel :
115141 // Decrement queue length after removing item from queue
116142 pkgmetrics .DecStatusQueueLength ()
117- u .log .Info ("received a status update" , "namespace" , update .NamespacedName .Namespace ,
118- "name" , update .NamespacedName .Name )
143+ u .log .V (1 ).Info ("received a status update" , "namespace" , update .NamespacedName .Namespace ,
144+ "name" , update .NamespacedName .Name ,
145+ "kind" , types .KindOf (update .Resource ),
146+ )
119147
120148 u .apply (ctx , update )
121149 }
@@ -144,3 +172,82 @@ func (u *UpdateWriter) Update(update Update) {
144172 // Increment queue length after adding new item
145173 pkgmetrics .IncStatusQueueLength ()
146174}
175+
176+ func statusEqual (a , b any , opts ... cmp.Option ) bool {
177+ var statusA , statusB any
178+
179+ switch a := a .(type ) {
180+ case * gatewayv1.GatewayClass :
181+ b , ok := b .(* gatewayv1.GatewayClass )
182+ if ! ok {
183+ return false
184+ }
185+ statusA , statusB = a .Status , b .Status
186+
187+ case * gatewayv1.Gateway :
188+ b , ok := b .(* gatewayv1.Gateway )
189+ if ! ok {
190+ return false
191+ }
192+ statusA , statusB = a .Status , b .Status
193+
194+ case * gatewayv1.HTTPRoute :
195+ b , ok := b .(* gatewayv1.HTTPRoute )
196+ if ! ok {
197+ return false
198+ }
199+ statusA , statusB = a .Status , b .Status
200+ case * v2.ApisixRoute :
201+ b , ok := b .(* v2.ApisixRoute )
202+ if ! ok {
203+ return false
204+ }
205+ statusA , statusB = a .Status , b .Status
206+ case * v2.ApisixGlobalRule :
207+ b , ok := b .(* v2.ApisixGlobalRule )
208+ if ! ok {
209+ return false
210+ }
211+ statusA , statusB = a .Status , b .Status
212+ case * v2.ApisixPluginConfig :
213+ b , ok := b .(* v2.ApisixPluginConfig )
214+ if ! ok {
215+ return false
216+ }
217+ statusA , statusB = a .Status , b .Status
218+ case * v2.ApisixTls :
219+ b , ok := b .(* v2.ApisixTls )
220+ if ! ok {
221+ return false
222+ }
223+ statusA , statusB = a .Status , b .Status
224+ case * v2.ApisixConsumer :
225+ b , ok := b .(* v2.ApisixConsumer )
226+ if ! ok {
227+ return false
228+ }
229+ statusA , statusB = a .Status , b .Status
230+ case * v1alpha1.HTTPRoutePolicy :
231+ b , ok := b .(* v1alpha1.HTTPRoutePolicy )
232+ if ! ok {
233+ return false
234+ }
235+ statusA , statusB = a .Status , b .Status
236+ case * v1alpha1.BackendTrafficPolicy :
237+ b , ok := b .(* v1alpha1.BackendTrafficPolicy )
238+ if ! ok {
239+ return false
240+ }
241+ statusA , statusB = a .Status , b .Status
242+ case * v1alpha1.Consumer :
243+ b , ok := b .(* v1alpha1.Consumer )
244+ if ! ok {
245+ return false
246+ }
247+ statusA , statusB = a .Status , b .Status
248+ default :
249+ return false
250+ }
251+
252+ return cmp .Equal (statusA , statusB , opts ... )
253+ }
0 commit comments