Skip to content

Commit

Permalink
Allow adding labels to partitions. (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jan 10, 2024
1 parent 451415e commit 6457ade
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/metal-api/internal/metal/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Partition struct {
BootConfiguration BootConfiguration `rethinkdb:"bootconfig" json:"bootconfig"`
MgmtServiceAddress string `rethinkdb:"mgmtserviceaddr" json:"mgmtserviceaddr"`
PrivateNetworkPrefixLength uint8 `rethinkdb:"privatenetworkprefixlength" json:"privatenetworkprefixlength"`
Labels map[string]string `rethinkdb:"labels" json:"labels"`
}

// BootConfiguration defines the metal-hammer initrd, kernel and commandline
Expand Down
8 changes: 8 additions & 0 deletions cmd/metal-api/internal/service/partition-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func (r *partitionResource) createPartition(request *restful.Request, response *
if requestPayload.MgmtServiceAddress != nil {
mgmtServiceAddress = *requestPayload.MgmtServiceAddress
}
labels := map[string]string{}
if requestPayload.Labels != nil {
labels = requestPayload.Labels
}
prefixLength := uint8(22)
if requestPayload.PrivateNetworkPrefixLength != nil {
prefixLength = uint8(*requestPayload.PrivateNetworkPrefixLength)
Expand Down Expand Up @@ -207,6 +211,7 @@ func (r *partitionResource) createPartition(request *restful.Request, response *
Name: name,
Description: description,
},
Labels: labels,
MgmtServiceAddress: mgmtServiceAddress,
PrivateNetworkPrefixLength: prefixLength,
BootConfiguration: metal.BootConfiguration{
Expand Down Expand Up @@ -274,6 +279,9 @@ func (r *partitionResource) updatePartition(request *restful.Request, response *
if requestPayload.MgmtServiceAddress != nil {
newPartition.MgmtServiceAddress = *requestPayload.MgmtServiceAddress
}
if requestPayload.Labels != nil {
newPartition.Labels = requestPayload.Labels
}
if requestPayload.PartitionBootConfiguration.ImageURL != nil {
err = checkImageURL("image", *requestPayload.PartitionBootConfiguration.ImageURL)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions cmd/metal-api/internal/service/v1/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
)

type PartitionBase struct {
MgmtServiceAddress *string `json:"mgmtserviceaddress" description:"the address to the management service of this partition" optional:"true"`
PrivateNetworkPrefixLength *int `json:"privatenetworkprefixlength" description:"the length of private networks for the machine's child networks in this partition, default 22" optional:"true" minimum:"16" maximum:"30"`
MgmtServiceAddress *string `json:"mgmtserviceaddress" description:"the address to the management service of this partition" optional:"true"`
PrivateNetworkPrefixLength *int `json:"privatenetworkprefixlength" description:"the length of private networks for the machine's child networks in this partition, default 22" optional:"true" minimum:"16" maximum:"30"`
Labels map[string]string `json:"labels" description:"free labels that you associate with this partition" optional:"true"`
}

type PartitionBootConfiguration struct {
Expand All @@ -25,13 +26,15 @@ type PartitionUpdateRequest struct {
Common
MgmtServiceAddress *string `json:"mgmtserviceaddress" description:"the address to the management service of this partition" optional:"true"`
PartitionBootConfiguration *PartitionBootConfiguration `json:"bootconfig" description:"the boot configuration of this partition" optional:"true"`
Labels map[string]string `json:"labels" description:"free labels that you associate with this partition" optional:"true"`
}

type PartitionResponse struct {
Common
PartitionBase
PartitionBootConfiguration PartitionBootConfiguration `json:"bootconfig" description:"the boot configuration of this partition"`
Timestamps
Labels map[string]string `json:"labels" description:"free labels that you associate with this partition" optional:"true"`
}

type PartitionCapacityRequest struct {
Expand Down Expand Up @@ -87,6 +90,7 @@ func NewPartitionResponse(p *metal.Partition) *PartitionResponse {
Created: p.Created,
Changed: p.Changed,
},
Labels: p.Labels,
}
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/metal-api/internal/service/v1/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ type SizeCreateRequest struct {
Common
SizeConstraints []SizeConstraint `json:"constraints" description:"a list of constraints that defines this size"`
SizeReservations []SizeReservation `json:"reservations,omitempty" description:"reservations for this size, which are considered during machine allocation" optional:"true"`
Labels map[string]string `json:"labels" description:"free labels that you associate with this network." optional:"true"`
Labels map[string]string `json:"labels" description:"free labels that you associate with this size." optional:"true"`
}

type SizeUpdateRequest struct {
Common
SizeConstraints *[]SizeConstraint `json:"constraints" description:"a list of constraints that defines this size" optional:"true"`
SizeReservations []SizeReservation `json:"reservations,omitempty" description:"reservations for this size, which are considered during machine allocation" optional:"true"`
Labels map[string]string `json:"labels" description:"free labels that you associate with this network." optional:"true"`
Labels map[string]string `json:"labels" description:"free labels that you associate with this size." optional:"true"`
}

type SizeResponse struct {
Common
SizeConstraints []SizeConstraint `json:"constraints" description:"a list of constraints that defines this size"`
SizeReservations []SizeReservation `json:"reservations,omitempty" description:"reservations for this size, which are considered during machine allocation" optional:"true"`
Labels map[string]string `json:"labels" description:"free labels that you associate with this network."`
Labels map[string]string `json:"labels" description:"free labels that you associate with this size."`
Timestamps
}

Expand Down
34 changes: 31 additions & 3 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3848,6 +3848,13 @@
},
"v1.PartitionBase": {
"properties": {
"labels": {
"additionalProperties": {
"type": "string"
},
"description": "free labels that you associate with this partition",
"type": "object"
},
"mgmtserviceaddress": {
"description": "the address to the management service of this partition",
"type": "string"
Expand Down Expand Up @@ -3933,6 +3940,13 @@
"type": "string",
"uniqueItems": true
},
"labels": {
"additionalProperties": {
"type": "string"
},
"description": "free labels that you associate with this partition",
"type": "object"
},
"mgmtserviceaddress": {
"description": "the address to the management service of this partition",
"type": "string"
Expand Down Expand Up @@ -3981,6 +3995,13 @@
"type": "string",
"uniqueItems": true
},
"labels": {
"additionalProperties": {
"type": "string"
},
"description": "free labels that you associate with this partition",
"type": "object"
},
"mgmtserviceaddress": {
"description": "the address to the management service of this partition",
"type": "string"
Expand Down Expand Up @@ -4017,6 +4038,13 @@
"type": "string",
"uniqueItems": true
},
"labels": {
"additionalProperties": {
"type": "string"
},
"description": "free labels that you associate with this partition",
"type": "object"
},
"mgmtserviceaddress": {
"description": "the address to the management service of this partition",
"type": "string"
Expand Down Expand Up @@ -4353,7 +4381,7 @@
"additionalProperties": {
"type": "string"
},
"description": "free labels that you associate with this network.",
"description": "free labels that you associate with this size.",
"type": "object"
},
"name": {
Expand Down Expand Up @@ -4611,7 +4639,7 @@
"additionalProperties": {
"type": "string"
},
"description": "free labels that you associate with this network.",
"description": "free labels that you associate with this size.",
"type": "object"
},
"name": {
Expand Down Expand Up @@ -4665,7 +4693,7 @@
"additionalProperties": {
"type": "string"
},
"description": "free labels that you associate with this network.",
"description": "free labels that you associate with this size.",
"type": "object"
},
"name": {
Expand Down

0 comments on commit 6457ade

Please sign in to comment.