Skip to content

Commit

Permalink
Avoids panics when VM type isn't found during scale from zero (#78)
Browse files Browse the repository at this point in the history
- Cluster autoscaler was trying to fetch VM details for AWS VMs instead of required Azure VMs for MCM (OOT) provider Azure. This lead to panics. Now, it fetches the details from the correct provider VM map.
- This PR also improves error handling in such scenarios to not panic.
  • Loading branch information
prashanth26 authored May 11, 2021
1 parent 205b3d6 commit a8d5b27
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cluster-autoscaler/cloudprovider/mcm/mcm_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ func (m *McmManager) GetMachineDeploymentNodeTemplate(machinedeployment *Machine
if err != nil {
return nil, fmt.Errorf("Unable to fetch AWSMachineClass object %s, Error: %v", machineClass.Name, err)
}
awsInstance := aws.InstanceTypes[mc.Spec.MachineType]
awsInstance, exists := aws.InstanceTypes[mc.Spec.MachineType]
if !exists {
return nil, fmt.Errorf("Unable to fetch details for VM type %s", mc.Spec.MachineType)
}
instance = instanceType{
InstanceType: awsInstance.InstanceType,
VCPU: awsInstance.VCPU,
Expand All @@ -642,7 +645,10 @@ func (m *McmManager) GetMachineDeploymentNodeTemplate(machinedeployment *Machine
if err != nil {
return nil, fmt.Errorf("Unable to fetch AzureMachineClass object %s, Error: %v", machineClass.Name, err)
}
azureInstance := azure.InstanceTypes[mc.Spec.Properties.HardwareProfile.VMSize]
azureInstance, exists := azure.InstanceTypes[mc.Spec.Properties.HardwareProfile.VMSize]
if !exists {
return nil, fmt.Errorf("Unable to fetch details for VM type %s", mc.Spec.Properties.HardwareProfile.VMSize)
}
instance = instanceType{
InstanceType: azureInstance.InstanceType,
VCPU: azureInstance.VCPU,
Expand All @@ -666,7 +672,10 @@ func (m *McmManager) GetMachineDeploymentNodeTemplate(machinedeployment *Machine
return nil, fmt.Errorf("Unable to convert from %s to %s for %s, Error: %v", kindMachineClass, providerAWS, machinedeployment.Name, err)
}

awsInstance := aws.InstanceTypes[providerSpec.MachineType]
awsInstance, exists := aws.InstanceTypes[providerSpec.MachineType]
if !exists {
return nil, fmt.Errorf("Unable to fetch details for VM type %s", providerSpec.MachineType)
}
instance = instanceType{
InstanceType: awsInstance.InstanceType,
VCPU: awsInstance.VCPU,
Expand All @@ -681,8 +690,10 @@ func (m *McmManager) GetMachineDeploymentNodeTemplate(machinedeployment *Machine
if err != nil {
return nil, fmt.Errorf("Unable to convert from %s to %s for %s, Error: %v", kindMachineClass, providerAzure, machinedeployment.Name, err)
}

azureInstance := aws.InstanceTypes[providerSpec.Properties.HardwareProfile.VMSize]
azureInstance, exists := azure.InstanceTypes[providerSpec.Properties.HardwareProfile.VMSize]
if !exists {
return nil, fmt.Errorf("Unable to fetch details for VM type %s", providerSpec.Properties.HardwareProfile.VMSize)
}
instance = instanceType{
InstanceType: azureInstance.InstanceType,
VCPU: azureInstance.VCPU,
Expand Down

0 comments on commit a8d5b27

Please sign in to comment.