Skip to content

Commit

Permalink
Merge pull request #81282 from feiskyer/fix-az-cancel
Browse files Browse the repository at this point in the history
Fix conflicted cache when the requests are canceled by other Azure operations
  • Loading branch information
k8s-ci-robot committed Aug 12, 2019
2 parents 0610bf0 + f692944 commit ae45744
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 46 additions & 1 deletion staging/src/k8s.io/legacy-cloud-providers/azure/azure_backoff.go
Expand Up @@ -36,6 +36,9 @@ import (
const (
// not active means the instance is under deleting from Azure VMSS.
vmssVMNotActiveErrorMessage = "not an active Virtual Machine Scale Set VM instanceId"

// operationCancledErrorMessage means the operation is canceled by another new operation.
operationCancledErrorMessage = "canceledandsupersededduetoanotheroperation"
)

// RequestBackoff if backoff is disabled in cloud provider it
Expand Down Expand Up @@ -197,6 +200,12 @@ func (az *Cloud) CreateOrUpdateSecurityGroup(service *v1.Service, sg network.Sec
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
az.nsgCache.Delete(*sg.Name)
}

// Invalidate the cache because another new operation has canceled the current request.
if strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.nsgCache.Delete(*sg.Name)
}

return err
}

Expand All @@ -222,6 +231,13 @@ func (az *Cloud) CreateOrUpdateSGWithRetry(service *v1.Service, sg network.Secur
az.nsgCache.Delete(*sg.Name)
return true, err
}

// Invalidate the cache and abort backoff because another new operation has canceled the current request.
if err != nil && strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.nsgCache.Delete(*sg.Name)
return true, err
}

return done, retryError
})
}
Expand All @@ -248,6 +264,10 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer)
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
az.lbCache.Delete(*lb.Name)
}
// Invalidate the cache because another new operation has canceled the current request.
if strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.lbCache.Delete(*lb.Name)
}
return err
}

Expand All @@ -271,7 +291,12 @@ func (az *Cloud) createOrUpdateLBWithRetry(service *v1.Service, lb network.LoadB

// Invalidate the cache and abort backoff because ETAG precondition mismatch.
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
az.nsgCache.Delete(*lb.Name)
az.lbCache.Delete(*lb.Name)
return true, err
}
// Invalidate the cache and abort backoff because another new operation has canceled the current request.
if err != nil && strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.lbCache.Delete(*lb.Name)
return true, err
}
return done, retryError
Expand Down Expand Up @@ -497,6 +522,10 @@ func (az *Cloud) CreateOrUpdateRouteTable(routeTable network.RouteTable) error {
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
az.rtCache.Delete(*routeTable.Name)
}
// Invalidate the cache because another new operation has canceled the current request.
if err != nil && strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.rtCache.Delete(*routeTable.Name)
}
return az.processHTTPResponse(nil, "", resp, err)
}

Expand All @@ -521,6 +550,11 @@ func (az *Cloud) createOrUpdateRouteTableWithRetry(routeTable network.RouteTable
az.rtCache.Delete(*routeTable.Name)
return true, err
}
// Invalidate the cache and abort backoff because another new operation has canceled the current request.
if err != nil && strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.rtCache.Delete(*routeTable.Name)
return true, err
}
return done, retryError
})
}
Expand All @@ -536,6 +570,10 @@ func (az *Cloud) CreateOrUpdateRoute(route network.Route) error {
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
az.rtCache.Delete(az.RouteTableName)
}
// Invalidate the cache because another new operation has canceled the current request.
if err != nil && strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.rtCache.Delete(az.RouteTableName)
}
return az.processHTTPResponse(nil, "", resp, err)
}

Expand All @@ -561,6 +599,13 @@ func (az *Cloud) createOrUpdateRouteWithRetry(route network.Route) error {
az.rtCache.Delete(az.RouteTableName)
return true, err
}

// Invalidate the cache and abort backoff because another new operation has canceled the current request.
if err != nil && strings.Contains(strings.ToLower(err.Error()), operationCancledErrorMessage) {
az.rtCache.Delete(az.RouteTableName)
return true, err
}

return done, retryError
})
}
Expand Down
Expand Up @@ -888,6 +888,8 @@ func (az *Cloud) reconcileLoadBalancer(clusterName string, service *v1.Service,
if wantLb && nodes != nil {
// Add the machines to the backend pool if they're not already
vmSetName := az.mapLoadBalancerNameToVMSet(lbName, clusterName)
// Etag would be changed when updating backend pools, so invalidate lbCache after it.
defer az.lbCache.Delete(lbName)
err := az.vmSet.EnsureHostsInPool(service, nodes, lbBackendPoolID, vmSetName, isInternal)
if err != nil {
return nil, err
Expand Down

0 comments on commit ae45744

Please sign in to comment.