@@ -21,6 +21,7 @@ import (
2121 "context"
2222 "encoding/json"
2323 "os"
24+ "slices"
2425 "sync"
2526 "time"
2627
@@ -353,6 +354,34 @@ func (d *adcClient) sync(ctx context.Context, task Task) error {
353354 return errors .New ("no adc configs provided" )
354355 }
355356
357+ // for global rules, we need to list all global rules and set it to the task resources
358+ if slices .Contains (task .ResourceTypes , "global_rule" ) {
359+ for _ , config := range task .configs {
360+ globalRules , err := d .store .ListGlobalRules (config .Name )
361+ if err != nil {
362+ return err
363+ }
364+ task .Resources .GlobalRules = * globalRules
365+ log .Debugw ("syncing resources global rules" , zap .Any ("globalRules" , task .Resources .GlobalRules ))
366+
367+ syncFilePath , cleanup , err := prepareSyncFile (task .Resources )
368+ if err != nil {
369+ return err
370+ }
371+ defer cleanup ()
372+
373+ args := BuildADCExecuteArgs (syncFilePath , task .Labels , task .ResourceTypes )
374+
375+ if err := d .executor .Execute (ctx , d .BackendMode , config , args ); err != nil {
376+ log .Errorw ("failed to execute adc command" , zap .Error (err ), zap .Any ("config" , config ))
377+ return err
378+ }
379+ }
380+
381+ return nil
382+ }
383+
384+ // every task resources is the same, so we can use the first config to prepare the sync file
356385 syncFilePath , cleanup , err := prepareSyncFile (task .Resources )
357386 if err != nil {
358387 return err
0 commit comments