mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-04 04:04:02 +00:00
Add resource modifier for velero restore describe CLI
Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
1
changelogs/unreleased/8139-blackpiglet
Normal file
1
changelogs/unreleased/8139-blackpiglet
Normal file
@@ -0,0 +1 @@
|
||||
Add resource modifier for velero restore describe CLI
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/volume"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
@@ -39,7 +40,15 @@ import (
|
||||
"github.com/vmware-tanzu/velero/pkg/util/results"
|
||||
)
|
||||
|
||||
func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *velerov1api.Restore, podVolumeRestores []velerov1api.PodVolumeRestore, details bool, insecureSkipTLSVerify bool, caCertFile string) string {
|
||||
func DescribeRestore(
|
||||
ctx context.Context,
|
||||
kbClient kbclient.Client,
|
||||
restore *velerov1api.Restore,
|
||||
podVolumeRestores []velerov1api.PodVolumeRestore,
|
||||
details bool,
|
||||
insecureSkipTLSVerify bool,
|
||||
caCertFile string,
|
||||
) string {
|
||||
return Describe(func(d *Describer) {
|
||||
d.DescribeMetadata(restore.ObjectMeta)
|
||||
|
||||
@@ -196,6 +205,11 @@ func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *vel
|
||||
d.Println()
|
||||
d.Printf("Preserve Service NodePorts:\t%s\n", BoolPointerString(restore.Spec.PreserveNodePorts, "false", "true", "auto"))
|
||||
|
||||
if restore.Spec.ResourceModifier != nil {
|
||||
d.Println()
|
||||
DescribeResourceModifier(d, restore.Spec.ResourceModifier)
|
||||
}
|
||||
|
||||
describeUploaderConfigForRestore(d, restore.Spec)
|
||||
|
||||
d.Println()
|
||||
@@ -472,3 +486,10 @@ func describeRestoreResourceList(ctx context.Context, kbClient kbclient.Client,
|
||||
d.Printf("\t%s:\n\t\t- %s\n", gvk, strings.Join(resourceList[gvk], "\n\t\t- "))
|
||||
}
|
||||
}
|
||||
|
||||
// DescribeResourceModifier describes resource policies in human-readable format
|
||||
func DescribeResourceModifier(d *Describer, resModifier *v1.TypedLocalObjectReference) {
|
||||
d.Printf("Resource modifier:\n")
|
||||
d.Printf("\tType:\t%s\n", resModifier.Kind)
|
||||
d.Printf("\tName:\t%s\n", resModifier.Name)
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@ package output
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/volume"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/volume"
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||
"github.com/vmware-tanzu/velero/pkg/itemoperation"
|
||||
@@ -389,3 +390,28 @@ CSI Snapshot Restores:
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescribeResourceModifier(t *testing.T) {
|
||||
d := &Describer{
|
||||
Prefix: "",
|
||||
out: &tabwriter.Writer{},
|
||||
buf: &bytes.Buffer{},
|
||||
}
|
||||
|
||||
d.out.Init(d.buf, 0, 8, 2, ' ', 0)
|
||||
|
||||
DescribeResourceModifier(d, &v1.TypedLocalObjectReference{
|
||||
APIGroup: &v1.SchemeGroupVersion.Group,
|
||||
Kind: "ConfigMap",
|
||||
Name: "resourceModifier",
|
||||
})
|
||||
d.out.Flush()
|
||||
|
||||
expectOutput := `Resource modifier:
|
||||
Type: ConfigMap
|
||||
Name: resourceModifier
|
||||
`
|
||||
|
||||
fmt.Println(d.buf.String())
|
||||
require.Equal(t, expectOutput, d.buf.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user