@@ -197,7 +197,7 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer)
197
197
ctx , cancel := getContextWithCancel ()
198
198
defer cancel ()
199
199
200
- resp , err := az .LoadBalancerClient .CreateOrUpdate (ctx , az .ResourceGroup , * lb .Name , lb )
200
+ resp , err := az .LoadBalancerClient .CreateOrUpdate (ctx , az .ResourceGroup , * lb .Name , lb , to . String ( lb . Etag ) )
201
201
klog .V (10 ).Infof ("LoadBalancerClient.CreateOrUpdate(%s): end" , * lb .Name )
202
202
if err == nil {
203
203
if isSuccessHTTPResponse (resp ) {
@@ -207,6 +207,11 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer)
207
207
return fmt .Errorf ("HTTP response %q" , resp .Status )
208
208
}
209
209
}
210
+
211
+ // Invalidate the cache because ETAG precondition mismatch.
212
+ if resp != nil && resp .StatusCode == http .StatusPreconditionFailed {
213
+ az .lbCache .Delete (* lb .Name )
214
+ }
210
215
return err
211
216
}
212
217
@@ -219,14 +224,20 @@ func (az *Cloud) createOrUpdateLBWithRetry(service *v1.Service, lb network.LoadB
219
224
ctx , cancel := getContextWithCancel ()
220
225
defer cancel ()
221
226
222
- resp , err := az .LoadBalancerClient .CreateOrUpdate (ctx , az .ResourceGroup , * lb .Name , lb )
227
+ resp , err := az .LoadBalancerClient .CreateOrUpdate (ctx , az .ResourceGroup , * lb .Name , lb , to . String ( lb . Etag ) )
223
228
klog .V (10 ).Infof ("LoadBalancerClient.CreateOrUpdate(%s): end" , * lb .Name )
224
- done , err := az .processHTTPRetryResponse (service , "CreateOrUpdateLoadBalancer" , resp , err )
229
+ done , retryError := az .processHTTPRetryResponse (service , "CreateOrUpdateLoadBalancer" , resp , err )
225
230
if done && err == nil {
226
231
// Invalidate the cache right after updating
227
232
az .lbCache .Delete (* lb .Name )
228
233
}
229
- return done , err
234
+
235
+ // Invalidate the cache and abort backoff because ETAG precondition mismatch.
236
+ if resp != nil && resp .StatusCode == http .StatusPreconditionFailed {
237
+ az .nsgCache .Delete (* lb .Name )
238
+ return true , err
239
+ }
240
+ return done , retryError
230
241
})
231
242
}
232
243
@@ -441,7 +452,10 @@ func (az *Cloud) CreateOrUpdateRouteTable(routeTable network.RouteTable) error {
441
452
ctx , cancel := getContextWithCancel ()
442
453
defer cancel ()
443
454
444
- resp , err := az .RouteTablesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , routeTable )
455
+ resp , err := az .RouteTablesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , routeTable , to .String (routeTable .Etag ))
456
+ if resp != nil && resp .StatusCode == http .StatusPreconditionFailed {
457
+ az .rtCache .Delete (* routeTable .Name )
458
+ }
445
459
return az .processHTTPResponse (nil , "" , resp , err )
446
460
}
447
461
@@ -454,8 +468,19 @@ func (az *Cloud) createOrUpdateRouteTableWithRetry(routeTable network.RouteTable
454
468
ctx , cancel := getContextWithCancel ()
455
469
defer cancel ()
456
470
457
- resp , err := az .RouteTablesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , routeTable )
458
- return az .processHTTPRetryResponse (nil , "" , resp , err )
471
+ resp , err := az .RouteTablesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , routeTable , to .String (routeTable .Etag ))
472
+ done , retryError := az .processHTTPRetryResponse (nil , "" , resp , err )
473
+ if done && err == nil {
474
+ az .rtCache .Delete (* routeTable .Name )
475
+ return done , nil
476
+ }
477
+
478
+ // Invalidate the cache and abort backoff because ETAG precondition mismatch.
479
+ if resp != nil && resp .StatusCode == http .StatusPreconditionFailed {
480
+ az .rtCache .Delete (* routeTable .Name )
481
+ return true , err
482
+ }
483
+ return done , retryError
459
484
})
460
485
}
461
486
@@ -465,8 +490,11 @@ func (az *Cloud) CreateOrUpdateRoute(route network.Route) error {
465
490
ctx , cancel := getContextWithCancel ()
466
491
defer cancel ()
467
492
468
- resp , err := az .RoutesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , * route .Name , route )
493
+ resp , err := az .RoutesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , * route .Name , route , to . String ( route . Etag ) )
469
494
klog .V (10 ).Infof ("RoutesClient.CreateOrUpdate(%s): end" , * route .Name )
495
+ if resp != nil && resp .StatusCode == http .StatusPreconditionFailed {
496
+ az .rtCache .Delete (az .RouteTableName )
497
+ }
470
498
return az .processHTTPResponse (nil , "" , resp , err )
471
499
}
472
500
@@ -479,9 +507,20 @@ func (az *Cloud) createOrUpdateRouteWithRetry(route network.Route) error {
479
507
ctx , cancel := getContextWithCancel ()
480
508
defer cancel ()
481
509
482
- resp , err := az .RoutesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , * route .Name , route )
510
+ resp , err := az .RoutesClient .CreateOrUpdate (ctx , az .RouteTableResourceGroup , az .RouteTableName , * route .Name , route , to . String ( route . Etag ) )
483
511
klog .V (10 ).Infof ("RoutesClient.CreateOrUpdate(%s): end" , * route .Name )
484
- return az .processHTTPRetryResponse (nil , "" , resp , err )
512
+ done , retryError := az .processHTTPRetryResponse (nil , "" , resp , err )
513
+ if done && err == nil {
514
+ az .rtCache .Delete (az .RouteTableName )
515
+ return done , nil
516
+ }
517
+
518
+ // Invalidate the cache and abort backoff because ETAG precondition mismatch.
519
+ if resp != nil && resp .StatusCode == http .StatusPreconditionFailed {
520
+ az .rtCache .Delete (az .RouteTableName )
521
+ return true , err
522
+ }
523
+ return done , retryError
485
524
})
486
525
}
487
526
0 commit comments