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

Update metal-go, partitions now have labels. #231

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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/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