Skip to content

Commit

Permalink
populate instance status state when machine lastOperation is Create (#…
Browse files Browse the repository at this point in the history
…315)

Co-authored-by: Rishabh Patel <[email protected]>
  • Loading branch information
aaronfern and rishabh-11 authored Jul 4, 2024
1 parent 14670b6 commit 8b9a0ed
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions cluster-autoscaler/cloudprovider/mcm/mcm_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,25 +646,28 @@ func findMatchingInstance(nodes []*v1.Node, machine *v1alpha1.Machine) cloudprov
// Report InstanceStatus only for `ResourceExhausted` errors
return cloudprovider.Instance{
Id: placeholderInstanceIDForMachineObj(machine.Name),
Status: checkAndGetResourceExhaustedInstanceStatus(machine),
Status: generateInstanceStatus(machine),
}
}

func placeholderInstanceIDForMachineObj(name string) string {
return fmt.Sprintf("requested://%s", name)
}

// checkAndGetResourceExhaustedInstanceStatus returns cloudprovider.InstanceStatus for the machine obj
func checkAndGetResourceExhaustedInstanceStatus(machine *v1alpha1.Machine) *cloudprovider.InstanceStatus {
if machine.Status.LastOperation.Type == v1alpha1.MachineOperationCreate && machine.Status.LastOperation.State == v1alpha1.MachineStateFailed && machine.Status.LastOperation.ErrorCode == machinecodes.ResourceExhausted.String() {
return &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
ErrorInfo: &cloudprovider.InstanceErrorInfo{
ErrorClass: cloudprovider.OutOfResourcesErrorClass,
ErrorCode: machinecodes.ResourceExhausted.String(),
ErrorMessage: machine.Status.LastOperation.Description,
},
// generateInstanceStatus returns cloudprovider.InstanceStatus for the machine obj
func generateInstanceStatus(machine *v1alpha1.Machine) *cloudprovider.InstanceStatus {
if machine.Status.LastOperation.Type == v1alpha1.MachineOperationCreate {
if machine.Status.LastOperation.State == v1alpha1.MachineStateFailed && machine.Status.LastOperation.ErrorCode == machinecodes.ResourceExhausted.String() {
return &cloudprovider.InstanceStatus{
State: cloudprovider.InstanceCreating,
ErrorInfo: &cloudprovider.InstanceErrorInfo{
ErrorClass: cloudprovider.OutOfResourcesErrorClass,
ErrorCode: machinecodes.ResourceExhausted.String(),
ErrorMessage: machine.Status.LastOperation.Description,
},
}
}
return &cloudprovider.InstanceStatus{State: cloudprovider.InstanceCreating}
}
return nil
}
Expand Down

0 comments on commit 8b9a0ed

Please sign in to comment.