Skip to content

Commit 9b1338e

Browse files
Joeavaikathclaude
andcommitted
Simplify NABSL request listing and fix output handling
- Remove complex NABSL-to-request UUID mapping in favor of direct request listing - Fix import path to use internal output package instead of Velero's - Skip output wrapper for delete commands to allow real-time display - Improve parent command checking for logs/describe/delete patterns Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Joseph <jvaikath@redhat.com>
1 parent cf096e6 commit 9b1338e

3 files changed

Lines changed: 38 additions & 75 deletions

File tree

cmd/nabsl-request/get.go

Lines changed: 24 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -105,92 +105,44 @@ func (o *GetOptions) Run(c *cobra.Command, f client.Factory) error {
105105
// Get the admin namespace (from client config) where requests are stored
106106
adminNS := f.Namespace()
107107

108-
// Get the current namespace to find user's NABSLs
109-
currentNS, err := shared.GetCurrentNamespace()
110-
if err != nil {
111-
return fmt.Errorf("failed to determine current namespace: %w", err)
112-
}
113-
114-
// First get all NABSLs in user's namespace to find related requests
115-
var nabslList nacv1alpha1.NonAdminBackupStorageLocationList
116-
err = o.client.List(context.Background(), &nabslList, kbclient.InNamespace(currentNS))
117-
if err != nil {
118-
return fmt.Errorf("failed to list NABSLs: %w", err)
119-
}
120-
121-
// Collect request UUIDs from NABSL statuses
122-
requestUUIDs := make(map[string]string) // UUID -> NABSL name
123-
for _, nabsl := range nabslList.Items {
124-
if nabsl.Status.VeleroBackupStorageLocation != nil && nabsl.Status.VeleroBackupStorageLocation.NACUUID != "" {
125-
requestUUIDs[nabsl.Status.VeleroBackupStorageLocation.NACUUID] = nabsl.Name
126-
}
127-
}
128-
129108
if o.Name != "" {
130-
// Get specific request by UUID or NABSL name
131-
var targetUUID string
132-
133-
// Check if o.Name is a UUID or NABSL name
134-
if _, exists := requestUUIDs[o.Name]; exists {
135-
// o.Name is a UUID
136-
targetUUID = o.Name
137-
} else {
138-
// o.Name might be a NABSL name, find its UUID
139-
for uuid, nabslName := range requestUUIDs {
140-
if nabslName == o.Name {
141-
targetUUID = uuid
142-
break
143-
}
144-
}
145-
}
146-
147-
if targetUUID != "" {
148-
var request nacv1alpha1.NonAdminBackupStorageLocationRequest
149-
err := o.client.Get(context.Background(), kbclient.ObjectKey{
150-
Name: targetUUID,
151-
Namespace: adminNS,
152-
}, &request)
153-
if err != nil {
154-
return fmt.Errorf("failed to get request for %q: %w", o.Name, err)
155-
}
156-
157-
if printed, err := output.PrintWithFormat(c, &request); printed || err != nil {
158-
return err
159-
}
160-
161-
list := &nacv1alpha1.NonAdminBackupStorageLocationRequestList{
162-
Items: []nacv1alpha1.NonAdminBackupStorageLocationRequest{request},
163-
}
164-
return printRequestTable(list)
165-
}
166-
167-
return fmt.Errorf("request %q not found for NABSLs in namespace %s", o.Name, currentNS)
168-
}
169-
170-
// List all requests related to user's NABSLs
171-
var userRequests []nacv1alpha1.NonAdminBackupStorageLocationRequest
172-
for uuid := range requestUUIDs {
109+
// Get specific request by name (UUID)
173110
var request nacv1alpha1.NonAdminBackupStorageLocationRequest
174111
err := o.client.Get(context.Background(), kbclient.ObjectKey{
175-
Name: uuid,
112+
Name: o.Name,
176113
Namespace: adminNS,
177114
}, &request)
178115
if err != nil {
179-
// Request might not exist yet, skip
180-
continue
116+
return fmt.Errorf("failed to get request %q: %w", o.Name, err)
117+
}
118+
119+
if printed, err := output.PrintWithFormat(c, &request); printed || err != nil {
120+
return err
121+
}
122+
123+
list := &nacv1alpha1.NonAdminBackupStorageLocationRequestList{
124+
Items: []nacv1alpha1.NonAdminBackupStorageLocationRequest{request},
181125
}
182-
userRequests = append(userRequests, request)
126+
return printRequestTable(list)
183127
}
184128

185-
requestList := &nacv1alpha1.NonAdminBackupStorageLocationRequestList{
186-
Items: userRequests,
129+
// List all requests in admin namespace
130+
var requestList nacv1alpha1.NonAdminBackupStorageLocationRequestList
131+
var err error
132+
if o.AllNamespaces {
133+
err = o.client.List(context.Background(), &requestList)
134+
} else {
135+
err = o.client.List(context.Background(), &requestList, kbclient.InNamespace(adminNS))
136+
}
137+
if err != nil {
138+
return fmt.Errorf("failed to list requests: %w", err)
187139
}
188140

189-
if printed, err := output.PrintWithFormat(c, requestList); printed || err != nil {
141+
if printed, err := output.PrintWithFormat(c, &requestList); printed || err != nil {
190142
return err
191143
}
192144

193-
return printRequestTable(requestList)
145+
return printRequestTable(&requestList)
194146
}
195147

196148
func printRequestTable(requestList *nacv1alpha1.NonAdminBackupStorageLocationRequestList) error {

cmd/non-admin/bsl/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import (
2525
"github.com/spf13/pflag"
2626
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
2727

28+
"github.com/migtools/oadp-cli/cmd/non-admin/output"
2829
"github.com/migtools/oadp-cli/cmd/shared"
2930
nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
3031
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
3132
"github.com/vmware-tanzu/velero/pkg/builder"
3233
"github.com/vmware-tanzu/velero/pkg/client"
3334
"github.com/vmware-tanzu/velero/pkg/cmd"
3435
"github.com/vmware-tanzu/velero/pkg/cmd/util/flag"
35-
"github.com/vmware-tanzu/velero/pkg/cmd/util/output"
3636
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3737
)
3838

cmd/root.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,21 @@ func replaceVeleroWithOADP(cmd *cobra.Command) *cobra.Command {
210210
cmd.Example = replaceVeleroCommandWithOADP(cmd.Example)
211211

212212
// Skip wrapping commands that stream output or make long-running requests
213-
// to allow real-time display without buffering
213+
// to allow real-time display without buffering. Check both the command itself
214+
// and its parent to handle both "backup describe" and "describe backup" patterns.
214215
isLogsCommand := cmd.Use == "logs" || strings.HasPrefix(cmd.Use, "logs ")
215216
isDescribeCommand := cmd.Use == "describe" || strings.HasPrefix(cmd.Use, "describe ")
216-
shouldSkipWrapper := isLogsCommand || isDescribeCommand
217+
isDeleteCommand := cmd.Use == "delete" || strings.HasPrefix(cmd.Use, "delete ")
218+
219+
// Also check if parent command is one we should skip
220+
if cmd.Parent() != nil {
221+
parentUse := cmd.Parent().Use
222+
isLogsCommand = isLogsCommand || parentUse == "logs" || strings.HasPrefix(parentUse, "logs ")
223+
isDescribeCommand = isDescribeCommand || parentUse == "describe" || strings.HasPrefix(parentUse, "describe ")
224+
isDeleteCommand = isDeleteCommand || parentUse == "delete" || strings.HasPrefix(parentUse, "delete ")
225+
}
226+
227+
shouldSkipWrapper := isLogsCommand || isDescribeCommand || isDeleteCommand
217228

218229
// Wrap the Run function to replace velero in output
219230
if cmd.Run != nil && !shouldSkipWrapper {

0 commit comments

Comments
 (0)