Skip to content

Commit 35901cd

Browse files
authored
Merge pull request kubernetes#3278 from marwanad/set-context-timeouts-on-gets
use contexts with timeouts in scale set GET calls
2 parents 77ba4bc + 3891852 commit 35901cd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

cluster-autoscaler/cloudprovider/azure/azure_scale_set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (scaleSet *ScaleSet) getVMSSInfo() (compute.VirtualMachineScaleSet, *retry.
174174
}
175175

176176
func (scaleSet *ScaleSet) getAllVMSSInfo() ([]compute.VirtualMachineScaleSet, *retry.Error) {
177-
ctx, cancel := getContextWithCancel()
177+
ctx, cancel := getContextWithTimeout(3 * time.Minute)
178178
defer cancel()
179179

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

345345
resourceGroup := scaleSet.manager.config.ResourceGroup

cluster-autoscaler/cloudprovider/azure/azure_util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sort"
3030
"strconv"
3131
"strings"
32+
"time"
3233

3334
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
3435
azStorage "github.com/Azure/azure-sdk-for-go/storage"
@@ -597,6 +598,10 @@ func getContextWithCancel() (context.Context, context.CancelFunc) {
597598
return context.WithCancel(context.Background())
598599
}
599600

601+
func getContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc) {
602+
return context.WithTimeout(context.Background(), timeout)
603+
}
604+
600605
// checkExistsFromError inspects an error and returns a true if err is nil,
601606
// false if error is an autorest.Error with StatusCode=404 and will return the
602607
// error back if error is another status code or another type of error.

0 commit comments

Comments
 (0)