Skip to content

Commit

Permalink
Add resource modifier for velero restore describe CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Aug 21, 2024
1 parent 8fde4a0 commit cfb83c7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
23 changes: 22 additions & 1 deletion pkg/cmd/util/output/restore_describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
30 changes: 28 additions & 2 deletions pkg/cmd/util/output/restore_describer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}

0 comments on commit cfb83c7

Please sign in to comment.