Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding labels to partitions. #486

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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