Merge pull request #2038 from mboersma/fix-azure-case-sensitive-instance-type-1.3

[cherry pick] Look up Azure instance types case-insensitively 1.3
This commit is contained in:
Kubernetes Prow Robot 2019-05-16 23:32:05 -07:00 committed by GitHub
commit ced8a1e006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View File

@ -43,12 +43,16 @@ type VirtualMachineScaleSetsClientMock struct {
// Get gets the VirtualMachineScaleSet by vmScaleSetName.
func (client *VirtualMachineScaleSetsClientMock) Get(ctx context.Context, resourceGroupName string, vmScaleSetName string) (result compute.VirtualMachineScaleSet, err error) {
capacity := int64(2)
name := "Standard_D8_V3" // typo to test case-insensitive lookup
location := "switzerlandwest"
properties := compute.VirtualMachineScaleSetProperties{}
return compute.VirtualMachineScaleSet{
Name: &vmScaleSetName,
Sku: &compute.Sku{
Capacity: &capacity,
Name: &name,
},
Location: &location,
VirtualMachineScaleSetProperties: &properties,
}, nil
}

View File

@ -383,7 +383,13 @@ func (scaleSet *ScaleSet) buildNodeFromTemplate(template compute.VirtualMachineS
Capacity: apiv1.ResourceList{},
}
vmssType := InstanceTypes[*template.Sku.Name]
var vmssType *instanceType
for k := range InstanceTypes {
if strings.EqualFold(k, *template.Sku.Name) {
vmssType = InstanceTypes[k]
break
}
}
if vmssType == nil {
return nil, fmt.Errorf("instance type %q not supported", *template.Sku.Name)
}

View File

@ -187,3 +187,23 @@ func TestScaleSetNodes(t *testing.T) {
assert.Equal(t, len(instances), 1)
assert.Equal(t, instances[0], fakeProviderID)
}
func TestTemplateNodeInfo(t *testing.T) {
provider := newTestProvider(t)
registered := provider.azureManager.RegisterAsg(
newTestScaleSet(provider.azureManager, "test-asg"))
assert.True(t, registered)
assert.Equal(t, len(provider.NodeGroups()), 1)
asg := ScaleSet{
manager: newTestAzureManager(t),
minSize: 1,
maxSize: 5,
}
asg.Name = "test-scale-set"
nodeInfo, err := asg.TemplateNodeInfo()
assert.NoError(t, err)
assert.NotNil(t, nodeInfo)
assert.NotEmpty(t, nodeInfo.Pods())
}