Skip to content

Commit

Permalink
Add labels to size reservations. (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jun 7, 2024
1 parent 818f4d3 commit d20fd82
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
9 changes: 5 additions & 4 deletions cmd/metal-api/internal/metal/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cmd/metal-api/internal/service/size-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/metal-api/internal/service/size-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func TestCreateSize(t *testing.T) {
ProjectID: "a",
PartitionIDs: []string{testdata.Partition1.ID},
Description: "test",
Labels: map[string]string{"a": "b"},
},
},
}
Expand Down
27 changes: 15 additions & 12 deletions cmd/metal-api/internal/service/v1/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down Expand Up @@ -4694,6 +4709,7 @@
}
},
"required": [
"labels",
"partitionid",
"projectallocations",
"projectid",
Expand Down

0 comments on commit d20fd82

Please sign in to comment.