use contexts with timeouts in scale set GET calls

This commit is contained in:
Marwan Ahmed 2020-07-03 20:17:56 -07:00
parent ca6bbc96a2
commit 3891852eec
2 changed files with 7 additions and 2 deletions

View File

@ -174,7 +174,7 @@ func (scaleSet *ScaleSet) getVMSSInfo() (compute.VirtualMachineScaleSet, *retry.
} }
func (scaleSet *ScaleSet) getAllVMSSInfo() ([]compute.VirtualMachineScaleSet, *retry.Error) { func (scaleSet *ScaleSet) getAllVMSSInfo() ([]compute.VirtualMachineScaleSet, *retry.Error) {
ctx, cancel := getContextWithCancel() ctx, cancel := getContextWithTimeout(3 * time.Minute)
defer cancel() defer cancel()
resourceGroup := scaleSet.manager.config.ResourceGroup resourceGroup := scaleSet.manager.config.ResourceGroup
@ -339,7 +339,7 @@ func (scaleSet *ScaleSet) IncreaseSize(delta int) error {
// GetScaleSetVms returns list of nodes for the given scale set. // GetScaleSetVms returns list of nodes for the given scale set.
func (scaleSet *ScaleSet) GetScaleSetVms() ([]compute.VirtualMachineScaleSetVM, *retry.Error) { func (scaleSet *ScaleSet) GetScaleSetVms() ([]compute.VirtualMachineScaleSetVM, *retry.Error) {
klog.V(4).Infof("GetScaleSetVms: starts") klog.V(4).Infof("GetScaleSetVms: starts")
ctx, cancel := getContextWithCancel() ctx, cancel := getContextWithTimeout(3 * time.Minute)
defer cancel() defer cancel()
resourceGroup := scaleSet.manager.config.ResourceGroup resourceGroup := scaleSet.manager.config.ResourceGroup

View File

@ -29,6 +29,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
azStorage "github.com/Azure/azure-sdk-for-go/storage" azStorage "github.com/Azure/azure-sdk-for-go/storage"
@ -597,6 +598,10 @@ func getContextWithCancel() (context.Context, context.CancelFunc) {
return context.WithCancel(context.Background()) return context.WithCancel(context.Background())
} }
func getContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), timeout)
}
// checkExistsFromError inspects an error and returns a true if err is nil, // checkExistsFromError inspects an error and returns a true if err is nil,
// false if error is an autorest.Error with StatusCode=404 and will return the // false if error is an autorest.Error with StatusCode=404 and will return the
// error back if error is another status code or another type of error. // error back if error is another status code or another type of error.