diff --git a/cluster-autoscaler/cloudprovider/azure/README.md b/cluster-autoscaler/cloudprovider/azure/README.md index 557814d74b3c..7b018c4f4643 100644 --- a/cluster-autoscaler/cloudprovider/azure/README.md +++ b/cluster-autoscaler/cloudprovider/azure/README.md @@ -197,7 +197,8 @@ The `AZURE_ENABLE_VMSS_FLEX` environment variable enables VMSS Flex support. By |---------------------------|---------|-----------------------------------------|---------------------------| | enableVmssFlex | false | AZURE_ENABLE_VMSS_FLEX | enableVmssFlex | -The `AZURE_GET_VMSS_SIZE_REFRESH_PERIOD` environment variable defines in seconds how frequently to call GET VMSS API to fetch VMSS info per nodegroup instance. By default, value is 30 seconds. +The AZURE_GET_VMSS_SIZE_REFRESH_PERIOD environment variable defines, in seconds, the frequency to call the GET VMSS API to fetch VMSS info per spot nodegroup instance. +By default, the value is 30 seconds. Currently, this API is only utilized for spot instances. | Config Name | Default | Environment Variable | Cloud Config File | |---------------------------|---------|-------------------------------------|---------------------------| diff --git a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go index 87886e57d367..6b6a39168366 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go @@ -39,7 +39,6 @@ var ( defaultVmssInstancesRefreshPeriod = 5 * time.Minute vmssContextTimeout = 3 * time.Minute vmssSizeMutex sync.Mutex - defaultGetVmssSizeRefreshPeriod = VmssSizeRefreshPeriodDefault * time.Second ) const ( @@ -60,19 +59,29 @@ type ScaleSet struct { maxSize int enableForceDelete bool - - sizeMutex sync.Mutex - curSize int64 - enableDynamicInstanceList bool + + // curSize tracks (and caches) the number of VMs in this ScaleSet. + // It is periodically updated from vmss.Sku.Capacity, with VMSS itself coming + // either from azure.Cache (which periodically does VMSS.List) + // or from direct VMSS.Get (used for Spot). + curSize int64 + // lastSizeRefresh is the time curSize was last refreshed from vmss.Sku.Capacity. + // Together with sizeRefreshPeriod, it is used to determine if it is time to refresh curSize. lastSizeRefresh time.Time + // sizeRefreshPeriod is how often curSize is refreshed from vmss.Sku.Capacity. + // (Set from azureCache.refreshInterval = VmssCacheTTL or [defaultMetadataCache]refreshInterval = 1min) sizeRefreshPeriod time.Duration + // getVmssSizeRefreshPeriod is how often curSize should be refreshed in case VMSS.Get call is used (only spot instances). + // (Set from GetVmssSizeRefreshPeriod, if specified = get-vmss-size-refresh-period = 30s, + // or override from autoscalerProfile.GetVmssSizeRefreshPeriod) getVmssSizeRefreshPeriod time.Duration instancesRefreshPeriod time.Duration instancesRefreshJitter int + sizeMutex sync.Mutex instanceMutex sync.Mutex instanceCache []cloudprovider.Instance lastInstanceRefresh time.Time