Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ go.work
.Trashes
ehthumbs.db
Thumbs.db

vendor/
Comment on lines +51 to +52
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you vendored locally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspecting the upstream velero implementations for some funcs that I'm using
eg the output format for -o yaml

57 changes: 29 additions & 28 deletions cmd/non-admin/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,83 +100,71 @@ func TestNonAdminBackupCommands(t *testing.T) {
name: "nonadmin get backup help",
args: []string{"nonadmin", "get", "backup", "--help"},
expectContains: []string{
"Get one or more non-admin resources",
"backup",
"Get one or more non-admin backups",
},
},
{
name: "nonadmin create backup help",
args: []string{"nonadmin", "create", "backup", "--help"},
expectContains: []string{
"Create non-admin resources",
"backup",
"bsl",
"Create a non-admin backup",
},
},
{
name: "nonadmin delete backup help",
args: []string{"nonadmin", "delete", "backup", "--help"},
expectContains: []string{
"Delete non-admin resources",
"backup",
"Delete one or more non-admin backups",
},
},
{
name: "nonadmin describe backup help",
args: []string{"nonadmin", "describe", "backup", "--help"},
expectContains: []string{
"Describe non-admin resources",
"backup",
"Describe a non-admin backup",
},
},
{
name: "nonadmin logs backup help",
args: []string{"nonadmin", "logs", "backup", "--help"},
expectContains: []string{
"Get logs for non-admin resources",
"backup",
"Show logs for a non-admin backup",
},
},
// Shorthand verb-noun order tests
{
name: "na get backup help",
args: []string{"na", "get", "backup", "--help"},
expectContains: []string{
"Get one or more non-admin resources",
"backup",
"Get one or more non-admin backups",
},
},
{
name: "na create backup help",
args: []string{"na", "create", "backup", "--help"},
expectContains: []string{
"Create non-admin resources",
"backup",
"bsl",
"Create a non-admin backup",
},
},
{
name: "na delete backup help",
args: []string{"na", "delete", "backup", "--help"},
expectContains: []string{
"Delete non-admin resources",
"backup",
"Delete one or more non-admin backups",
},
},
{
name: "na describe backup help",
args: []string{"na", "describe", "backup", "--help"},
expectContains: []string{
"Describe non-admin resources",
"backup",
"Describe a non-admin backup",
},
},
{
name: "na logs backup help",
args: []string{"na", "logs", "backup", "--help"},
expectContains: []string{
"Get logs for non-admin resources",
"backup",
"Show logs for a non-admin backup",
},
},
}
Expand Down Expand Up @@ -400,13 +388,13 @@ func TestVerbNounOrderExamples(t *testing.T) {
})

t.Run("verb commands with specific resources show proper examples", func(t *testing.T) {
// Test that verb commands with specific resources show examples
// Test that verb commands with specific resources show examples (noun-first format from underlying commands)
expectedExamples := []string{
"kubectl oadp nonadmin get backup my-backup",
"kubectl oadp nonadmin create backup my-backup",
"kubectl oadp nonadmin delete backup my-backup",
"kubectl oadp nonadmin describe backup my-backup",
"kubectl oadp nonadmin logs backup my-backup",
"kubectl oadp nonadmin backup get",
"kubectl oadp nonadmin backup create backup1",
"kubectl oadp nonadmin backup delete my-backup",
"kubectl oadp nonadmin backup describe my-backup",
"kubectl oadp nonadmin backup logs my-backup",
}

commands := [][]string{
Expand Down Expand Up @@ -510,6 +498,19 @@ func TestNonAdminBackupDeleteAllFlagExamples(t *testing.T) {
[]string{"nonadmin", "backup", "delete", "--help"},
expectedPatterns)
})

t.Run("delete help has examples section", func(t *testing.T) {
// Test that examples section exists and shows various delete patterns
expectedExamples := []string{
"kubectl oadp nonadmin backup delete my-backup",
"kubectl oadp nonadmin backup delete --all",
"kubectl oadp nonadmin backup delete my-backup --confirm",
}

testutil.TestHelpCommand(t, binaryPath,
[]string{"nonadmin", "backup", "delete", "--help"},
expectedExamples)
})
}

