Merge pull request #87685 from feiskyer/vmas-disable

Add disableAvailabilitySetNodes to avoid VM list for VMSS clusters
This commit is contained in:
Kubernetes Prow Robot 2020-01-31 20:07:34 -08:00 committed by GitHub
commit 21e6ec0ba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 3 deletions

View File

@ -213,6 +213,9 @@ type Config struct {
NsgCacheTTLInSeconds int `json:"nsgCacheTTLInSeconds,omitempty" yaml:"nsgCacheTTLInSeconds,omitempty"`
// RouteTableCacheTTLInSeconds sets the cache TTL for route table
RouteTableCacheTTLInSeconds int `json:"routeTableCacheTTLInSeconds,omitempty" yaml:"routeTableCacheTTLInSeconds,omitempty"`
// DisableAvailabilitySetNodes disables VMAS nodes support when "VMType" is set to "vmss".
DisableAvailabilitySetNodes bool `json:"disableAvailabilitySetNodes,omitempty" yaml:"disableAvailabilitySetNodes,omitempty"`
}
var _ cloudprovider.Interface = (*Cloud)(nil)
@ -353,6 +356,10 @@ func (az *Cloud) InitializeCloudFromConfig(config *Config, fromSecret bool) erro
config.VMType = vmTypeStandard
}
if config.DisableAvailabilitySetNodes && config.VMType != vmTypeVMSS {
return fmt.Errorf("disableAvailabilitySetNodes %v is only supported when vmType is 'vmss'", config.DisableAvailabilitySetNodes)
}
if config.CloudConfigType == "" {
// The default cloud config type is cloudConfigTypeMerge.
config.CloudConfigType = cloudConfigTypeMerge

View File

@ -1511,6 +1511,8 @@ func TestNewCloudFromJSON(t *testing.T) {
"loadBalancerCacheTTLInSeconds": 100,
"nsgCacheTTLInSeconds": 100,
"routeTableCacheTTLInSeconds": 100,
"vmType": "vmss",
"disableAvailabilitySetNodes": true
}`
validateConfig(t, config)
}
@ -1568,6 +1570,8 @@ vmCacheTTLInSeconds: 100
loadBalancerCacheTTLInSeconds: 100
nsgCacheTTLInSeconds: 100
routeTableCacheTTLInSeconds: 100
vmType: vmss
disableAvailabilitySetNodes: true
`
validateConfig(t, config)
}
@ -1665,6 +1669,12 @@ func validateConfig(t *testing.T, config string) {
if azureCloud.RouteTableCacheTTLInSeconds != 100 {
t.Errorf("got incorrect value for routeTableCacheTTLInSeconds")
}
if azureCloud.VMType != vmTypeVMSS {
t.Errorf("got incorrect value for vmType")
}
if !azureCloud.DisableAvailabilitySetNodes {
t.Errorf("got incorrect value for disableAvailabilitySetNodes")
}
}
func getCloudFromConfig(t *testing.T, config string) *Cloud {

View File

@ -75,9 +75,11 @@ func newScaleSet(az *Cloud) (VMSet, error) {
availabilitySet: newAvailabilitySet(az),
}
ss.availabilitySetNodesCache, err = ss.newAvailabilitySetNodesCache()
if err != nil {
return nil, err
if !ss.DisableAvailabilitySetNodes {
ss.availabilitySetNodesCache, err = ss.newAvailabilitySetNodesCache()
if err != nil {
return nil, err
}
}
ss.vmssCache, err = ss.newVMSSCache()

View File

@ -256,6 +256,12 @@ func (ss *scaleSet) newAvailabilitySetNodesCache() (*timedCache, error) {
}
func (ss *scaleSet) isNodeManagedByAvailabilitySet(nodeName string, crt cacheReadType) (bool, error) {
// Assume all nodes are managed by VMSS when DisableAvailabilitySetNodes is enabled.
if ss.DisableAvailabilitySetNodes {
klog.V(2).Infof("Assuming node %q is managed by VMSS since DisableAvailabilitySetNodes is set to true", nodeName)
return false, nil
}
cached, err := ss.availabilitySetNodesCache.Get(availabilitySetNodesKey, crt)
if err != nil {
return false, err