From d20fd82131e1344a6aa52aaabeb0e23b5f980643 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Fri, 7 Jun 2024 10:30:55 +0200 Subject: [PATCH] Add labels to size reservations. (#534) --- cmd/metal-api/internal/metal/size.go | 9 ++++--- .../internal/service/size-service.go | 3 +++ .../internal/service/size-service_test.go | 1 + cmd/metal-api/internal/service/v1/size.go | 27 ++++++++++--------- spec/metal-api.json | 16 +++++++++++ 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/cmd/metal-api/internal/metal/size.go b/cmd/metal-api/internal/metal/size.go index 698ad5222..13228b5bb 100644 --- a/cmd/metal-api/internal/metal/size.go +++ b/cmd/metal-api/internal/metal/size.go @@ -20,10 +20,11 @@ type Size struct { // Reservation defines a reservation of a size for machine allocations type Reservation struct { - Amount int `rethinkdb:"amount" json:"amount"` - Description string `rethinkdb:"description" json:"description"` - ProjectID string `rethinkdb:"projectid" json:"projectid"` - PartitionIDs []string `rethinkdb:"partitionids" json:"partitionids"` + Amount int `rethinkdb:"amount" json:"amount"` + Description string `rethinkdb:"description" json:"description"` + ProjectID string `rethinkdb:"projectid" json:"projectid"` + PartitionIDs []string `rethinkdb:"partitionids" json:"partitionids"` + Labels map[string]string `rethinkdb:"labels" json:"labels"` } type Reservations []Reservation diff --git a/cmd/metal-api/internal/service/size-service.go b/cmd/metal-api/internal/service/size-service.go index d80e540c8..492006b1d 100644 --- a/cmd/metal-api/internal/service/size-service.go +++ b/cmd/metal-api/internal/service/size-service.go @@ -267,6 +267,7 @@ func (r *sizeResource) createSize(request *restful.Request, response *restful.Re Description: r.Description, ProjectID: r.ProjectID, PartitionIDs: r.PartitionIDs, + Labels: r.Labels, }) } @@ -384,6 +385,7 @@ func (r *sizeResource) updateSize(request *restful.Request, response *restful.Re Description: r.Description, ProjectID: r.ProjectID, PartitionIDs: r.PartitionIDs, + Labels: r.Labels, }) } newSize.Reservations = reservations @@ -471,6 +473,7 @@ func (r *sizeResource) listSizeReservations(request *restful.Request, response * Reservations: reservation.Amount, UsedReservations: min(reservation.Amount, allocations), ProjectAllocations: allocations, + Labels: reservation.Labels, }) } } diff --git a/cmd/metal-api/internal/service/size-service_test.go b/cmd/metal-api/internal/service/size-service_test.go index 60ed7d237..d604ee62a 100644 --- a/cmd/metal-api/internal/service/size-service_test.go +++ b/cmd/metal-api/internal/service/size-service_test.go @@ -210,6 +210,7 @@ func TestCreateSize(t *testing.T) { ProjectID: "a", PartitionIDs: []string{testdata.Partition1.ID}, Description: "test", + Labels: map[string]string{"a": "b"}, }, }, } diff --git a/cmd/metal-api/internal/service/v1/size.go b/cmd/metal-api/internal/service/v1/size.go index 92a48048d..b8a383fdb 100644 --- a/cmd/metal-api/internal/service/v1/size.go +++ b/cmd/metal-api/internal/service/v1/size.go @@ -12,10 +12,11 @@ type SizeConstraint struct { } type SizeReservation struct { - Amount int `json:"amount" description:"the amount of reserved machine allocations for this size"` - Description string `json:"description,omitempty" description:"a description for this reservation"` - ProjectID string `json:"projectid" description:"the project for which this size reservation is considered"` - PartitionIDs []string `json:"partitionids" description:"the partitions in which this size reservation is considered, the amount is valid for every partition"` + Amount int `json:"amount" description:"the amount of reserved machine allocations for this size"` + Description string `json:"description,omitempty" description:"a description for this reservation"` + ProjectID string `json:"projectid" description:"the project for which this size reservation is considered"` + PartitionIDs []string `json:"partitionids" description:"the partitions in which this size reservation is considered, the amount is valid for every partition"` + Labels map[string]string `json:"labels" description:"free labels associated with this size reservation."` } type SizeCreateRequest struct { @@ -41,14 +42,15 @@ type SizeResponse struct { } type SizeReservationResponse struct { - SizeID string `json:"sizeid" description:"the size id of this size reservation"` - PartitionID string `json:"partitionid" description:"the partition id of this size reservation"` - Tenant string `json:"tenant" description:"the tenant of this size reservation"` - ProjectID string `json:"projectid" description:"the project id of this size reservation"` - ProjectName string `json:"projectname" description:"the project name of this size reservation"` - Reservations int `json:"reservations" description:"the amount of reservations of this size reservation"` - UsedReservations int `json:"usedreservations" description:"the used amount of reservations of this size reservation"` - ProjectAllocations int `json:"projectallocations" description:"the amount of allocations of this project referenced by this size reservation"` + SizeID string `json:"sizeid" description:"the size id of this size reservation"` + PartitionID string `json:"partitionid" description:"the partition id of this size reservation"` + Tenant string `json:"tenant" description:"the tenant of this size reservation"` + ProjectID string `json:"projectid" description:"the project id of this size reservation"` + ProjectName string `json:"projectname" description:"the project name of this size reservation"` + Reservations int `json:"reservations" description:"the amount of reservations of this size reservation"` + UsedReservations int `json:"usedreservations" description:"the used amount of reservations of this size reservation"` + ProjectAllocations int `json:"projectallocations" description:"the amount of allocations of this project referenced by this size reservation"` + Labels map[string]string `json:"labels" description:"free labels associated with this size reservation."` } type SizeSuggestRequest struct { @@ -91,6 +93,7 @@ func NewSizeResponse(s *metal.Size) *SizeResponse { Description: r.Description, ProjectID: r.ProjectID, PartitionIDs: r.PartitionIDs, + Labels: r.Labels, } reservations = append(reservations, reservation) } diff --git a/spec/metal-api.json b/spec/metal-api.json index 2b05d109c..a832a0557 100644 --- a/spec/metal-api.json +++ b/spec/metal-api.json @@ -4637,6 +4637,13 @@ "description": "a description for this reservation", "type": "string" }, + "labels": { + "additionalProperties": { + "type": "string" + }, + "description": "free labels associated with this size reservation.", + "type": "object" + }, "partitionids": { "description": "the partitions in which this size reservation is considered, the amount is valid for every partition", "items": { @@ -4651,12 +4658,20 @@ }, "required": [ "amount", + "labels", "partitionids", "projectid" ] }, "v1.SizeReservationResponse": { "properties": { + "labels": { + "additionalProperties": { + "type": "string" + }, + "description": "free labels associated with this size reservation.", + "type": "object" + }, "partitionid": { "description": "the partition id of this size reservation", "type": "string" @@ -4694,6 +4709,7 @@ } }, "required": [ + "labels", "partitionid", "projectallocations", "projectid",