diff --git a/cmd/admin/v2/size-reservation.go b/cmd/admin/v2/size-reservation.go new file mode 100644 index 0000000..eafd6f6 --- /dev/null +++ b/cmd/admin/v2/size-reservation.go @@ -0,0 +1,243 @@ +package v2 + +import ( + "fmt" + + "github.com/metal-stack/api/go/errorutil" + adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" + apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" + "github.com/metal-stack/cli/cmd/config" + "github.com/metal-stack/cli/cmd/sorters" + "github.com/metal-stack/cli/pkg/helpers" + "github.com/metal-stack/metal-lib/pkg/genericcli" + "github.com/metal-stack/metal-lib/pkg/genericcli/printers" + "github.com/metal-stack/metal-lib/pkg/pointer" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +type sizeReservation struct { + c *config.Config +} + +func newSizeReservationCmd(c *config.Config) *cobra.Command { + w := &sizeReservation{ + c: c, + } + + cmdsConfig := &genericcli.CmdsConfig[*adminv2.SizeReservationServiceCreateRequest, *adminv2.SizeReservationServiceUpdateRequest, *apiv2.SizeReservation]{ + BinaryName: config.BinaryName, + GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.Fs), + Singular: "reservation", + Plural: "reservations", + Description: "manage size reservations which reserve machine capacity for a project", + Sorter: sorters.SizeReservationSorter(), + DescribePrinter: func() printers.Printer { return c.DescribePrinter }, + ListPrinter: func() printers.Printer { return c.ListPrinter }, + ValidArgsFn: c.Completion.AdminSizeReservation, + ListCmdMutateFn: func(cmd *cobra.Command) { + cmd.Flags().String("name", "", "size reservation name to filter for") + cmd.Flags().String("description", "", "size reservation description to filter for") + cmd.Flags().String("size", "", "size id to filter for") + cmd.Flags().String("project", "", "project id to filter for") + cmd.Flags().String("partition", "", "partition id to filter for") + cmd.Flags().StringSlice("labels", nil, "labels to filter for") + + genericcli.Must(cmd.RegisterFlagCompletionFunc("size", c.Completion.Size)) + genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project)) + genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.Completion.Partition)) + }, + CreateCmdMutateFn: func(cmd *cobra.Command) { + cmd.Flags().String("name", "", "the name of the size reservation to create") + cmd.Flags().String("description", "", "the description of the size reservation to create") + cmd.Flags().String("project", "", "the project id of the size reservation to create") + cmd.Flags().String("size", "", "the size id of the size reservation to create") + cmd.Flags().StringSlice("partitions", nil, "the partition ids the size reservation applies to") + cmd.Flags().Int32("amount", 0, "the amount of machines to reserve") + cmd.Flags().StringSlice("labels", nil, "labels to add to the size reservation") + + genericcli.Must(cmd.RegisterFlagCompletionFunc("size", c.Completion.Size)) + genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project)) + genericcli.Must(cmd.RegisterFlagCompletionFunc("partitions", c.Completion.Partition)) + }, + CreateRequestFromCLI: w.createRequestFromCLI, + UpdateCmdMutateFn: func(cmd *cobra.Command) { + cmd.Flags().String("name", "", "the name of the size reservation") + cmd.Flags().String("description", "", "the description of the size reservation") + cmd.Flags().StringSlice("partitions", nil, "the partition ids the size reservation applies to") + cmd.Flags().Int32("amount", 0, "the amount of machines to reserve") + cmd.Flags().StringSlice("labels", nil, "labels to replace for the size reservation") + cmd.Flags().StringSlice("add-labels", nil, "labels to add to the size reservation") + cmd.Flags().StringSlice("remove-labels", nil, "labels to remove from the size reservation") + + genericcli.Must(cmd.RegisterFlagCompletionFunc("partitions", c.Completion.Partition)) + }, + UpdateRequestFromCLI: w.updateRequestFromCLI, + } + + return genericcli.NewCmds(cmdsConfig) +} + +func (c *sizeReservation) Get(id string) (*apiv2.SizeReservation, error) { + ctx, cancel := c.c.NewRequestContext() + defer cancel() + + // the admin api does not offer a dedicated get call for size reservations, + // so we filter the list by the given id. + resp, err := c.c.Client.Adminv2().SizeReservation().List(ctx, &adminv2.SizeReservationServiceListRequest{ + Query: &apiv2.SizeReservationQuery{ + Id: new(id), + }, + }) + if err != nil { + return nil, fmt.Errorf("failed to get size reservation: %w", err) + } + + reservations := resp.GetSizeReservations() + if len(reservations) == 0 { + return nil, fmt.Errorf("size reservation %q not found", id) + } + + return reservations[0], nil +} + +func (c *sizeReservation) List() ([]*apiv2.SizeReservation, error) { + ctx, cancel := c.c.NewRequestContext() + defer cancel() + + req := &adminv2.SizeReservationServiceListRequest{ + Query: &apiv2.SizeReservationQuery{ + Name: pointer.PointerOrNil(viper.GetString("name")), + Description: pointer.PointerOrNil(viper.GetString("description")), + Size: pointer.PointerOrNil(viper.GetString("size")), + Project: pointer.PointerOrNil(viper.GetString("project")), + Partition: pointer.PointerOrNil(viper.GetString("partition")), + }, + } + + if labelSlice := viper.GetStringSlice("labels"); len(labelSlice) > 0 { + labels, err := helpers.LabelsFromSlice(labelSlice) + if err != nil { + return nil, err + } + + req.Query.Labels = labels + } + + resp, err := c.c.Client.Adminv2().SizeReservation().List(ctx, req) + if err != nil { + return nil, fmt.Errorf("failed to list size reservations: %w", err) + } + + return resp.GetSizeReservations(), nil +} + +func (c *sizeReservation) Create(rq *adminv2.SizeReservationServiceCreateRequest) (*apiv2.SizeReservation, error) { + ctx, cancel := c.c.NewRequestContext() + defer cancel() + + resp, err := c.c.Client.Adminv2().SizeReservation().Create(ctx, rq) + if err != nil { + if errorutil.IsConflict(err) { + return nil, genericcli.AlreadyExistsError() + } + + return nil, fmt.Errorf("failed to create size reservation: %w", err) + } + + return resp.GetSizeReservation(), nil +} + +func (c *sizeReservation) Update(rq *adminv2.SizeReservationServiceUpdateRequest) (*apiv2.SizeReservation, error) { + ctx, cancel := c.c.NewRequestContext() + defer cancel() + + resp, err := c.c.Client.Adminv2().SizeReservation().Update(ctx, rq) + if err != nil { + return nil, fmt.Errorf("failed to update size reservation: %w", err) + } + + return resp.GetSizeReservation(), nil +} + +func (c *sizeReservation) Delete(id string) (*apiv2.SizeReservation, error) { + ctx, cancel := c.c.NewRequestContext() + defer cancel() + + resp, err := c.c.Client.Adminv2().SizeReservation().Delete(ctx, &adminv2.SizeReservationServiceDeleteRequest{ + Id: id, + }) + if err != nil { + return nil, fmt.Errorf("failed to delete size reservation: %w", err) + } + + return resp.GetSizeReservation(), nil +} + +func (c *sizeReservation) Convert(r *apiv2.SizeReservation) (string, *adminv2.SizeReservationServiceCreateRequest, *adminv2.SizeReservationServiceUpdateRequest, error) { + return r.Id, + &adminv2.SizeReservationServiceCreateRequest{ + SizeReservation: r, + }, + &adminv2.SizeReservationServiceUpdateRequest{ + Id: r.Id, + UpdateMeta: helpers.UpdateMetaFromMeta(r.Meta), + Name: pointer.PointerOrNil(r.Name), + Description: pointer.PointerOrNil(r.Description), + Partitions: r.Partitions, + Amount: pointer.PointerOrNil(r.Amount), + Labels: helpers.UpdateLabelsFromMeta(r.Meta), + }, nil +} + +func (c *sizeReservation) createRequestFromCLI() (*adminv2.SizeReservationServiceCreateRequest, error) { + reservation := &apiv2.SizeReservation{ + Name: viper.GetString("name"), + Description: viper.GetString("description"), + Project: viper.GetString("project"), + Size: viper.GetString("size"), + Partitions: viper.GetStringSlice("partitions"), + Amount: viper.GetInt32("amount"), + } + + labels, err := helpers.LabelsFromSlice(viper.GetStringSlice("labels")) + if err != nil { + return nil, err + } + if labels != nil { + reservation.Meta = &apiv2.Meta{Labels: labels} + } + + return &adminv2.SizeReservationServiceCreateRequest{ + SizeReservation: reservation, + }, nil +} + +func (c *sizeReservation) updateRequestFromCLI(args []string) (*adminv2.SizeReservationServiceUpdateRequest, error) { + id, err := genericcli.GetExactlyOneArg(args) + if err != nil { + return nil, err + } + + updateLabels, err := helpers.UpdateLabelsFromCLI() + if err != nil { + return nil, err + } + + req := &adminv2.SizeReservationServiceUpdateRequest{ + Id: id, + UpdateMeta: &apiv2.UpdateMeta{ + LockingStrategy: apiv2.OptimisticLockingStrategy_OPTIMISTIC_LOCKING_STRATEGY_SERVER, + }, + Name: pointer.PointerOrNil(viper.GetString("name")), + Description: pointer.PointerOrNil(viper.GetString("description")), + Amount: pointer.PointerOrNil(viper.GetInt32("amount")), + Labels: updateLabels, + } + + if partitions := viper.GetStringSlice("partitions"); len(partitions) > 0 { + req.Partitions = partitions + } + + return req, nil +} diff --git a/cmd/admin/v2/size.go b/cmd/admin/v2/size.go index dc1cd7c..8ef1457 100644 --- a/cmd/admin/v2/size.go +++ b/cmd/admin/v2/size.go @@ -42,7 +42,7 @@ func newSizeCmd(c *config.Config) *cobra.Command { }, } - return genericcli.NewCmds(cmdsConfig) + return genericcli.NewCmds(cmdsConfig, newSizeReservationCmd(c)) } func (c *size) Get(id string) (*apiv2.Size, error) { diff --git a/cmd/completion/size_reservation.go b/cmd/completion/size_reservation.go new file mode 100644 index 0000000..a0effd7 --- /dev/null +++ b/cmd/completion/size_reservation.go @@ -0,0 +1,23 @@ +package completion + +import ( + adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" + apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" + "github.com/spf13/cobra" +) + +func (c *Completion) AdminSizeReservation(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + resp, err := c.Client.Adminv2().SizeReservation().List(cmd.Context(), &adminv2.SizeReservationServiceListRequest{ + Query: &apiv2.SizeReservationQuery{}, + }) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + var names []string + for _, r := range resp.SizeReservations { + names = append(names, r.Id+"\t"+r.Name) + } + + return names, cobra.ShellCompDirectiveNoFileComp +} diff --git a/cmd/sorters/size_reservation.go b/cmd/sorters/size_reservation.go new file mode 100644 index 0000000..9147899 --- /dev/null +++ b/cmd/sorters/size_reservation.go @@ -0,0 +1,29 @@ +package sorters + +import ( + apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" + "github.com/metal-stack/metal-lib/pkg/multisort" +) + +func SizeReservationSorter() *multisort.Sorter[*apiv2.SizeReservation] { + return multisort.New(multisort.FieldMap[*apiv2.SizeReservation]{ + "id": func(a, b *apiv2.SizeReservation, descending bool) multisort.CompareResult { + return multisort.Compare(a.Id, b.Id, descending) + }, + "name": func(a, b *apiv2.SizeReservation, descending bool) multisort.CompareResult { + return multisort.Compare(a.Name, b.Name, descending) + }, + "description": func(a, b *apiv2.SizeReservation, descending bool) multisort.CompareResult { + return multisort.Compare(a.Description, b.Description, descending) + }, + "project": func(a, b *apiv2.SizeReservation, descending bool) multisort.CompareResult { + return multisort.Compare(a.Project, b.Project, descending) + }, + "size": func(a, b *apiv2.SizeReservation, descending bool) multisort.CompareResult { + return multisort.Compare(a.Size, b.Size, descending) + }, + "amount": func(a, b *apiv2.SizeReservation, descending bool) multisort.CompareResult { + return multisort.Compare(a.Amount, b.Amount, descending) + }, + }, multisort.Keys{{ID: "id"}}) +} diff --git a/cmd/tableprinters/common.go b/cmd/tableprinters/common.go index a9212ff..2e3ad80 100644 --- a/cmd/tableprinters/common.go +++ b/cmd/tableprinters/common.go @@ -153,6 +153,11 @@ func (t *TablePrinter) ToHeaderAndRows(data any, wide bool) ([]string, [][]strin case []*apiv2.Size: return t.SizeTable(d, wide) + case *apiv2.SizeReservation: + return t.SizeReservationTable(pointer.WrapInSlice(d), wide) + case []*apiv2.SizeReservation: + return t.SizeReservationTable(d, wide) + case []*apiv2.Switch: return t.SwitchTable(d, wide) case []SwitchDetail: diff --git a/cmd/tableprinters/size_reservation.go b/cmd/tableprinters/size_reservation.go new file mode 100644 index 0000000..091a865 --- /dev/null +++ b/cmd/tableprinters/size_reservation.go @@ -0,0 +1,43 @@ +package tableprinters + +import ( + "fmt" + "sort" + "strings" + + apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" + "github.com/metal-stack/metal-lib/pkg/genericcli" +) + +func (t *TablePrinter) SizeReservationTable(data []*apiv2.SizeReservation, wide bool) ([]string, [][]string, error) { + var ( + header = []string{"ID", "Name", "Description", "Project", "Size", "Partitions", "Amount"} + rows [][]string + ) + + if wide { + header = append(header, "Labels") + } + + for _, r := range data { + row := []string{ + r.Id, + r.Name, + r.Description, + r.Project, + r.Size, + strings.Join(r.Partitions, "\n"), + fmt.Sprintf("%d", r.Amount), + } + + if wide { + labels := genericcli.MapToLabels(r.Meta.GetLabels().GetLabels()) + sort.Strings(labels) + row = append(row, strings.Join(labels, "\n")) + } + + rows = append(rows, row) + } + + return header, rows, nil +} diff --git a/go.mod b/go.mod index 0dd4531..8d2b683 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/metal-stack/cli -go 1.27.3 +go 1.27.4 require ( connectrpc.com/connect v1.21.1 @@ -24,10 +24,10 @@ require ( require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.2 // indirect - buf.build/go/protovalidate v1.4.0 // indirect + buf.build/go/protovalidate v1.4.1 // indirect buf.build/go/protoyaml v0.8.0 // indirect - cel.dev/cel-go v0.33.2 // indirect - cel.dev/expr v0.25.3 // indirect + cel.dev/cel-go v0.33.4 // indirect + cel.dev/expr v0.26.0 // indirect connectrpc.com/connect/v2 v2.0.2 // indirect filippo.io/edwards25519 v1.2.0 // indirect github.com/akutz/memconn v0.1.0 // indirect @@ -59,14 +59,15 @@ require ( github.com/huin/goupnp v1.3.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jsimonetti/rtnetlink v1.4.2 // indirect - github.com/klauspost/compress v1.20.3 // indirect + github.com/klauspost/compress v1.20.4 // indirect github.com/klauspost/connect-compress/v2 v2.1.1 // indirect + github.com/klauspost/cpuid/v2 v2.4.2 // indirect github.com/mattn/go-colorable v0.1.16 // indirect github.com/mattn/go-isatty v0.0.24 // indirect github.com/mattn/go-runewidth v0.0.31 // indirect github.com/mdlayher/netlink v1.11.2 // indirect github.com/mdlayher/socket v0.8.0 // indirect - github.com/minio/minlz v1.2.3 // indirect + github.com/minio/minlz v1.3.0 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect github.com/oklog/ulid/v2 v2.1.2 // indirect github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect @@ -79,7 +80,7 @@ require ( github.com/safchain/ethtool v0.7.0 // indirect github.com/sagikazarmark/locafero v0.12.0 // indirect github.com/spf13/cast v1.10.0 // indirect - github.com/spf13/pflag v1.0.10 // indirect + github.com/spf13/pflag v1.1.0 // indirect github.com/stretchr/objx v0.8.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/tailscale/certstore v0.1.1-0.20260409135935-3638fb84b77d // indirect @@ -87,29 +88,30 @@ require ( github.com/tailscale/hujson v0.0.0-20260727124030-b80ff77dac4f // indirect github.com/tailscale/peercred v0.0.0-20250107143737-35a0c7bd7edc // indirect github.com/tailscale/web-client-prebuilt v0.0.0-20260917222731-e0ed2d0d0fea // indirect - github.com/tailscale/wireguard-go v0.0.0-20260928213032-417aef361226 // indirect + github.com/tailscale/wireguard-go v0.0.0-20261106233718-9e0ab45c16ca // indirect github.com/x448/float16 v0.8.4 // indirect + github.com/zeebo/xxh3 v1.1.1-0.20260908150653-f7225998cebf // indirect go.yaml.in/yaml/v2 v2.4.5 // indirect go.yaml.in/yaml/v3 v3.0.6 // indirect go4.org/mem v0.0.0-20240501181205-ae6ca9944745 // indirect go4.org/netipx v0.0.0-20260823151212-3075585bcbeb // indirect - golang.org/x/crypto v0.58.0 // indirect - golang.org/x/exp v0.0.0-20261014143641-f0251eb4aa3e // indirect - golang.org/x/net v0.62.0 // indirect - golang.org/x/oauth2 v0.37.0 // indirect - golang.org/x/sync v0.24.0 // indirect - golang.org/x/sys v0.49.0 // indirect - golang.org/x/term v0.47.0 // indirect - golang.org/x/text v0.43.0 // indirect + golang.org/x/crypto v0.59.0 // indirect + golang.org/x/exp v0.0.0-20261119141654-b15d094f3610 // indirect + golang.org/x/net v0.63.0 // indirect + golang.org/x/oauth2 v0.38.0 // indirect + golang.org/x/sync v0.25.0 // indirect + golang.org/x/sys v0.50.0 // indirect + golang.org/x/term v0.48.0 // indirect + golang.org/x/text v0.44.0 // indirect golang.org/x/time v0.16.0 // indirect golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect golang.zx2c4.com/wireguard/windows v1.1.1 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20261104224025-d1e00e9f33ab // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20261104224025-d1e00e9f33ab // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20261118221215-c8830f628b3f // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gvisor.dev/gvisor v0.0.0-20260915211658-a6f909f08a72 // indirect - k8s.io/apimachinery v0.37.1 // indirect + k8s.io/apimachinery v0.37.2 // indirect sigs.k8s.io/json v0.0.0-20260909141634-11ed52e25bc5 // indirect - tailscale.com v1.104.5 // indirect + tailscale.com v1.104.7 // indirect ) diff --git a/go.sum b/go.sum index 9c59357..9fbb7b7 100644 --- a/go.sum +++ b/go.sum @@ -2,14 +2,14 @@ 9fans.net/go v0.0.8-0.20250307142834-96bdba94b63f/go.mod h1:hHyrZRryGqVdqrknjq5OWDLGCTJ2NeEvtrpR96mjraM= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.2 h1:NbnlmV26O7oZ1iM5tsCI+GEx+3ZSdrhvnKQ/eWSrLiY= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.12-20260825204119-511051f7f437.2/go.mod h1:TCt1lluMFnctISJXvkIQ4x3ABrPuUKCWKyjKdkJNBpw= -buf.build/go/protovalidate v1.4.0 h1:UjLrYbt5VX7+TMOs2+pG5FhZhIG1mSfK4EIopbb4LcM= -buf.build/go/protovalidate v1.4.0/go.mod h1:8vJfzNT6NIG2qm3uFsJDXMlRmG+bQJzbcIn1Aa0vPGs= +buf.build/go/protovalidate v1.4.1 h1:G/AHf1EKrY9E0gXXxkPavEppwZe/7oAVq4rBbSWu0hQ= +buf.build/go/protovalidate v1.4.1/go.mod h1:rwfPjgeCqK+DsDsBtLUNT1l5uoXl/0KFA632z3wlyCQ= buf.build/go/protoyaml v0.8.0 h1:n6q7ygZTZo4kLzKXsymkiLharUgHfd507Ymi4t5xhY8= buf.build/go/protoyaml v0.8.0/go.mod h1:3XRN/7BQCQNlhIgwzE46QTHLuUScH2d76lAFLCQEFWo= -cel.dev/cel-go v0.33.2 h1:eAcEdBguc6AFrGbPOyE0g168Uey4kKFW9J6qsBLSeMU= -cel.dev/cel-go v0.33.2/go.mod h1:DnVip7tpJSsgZymwfT+m1tnEVy3ivAjSMXPx12YrMkU= -cel.dev/expr v0.25.3 h1:A2jO8jwOugrrovveCWfj0KEZOfqiLgAcwjpHPhzIGw0= -cel.dev/expr v0.25.3/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= +cel.dev/cel-go v0.33.4 h1:9hd5BRPQZwj81qOddEXh0WhE1N3shkG3ad89pSqk+iU= +cel.dev/cel-go v0.33.4/go.mod h1:DnVip7tpJSsgZymwfT+m1tnEVy3ivAjSMXPx12YrMkU= +cel.dev/expr v0.26.0 h1:oLXvOF0jiYA5A/tmzU91pLEWZkKynhLJlC9Gw7PrKvs= +cel.dev/expr v0.26.0/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= connectrpc.com/connect v1.21.1 h1:h2kacdlzXpZU2OQFSv98xkjYXNUSr/ptxmGVbS/+CRM= connectrpc.com/connect v1.21.1/go.mod h1:fhMcVJ5w6r/yTYhnkEbW6+sIF7OZ5Ay7KYgmfebh2ek= connectrpc.com/connect/v2 v2.0.2 h1:PoPDmOlhc46elsuCdKCKTxjNBb3HJlKF+s/sP2oucPw= @@ -171,10 +171,12 @@ github.com/jsimonetti/rtnetlink v1.4.2 h1:Df9w9TZ3npHTyDn0Ev9e1uzmN2odmXd0QX+J5G github.com/jsimonetti/rtnetlink v1.4.2/go.mod h1:92s6LJdE+1iOrw+F2/RO7LYI2Qd8pPpFNNUYW06gcoM= github.com/kamstrup/intmap v0.5.2 h1:qnwBm1mh4XAnW9W9Ue9tZtTff8pS6+s6iKF6JRIV2Dk= github.com/kamstrup/intmap v0.5.2/go.mod h1:gWUVWHKzWj8xpJVFf5GC0O26bWmv3GqdnIX/LMT6Aq4= -github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4= -github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= +github.com/klauspost/compress v1.20.4 h1:dD0v/bvxtjCBqQu6sx1TNWkalEY5lNTIe+HY9w8TeNI= +github.com/klauspost/compress v1.20.4/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/klauspost/connect-compress/v2 v2.1.1 h1:ycZNp4rWOZBodVE2Ls5AzK4aHkyK+GteEfzRZgKNs+c= github.com/klauspost/connect-compress/v2 v2.1.1/go.mod h1:9oilsPHJMzGKkjafSBk9J7iVo4mO+dw0G0KSdVpnlVE= +github.com/klauspost/cpuid/v2 v2.4.2 h1:xRw7IZEsAgVCp6trS/DgWbTAqpixhmywgVgBjYGg1bQ= +github.com/klauspost/cpuid/v2 v2.4.2/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU= github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a h1:+RR6SqnTkDLWyICxS1xpjCi/3dhyV+TgZwA6Ww3KncQ= github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a/go.mod h1:YTtCCM3ryyfiu4F7t8HQ1mxvp1UBdWM2r6Xa+nGWvDk= github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= @@ -207,8 +209,8 @@ github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs= github.com/metal-stack/v v1.0.3/go.mod h1:YTahEu7/ishwpYKnp/VaW/7nf8+PInogkfGwLcGPdXg= github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE= github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ= -github.com/minio/minlz v1.2.3 h1:xUNhxBd8AlRJbJIsFkVmrN96gk9as9PjheVh3f9x90s= -github.com/minio/minlz v1.2.3/go.mod h1:xHhZ+MJmC2U4ssK/rSENsoyCfv0VFQo1mT6AdCA2RJ8= +github.com/minio/minlz v1.3.0 h1:RWLIQO6A3ijwoddX5YJ835nLcwWp6L5ArWXmw3EUM+s= +github.com/minio/minlz v1.3.0/go.mod h1:pIQFuJBapMWV6eifwauy1U7tM6vqbGWDHB4u6B84Fv0= github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -255,8 +257,8 @@ github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qq github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= -github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.1.0 h1:6W6MbVUrnMb8PEhjkqwsVLY7ryuzRfFHF4mQd7L94ag= +github.com/spf13/pflag v1.1.0/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= github.com/stretchr/objx v0.8.0 h1:rm9oMkeprG/wHifkZP4EuDww9S0mvEaQ/p9cXTNT4cw= @@ -285,8 +287,8 @@ github.com/tailscale/web-client-prebuilt v0.0.0-20260917222731-e0ed2d0d0fea h1:a github.com/tailscale/web-client-prebuilt v0.0.0-20260917222731-e0ed2d0d0fea/go.mod h1:agQPE6y6ldqCOui2gkIh7ZMztTkIQKH049tv8siLuNQ= github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6 h1:l10Gi6w9jxvinoiq15g8OToDdASBni4CyJOdHY1Hr8M= github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6/go.mod h1:ZXRML051h7o4OcI0d3AaILDIad/Xw0IkXaHM17dic1Y= -github.com/tailscale/wireguard-go v0.0.0-20260928213032-417aef361226 h1:v3Lpj2iHPWQDqeCwemQPz4fWweIEMLqBkwJqCjRyJQc= -github.com/tailscale/wireguard-go v0.0.0-20260928213032-417aef361226/go.mod h1:rUelGmuK4UnSJYM5gl5Mknp6YbwwcL8+VAPMhNYe+jg= +github.com/tailscale/wireguard-go v0.0.0-20261106233718-9e0ab45c16ca h1:m34ObTyPjPiDaSFWeMk7FBQR8my9wpT98t1EXp5c5X0= +github.com/tailscale/wireguard-go v0.0.0-20261106233718-9e0ab45c16ca/go.mod h1:rUelGmuK4UnSJYM5gl5Mknp6YbwwcL8+VAPMhNYe+jg= github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e h1:zOGKqN5D5hHhiYUp091JqK7DPCqSARyUfduhGUY8Bek= github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e/go.mod h1:orPd6JZXXRyuDusYilywte7k094d7dycXXU5YnWsrwg= github.com/tc-hib/winres v0.3.1 h1:CwRjEGrKdbi5CvZ4ID+iyVhgyfatxFoizjPhzez9Io4= @@ -299,6 +301,10 @@ github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zd github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= +github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ= +github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= +github.com/zeebo/xxh3 v1.1.1-0.20260908150653-f7225998cebf h1:enYm6eO9pkyOXOHgdbVr0E8qKt7JDRfyeDtz/JBrF3c= +github.com/zeebo/xxh3 v1.1.1-0.20260908150653-f7225998cebf/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s= go.yaml.in/yaml/v2 v2.4.5 h1:a5nxWvYi94DRl6QSLlTbLpVmutgx2qg8EVjnJtuFpwI= go.yaml.in/yaml/v2 v2.4.5/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= @@ -308,43 +314,43 @@ go4.org/mem v0.0.0-20240501181205-ae6ca9944745 h1:Tl++JLUCe4sxGu8cTpDzRLd3tN7US4 go4.org/mem v0.0.0-20240501181205-ae6ca9944745/go.mod h1:reUoABIJ9ikfM5sgtSF3Wushcza7+WeD01VB9Lirh3g= go4.org/netipx v0.0.0-20260823151212-3075585bcbeb h1:XBM4hvfwGAttkkiTIFfeigdfcL1xIfdKXqFdgiHGtDs= go4.org/netipx v0.0.0-20260823151212-3075585bcbeb/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y= -golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54= -golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w= -golang.org/x/exp v0.0.0-20261014143641-f0251eb4aa3e h1:HgI6W1OolKK6tcV74is+rl9SMT0njsHlp0TbQiGXI/A= -golang.org/x/exp v0.0.0-20261014143641-f0251eb4aa3e/go.mod h1:DBoxwWhjaW8DJJw/YeM4zpeOKMC1FMXSblsYy+1mFSw= +golang.org/x/crypto v0.59.0 h1:xS2jhqYbzNrpvkWP2YTDf4TJwBy3ykR03i8vFDxEc7c= +golang.org/x/crypto v0.59.0/go.mod h1:veDyUwATGs3c+vN3VfTbzViMGXeTBk3WyhBOkn+F/4U= +golang.org/x/exp v0.0.0-20261119141654-b15d094f3610 h1:bT3evuloD7Y8n1TA3NUVVL51/Y4GsLNTHmqiQkViumw= +golang.org/x/exp v0.0.0-20261119141654-b15d094f3610/go.mod h1:xeYMf2GfgE/gQmBtvdPsBN608YETsXuvoiEhaOxGg/w= golang.org/x/exp/typeparams v0.0.0-20260811152304-ee035b5b010f h1:+lI8cDJ4uceLipg2f1ODay7fEuLkk0BIHXd6PB8icxo= golang.org/x/exp/typeparams v0.0.0-20260811152304-ee035b5b010f/go.mod h1:PqrXSW65cXDZH0k4IeUbhmg/bcAZDbzNz3byBpKCsXo= golang.org/x/image v0.46.0 h1:b1+oYj0Jbp6K5MDT4i4/eZpYlk3V8SJhhDKh6LBHAyQ= golang.org/x/image v0.46.0/go.mod h1:3B3W05VGVQyuXucLINLjXKrqISASfi4Xj+iCVkLMwew= -golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg= -golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs= -golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY= -golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI= -golang.org/x/oauth2 v0.37.0 h1:JUlcxA8oAtauLfiH8FX2/FkAWHAdi0QtGCGc+hofE98= -golang.org/x/oauth2 v0.37.0/go.mod h1:IxwZNxUULJmpBFf9K/9NTMSIfZZuvuTy1gGxhigP/58= +golang.org/x/mod v0.43.0 h1:MFuq5J6s35W9D3IjkwyWc9vHh0nENOrt5K8Iof4ofmg= +golang.org/x/mod v0.43.0/go.mod h1:4ec1JnuyBz5+FIVhg86UsA39YG8BpnrZdJYSNHmGzHY= +golang.org/x/net v0.63.0 h1:HCoTmNh9EpD1PpK8gBNFY4gcTY4N+KQEO8ylfIKqFJ0= +golang.org/x/net v0.63.0/go.mod h1:15JLg3IX1bLjHK264EZQEbIpTiR/KVLuo9CTRWd0pig= +golang.org/x/oauth2 v0.38.0 h1:uW7XQbcu1eoiQS7uMJvLOjPMl04bTbmY1VeRPxvbspI= +golang.org/x/oauth2 v0.38.0/go.mod h1:IxwZNxUULJmpBFf9K/9NTMSIfZZuvuTy1gGxhigP/58= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA= -golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= -golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA= -golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= -golang.org/x/term v0.47.0 h1:cpyOwQkr2Nzxe2p6KnrTG7Ei2wtzjsuSjhpXXepZ/BM= -golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY= -golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc= -golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s= +golang.org/x/sync v0.25.0 h1:dJnifr0nMV8/SBnBvdo4eSGGnrc3O4FFx6IqvtLcmRs= +golang.org/x/sync v0.25.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= +golang.org/x/sys v0.50.0 h1:dkKZEFTEKaLr1sjhs0WiKqoi8Jj5nHbS3Njmx1UoMJs= +golang.org/x/sys v0.50.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= +golang.org/x/term v0.48.0 h1:G6UU1eiSB8nl3DzeUGt7Mg+2SctI8tPS6Z5/mBt6cOk= +golang.org/x/term v0.48.0/go.mod h1:BRDLHCZr2SUjIeBHHpRyQeC9xzSAVbzY2rvKgafnHf4= +golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo= +golang.org/x/text v0.44.0/go.mod h1:S4FR1waQ9LbjQTls97SyRjDaUUVkaM+cXwwuG/G+MwY= golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE= golang.org/x/time v0.16.0/go.mod h1:rVKOqvZeKvrDKTQiAHJ7wmwP0RzleSphoEA9RcdLA0s= -golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs= -golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs= +golang.org/x/tools v0.53.0 h1:T3bIVp3zjHG9/aEiFk6BXxFh5/Vcbk7JA5hRq1cG8IU= +golang.org/x/tools v0.53.0/go.mod h1:vg+Vrb7y5mTTtxZLTdbTK8G745wcaLcsCtgCWgQONCI= golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg= golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI= golang.zx2c4.com/wireguard v0.0.0-20260522210424-ecfc5a8d5446 h1:cqHQ3AycTHvM2R7ikgyX57D+XvtcSnGylsLkOVhta/w= golang.zx2c4.com/wireguard v0.0.0-20260522210424-ecfc5a8d5446/go.mod h1:rpwXGsirqLqN2L0JDJQlwOboGHmptD5ZD6T2VmcqhTw= golang.zx2c4.com/wireguard/windows v1.1.1 h1:8/H97U1v1PNDNcBsMZgU3KFuND9MQdTsU2NOwmCXArE= golang.zx2c4.com/wireguard/windows v1.1.1/go.mod h1:+fbT3FFdX4zzYDLwJh5+HPEcNN/3HyNdzhNSVsQM+zs= -google.golang.org/genproto/googleapis/api v0.0.0-20261104224025-d1e00e9f33ab h1:n6IDWZ1RzI/NberLoLLFNrjl1H45uhc4+WYsUf5lPPc= -google.golang.org/genproto/googleapis/api v0.0.0-20261104224025-d1e00e9f33ab/go.mod h1:vHV3wJM9WZyfV7GyB+OQGq5dWVrFwCDxapPK4WlRD88= -google.golang.org/genproto/googleapis/rpc v0.0.0-20261104224025-d1e00e9f33ab h1:8sYjjefPfQ+FZEh1ZwBAqK/NifJVhOxut8nRh3SJzZM= -google.golang.org/genproto/googleapis/rpc v0.0.0-20261104224025-d1e00e9f33ab/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= +google.golang.org/genproto/googleapis/api v0.0.0-20261118221215-c8830f628b3f h1:7CbYDSDM5xqpq8v2tNm+Q057COf1lvA0gorVk+304tY= +google.golang.org/genproto/googleapis/api v0.0.0-20261118221215-c8830f628b3f/go.mod h1:CPxXEEQ1S9iJmInAF/8MNc8tKWnya8I8Kni9Zh2hV0M= +google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f h1:aDW6Vb2T1K0xbAgW+ED8iz39WlgjjX/OKiNh6tXv/+g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= google.golang.org/grpc v1.85.0 h1:BPBCfuVRQ1qvBhKDOq9uvQllMvO59rKsYhXpp7Dd8vw= google.golang.org/grpc v1.85.0/go.mod h1:0rQrOD58yjal/0EaVbGBANindixsCZNQPDV3VKtaKuQ= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= @@ -362,13 +368,13 @@ honnef.co/go/tools v0.8.1 h1:+JKf3xJ1ni4CwrhVg4/pqsfPGP6vNAXcKbMXJodYx3w= honnef.co/go/tools v0.8.1/go.mod h1:XA+OnlRA9EDh/ukGvXMNSZNKGwFQJ+5dER0ioUkOxks= howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM= howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= -k8s.io/apimachinery v0.37.1 h1:hGCYyvKHCwtwMitj2vU4vYx0Z16N9GyZk9BBnz0wDAE= -k8s.io/apimachinery v0.37.1/go.mod h1:jF84AyUi/IRIXRot5f+lm6MpxoWI+F1XgjaMmwCdTFw= +k8s.io/apimachinery v0.37.2 h1:G4t9RGoPDbQML38hz/kQQiltttgd3egg2ODCR8aIc2o= +k8s.io/apimachinery v0.37.2/go.mod h1:qaAvSNvgU2x07wRM95MSHSJTPQ/ob/LeNAGbeDgqQJg= sigs.k8s.io/json v0.0.0-20260909141634-11ed52e25bc5 h1:k9jo7ED/fsfOcz3L1P20P5tjTNtsdQNwMOG2aKzHrl8= sigs.k8s.io/json v0.0.0-20260909141634-11ed52e25bc5/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= software.sslmate.com/src/go-pkcs12 v0.7.3 h1:JBQD3FDqYjTeyDAeZQklj2ar88ykBLtALloPJHyAauU= software.sslmate.com/src/go-pkcs12 v0.7.3/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI= -tailscale.com v1.104.5 h1:TLemRww20+bcQ0FEVTTZ7yMtVDZ4pOpSCL86Oo9g3mA= -tailscale.com v1.104.5/go.mod h1:Hq4zB8UpaxMW1fvqO30CLVQo3A7Ith0t9MnvEyiuoSA= +tailscale.com v1.104.7 h1:YqImcXyNIe25x7Qwei8PgbtkjFd3pKed9cFY0Flkitc= +tailscale.com v1.104.7/go.mod h1:pNl682NgUoac2/Um3khv8pduX3D1YPBZTL067+zo8wY= diff --git a/tests/e2e/admin/size_reservation_test.go b/tests/e2e/admin/size_reservation_test.go new file mode 100644 index 0000000..8f681c3 --- /dev/null +++ b/tests/e2e/admin/size_reservation_test.go @@ -0,0 +1,380 @@ +package admin_e2e + +import ( + "fmt" + "testing" + + "connectrpc.com/connect" + "github.com/metal-stack/api/go/client" + adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" + apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" + e2erootcmd "github.com/metal-stack/cli/testing/e2e" + "github.com/metal-stack/cli/tests/e2e/testresources" + e2e "github.com/metal-stack/metal-lib/pkg/genericcli/e2e" + "github.com/spf13/afero" + "github.com/stretchr/testify/require" +) + +func Test_AdminSizeReservationCmd_List(t *testing.T) { + tests := []*e2e.Test[adminv2.SizeReservationServiceListResponse, []*apiv2.SizeReservation]{ + { + Name: "list", + CmdArgs: []string{"admin", "size", "reservation", "list"}, + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceListRequest{ + Query: &apiv2.SizeReservationQuery{}, + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceListResponse{ + SizeReservations: []*apiv2.SizeReservation{ + testresources.SizeReservation2(), + testresources.SizeReservation1(), + }, + }) + }, + }, + }, + }), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + b2c3d4e5-f6a7-8901-bcde-f12345678901 reservation-b second reservation f3b4e6a1-2c8d-4e5f-a7b9-1d3e5f7a9b0c g1-medium-x86 partition-2 1 + `), + WantWideTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT LABELS + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 a=b + b2c3d4e5-f6a7-8901-bcde-f12345678901 reservation-b second reservation f3b4e6a1-2c8d-4e5f-a7b9-1d3e5f7a9b0c g1-medium-x86 partition-2 1 c=d + `), + Template: new("{{ .id }} {{ .name }}"), + WantTemplate: new(` +a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a +b2c3d4e5-f6a7-8901-bcde-f12345678901 reservation-b + `), + WantMarkdown: new(` + | ID | NAME | DESCRIPTION | PROJECT | SIZE | PARTITIONS | AMOUNT | + |--------------------------------------|---------------|--------------------|--------------------------------------|---------------|-------------|--------| + | a1b2c3d4-e5f6-7890-abcd-ef1234567890 | reservation-a | first reservation | 0d81bca7-73f6-4da3-8397-4a8c52a0c583 | v1-medium-x86 | partition-1 | 3 | + | b2c3d4e5-f6a7-8901-bcde-f12345678901 | reservation-b | second reservation | f3b4e6a1-2c8d-4e5f-a7b9-1d3e5f7a9b0c | g1-medium-x86 | partition-2 | 1 | + `), + }, + } + for _, tt := range tests { + tt.TestCmd(t) + } +} + +func Test_AdminSizeReservationCmd_Describe(t *testing.T) { + tests := []*e2e.Test[adminv2.SizeReservationServiceListResponse, *apiv2.SizeReservation]{ + { + Name: "describe", + CmdArgs: []string{"admin", "size", "reservation", "describe", testresources.SizeReservation1().Id}, + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceListRequest{ + Query: &apiv2.SizeReservationQuery{ + Id: new(testresources.SizeReservation1().Id), + }, + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceListResponse{ + SizeReservations: []*apiv2.SizeReservation{ + testresources.SizeReservation1(), + }, + }) + }, + }, + }, + }), + WantProtoObject: testresources.SizeReservation1(), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + WantMarkdown: new(` + | ID | NAME | DESCRIPTION | PROJECT | SIZE | PARTITIONS | AMOUNT | + |--------------------------------------|---------------|-------------------|--------------------------------------|---------------|-------------|--------| + | a1b2c3d4-e5f6-7890-abcd-ef1234567890 | reservation-a | first reservation | 0d81bca7-73f6-4da3-8397-4a8c52a0c583 | v1-medium-x86 | partition-1 | 3 | + `), + }, + } + for _, tt := range tests { + tt.TestCmd(t) + } +} + +func Test_AdminSizeReservationCmd_Delete(t *testing.T) { + tests := []*e2e.Test[adminv2.SizeReservationServiceDeleteResponse, *apiv2.SizeReservation]{ + { + Name: "delete", + CmdArgs: []string{"admin", "size", "reservation", "delete", testresources.SizeReservation1().Id}, + NewRootCmd: e2erootcmd.NewRootCmd(t, &e2erootcmd.TestConfig{ + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceDeleteRequest{ + Id: testresources.SizeReservation1().Id, + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceDeleteResponse{ + SizeReservation: testresources.SizeReservation1(), + }) + }, + }, + }, + }), + WantProtoObject: testresources.SizeReservation1(), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + WantMarkdown: new(` + | ID | NAME | DESCRIPTION | PROJECT | SIZE | PARTITIONS | AMOUNT | + |--------------------------------------|---------------|-------------------|--------------------------------------|---------------|-------------|--------| + | a1b2c3d4-e5f6-7890-abcd-ef1234567890 | reservation-a | first reservation | 0d81bca7-73f6-4da3-8397-4a8c52a0c583 | v1-medium-x86 | partition-1 | 3 | + `), + }, + } + for _, tt := range tests { + tt.TestCmd(t) + } +} + +func Test_AdminSizeReservationCmd_Create(t *testing.T) { + tests := []*e2e.Test[adminv2.SizeReservationServiceCreateResponse, *apiv2.SizeReservation]{ + { + Name: "create from file", + CmdArgs: append([]string{"admin", "size", "reservation", "create"}, e2e.AppendFromFileCommonArgs()...), + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ + FsMocks: func(fs *afero.Afero) { + require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.SizeReservation1()), 0755)) + }, + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceCreateRequest{ + SizeReservation: testresources.SizeReservation1(), + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceCreateResponse{ + SizeReservation: testresources.SizeReservation1(), + }) + }, + }, + }, + }), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + WantMarkdown: new(` + | ID | NAME | DESCRIPTION | PROJECT | SIZE | PARTITIONS | AMOUNT | + |--------------------------------------|---------------|-------------------|--------------------------------------|---------------|-------------|--------| + | a1b2c3d4-e5f6-7890-abcd-ef1234567890 | reservation-a | first reservation | 0d81bca7-73f6-4da3-8397-4a8c52a0c583 | v1-medium-x86 | partition-1 | 3 | + `), + }, + { + Name: "create from flags", + CmdArgs: []string{"admin", "size", "reservation", "create", "--name", "reservation-a", "--description", "first reservation", "--project", testresources.Project1().Uuid, "--size", testresources.Size1().Id, "--partitions", testresources.Partition1().Id, "--amount", "3", "--labels", "a=b"}, + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceCreateRequest{ + SizeReservation: &apiv2.SizeReservation{ + Name: "reservation-a", + Description: "first reservation", + Project: testresources.Project1().Uuid, + Size: testresources.Size1().Id, + Partitions: []string{testresources.Partition1().Id}, + Amount: 3, + Meta: &apiv2.Meta{ + Labels: testresources.SizeReservation1().Meta.Labels, + }, + }, + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceCreateResponse{ + SizeReservation: testresources.SizeReservation1(), + }) + }, + }, + }, + }), + WantProtoObject: testresources.SizeReservation1(), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + }, + } + for _, tt := range tests { + tt.TestCmd(t) + } +} + +func Test_AdminSizeReservationCmd_Update(t *testing.T) { + tests := []*e2e.Test[adminv2.SizeReservationServiceUpdateResponse, *apiv2.SizeReservation]{ + { + Name: "update from file", + CmdArgs: append([]string{"admin", "size", "reservation", "update"}, e2e.AppendFromFileCommonArgs()...), + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ + FsMocks: func(fs *afero.Afero) { + require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.SizeReservation1()), 0755)) + }, + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceUpdateRequest{ + Id: testresources.SizeReservation1().Id, + Name: new(testresources.SizeReservation1().Name), + Description: new(testresources.SizeReservation1().Description), + UpdateMeta: &apiv2.UpdateMeta{ + LockingStrategy: apiv2.OptimisticLockingStrategy_OPTIMISTIC_LOCKING_STRATEGY_SERVER, + }, + Partitions: testresources.SizeReservation1().Partitions, + Amount: new(testresources.SizeReservation1().Amount), + Labels: &apiv2.UpdateLabels{ + Strategy: &apiv2.UpdateLabels_Replace{ + Replace: testresources.SizeReservation1().Meta.Labels, + }, + }, + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceUpdateResponse{ + SizeReservation: testresources.SizeReservation1(), + }) + }, + }, + }, + }), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + }, + { + Name: "update from flags", + CmdArgs: []string{"admin", "size", "reservation", "update", testresources.SizeReservation1().Id, "--description", "updated reservation", "--amount", "5", "--partitions", testresources.Partition1().Id, "--add-labels", "x=y"}, + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceUpdateRequest{ + Id: testresources.SizeReservation1().Id, + UpdateMeta: &apiv2.UpdateMeta{ + LockingStrategy: apiv2.OptimisticLockingStrategy_OPTIMISTIC_LOCKING_STRATEGY_SERVER, + }, + Description: new("updated reservation"), + Amount: new(int32(5)), + Partitions: []string{testresources.Partition1().Id}, + Labels: &apiv2.UpdateLabels{ + Strategy: &apiv2.UpdateLabels_Patch{ + Patch: &apiv2.LabelsPatch{ + Update: &apiv2.Labels{ + Labels: map[string]string{ + "x": "y", + }, + }, + }, + }, + }, + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceUpdateResponse{ + SizeReservation: testresources.SizeReservation1(), + }) + }, + }, + }, + }), + WantProtoObject: testresources.SizeReservation1(), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + }, + } + for _, tt := range tests { + tt.TestCmd(t) + } +} + +func Test_AdminSizeReservationCmd_Apply(t *testing.T) { + tests := []*e2e.Test[adminv2.SizeReservationServiceUpdateResponse, *apiv2.SizeReservation]{ + { + Name: "apply", + CmdArgs: append([]string{"admin", "size", "reservation", "apply"}, e2e.AppendFromFileCommonArgs()...), + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ + FsMocks: func(fs *afero.Afero) { + require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.SizeReservation1()), 0755)) + }, + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceCreateRequest{ + SizeReservation: testresources.SizeReservation1(), + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceCreateResponse{ + SizeReservation: testresources.SizeReservation1(), + }) + }, + }, + }, + }), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + }, + { + Name: "apply already exists", + CmdArgs: append([]string{"admin", "size", "reservation", "apply"}, e2e.AppendFromFileCommonArgs()...), + NewRootCmd: e2erootcmd.NewRootCmd(t, + &e2erootcmd.TestConfig{ + FsMocks: func(fs *afero.Afero) { + require.NoError(t, fs.WriteFile(e2e.InputFilePath, e2e.MustMarshal(t, testresources.SizeReservation1()), 0755)) + }, + ClientCalls: []client.ClientCall{ + { + WantRequest: &adminv2.SizeReservationServiceCreateRequest{ + SizeReservation: testresources.SizeReservation1(), + }, + WantError: connect.NewError(connect.CodeAlreadyExists, fmt.Errorf("already exists")), + }, + { + WantRequest: &adminv2.SizeReservationServiceUpdateRequest{ + Id: testresources.SizeReservation1().Id, + Name: new(testresources.SizeReservation1().Name), + Description: new(testresources.SizeReservation1().Description), + UpdateMeta: &apiv2.UpdateMeta{ + LockingStrategy: apiv2.OptimisticLockingStrategy_OPTIMISTIC_LOCKING_STRATEGY_SERVER, + }, + Partitions: testresources.SizeReservation1().Partitions, + Amount: new(testresources.SizeReservation1().Amount), + Labels: &apiv2.UpdateLabels{ + Strategy: &apiv2.UpdateLabels_Replace{ + Replace: testresources.SizeReservation1().Meta.Labels, + }, + }, + }, + WantResponse: func() connect.AnyResponse { + return connect.NewResponse(&adminv2.SizeReservationServiceUpdateResponse{ + SizeReservation: testresources.SizeReservation1(), + }) + }, + }, + }, + }), + WantTable: new(` + ID NAME DESCRIPTION PROJECT SIZE PARTITIONS AMOUNT + a1b2c3d4-e5f6-7890-abcd-ef1234567890 reservation-a first reservation 0d81bca7-73f6-4da3-8397-4a8c52a0c583 v1-medium-x86 partition-1 3 + `), + }, + } + for _, tt := range tests { + tt.TestCmd(t) + } +} diff --git a/tests/e2e/testresources/size_reservations.go b/tests/e2e/testresources/size_reservations.go new file mode 100644 index 0000000..ddcf102 --- /dev/null +++ b/tests/e2e/testresources/size_reservations.go @@ -0,0 +1,44 @@ +package testresources + +import ( + apiv2 "github.com/metal-stack/api/go/metalstack/api/v2" +) + +var ( + SizeReservation1 = func() *apiv2.SizeReservation { + return &apiv2.SizeReservation{ + Id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", + Name: "reservation-a", + Description: "first reservation", + Project: Project1().Uuid, + Size: Size1().Id, + Partitions: []string{Partition1().Id}, + Amount: 3, + Meta: &apiv2.Meta{ + Labels: &apiv2.Labels{ + Labels: map[string]string{ + "a": "b", + }, + }, + }, + } + } + SizeReservation2 = func() *apiv2.SizeReservation { + return &apiv2.SizeReservation{ + Id: "b2c3d4e5-f6a7-8901-bcde-f12345678901", + Name: "reservation-b", + Description: "second reservation", + Project: Project2().Uuid, + Size: Size2().Id, + Partitions: []string{Partition2().Id}, + Amount: 1, + Meta: &apiv2.Meta{ + Labels: &apiv2.Labels{ + Labels: map[string]string{ + "c": "d", + }, + }, + }, + } + } +)