Skip to content

Commit

Permalink
omitempty for min/max
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Mar 19, 2024
1 parent 904d939 commit 597a22c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions cmd/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,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 Down
28 changes: 14 additions & 14 deletions cmd/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ var (
size1 = &models.V1SizeResponse{
Constraints: []*models.V1SizeConstraint{
{
Max: pointer.Pointer(int64(2)),
Min: pointer.Pointer(int64(1)),
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer("storage"),
},
{
Max: pointer.Pointer(int64(4)),
Min: pointer.Pointer(int64(3)),
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer("memory"),
},
{
Max: pointer.Pointer(int64(6)),
Min: pointer.Pointer(int64(5)),
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer("cores"),
},
},
Expand Down Expand Up @@ -59,18 +59,18 @@ var (
size2 = &models.V1SizeResponse{
Constraints: []*models.V1SizeConstraint{
{
Max: pointer.Pointer(int64(2)),
Min: pointer.Pointer(int64(1)),
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer("storage"),
},
{
Max: pointer.Pointer(int64(4)),
Min: pointer.Pointer(int64(3)),
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer("memory"),
},
{
Max: pointer.Pointer(int64(6)),
Min: pointer.Pointer(int64(5)),
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer("cores"),
},
},
Expand Down Expand Up @@ -266,8 +266,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
20 changes: 13 additions & 7 deletions cmd/tableprinters/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ func (t *TablePrinter) SizeTable(data []*models.V1SizeResponse, wide bool) ([]st
for _, c := range size.Constraints {
switch *c.Type {
case models.V1SizeConstraintTypeCores:
cpu = fmt.Sprintf("%d - %d", *c.Min, *c.Max)
cpu = fmt.Sprintf("%d - %d", c.Min, c.Max)
case models.V1SizeConstraintTypeMemory:
memory = fmt.Sprintf("%s - %s", humanize.Bytes(uint64(*c.Min)), humanize.Bytes(uint64(*c.Max)))
memory = fmt.Sprintf("%s - %s", humanize.Bytes(uint64(c.Min)), humanize.Bytes(uint64(c.Max)))
case models.V1SizeConstraintTypeStorage:
storage = fmt.Sprintf("%s - %s", humanize.Bytes(uint64(*c.Min)), humanize.Bytes(uint64(*c.Max)))
storage = fmt.Sprintf("%s - %s", humanize.Bytes(uint64(c.Min)), humanize.Bytes(uint64(c.Max)))
case models.V1SizeConstraintTypeGpu:
gpu = fmt.Sprintf("%v", c.Gpus)
var gpus []string
for model, count := range c.Gpus {
gpus = append(gpus, fmt.Sprintf("%d x %s", count, model))
}
if len(gpus) > 0 {
gpu = strings.Join(gpus, ",")
}
}

}
Expand Down Expand Up @@ -75,11 +81,11 @@ func (t *TablePrinter) SizeMatchingLogTable(data []*models.V1SizeMatchingLog, wi
c := cs.Constraint
switch *c.Type {
case "cores": // TODO: should be enums in spec
cpu = fmt.Sprintf("%d - %d\n%s\nmatches: %v", *c.Min, *c.Max, *cs.Log, *cs.Match)
cpu = fmt.Sprintf("%d - %d\n%s\nmatches: %v", c.Min, c.Max, *cs.Log, *cs.Match)
case "memory":
memory = fmt.Sprintf("%s - %s\n%s\nmatches: %v", humanize.Bytes(uint64(*c.Min)), humanize.Bytes(uint64(*c.Max)), *cs.Log, *cs.Match)
memory = fmt.Sprintf("%s - %s\n%s\nmatches: %v", humanize.Bytes(uint64(c.Min)), humanize.Bytes(uint64(c.Max)), *cs.Log, *cs.Match)
case "storage":
storage = fmt.Sprintf("%s - %s\n%s\nmatches: %v", humanize.Bytes(uint64(*c.Min)), humanize.Bytes(uint64(*c.Max)), *cs.Log, *cs.Match)
storage = fmt.Sprintf("%s - %s\n%s\nmatches: %v", humanize.Bytes(uint64(c.Min)), humanize.Bytes(uint64(c.Max)), *cs.Log, *cs.Match)
}
}
sizeMatch := fmt.Sprintf("%v", *d.Match)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-openapi/runtime v0.28.0
github.com/go-openapi/strfmt v0.23.0
github.com/google/go-cmp v0.6.0
github.com/metal-stack/metal-go v0.28.2-0.20240319091838-c7e02da9af08
github.com/metal-stack/metal-go v0.28.2-0.20240319120116-48ca93c2831a
github.com/metal-stack/metal-lib v0.15.1
github.com/metal-stack/updater v1.2.1
github.com/metal-stack/v v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ
github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/metal-stack/metal-go v0.28.2-0.20240319091838-c7e02da9af08 h1:1pu69TIhLm6+ckopXO+w2/JSsNWRx/U3TmK1TvuxkhQ=
github.com/metal-stack/metal-go v0.28.2-0.20240319091838-c7e02da9af08/go.mod h1:1MepfVbYaEuCKErsdDY+QqNgPMKcWiIRkD9Mjq1kC1o=
github.com/metal-stack/metal-go v0.28.2-0.20240319120116-48ca93c2831a h1:xBUVYZF2aWtFTZwgofdBzLkWbylb1pnflpxZM2ifIx0=
github.com/metal-stack/metal-go v0.28.2-0.20240319120116-48ca93c2831a/go.mod h1:1MepfVbYaEuCKErsdDY+QqNgPMKcWiIRkD9Mjq1kC1o=
github.com/metal-stack/metal-lib v0.15.1 h1:QCmtZ6ci6pHsf3RQnSDbbvYshpyRaxCSeXghVvbDFuA=
github.com/metal-stack/metal-lib v0.15.1/go.mod h1:x1nyPRi+b/WeK7N41cm4R8w4pScnhOYv8hos2UM4lXY=
github.com/metal-stack/security v0.7.2 h1:kUdWej+a0+YPBGt4fT56Mu8cWX/tOjeKL/FWNlUuoe8=
Expand Down

0 comments on commit 597a22c

Please sign in to comment.