Skip to content

Commit

Permalink
Allow adding labels to partitions.
Browse files Browse the repository at this point in the history
This can be useful to attach arbitrary information to a partition (in our case we need a speaking description of a region).
  • Loading branch information
Gerrit91 committed Jan 10, 2024
1 parent 451415e commit d0ff776
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 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
6 changes: 4 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,6 +26,7 @@ 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 {
Expand Down
28 changes: 28 additions & 0 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

0 comments on commit d0ff776

Please sign in to comment.