@@ -24,6 +24,7 @@ import (
2424 "os"
2525 "slices"
2626 "strings"
27+ "sync"
2728 "time"
2829
2930 "github.com/api7/gopkg/pkg/log"
@@ -37,6 +38,7 @@ import (
3738)
3839
3940type Client struct {
41+ mu sync.Mutex
4042 * cache.Store
4143
4244 executor ADCExecutor
@@ -60,6 +62,8 @@ type Task struct {
6062}
6163
6264func (d * Client ) Insert (ctx context.Context , args Task ) error {
65+ d .mu .Lock ()
66+ defer d .mu .Unlock ()
6367 for _ , config := range args .Configs {
6468 if err := d .Store .Insert (config .Name , args .ResourceTypes , args .Resources , args .Labels ); err != nil {
6569 log .Errorw ("failed to insert resources into store" ,
@@ -73,6 +77,8 @@ func (d *Client) Insert(ctx context.Context, args Task) error {
7377}
7478
7579func (d * Client ) Remove (ctx context.Context , args Task ) error {
80+ d .mu .Lock ()
81+ defer d .mu .Unlock ()
7682 for _ , config := range args .Configs {
7783 if err := d .Delete (config .Name , args .ResourceTypes , args .Labels ); err != nil {
7884 log .Errorw ("failed to delete resources from store" ,
@@ -86,10 +92,14 @@ func (d *Client) Remove(ctx context.Context, args Task) error {
8692}
8793
8894func (d * Client ) Update (ctx context.Context , args Task ) error {
95+ d .mu .Lock ()
96+ defer d .mu .Unlock ()
8997 return d .sync (ctx , args )
9098}
9199
92100func (c * Client ) Sync (ctx context.Context , cfg map [string ]adctypes.Config ) (map [string ]types.ADCExecutionErrors , error ) {
101+ c .mu .Lock ()
102+ defer c .mu .Unlock ()
93103 log .Debug ("syncing all resources" )
94104
95105 if len (cfg ) == 0 {
0 commit comments