@@ -94,6 +94,8 @@ type adcClient struct {
9494
9595 updater status.Updater
9696 statusUpdateMap map [types.NamespacedNameKind ][]string
97+
98+ syncCh chan struct {}
9799}
98100
99101type Task struct {
@@ -116,6 +118,7 @@ func New(updater status.Updater, opts ...Option) (provider.Provider, error) {
116118 store : NewStore (),
117119 executor : & DefaultADCExecutor {},
118120 updater : updater ,
121+ syncCh : make (chan struct {}, 1 ),
119122 }, nil
120123}
121124
@@ -220,6 +223,7 @@ func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext,
220223 // which only needs to be saved in cache
221224 // and triggered by a timer for synchronization
222225 if d .BackendMode == BackendModeAPISIXStandalone || d .BackendMode == BackendModeAPISIX {
226+ d .syncNotify ()
223227 return nil
224228 }
225229
@@ -289,6 +293,8 @@ func (d *adcClient) Delete(ctx context.Context, obj client.Object) error {
289293 Name : obj .GetName (),
290294 configs : configs ,
291295 })
296+ } else {
297+ d .syncNotify ()
292298 }
293299 return nil
294300 case BackendModeAPI7EE :
@@ -306,26 +312,34 @@ func (d *adcClient) Delete(ctx context.Context, obj client.Object) error {
306312
307313func (d * adcClient ) Start (ctx context.Context ) error {
308314 initalSyncDelay := d .InitSyncDelay
309- time .AfterFunc (initalSyncDelay , func () {
310- if err := d .Sync (ctx ); err != nil {
311- log .Error (err )
312- return
313- }
314- })
315+ if initalSyncDelay > 0 {
316+ time .AfterFunc (initalSyncDelay , func () {
317+ if err := d .Sync (ctx ); err != nil {
318+ log .Error (err )
319+ return
320+ }
321+ })
322+ }
315323
316324 if d .SyncPeriod < 1 {
317325 return nil
318326 }
319327 ticker := time .NewTicker (d .SyncPeriod )
320328 defer ticker .Stop ()
321329 for {
330+ synced := false
322331 select {
332+ case <- d .syncCh :
333+ synced = true
323334 case <- ticker .C :
335+ synced = true
336+ case <- ctx .Done ():
337+ return nil
338+ }
339+ if synced {
324340 if err := d .Sync (ctx ); err != nil {
325341 log .Error (err )
326342 }
327- case <- ctx .Done ():
328- return nil
329343 }
330344 }
331345}
@@ -506,6 +520,13 @@ func (d *adcClient) sync(ctx context.Context, task Task) error {
506520 return nil
507521}
508522
523+ func (d * adcClient ) syncNotify () {
524+ select {
525+ case d .syncCh <- struct {}{}:
526+ default :
527+ }
528+ }
529+
509530func prepareSyncFile (resources any ) (string , func (), error ) {
510531 data , err := json .Marshal (resources )
511532 if err != nil {
0 commit comments