@@ -39,7 +39,8 @@ import (
3939)
4040
4141type Client struct {
42- mu sync.Mutex
42+ syncMu sync.Mutex
43+ mu sync.Mutex
4344 * cache.Store
4445
4546 executor ADCExecutor
@@ -74,9 +75,7 @@ type Task struct {
7475
7576func (d * Client ) Update (ctx context.Context , args Task ) error {
7677 d .mu .Lock ()
77- defer d .mu .Unlock ()
7878 deleteConfigs := d .ConfigManager .Update (args .Key , args .Configs )
79-
8079 for _ , config := range deleteConfigs {
8180 if err := d .Store .Delete (config .Name , args .ResourceTypes , args .Labels ); err != nil {
8281 log .Errorw ("failed to delete resources from store" ,
@@ -96,6 +95,7 @@ func (d *Client) Update(ctx context.Context, args Task) error {
9695 return err
9796 }
9897 }
98+ d .mu .Unlock ()
9999
100100 if len (deleteConfigs ) > 0 {
101101 err := d .sync (ctx , Task {
@@ -140,8 +140,6 @@ func (d *Client) UpdateConfig(ctx context.Context, args Task) error {
140140
141141func (d * Client ) Delete (ctx context.Context , args Task ) error {
142142 d .mu .Lock ()
143- defer d .mu .Unlock ()
144-
145143 configs := d .ConfigManager .Get (args .Key )
146144 d .ConfigManager .Delete (args .Key )
147145
@@ -154,6 +152,7 @@ func (d *Client) Delete(ctx context.Context, args Task) error {
154152 return err
155153 }
156154 }
155+ d .mu .Unlock ()
157156
158157 return d .sync (ctx , Task {
159158 Labels : args .Labels ,
@@ -183,8 +182,8 @@ func (d *Client) DeleteConfig(ctx context.Context, args Task) error {
183182}
184183
185184func (c * Client ) Sync (ctx context.Context ) (map [string ]types.ADCExecutionErrors , error ) {
186- c .mu .Lock ()
187- defer c .mu .Unlock ()
185+ c .syncMu .Lock ()
186+ defer c .syncMu .Unlock ()
188187 log .Debug ("syncing all resources" )
189188
190189 configs := c .ConfigManager .List ()
@@ -194,16 +193,12 @@ func (c *Client) Sync(ctx context.Context) (map[string]types.ADCExecutionErrors,
194193 return nil , nil
195194 }
196195
197- cfg := map [string ]adctypes.Config {}
198- for _ , config := range configs {
199- cfg [config .Name ] = config
200- }
201-
202- log .Debugw ("syncing resources with multiple configs" , zap .Any ("configs" , cfg ))
196+ log .Debugw ("syncing resources with multiple configs" , zap .Any ("configs" , configs ))
203197
204198 failedMap := map [string ]types.ADCExecutionErrors {}
205199 var failedConfigs []string
206- for name , config := range cfg {
200+ for _ , config := range configs {
201+ name := config .Name
207202 resources , err := c .GetResources (name )
208203 if err != nil {
209204 log .Errorw ("failed to get resources from store" , zap .String ("name" , name ), zap .Error (err ))
0 commit comments