Skip to content

Commit 75aede2

Browse files
authored
Merge pull request kubernetes#90484 from nilo19/cleanup/add-unit-tests-for-race-condition
Add unit tests for azure race conditions.
2 parents 64d55ae + e48f69d commit 75aede2

File tree

5 files changed

+665
-144
lines changed

5 files changed

+665
-144
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ go_library(
109109
go_test(
110110
name = "go_default_test",
111111
srcs = [
112+
"azure_backoff_test.go",
112113
"azure_config_test.go",
113114
"azure_controller_common_test.go",
114115
"azure_controller_standard_test.go",
@@ -132,7 +133,9 @@ go_test(
132133
"//staging/src/k8s.io/api/core/v1:go_default_library",
133134
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
134135
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
136+
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
135137
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
138+
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
136139
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
137140
"//staging/src/k8s.io/cloud-provider:go_default_library",
138141
"//staging/src/k8s.io/cloud-provider/service/helpers:go_default_library",
@@ -144,6 +147,7 @@ go_test(
144147
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/mockinterfaceclient:go_default_library",
145148
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/loadbalancerclient/mockloadbalancerclient:go_default_library",
146149
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/publicipclient/mockpublicipclient:go_default_library",
150+
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routeclient/mockrouteclient:go_default_library",
147151
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/routetableclient/mockroutetableclient:go_default_library",
148152
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/securitygroupclient/mocksecuritygroupclient:go_default_library",
149153
"//staging/src/k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient/mockstorageaccountclient:go_default_library",

staging/src/k8s.io/legacy-cloud-providers/azure/azure_backoff.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const (
4040
// not active means the instance is under deleting from Azure VMSS.
4141
vmssVMNotActiveErrorMessage = "not an active Virtual Machine Scale Set VM instanceId"
4242

43-
// operationCancledErrorMessage means the operation is canceled by another new operation.
44-
operationCancledErrorMessage = "canceledandsupersededduetoanotheroperation"
43+
// operationCanceledErrorMessage means the operation is canceled by another new operation.
44+
operationCanceledErrorMessage = "canceledandsupersededduetoanotheroperation"
4545
)
4646

4747
// RequestBackoff if backoff is disabled in cloud provider it
@@ -166,8 +166,8 @@ func (az *Cloud) CreateOrUpdateSecurityGroup(service *v1.Service, sg network.Sec
166166
}
167167

168168
// Invalidate the cache because another new operation has canceled the current request.
169-
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCancledErrorMessage) {
170-
klog.V(3).Infof("SecurityGroup cache for %s is cleanup because CreateOrUpdateSecurityGroup is canceld by another operation", *sg.Name)
169+
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCanceledErrorMessage) {
170+
klog.V(3).Infof("SecurityGroup cache for %s is cleanup because CreateOrUpdateSecurityGroup is canceled by another operation", *sg.Name)
171171
az.nsgCache.Delete(*sg.Name)
172172
}
173173

@@ -194,7 +194,7 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer)
194194
az.lbCache.Delete(*lb.Name)
195195
}
196196
// Invalidate the cache because another new operation has canceled the current request.
197-
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCancledErrorMessage) {
197+
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCanceledErrorMessage) {
198198
klog.V(3).Infof("LoadBalancer cache for %s is cleanup because CreateOrUpdate is canceled by another operation", *lb.Name)
199199
az.lbCache.Delete(*lb.Name)
200200
}
@@ -317,7 +317,7 @@ func (az *Cloud) CreateOrUpdateRouteTable(routeTable network.RouteTable) error {
317317
az.rtCache.Delete(*routeTable.Name)
318318
}
319319
// Invalidate the cache because another new operation has canceled the current request.
320-
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCancledErrorMessage) {
320+
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCanceledErrorMessage) {
321321
klog.V(3).Infof("Route table cache for %s is cleanup because CreateOrUpdateRouteTable is canceld by another operation", *routeTable.Name)
322322
az.rtCache.Delete(*routeTable.Name)
323323
}
@@ -342,7 +342,7 @@ func (az *Cloud) CreateOrUpdateRoute(route network.Route) error {
342342
az.rtCache.Delete(az.RouteTableName)
343343
}
344344
// Invalidate the cache because another new operation has canceled the current request.
345-
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCancledErrorMessage) {
345+
if strings.Contains(strings.ToLower(rerr.Error().Error()), operationCanceledErrorMessage) {
346346
klog.V(3).Infof("Route cache for %s is cleanup because CreateOrUpdateRouteTable is canceld by another operation", *route.Name)
347347
az.rtCache.Delete(az.RouteTableName)
348348
}

0 commit comments

Comments
 (0)