diff --git a/cluster-autoscaler/cloudprovider/azure/azure_autodiscovery.go b/cluster-autoscaler/cloudprovider/azure/azure_autodiscovery.go index 3e84d1ee49b0..a218dfe637e9 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_autodiscovery.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_autodiscovery.go @@ -40,6 +40,11 @@ type labelAutoDiscoveryConfig struct { MaxSize *int } +type autoDiscoveryConfigSizes struct { + Min int + Max int +} + // ParseLabelAutoDiscoverySpecs returns any provided NodeGroupAutoDiscoverySpecs // parsed into configuration appropriate for node group autodiscovery. func ParseLabelAutoDiscoverySpecs(o cloudprovider.NodeGroupDiscoveryOptions) ([]labelAutoDiscoveryConfig, error) { @@ -102,29 +107,30 @@ func parseLabelAutoDiscoverySpec(spec string) (labelAutoDiscoveryConfig, error) return cfg, nil } -// returns true if the VMSS's tags match the autodiscovery configs +// returns an autoDiscoveryConfigSizes struct if the VMSS's tags match the autodiscovery configs +// if the VMSS's tags do not match then return nil // if there are multiple min/max sizes defined, return the highest min value and the lowest max value -func matchDiscoveryConfig(labels map[string]*string, configs []labelAutoDiscoveryConfig) (bool, int, int) { +func matchDiscoveryConfig(labels map[string]*string, configs []labelAutoDiscoveryConfig) *autoDiscoveryConfigSizes { if len(configs) == 0 { - return false, 0, 0 + return nil } minSize := -1 maxSize := -1 for _, c := range configs { if len(c.Selector) == 0 { - return false, 0, 0 + return nil } for k, v := range c.Selector { value, ok := labels[k] if !ok { - return false, 0, 0 + return nil } if len(v) > 0 { if value == nil || *value != v { - return false, 0, 0 + return nil } } } @@ -136,5 +142,8 @@ func matchDiscoveryConfig(labels map[string]*string, configs []labelAutoDiscover } } - return true, minSize, maxSize + return &autoDiscoveryConfigSizes{ + Min: minSize, + Max: maxSize, + } } diff --git a/cluster-autoscaler/cloudprovider/azure/azure_manager.go b/cluster-autoscaler/cloudprovider/azure/azure_manager.go index 4b4c7770ba15..b31ec60b872c 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_manager.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_manager.go @@ -293,14 +293,13 @@ func (m *AzureManager) getFilteredScaleSets(filter []labelAutoDiscoveryConfig) ( var nodeGroups []cloudprovider.NodeGroup for _, scaleSet := range vmssList { - var found bool - var cfgMinSize, cfgMaxSize int + var cfgSizes *autoDiscoveryConfigSizes if len(filter) > 0 { if scaleSet.Tags == nil || len(scaleSet.Tags) == 0 { continue } - if found, cfgMinSize, cfgMaxSize = matchDiscoveryConfig(scaleSet.Tags, filter); !found { + if cfgSizes = matchDiscoveryConfig(scaleSet.Tags, filter); cfgSizes == nil { continue } } @@ -318,8 +317,8 @@ func (m *AzureManager) getFilteredScaleSets(filter []labelAutoDiscoveryConfig) ( klog.Warningf("ignoring vmss %q because of invalid minimum size specified for vmss: %s", *scaleSet.Name, err) continue } - } else if cfgMinSize >= 0 { - spec.MinSize = cfgMinSize + } else if cfgSizes.Min >= 0 { + spec.MinSize = cfgSizes.Min } else { klog.Warningf("ignoring vmss %q because of no minimum size specified for vmss", *scaleSet.Name) continue @@ -335,8 +334,8 @@ func (m *AzureManager) getFilteredScaleSets(filter []labelAutoDiscoveryConfig) ( klog.Warningf("ignoring vmss %q because of invalid maximum size specified for vmss: %s", *scaleSet.Name, err) continue } - } else if cfgMaxSize >= 0 { - spec.MaxSize = cfgMaxSize + } else if cfgSizes.Max >= 0 { + spec.MaxSize = cfgSizes.Max } else { klog.Warningf("ignoring vmss %q because of no maximum size specified for vmss", *scaleSet.Name) continue