Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider/Azure: Add VM cache. #2683

Merged
merged 1 commit into from
Dec 24, 2019
Merged

Conversation

nilo19
Copy link
Member

@nilo19 nilo19 commented Dec 23, 2019

What this PR does:

  1. Add standard VM cache to prevent the throttling issue;
  2. Revise the "standard agent pool name" related doc.

/area provider/azure
/kind feature

@k8s-ci-robot k8s-ci-robot added area/provider/azure Issues or PRs related to azure provider kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 23, 2019
var instances []compute.VirtualMachine
var err error

if virtualMachinesStatusCache.lastRefresh.Add(vmInstancesRefreshPeriod).After(time.Now()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there're three places of such codes, let's extract a new func for getting VMs from cache and refresh if the cache is outdated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished.

return virtualMachinesStatusCache.virtualMachines, nil
}

vms, err := as.GetVirtualMachines()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check err before the cache update. or else, the cache may be cleaned on errors

// GetVMIndexes gets indexes of all virtual machines belonging to the agent pool.
func (as *AgentPool) GetVMIndexes() ([]int, map[int]string, error) {
instances, err := as.GetVirtualMachines()
virtualMachinesStatusCache.mutex.Lock()
defer virtualMachinesStatusCache.mutex.Unlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtualMachinesStatusCache has already been locked within getAllVirtualMachinesWithCache, hence it shouldn't be locked again

@@ -117,9 +131,35 @@ func (as *AgentPool) MaxSize() int {
return as.maxSize
}

func (as *AgentPool) getAllVirtualMachinesWithCache() ([]compute.VirtualMachine, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAllVirtualMachinesWithCache -> getVirtualMachinesFromCache

@nilo19
Copy link
Member Author

nilo19 commented Dec 23, 2019

The function's been tested.

Copy link
Member

@feiskyer feiskyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 24, 2019
@feiskyer
Copy link
Member

@nilo19 please cherry pick the fix to old branches

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feiskyer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 24, 2019
@k8s-ci-robot k8s-ci-robot merged commit a1cd503 into kubernetes:master Dec 24, 2019
@nilo19 nilo19 deleted the qi-add-vm-cache branch December 24, 2019 02:18
k8s-ci-robot added a commit that referenced this pull request Dec 24, 2019
k8s-ci-robot added a commit that referenced this pull request Dec 24, 2019
k8s-ci-robot added a commit that referenced this pull request Dec 24, 2019
k8s-ci-robot added a commit that referenced this pull request Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/provider/azure Issues or PRs related to azure provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants