Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU Support #240

Merged
merged 9 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func Test_HealthCmd(t *testing.T) {
},
},
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Message: "ok",
Status: rest.HealthStatusHealthy,
Message: "ok",
Services: nil,
},
},
{
Expand All @@ -50,8 +51,9 @@ func Test_HealthCmd(t *testing.T) {
},
},
want: &rest.HealthResponse{
Status: rest.HealthStatusUnhealthy,
Message: "error",
Status: rest.HealthStatusUnhealthy,
Message: "error",
Services: nil,
},
},
}
Expand Down
70 changes: 11 additions & 59 deletions cmd/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"time"

"github.com/dustin/go-humanize"
"github.com/go-openapi/strfmt"
"github.com/google/uuid"
"github.com/metal-stack/metal-go/api/client/size"
Expand Down Expand Up @@ -45,8 +44,8 @@ func newSizeCmd(c *config) *cobra.Command {
Description: viper.GetString("description"),
Constraints: []*models.V1SizeConstraint{
{
Max: pointer.Pointer(viper.GetInt64("max")),
Min: pointer.Pointer(viper.GetInt64("min")),
Max: viper.GetInt64("max"),
Min: viper.GetInt64("min"),
Type: pointer.Pointer(viper.GetString("type")),
},
},
Expand All @@ -63,18 +62,6 @@ func newSizeCmd(c *config) *cobra.Command {
},
}

tryCmd := &cobra.Command{
Use: "try",
Short: "try a specific hardware spec and give the chosen size back",
RunE: func(cmd *cobra.Command, args []string) error {
return w.try()
},
}

tryCmd.Flags().Int32P("cores", "C", 0, "Cores of the hardware to try")
tryCmd.Flags().StringP("memory", "M", "", "Memory of the hardware to try, can be given in bytes or any human readable size spec")
tryCmd.Flags().StringP("storagesize", "S", "", "Total storagesize of the hardware to try, can be given in bytes or any human readable size spec")

reservationsCmd := &cobra.Command{
Use: "reservations",
Short: "manage size reservations",
Expand Down Expand Up @@ -111,7 +98,7 @@ func newSizeCmd(c *config) *cobra.Command {

must(suggestCmd.RegisterFlagCompletionFunc("machine-id", c.comp.MachineListCompletion))

return genericcli.NewCmds(cmdsConfig, newSizeImageConstraintCmd(c), tryCmd, reservationsCmd, suggestCmd)
return genericcli.NewCmds(cmdsConfig, newSizeImageConstraintCmd(c), reservationsCmd, suggestCmd)
}

func (c sizeCmd) Get(id string) (*models.V1SizeResponse, error) {
Expand Down Expand Up @@ -174,9 +161,10 @@ func sizeResponseToCreate(r *models.V1SizeResponse) *models.V1SizeCreateRequest
var constraints []*models.V1SizeConstraint
for i := range r.Constraints {
constraints = append(constraints, &models.V1SizeConstraint{
Max: r.Constraints[i].Max,
Min: r.Constraints[i].Min,
Type: r.Constraints[i].Type,
Max: r.Constraints[i].Max,
Min: r.Constraints[i].Min,
Type: r.Constraints[i].Type,
Identifier: r.Constraints[i].Identifier,
})
}
return &models.V1SizeCreateRequest{
Expand All @@ -191,9 +179,10 @@ func sizeResponseToUpdate(r *models.V1SizeResponse) *models.V1SizeUpdateRequest
var constraints []*models.V1SizeConstraint
for i := range r.Constraints {
constraints = append(constraints, &models.V1SizeConstraint{
Max: r.Constraints[i].Max,
Min: r.Constraints[i].Min,
Type: r.Constraints[i].Type,
Max: r.Constraints[i].Max,
Min: r.Constraints[i].Min,
Type: r.Constraints[i].Type,
Identifier: r.Constraints[i].Identifier,
})
}
return &models.V1SizeUpdateRequest{
Expand All @@ -208,43 +197,6 @@ func sizeResponseToUpdate(r *models.V1SizeResponse) *models.V1SizeUpdateRequest

// non-generic command handling

func (c *sizeCmd) try() error {
var (
memory int64
disks []*models.V1MachineBlockDevice
)

if viper.IsSet("memory") {
m, err := humanize.ParseBytes(viper.GetString("memory"))
if err != nil {
return err
}
memory = int64(m)
}

if viper.IsSet("storagesize") {
s, err := humanize.ParseBytes(viper.GetString("storagesize"))
if err != nil {
return err
}
disks = append(disks, &models.V1MachineBlockDevice{
Name: pointer.Pointer("/dev/trydisk"),
Size: pointer.Pointer(int64(s)),
})
}

resp, err := c.client.Size().FromHardware(size.NewFromHardwareParams().WithBody(&models.V1MachineHardware{
CPUCores: pointer.Pointer(viper.GetInt32("cores")),
Memory: &memory,
Disks: disks,
}), nil)
if err != nil {
return err
}

return c.listPrinter.Print(resp.Payload)
}

func (c sizeCmd) listReverations() error {
resp, err := c.client.Size().ListSizeReservations(size.NewListSizeReservationsParams().WithBody(emptyBody), nil)
if err != nil {
Expand Down
116 changes: 61 additions & 55 deletions cmd/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ var (
size1 = &models.V1SizeResponse{
Constraints: []*models.V1SizeConstraint{
{
Max: pointer.Pointer(int64(2)),
Min: pointer.Pointer(int64(1)),
Type: pointer.Pointer("storage"),
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer(models.V1SizeConstraintTypeStorage),
},
{
Max: pointer.Pointer(int64(4)),
Min: pointer.Pointer(int64(3)),
Type: pointer.Pointer("memory"),
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer(models.V1SizeConstraintTypeMemory),
},
{
Max: pointer.Pointer(int64(6)),
Min: pointer.Pointer(int64(5)),
Type: pointer.Pointer("cores"),
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer(models.V1SizeConstraintTypeCores),
},
{
Max: int64(1),
Min: int64(1),
Type: pointer.Pointer(models.V1SizeConstraintTypeGpu),
Identifier: "AD120GL*",
},
},
Reservations: []*models.V1SizeReservation{
Expand Down Expand Up @@ -60,19 +66,19 @@ var (
size2 = &models.V1SizeResponse{
Constraints: []*models.V1SizeConstraint{
{
Max: pointer.Pointer(int64(2)),
Min: pointer.Pointer(int64(1)),
Type: pointer.Pointer("storage"),
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer(models.V1SizeConstraintTypeStorage),
},
{
Max: pointer.Pointer(int64(4)),
Min: pointer.Pointer(int64(3)),
Type: pointer.Pointer("memory"),
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer(models.V1SizeConstraintTypeMemory),
},
{
Max: pointer.Pointer(int64(6)),
Min: pointer.Pointer(int64(5)),
Type: pointer.Pointer("cores"),
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer(models.V1SizeConstraintTypeCores),
},
},
Description: "size 2",
Expand Down Expand Up @@ -103,14 +109,14 @@ func Test_SizeCmd_MultiResult(t *testing.T) {
size2,
},
wantTable: pointer.Pointer(`
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE GPU RANGE
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B AD120GL*: 1 - 1
2 size-2 size 2 0 5 - 6 3 B - 4 B 1 B - 2 B
`),
wantWideTable: pointer.Pointer(`
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE LABELS
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B size.metal-stack.io/cpu-description=1x Intel(R) Xeon(R) D-2141I CPU @ 2.20GHz
size.metal-stack.io/drive-description=960GB NVMe
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE GPU RANGE LABELS
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B AD120GL*: 1 - 1 size.metal-stack.io/cpu-description=1x Intel(R) Xeon(R) D-2141I CPU @ 2.20GHz
size.metal-stack.io/drive-description=960GB NVMe
2 size-2 size 2 0 5 - 6 3 B - 4 B 1 B - 2 B
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
Expand All @@ -119,10 +125,10 @@ ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RA
2 size-2
`),
wantMarkdown: pointer.Pointer(`
| ID | NAME | DESCRIPTION | RESERVATIONS | CPU RANGE | MEMORY RANGE | STORAGE RANGE |
|----|--------|-------------|--------------|-----------|--------------|---------------|
| 1 | size-1 | size 1 | 7 | 5 - 6 | 3 B - 4 B | 1 B - 2 B |
| 2 | size-2 | size 2 | 0 | 5 - 6 | 3 B - 4 B | 1 B - 2 B |
| ID | NAME | DESCRIPTION | RESERVATIONS | CPU RANGE | MEMORY RANGE | STORAGE RANGE | GPU RANGE |
|----|--------|-------------|--------------|-----------|--------------|---------------|-----------------|
| 1 | size-1 | size 1 | 7 | 5 - 6 | 3 B - 4 B | 1 B - 2 B | AD120GL*: 1 - 1 |
| 2 | size-2 | size 2 | 0 | 5 - 6 | 3 B - 4 B | 1 B - 2 B | |
`),
},
{
Expand Down Expand Up @@ -228,22 +234,22 @@ func Test_SizeCmd_SingleResult(t *testing.T) {
},
want: size1,
wantTable: pointer.Pointer(`
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE GPU RANGE
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B AD120GL*: 1 - 1
`),
wantWideTable: pointer.Pointer(`
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE LABELS
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B size.metal-stack.io/cpu-description=1x Intel(R) Xeon(R) D-2141I CPU @ 2.20GHz
size.metal-stack.io/drive-description=960GB NVMe
ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RANGE GPU RANGE LABELS
1 size-1 size 1 7 5 - 6 3 B - 4 B 1 B - 2 B AD120GL*: 1 - 1 size.metal-stack.io/cpu-description=1x Intel(R) Xeon(R) D-2141I CPU @ 2.20GHz
size.metal-stack.io/drive-description=960GB NVMe
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
1 size-1
`),
wantMarkdown: pointer.Pointer(`
| ID | NAME | DESCRIPTION | RESERVATIONS | CPU RANGE | MEMORY RANGE | STORAGE RANGE |
|----|--------|-------------|--------------|-----------|--------------|---------------|
| 1 | size-1 | size 1 | 7 | 5 - 6 | 3 B - 4 B | 1 B - 2 B |
| ID | NAME | DESCRIPTION | RESERVATIONS | CPU RANGE | MEMORY RANGE | STORAGE RANGE | GPU RANGE |
|----|--------|-------------|--------------|-----------|--------------|---------------|-----------------|
| 1 | size-1 | size 1 | 7 | 5 - 6 | 3 B - 4 B | 1 B - 2 B | AD120GL*: 1 - 1 |
`),
},
{
Expand All @@ -267,8 +273,8 @@ ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RA
"--id", *want.ID,
"--name", want.Name,
"--description", want.Description,
"--max", strconv.FormatInt(*want.Constraints[0].Max, 10),
"--min", strconv.FormatInt(*want.Constraints[0].Min, 10),
"--max", strconv.FormatInt(want.Constraints[0].Max, 10),
"--min", strconv.FormatInt(want.Constraints[0].Min, 10),
"--type", *want.Constraints[0].Type,
}
assertExhaustiveArgs(t, args, commonExcludedFileArgs()...)
Expand Down Expand Up @@ -307,19 +313,19 @@ ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RA
})), nil).Return(&size.SuggestOK{
Payload: []*models.V1SizeConstraint{
{
Max: pointer.Pointer(int64(2)),
Min: pointer.Pointer(int64(1)),
Type: pointer.Pointer("storage"),
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer(models.V1SizeConstraintTypeStorage),
},
{
Max: pointer.Pointer(int64(4)),
Min: pointer.Pointer(int64(3)),
Type: pointer.Pointer("memory"),
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer(models.V1SizeConstraintTypeMemory),
},
{
Max: pointer.Pointer(int64(6)),
Min: pointer.Pointer(int64(5)),
Type: pointer.Pointer("cores"),
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer(models.V1SizeConstraintTypeCores),
},
},
}, nil)
Expand All @@ -328,19 +334,19 @@ ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RA
want: &models.V1SizeResponse{
Constraints: []*models.V1SizeConstraint{
{
Max: pointer.Pointer(int64(2)),
Min: pointer.Pointer(int64(1)),
Type: pointer.Pointer("storage"),
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer(models.V1SizeConstraintTypeStorage),
},
{
Max: pointer.Pointer(int64(4)),
Min: pointer.Pointer(int64(3)),
Type: pointer.Pointer("memory"),
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer(models.V1SizeConstraintTypeMemory),
},
{
Max: pointer.Pointer(int64(6)),
Min: pointer.Pointer(int64(5)),
Type: pointer.Pointer("cores"),
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer(models.V1SizeConstraintTypeCores),
},
},
Description: "foo",
Expand Down
4 changes: 0 additions & 4 deletions cmd/tableprinters/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ func (t *TablePrinter) ToHeaderAndRows(data any, wide bool) ([]string, [][]strin
return t.SizeTable(pointer.WrapInSlice(d), wide)
case []*models.V1SizeResponse:
return t.SizeTable(d, wide)
case *models.V1SizeMatchingLog:
return t.SizeMatchingLogTable(pointer.WrapInSlice(d), wide)
case []*models.V1SizeMatchingLog:
return t.SizeMatchingLogTable(d, wide)
case *models.V1SizeReservationResponse:
return t.SizeReservationTable(pointer.WrapInSlice(d), wide)
case []*models.V1SizeReservationResponse:
Expand Down
Loading
Loading