Skip to content

Commit

Permalink
Feat/create fleets error handling (#30)
Browse files Browse the repository at this point in the history
* chg: fix: add error handling for create fleets errors

* chg: docs: add note about account validation
  • Loading branch information
felipemarinho97 authored Oct 19, 2023
1 parent 5e7114a commit f0ec17e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CREATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ See the [Recommended AMIs](#recommended-amis) section for more information.

For all the available options, run `dev-spaces create --help`. Also, see the [Command Parameters](#command-parameters) section for more information.

> **Note**
If you are using your AWS account for the first time, it is possible that the first attempt fail on "CreateFleet" because the AWS is performing additional validation on your account. You should receive an email from AWS informing you about this. If that happens, just try again after a few minutes.

Once created, you can use the command `dev-spaces start` to start the space.

$ dev-spaces start -n MyAmazonLinux2023 -c 1 -m 1 --wait
Expand Down
2 changes: 2 additions & 0 deletions cli/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func CreateCommand(c *cli.Context) error {
if strings.Contains(err.Error(), "already exists") {
log.Warn(fmt.Sprintf("DevSpace \"%s\" already exists.", name))
return err
} else {
DestroyCommand(c)
}
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ func (h *Handler) Create(ctx context.Context, opts CreateOptions) (CreateOutput,
}
log.Info(fmt.Sprintf("Spot task created: %s - Waiting instance to be assigned..", *taskRunner.FleetId))
id, err := helpers.WaitForFleetInstance(ctx, client, *taskRunner.FleetId, types.InstanceStateNameRunning)
log.Info(fmt.Sprintf("Instance assigned: %s", id))
if err != nil {
return CreateOutput{}, err
}
log.Info(fmt.Sprintf("Instance assigned: %s", id))

// get the volume id associated with the instance
instanceData, err := helpers.GetInstanceData(ctx, client, id)
Expand Down
18 changes: 18 additions & 0 deletions core/helpers/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,23 @@ func WaitForFleetInstance(ctx context.Context, client clients.IEC2Client, reques
}

}

// get fleet history
out3, err := client.DescribeFleetHistory(ctx, &ec2.DescribeFleetHistoryInput{
FleetId: &requestID,
StartTime: aws.Time(time.Now().Add(-24 * time.Hour)),
})
if err != nil {
continue
}

if len(out3.HistoryRecords) > 0 {
// iterate over history records, if there is a record with a status of error, return error and print error message
for _, record := range out3.HistoryRecords {
if record.EventType == "error" && record.EventInformation.EventDescription != nil {
return "", fmt.Errorf("error creating instance: %s", *record.EventInformation.EventDescription)
}
}
}
}
}

0 comments on commit f0ec17e

Please sign in to comment.