Unverified Commit 746464bc authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #57644 from feiskyer/vmss-master

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Reduce VirtualMachineScaleSetsClient#List calls for Azure cloud provider **What this PR does / why we need it**: For master nodes not managed by VMSS, current cloud provider would updateCaches each time when finding master nodes info. This could result in call limits of `VirtualMachineScaleSetsClient#List`. This PR adds a caches to those nodes which reduces the cache updating significantly. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Continue of #43287. **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
parents 5de71ab1 80d89e02
...@@ -132,7 +132,7 @@ type Config struct { ...@@ -132,7 +132,7 @@ type Config struct {
MaximumLoadBalancerRuleCount int `json:"maximumLoadBalancerRuleCount"` MaximumLoadBalancerRuleCount int `json:"maximumLoadBalancerRuleCount"`
} }
// VirtualMachinesClient defines needed functions for azure network.VirtualMachinesClient // VirtualMachinesClient defines needed functions for azure compute.VirtualMachinesClient
type VirtualMachinesClient interface { type VirtualMachinesClient interface {
CreateOrUpdate(resourceGroupName string, VMName string, parameters compute.VirtualMachine, cancel <-chan struct{}) (<-chan compute.VirtualMachine, <-chan error) CreateOrUpdate(resourceGroupName string, VMName string, parameters compute.VirtualMachine, cancel <-chan struct{}) (<-chan compute.VirtualMachine, <-chan error)
Get(resourceGroupName string, VMName string, expand compute.InstanceViewTypes) (result compute.VirtualMachine, err error) Get(resourceGroupName string, VMName string, expand compute.InstanceViewTypes) (result compute.VirtualMachine, err error)
......
...@@ -76,15 +76,17 @@ type scaleSet struct { ...@@ -76,15 +76,17 @@ type scaleSet struct {
cacheMutex sync.Mutex cacheMutex sync.Mutex
// 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.
func newScaleSet(az *Cloud) VMSet { func newScaleSet(az *Cloud) VMSet {
ss := &scaleSet{ ss := &scaleSet{
Cloud: az, Cloud: az,
availabilitySet: newAvailabilitySet(az), availabilitySet: newAvailabilitySet(az),
cache: make(map[string][]scaleSetVMInfo), availabilitySetNodesCache: sets.NewString(),
cache: make(map[string][]scaleSetVMInfo),
} }
go wait.Until(func() { go wait.Until(func() {
...@@ -179,6 +181,11 @@ func (ss *scaleSet) getCachedVirtualMachine(nodeName string) (scaleSetVMInfo, er ...@@ -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 ...@@ -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
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment