From c9689a19429c7f3f8657f30d0a2eacf90ed31fe7 Mon Sep 17 00:00:00 2001 From: Gerrit91 Date: Wed, 10 Jan 2024 09:31:27 +0100 Subject: [PATCH 1/2] Partitions now have labels. --- cmd/partition.go | 1 + cmd/partition_test.go | 11 +++++++---- cmd/tableprinters/partition.go | 16 +++++++++++++++- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cmd/partition.go b/cmd/partition.go index 7650c128..09284a24 100644 --- a/cmd/partition.go +++ b/cmd/partition.go @@ -159,6 +159,7 @@ func partitionResponseToUpdate(r *models.V1PartitionResponse) *models.V1Partitio ID: r.ID, Mgmtserviceaddress: r.Mgmtserviceaddress, Name: r.Name, + Labels: r.Labels, } } diff --git a/cmd/partition_test.go b/cmd/partition_test.go index 95ed48e8..43b2d317 100644 --- a/cmd/partition_test.go +++ b/cmd/partition_test.go @@ -26,6 +26,9 @@ var ( Mgmtserviceaddress: "mgmt", Name: "partition-1", Privatenetworkprefixlength: 24, + Labels: map[string]string{ + "a": "b", + }, } partition2 = &models.V1PartitionResponse{ Bootconfig: &models.V1PartitionBootConfiguration{ @@ -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 }}"), @@ -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(` diff --git a/cmd/tableprinters/partition.go b/cmd/tableprinters/partition.go index 9aa5ea31..14fd6cf4 100644 --- a/cmd/tableprinters/partition.go +++ b/cmd/tableprinters/partition.go @@ -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" ) @@ -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 diff --git a/go.mod b/go.mod index 7f070551..f3a907c4 100644 --- a/go.mod +++ b/go.mod @@ -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-0.20240110082349-b3c02876b89c 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 diff --git a/go.sum b/go.sum index cc83cada..e1070e4d 100644 --- a/go.sum +++ b/go.sum @@ -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-0.20240110082349-b3c02876b89c h1:GlY0TZZvs1GbtYhXrwpA0ulP1/AiCqwp3pCkJKFECUo= +github.com/metal-stack/metal-go v0.26.2-0.20240110082349-b3c02876b89c/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= From 3146a945b0a47ff93abcafd20891e91d4acd23ed Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 10 Jan 2024 09:36:40 +0100 Subject: [PATCH 2/2] Pin. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f3a907c4..23fc1978 100644 --- a/go.mod +++ b/go.mod @@ -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.2-0.20240110082349-b3c02876b89c + 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 diff --git a/go.sum b/go.sum index e1070e4d..2241d4e1 100644 --- a/go.sum +++ b/go.sum @@ -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.2-0.20240110082349-b3c02876b89c h1:GlY0TZZvs1GbtYhXrwpA0ulP1/AiCqwp3pCkJKFECUo= -github.com/metal-stack/metal-go v0.26.2-0.20240110082349-b3c02876b89c/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=