@@ -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
196148func printRequestTable (requestList * nacv1alpha1.NonAdminBackupStorageLocationRequestList ) error {
0 commit comments