// TestNonAdminBackupDeleteAllFlagBehavior tests the behavioral aspects of the --all flag
Expand Down
11 changes: 11 additions & 0 deletions cmd/non-admin/backup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
cmd.CheckError(o.Validate())
cmd.CheckError(o.Run())
},
Example: ` # Delete a specific backup
kubectl oadp nonadmin backup delete my-backup

# Delete multiple backups
kubectl oadp nonadmin backup delete backup1 backup2 backup3

# Delete all backups in the current namespace
kubectl oadp nonadmin backup delete --all

# Delete without confirmation prompt
kubectl oadp nonadmin backup delete my-backup --confirm`,
}

o.BindFlags(c.Flags())
Expand Down
34 changes: 18 additions & 16 deletions cmd/non-admin/backup/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
}

// Print in Velero-style format
printNonAdminBackupDetails(cmd, &nab, kbClient, backupName, userNamespace, effectiveTimeout)
printNonAdminBackupDetails(cmd, &nab, kbClient, backupName, userNamespace, effectiveTimeout, details)

// Add detailed output if --details flag is set
if details {
Expand All @@ -98,7 +98,7 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
}

// printNonAdminBackupDetails prints backup details in Velero admin describe format
func printNonAdminBackupDetails(cmd *cobra.Command, nab *nacv1alpha1.NonAdminBackup, kbClient kbclient.Client, backupName string, userNamespace string, timeout time.Duration) {
func printNonAdminBackupDetails(cmd *cobra.Command, nab *nacv1alpha1.NonAdminBackup, kbClient kbclient.Client, backupName string, userNamespace string, timeout time.Duration, showDetails bool) {
out := cmd.OutOrStdout()

// Get Velero backup reference if available
Expand Down Expand Up @@ -322,22 +322,24 @@ func printNonAdminBackupDetails(cmd *cobra.Command, nab *nacv1alpha1.NonAdminBac

fmt.Fprintf(out, "\n")

// Fetch and display Resource List
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
// Fetch and display Resource List (only if showDetails is true)
if showDetails {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

resourceList, err := shared.ProcessDownloadRequest(ctx, kbClient, shared.DownloadRequestOptions{
BackupName: backupName,
DataType: "BackupResourceList",
Namespace: userNamespace,
HTTPTimeout: timeout,
})
resourceList, err := shared.ProcessDownloadRequest(ctx, kbClient, shared.DownloadRequestOptions{
BackupName: backupName,
DataType: "BackupResourceList",
Namespace: userNamespace,
HTTPTimeout: timeout,
})

if err == nil && resourceList != "" {
if formattedList := formatResourceList(resourceList); formattedList != "" {
fmt.Fprintf(out, "Resource List:\n")
fmt.Fprintf(out, "%s\n", formattedList)
fmt.Fprintf(out, "\n")
if err == nil && resourceList != "" {
if formattedList := formatResourceList(resourceList); formattedList != "" {
fmt.Fprintf(out, "Resource List:\n")
fmt.Fprintf(out, "%s\n", formattedList)
fmt.Fprintf(out, "\n")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/non-admin/backup/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"fmt"
"time"

"github.com/migtools/oadp-cli/cmd/non-admin/output"
"github.com/migtools/oadp-cli/cmd/shared"
nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
"github.com/spf13/cobra"
"github.com/vmware-tanzu/velero/pkg/client"
"github.com/vmware-tanzu/velero/pkg/cmd/util/output"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/non-admin/bsl/bsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewBSLCommand(f client.Factory) *cobra.Command {
}

c.AddCommand(
NewCreateCommand(f),
NewCreateCommand(f, "create"),
NewGetCommand(f, "get"),
)

Expand Down
16 changes: 6 additions & 10 deletions cmd/non-admin/bsl/bsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,29 @@ func TestNonAdminBSLCommands(t *testing.T) {
name: "nonadmin get bsl help",
args: []string{"nonadmin", "get", "bsl", "--help"},
expectContains: []string{
"Get one or more non-admin resources",
"bsl",
"Get one or more non-admin backup storage locations",
},
},
{
name: "nonadmin create bsl help",
args: []string{"nonadmin", "create", "bsl", "--help"},
expectContains: []string{
"Create non-admin resources",
"bsl",
"Create a non-admin backup storage location",
},
},
// Shorthand verb-noun order tests
{
name: "na get bsl help",
args: []string{"na", "get", "bsl", "--help"},
expectContains: []string{
"Get one or more non-admin resources",
"bsl",
"Get one or more non-admin backup storage locations",
},
},
{
name: "na create bsl help",
args: []string{"na", "create", "bsl", "--help"},
expectContains: []string{
"Create non-admin resources",
"bsl",
"Create a non-admin backup storage location",
},
},
}
Expand Down Expand Up @@ -297,7 +293,7 @@ func TestVerbNounOrderBSLExamples(t *testing.T) {

t.Run("get bsl with specific resource shows proper examples", func(t *testing.T) {
expectedExamples := []string{
"kubectl oadp nonadmin get bsl",
"kubectl oadp nonadmin bsl get", // Shows noun-first format from underlying command
}

testutil.TestHelpCommand(t, binaryPath,
Expand All @@ -307,7 +303,7 @@ func TestVerbNounOrderBSLExamples(t *testing.T) {

t.Run("create bsl with specific resource shows proper examples", func(t *testing.T) {
expectedExamples := []string{
"kubectl oadp nonadmin create bsl",
"kubectl oadp nonadmin bsl create", // Shows noun-first format from underlying command
}

testutil.TestHelpCommand(t, binaryPath,
Expand Down
4 changes: 2 additions & 2 deletions cmd/non-admin/bsl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func NewCreateCommand(f client.Factory) *cobra.Command {
func NewCreateCommand(f client.Factory, use string) *cobra.Command {
o := NewCreateOptions()

c := &cobra.Command{
Use: "create NAME",
Use: use + " NAME",
Short: "Create a non-admin backup storage location",
Args: cobra.ExactArgs(1),
Run: func(c *cobra.Command, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/non-admin/bsl/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"fmt"
"time"

"github.com/migtools/oadp-cli/cmd/non-admin/output"
"github.com/migtools/oadp-cli/cmd/shared"
nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
"github.com/spf13/cobra"
"github.com/vmware-tanzu/velero/pkg/client"
"github.com/vmware-tanzu/velero/pkg/cmd/util/output"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down
24 changes: 7 additions & 17 deletions cmd/non-admin/nonadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,50 +110,42 @@ func TestNonAdminCommands(t *testing.T) {
name: "nonadmin get backup help",
args: []string{"nonadmin", "get", "backup", "--help"},
expectContains: []string{
"Get one or more non-admin resources",
"backup",
"Get one or more non-admin backups",
},
},
{
name: "nonadmin create backup help",
args: []string{"nonadmin", "create", "backup", "--help"},
expectContains: []string{
"Create non-admin resources",
"backup",
"bsl",
"Create a non-admin backup",
},
},
{
name: "nonadmin delete backup help",
args: []string{"nonadmin", "delete", "backup", "--help"},
expectContains: []string{
"Delete non-admin resources",
"backup",
"Delete one or more non-admin backups",
},
},
{
name: "nonadmin describe backup help",
args: []string{"nonadmin", "describe", "backup", "--help"},
expectContains: []string{
"Describe non-admin resources",
"backup",
"Describe a non-admin backup",
},
},
{
name: "nonadmin logs backup help",
args: []string{"nonadmin", "logs", "backup", "--help"},
expectContains: []string{
"Get logs for non-admin resources",
"backup",
"Show logs for a non-admin backup",
},
},
{
name: "nonadmin create bsl help",
args: []string{"nonadmin", "create", "bsl", "--help"},
expectContains: []string{
"Create non-admin resources",
"backup",
"bsl",
"Create a non-admin backup storage location",
},
},
// Shorthand tests for verb-noun order
Expand All @@ -169,9 +161,7 @@ func TestNonAdminCommands(t *testing.T) {
name: "na create backup help",
args: []string{"na", "create", "backup", "--help"},
expectContains: []string{
"Create non-admin resources",
"backup",
"bsl",
"Create a non-admin backup",
},
},
}
Expand Down
Loading
Loading