@@ -29,7 +29,12 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
2929 Args : cobra .ExactArgs (1 ),
3030 RunE : func (cmd * cobra.Command , args []string ) error {
3131 backupName := args [0 ]
32- userNamespace := f .Namespace ()
32+
33+ // Get the current namespace from kubectl context
34+ userNamespace , err := getCurrentNamespace ()
35+ if err != nil {
36+ return fmt .Errorf ("failed to determine current namespace: %w" , err )
37+ }
3338
3439 // Setup scheme and client for NonAdminBackup resources
3540 scheme := runtime .NewScheme ()
@@ -39,6 +44,9 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
3944 if err := velerov1 .AddToScheme (scheme ); err != nil {
4045 return fmt .Errorf ("failed to add Velero types to scheme: %w" , err )
4146 }
47+ if err := corev1 .AddToScheme (scheme ); err != nil {
48+ return fmt .Errorf ("failed to add core v1 types to scheme: %w" , err )
49+ }
4250
4351 restConfig , err := f .ClientConfig ()
4452 if err != nil {
@@ -128,6 +136,15 @@ func NonAdminDescribeBackup(cmd *cobra.Command, kbClient kbclient.Client, nab *n
128136 if nab .Status .VeleroBackup != nil && nab .Status .VeleroBackup .Name != "" {
129137 veleroBackupName := nab .Status .VeleroBackup .Name
130138
139+ // Try to get additional backup details, but don't block if they're not available
140+ fmt .Fprintf (cmd .OutOrStdout (), "\n Fetching additional backup details..." )
141+
142+ // Get backup results using NonAdminDownloadRequest (most important data)
143+ if results , err := downloadBackupData (ctx , kbClient , userNamespace , veleroBackupName , "BackupResults" ); err == nil {
144+ fmt .Fprintf (cmd .OutOrStdout (), "\n Backup Results:\n " )
145+ fmt .Fprintf (cmd .OutOrStdout (), "%s" , indent (results , " " ))
146+ }
147+
131148 // Get backup details using NonAdminDownloadRequest for BackupResourceList
132149 if resourceList , err := downloadBackupData (ctx , kbClient , userNamespace , veleroBackupName , "BackupResourceList" ); err == nil {
133150 fmt .Fprintf (cmd .OutOrStdout (), "\n Backup Resource List:\n " )
@@ -146,11 +163,7 @@ func NonAdminDescribeBackup(cmd *cobra.Command, kbClient kbclient.Client, nab *n
146163 fmt .Fprintf (cmd .OutOrStdout (), "%s" , indent (itemOps , " " ))
147164 }
148165
149- // Get backup results using NonAdminDownloadRequest
150- if results , err := downloadBackupData (ctx , kbClient , userNamespace , veleroBackupName , "BackupResults" ); err == nil {
151- fmt .Fprintf (cmd .OutOrStdout (), "\n Backup Results:\n " )
152- fmt .Fprintf (cmd .OutOrStdout (), "%s" , indent (results , " " ))
153- }
166+ fmt .Fprintf (cmd .OutOrStdout (), "\n Done fetching additional details." )
154167 }
155168
156169 // Print NonAdminBackup Spec (excluding sensitive information)
@@ -159,39 +172,19 @@ func NonAdminDescribeBackup(cmd *cobra.Command, kbClient kbclient.Client, nab *n
159172 if err != nil {
160173 fmt .Fprintf (cmd .OutOrStdout (), "\n Spec: <error marshaling spec: %v>\n " , err )
161174 } else {
162- lines := strings .Split (string (specYaml ), "\n " )
163- var filtered []string
164- skip := false
165- for i := 0 ; i < len (lines ); i ++ {
166- line := lines [i ]
167- trimmed := strings .TrimSpace (line )
168- if ! skip && (strings .HasPrefix (trimmed , "includedNamespaces:" ) || strings .HasPrefix (trimmed , "includednamespaces:" )) {
169- skip = true
170- continue
171- }
172- if skip {
173- // Skip all list items or indented lines after the key
174- if strings .HasPrefix (trimmed , "- " ) || strings .HasPrefix (line , " " ) || strings .HasPrefix (line , "\t " ) || trimmed == "" {
175- continue
176- } else {
177- // Found a new top-level key, stop skipping
178- skip = false
179- }
180- }
181- if ! skip {
182- filtered = append (filtered , line )
183- }
184- }
185- fmt .Fprintf (cmd .OutOrStdout (), "\n Spec:\n %s" , indent (strings .Join (filtered , "\n " ), " " ))
175+ filteredSpec := filterIncludedNamespaces (string (specYaml ))
176+ fmt .Fprintf (cmd .OutOrStdout (), "\n Spec:\n %s" , indent (filteredSpec , " " ))
186177 }
187178 }
188179
189- // Print NonAdminBackup Status
180+ // Print NonAdminBackup Status (excluding sensitive information)
190181 statusYaml , err := yaml .Marshal (nab .Status )
191182 if err != nil {
192183 fmt .Fprintf (cmd .OutOrStdout (), "\n Status: <error marshaling status: %v>\n " , err )
193184 } else {
194- fmt .Fprintf (cmd .OutOrStdout (), "\n Status:\n %s" , indent (string (statusYaml ), " " ))
185+ // Filter out includednamespaces from status output as well
186+ filteredStatus := filterIncludedNamespaces (string (statusYaml ))
187+ fmt .Fprintf (cmd .OutOrStdout (), "\n Status:\n %s" , indent (filteredStatus , " " ))
195188 }
196189
197190 // Print Events for NonAdminBackup
@@ -249,7 +242,7 @@ func downloadBackupData(ctx context.Context, kbClient kbclient.Client, userNames
249242 }()
250243
251244 // Wait for the download request to be processed
252- timeout := time .After (30 * time .Second )
245+ timeout := time .After (10 * time .Second ) // Reduced timeout since most failures are quick
253246 tick := time .Tick (1 * time .Second )
254247
255248 for {
@@ -265,16 +258,21 @@ func downloadBackupData(ctx context.Context, kbClient kbclient.Client, userNames
265258 return "" , fmt .Errorf ("failed to get NonAdminDownloadRequest: %w" , err )
266259 }
267260
268- switch updated .Status .Phase {
269- case "Processed" :
270- if updated .Status .VeleroDownloadRequest .Status .DownloadURL != "" {
271- // Download and return the content
272- return downloadContent (updated .Status .VeleroDownloadRequest .Status .DownloadURL )
261+ // Check if the download request was processed successfully
262+ for _ , condition := range updated .Status .Conditions {
263+ if condition .Type == "Processed" && condition .Status == "True" {
264+ if updated .Status .VeleroDownloadRequest .Status .DownloadURL != "" {
265+ // Download and return the content
266+ return downloadContent (updated .Status .VeleroDownloadRequest .Status .DownloadURL )
267+ }
268+ }
269+ }
270+
271+ // Check for failure conditions
272+ for _ , condition := range updated .Status .Conditions {
273+ if condition .Status == "True" && condition .Reason == "Error" {
274+ return "" , fmt .Errorf ("NonAdminDownloadRequest failed for %s: %s - %s" , dataType , condition .Type , condition .Message )
273275 }
274- case "Failed" :
275- return "" , fmt .Errorf ("NonAdminDownloadRequest failed for %s: phase=%s" , dataType , updated .Status .Phase )
276- default :
277- // Continue waiting
278276 }
279277 }
280278 }
@@ -313,6 +311,46 @@ func downloadContent(url string) (string, error) {
313311 return string (content ), nil
314312}
315313
314+ // Helper to filter out includednamespaces from YAML output
315+ func filterIncludedNamespaces (yamlContent string ) string {
316+ lines := strings .Split (yamlContent , "\n " )
317+ var filtered []string
318+ skip := false
319+ var skipIndentLevel int
320+
321+ for i := 0 ; i < len (lines ); i ++ {
322+ line := lines [i ]
323+ trimmed := strings .TrimSpace (line )
324+
325+ // Calculate indentation level
326+ indentLevel := len (line ) - len (strings .TrimLeft (line , " \t " ))
327+
328+ // Check if this line starts the includednamespaces field
329+ if ! skip && (trimmed == "includednamespaces:" || trimmed == "includedNamespaces:" ||
330+ strings .HasPrefix (trimmed , "includednamespaces: " ) || strings .HasPrefix (trimmed , "includedNamespaces: " )) {
331+ skip = true
332+ skipIndentLevel = indentLevel
333+ continue
334+ }
335+
336+ if skip {
337+ // Stop skipping if we found a line at the same or lesser indentation level
338+ // and it's not an empty line and it's not a list item belonging to the skipped field
339+ if trimmed != "" && indentLevel <= skipIndentLevel && ! strings .HasPrefix (trimmed , "- " ) {
340+ skip = false
341+ // Process this line since we're no longer skipping
342+ filtered = append (filtered , line )
343+ }
344+ // If we're still skipping, don't add the line
345+ continue
346+ }
347+
348+ // Add the line if we're not skipping
349+ filtered = append (filtered , line )
350+ }
351+ return strings .Join (filtered , "\n " )
352+ }
353+
316354// Helper to indent YAML blocks
317355func indent (s , prefix string ) string {
318356 lines := strings .Split (s , "\n " )
0 commit comments