fix nil vmss name

This commit is contained in:
qini 2020-12-17 20:07:51 +08:00
parent 8b8de03168
commit 55fd3685d9
2 changed files with 7 additions and 6 deletions

View File

@ -740,7 +740,7 @@ func (ss *scaleSet) getAgentPoolScaleSets(nodes []*v1.Node) (*[]string, error) {
// (depending vmType configured) for service load balancer. If the service has
// no loadbalancer mode annotation returns the primary VMSet. If service annotation
// for loadbalancer exists then return the eligible VMSet.
func (ss *scaleSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (vmSetNames *[]string, err error) {
func (ss *scaleSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (*[]string, error) {
hasMode, isAuto, serviceVMSetNames := getServiceLoadBalancerMode(service)
useSingleSLB := ss.useStandardLoadBalancer() && !ss.EnableMultipleStandardLoadBalancers
if !hasMode || useSingleSLB {
@ -764,7 +764,7 @@ func (ss *scaleSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (vmSetN
sort.Strings(*scaleSetNames)
if !isAuto {
if serviceVMSetNames == nil || len(serviceVMSetNames) == 0 {
if len(serviceVMSetNames) == 0 {
return nil, fmt.Errorf("service annotation for LoadBalancerMode is empty, it should have __auto__ or availability sets value")
}
// validate scale set exists
@ -782,10 +782,10 @@ func (ss *scaleSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (vmSetN
return nil, fmt.Errorf("scale set (%s) - not found", serviceVMSetNames[sasx])
}
}
vmSetNames = &serviceVMSetNames
scaleSetNames = &serviceVMSetNames
}
return vmSetNames, nil
return scaleSetNames, nil
}
// extractResourceGroupByVMSSNicID extracts the resource group name by vmss nicID.

View File

@ -1436,7 +1436,7 @@ func TestGetVMSetNames(t *testing.T) {
expectedVMSetNames: &[]string{"vmss"},
},
{
description: "GetVMSetNames should return nil if the service has auto mode annotation",
description: "GetVMSetNames should return all scale sets if the service has auto mode annotation",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{ServiceAnnotationLoadBalancerMode: ServiceAnnotationLoadBalancerAutoModeValue}},
},
@ -1447,6 +1447,7 @@ func TestGetVMSetNames(t *testing.T) {
},
},
},
expectedVMSetNames: &[]string{"vmss"},
},
{
description: "GetVMSetNames should report the error if there's no such vmss",
@ -1516,7 +1517,7 @@ func TestGetVMSetNames(t *testing.T) {
vmSetNames, err := ss.GetVMSetNames(test.service, test.nodes)
assert.Equal(t, test.expectedErr, err, test.description+", but an error occurs")
assert.Equal(t, test.expectedVMSetNames, vmSetNames)
assert.Equal(t, test.expectedVMSetNames, vmSetNames, test.description)
}
}