Skip to content

Commit

Permalink
Update metal-go, partitions now have labels. (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jan 10, 2024
1 parent 230301f commit 2a46dcb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func partitionResponseToUpdate(r *models.V1PartitionResponse) *models.V1Partitio
ID: r.ID,
Mgmtserviceaddress: r.Mgmtserviceaddress,
Name: r.Name,
Labels: r.Labels,
}
}

Expand Down
11 changes: 7 additions & 4 deletions cmd/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var (
Mgmtserviceaddress: "mgmt",
Name: "partition-1",
Privatenetworkprefixlength: 24,
Labels: map[string]string{
"a": "b",
},
}
partition2 = &models.V1PartitionResponse{
Bootconfig: &models.V1PartitionBootConfiguration{
Expand Down Expand Up @@ -68,8 +71,8 @@ ID NAME DESCRIPTION
2 partition-2 partition 2
`),
wantWideTable: pointer.Pointer(`
ID NAME DESCRIPTION
1 partition-1 partition 1
ID NAME DESCRIPTION LABELS
1 partition-1 partition 1 a=b
2 partition-2 partition 2
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
Expand Down Expand Up @@ -191,8 +194,8 @@ ID NAME DESCRIPTION
1 partition-1 partition 1
`),
wantWideTable: pointer.Pointer(`
ID NAME DESCRIPTION
1 partition-1 partition 1
ID NAME DESCRIPTION LABELS
1 partition-1 partition 1 a=b
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
Expand Down
16 changes: 15 additions & 1 deletion cmd/tableprinters/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package tableprinters

import (
"fmt"
"sort"
"strings"

"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/pointer"
)

Expand All @@ -14,8 +16,20 @@ func (t *TablePrinter) PartitionTable(data []*models.V1PartitionResponse, wide b
rows [][]string
)

if wide {
header = []string{"ID", "Name", "Description", "Labels"}
}

for _, p := range data {
rows = append(rows, []string{pointer.SafeDeref(p.ID), p.Name, p.Description})
row := []string{pointer.SafeDeref(p.ID), p.Name, p.Description}

if wide {
labels := genericcli.MapToLabels(p.Labels)
sort.Strings(labels)
row = append(row, strings.Join(labels, "\n"))
}

rows = append(rows, row)
}

return header, rows, nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-openapi/runtime v0.26.2
github.com/go-openapi/strfmt v0.22.0
github.com/google/go-cmp v0.6.0
github.com/metal-stack/metal-go v0.26.1
github.com/metal-stack/metal-go v0.26.2
github.com/metal-stack/metal-lib v0.14.2
github.com/metal-stack/updater v1.2.1
github.com/metal-stack/v v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ
github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE=
github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI=
github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI=
github.com/metal-stack/metal-go v0.26.1 h1:70diputj1sD2BHVSQB2S+86bWxNYuuMZhxnU5Un5qz4=
github.com/metal-stack/metal-go v0.26.1/go.mod h1:olJ3Az7RBh39Q5WFCJOQBd7cJi0xgGYwMTEIFvkDQQY=
github.com/metal-stack/metal-go v0.26.2 h1:KZRV1wtCsj0dMo4GpW2+XemmAkPZAYFjbGe7QhhcH1k=
github.com/metal-stack/metal-go v0.26.2/go.mod h1:olJ3Az7RBh39Q5WFCJOQBd7cJi0xgGYwMTEIFvkDQQY=
github.com/metal-stack/metal-lib v0.14.2 h1:ntIZiV8fVoWsgPLXOy9xrObZr1NdU5caYUP0zzefUME=
github.com/metal-stack/metal-lib v0.14.2/go.mod h1:2wKxFXSCpA1Dr+Rq0ddpQCPKPGMWJp4cpIaVTM4lDi0=
github.com/metal-stack/security v0.7.1 h1:bwiPhT/gArl9IRJlhpDZzAs5Us6rmIt9bcuQXcLKO5k=
Expand Down

0 comments on commit 2a46dcb

Please sign in to comment.