mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-24 08:54:30 +00:00
Merge pull request #1741 from prydonius/1731-sort-resource-list
sort output of resource list in `velero backup describe --details`
This commit is contained in:
@@ -0,0 +1 @@
|
||||
sort output of resource list in `velero backup describe --details`
|
||||
@@ -18,6 +18,7 @@ package backup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
"github.com/heptio/velero/pkg/util/collections"
|
||||
@@ -58,5 +59,11 @@ func (r *Request) BackupResourceList() map[string][]string {
|
||||
}
|
||||
resources[i.resource] = append(resources[i.resource], entry)
|
||||
}
|
||||
|
||||
// sort namespace/name entries for each GVK
|
||||
for _, v := range resources {
|
||||
sort.Strings(v)
|
||||
}
|
||||
|
||||
return resources
|
||||
}
|
||||
|
||||
@@ -50,9 +50,33 @@ func TestRequest_BackupResourceList(t *testing.T) {
|
||||
}
|
||||
|
||||
req := Request{BackedUpItems: backedUpItems}
|
||||
assert.Equal(t, req.BackupResourceList(), map[string][]string{
|
||||
assert.Equal(t, map[string][]string{
|
||||
"apps/v1/Deployment": {"default/my-deploy"},
|
||||
"v1/Pod": {"ns1/pod1", "ns2/pod2"},
|
||||
"v1/PersistentVolume": {"my-pv"},
|
||||
})
|
||||
}, req.BackupResourceList())
|
||||
}
|
||||
|
||||
func TestRequest_BackupResourceListEntriesSorted(t *testing.T) {
|
||||
items := []itemKey{
|
||||
{
|
||||
resource: "v1/Pod",
|
||||
name: "pod2",
|
||||
namespace: "ns2",
|
||||
},
|
||||
{
|
||||
resource: "v1/Pod",
|
||||
name: "pod1",
|
||||
namespace: "ns1",
|
||||
},
|
||||
}
|
||||
backedUpItems := map[itemKey]struct{}{}
|
||||
for _, it := range items {
|
||||
backedUpItems[it] = struct{}{}
|
||||
}
|
||||
|
||||
req := Request{BackedUpItems: backedUpItems}
|
||||
assert.Equal(t, map[string][]string{
|
||||
"v1/Pod": {"ns1/pod1", "ns2/pod2"},
|
||||
}, req.BackupResourceList())
|
||||
}
|
||||
|
||||
@@ -284,8 +284,16 @@ func describeBackupResourceList(d *Describer, backup *velerov1api.Backup, velero
|
||||
}
|
||||
|
||||
d.Println("Resource List:")
|
||||
for gvk, items := range resourceList {
|
||||
d.Printf("\t%s:\n\t\t- %s\n", gvk, strings.Join(items, "\n\t\t- "))
|
||||
|
||||
// Sort GVKs in output
|
||||
gvks := make([]string, 0, len(resourceList))
|
||||
for gvk := range resourceList {
|
||||
gvks = append(gvks, gvk)
|
||||
}
|
||||
sort.Strings(gvks)
|
||||
|
||||
for _, gvk := range gvks {
|
||||
d.Printf("\t%s:\n\t\t- %s\n", gvk, strings.Join(resourceList[gvk], "\n\t\t- "))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user