Skip to content

Commit 1e9f330

Browse files
committed
fix(azure): set default value of VmssVirtualMachinesCacheTTLInSeconds during init to prevent data race
Signed-off-by: knight42 <[email protected]>
1 parent 7740b81 commit 1e9f330

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ type scaleSet struct {
8383

8484
// newScaleSet creates a new scaleSet.
8585
func newScaleSet(az *Cloud) (VMSet, error) {
86-
var err error
86+
if az.Config.VmssVirtualMachinesCacheTTLInSeconds == 0 {
87+
az.Config.VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds
88+
}
8789
ss := &scaleSet{
8890
Cloud: az,
8991
availabilitySet: newAvailabilitySet(az),
9092
vmssVMCache: &sync.Map{},
9193
}
9294

95+
var err error
9396
if !ss.DisableAvailabilitySetNodes {
9497
ss.availabilitySetNodesCache, err = ss.newAvailabilitySetNodesCache()
9598
if err != nil {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ func (ss *scaleSet) gcVMSSVMCache() error {
154154

155155
// newVMSSVirtualMachinesCache instanciates a new VMs cache for VMs belonging to the provided VMSS.
156156
func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cacheKey string) (*azcache.TimedCache, error) {
157-
if ss.Config.VmssVirtualMachinesCacheTTLInSeconds == 0 {
158-
ss.Config.VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds
159-
}
160157
vmssVirtualMachinesCacheTTL := time.Duration(ss.Config.VmssVirtualMachinesCacheTTLInSeconds) * time.Second
161158

162159
getter := func(key string) (interface{}, error) {

0 commit comments

Comments
 (0)