Reduce VirtualMachineScaleSetsClient#List calls

This commit is contained in:
Pengfei Ni
2017-12-27 13:50:49 +08:00
parent c690ab8cd0
commit 80d89e0221

View File

@@ -77,6 +77,7 @@ type scaleSet struct {
// A local cache of scale sets. The key is scale set name and the value is a // A local cache of scale sets. The key is scale set name and the value is a
// list of virtual machines belonging to the scale set. // list of virtual machines belonging to the scale set.
cache map[string][]scaleSetVMInfo cache map[string][]scaleSetVMInfo
availabilitySetNodesCache sets.String
} }
// newScaleSet creates a new scaleSet. // newScaleSet creates a new scaleSet.
@@ -84,6 +85,7 @@ func newScaleSet(az *Cloud) VMSet {
ss := &scaleSet{ ss := &scaleSet{
Cloud: az, Cloud: az,
availabilitySet: newAvailabilitySet(az), availabilitySet: newAvailabilitySet(az),
availabilitySetNodesCache: sets.NewString(),
cache: make(map[string][]scaleSetVMInfo), cache: make(map[string][]scaleSetVMInfo),
} }
@@ -179,6 +181,11 @@ func (ss *scaleSet) getCachedVirtualMachine(nodeName string) (scaleSetVMInfo, er
return vm, nil return vm, nil
} }
// Known node not managed by scale sets.
if ss.availabilitySetNodesCache.Has(nodeName) {
return scaleSetVMInfo{}, cloudprovider.InstanceNotFound
}
// Update cache and try again. // Update cache and try again.
if err = ss.updateCache(); err != nil { if err = ss.updateCache(); err != nil {
return scaleSetVMInfo{}, err return scaleSetVMInfo{}, err
@@ -188,6 +195,8 @@ func (ss *scaleSet) getCachedVirtualMachine(nodeName string) (scaleSetVMInfo, er
return vm, nil return vm, nil
} }
// Node still not found, assuming it is not managed by scale sets.
ss.availabilitySetNodesCache.Insert(nodeName)
return scaleSetVMInfo{}, cloudprovider.InstanceNotFound return scaleSetVMInfo{}, cloudprovider.InstanceNotFound
} }