Skip to content

Command cleanup#140

Merged
Joeavaikath merged 6 commits intomigtools:oadp-devfrom
Joeavaikath:command-cleanup
Feb 25, 2026
Merged

Command cleanup#140
Joeavaikath merged 6 commits intomigtools:oadp-devfrom
Joeavaikath:command-cleanup

Conversation

@Joeavaikath
Copy link
Contributor

@Joeavaikath Joeavaikath commented Feb 19, 2026

Why the changes were made

  • Removes the -n flag test, which is redundant: the flag will appear if BindFlags is called from the veleroClient
  • Add a check for GOOS before make install runs
  • Cleanup client.go
  • Fix NABSL commands not getting the right resource, NonAdminBackupStorageLocation Request

How to test the changes made

oc oadp nabsl-request describe should now work correctly

Summary by CodeRabbit

  • New Features

    • Describe output enhanced with colorized phases, improved alignment, and clearer request details.
  • Bug Fixes

    • Install target now errors if the build target is undefined, preventing invalid builds.
  • Changes

    • Removed bug, datamover, repo, and repomantenance CLI commands.
    • Simplified NABSL request lookup to directly resolve by name/UUID in the admin scope.
    • Removed the all-namespaces flag; single-list behavior now targets admin scope.
    • Streamlined approve/reject flows by removing redundant validation steps.
  • Tests

    • Removed the namespace-flag help test.

Signed-off-by: Joseph <jvaikath@redhat.com>
Signed-off-by: Joseph <jvaikath@redhat.com>
Signed-off-by: Joseph <jvaikath@redhat.com>
Signed-off-by: Joseph <jvaikath@redhat.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

📝 Walkthrough

Walkthrough

This PR simplifies NABSL-request CLI flows by removing no-op validation hooks and namespace flag handling, resolving requests via direct admin-namespace Get/List lookup, improving describe output formatting (alignment, color, indented maps), adding shared output helpers, pruning indirect go.mod deps, removing several root subcommands, and adding a Makefile GOOS validation.

Changes

Cohort / File(s) Summary
Approve / Reject commands
cmd/nabsl-request/approve.go, cmd/nabsl-request/reject.go
Removed Validate methods and their invocations; command execution now follows Complete → Run directly.
Describe command
cmd/nabsl-request/describe.go
Switched to direct admin-namespace lookup via name/UUID, replaced Name with UUID_Name, and reworked output to aligned fields, colorized phase, and structured printing of BSL details, labels, and config.
Get command
cmd/nabsl-request/get.go
Removed all-namespaces flag/BindFlags/Validate; uses FindNABSLRequestByNameOrUUID for canonical name resolution and always scopes listing to admin namespace.
Shared output utilities
cmd/shared/output.go
New helpers: Indent, ColorizePhase, and PrintLabelsOrAnnotations for formatted, aligned, and colorized CLI output.
NABSL lookup helper
cmd/shared/nabsl_requests.go
FindNABSLRequestByNameOrUUID now attempts Get by name/UUID first, falls back to List in admin namespace and matches on Status.SourceNonAdminBSL.Name.
Client init
cmd/shared/client.go
Refactored NewClientWithScheme to build scheme and rest config up-front and unify timeout handling to remove duplicated paths.
CLI root
cmd/root.go
Removed registration of bug, datamover, repo, and repomaintenance subcommands from the root command.
Build & tests
Makefile, cmd/namespace_flag_test.go
Added GOOS validation to Makefile install target; deleted cmd/namespace_flag_test.go.
Dependencies
go.mod
Pruned many indirect dependencies, substantially reducing transitive requires.

Sequence Diagram(s)

sequenceDiagram
    actor CLI as CLI Client
    participant Finder as FindNABSLRequestByNameOrUUID
    participant API as API Server (admin namespace)
    participant Formatter as Describe Output Formatter

    CLI->>Finder: Resolve input (name or UUID)
    Finder->>API: Get request by name/UUID in admin ns
    alt Get succeeds
        API-->>Finder: Return request
    else NotFound
        Finder->>API: List requests in admin ns
        API-->>Finder: Return list
        Finder->>Finder: Match on Status.SourceNonAdminBSL.Name
    end
    Finder-->>CLI: Return canonical request name

    CLI->>API: Get full request details by canonical name
    API-->>CLI: Return request object

    CLI->>Formatter: Format description
    Formatter->>Formatter: Colorize phase, indent, print labels/config aligned
    Formatter-->>CLI: Rendered output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • kaovilai
  • stillalearner
  • weshayutin

Poem

🐇 I hopped through code with nimble feet,
Direct lookups now make matches neat,
Phases in color, labels aligned sweet,
Fewer flags to puzzle, fewer commands to meet,
A tiny rabbit cheers this tidy feat! 🎉

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Command cleanup' is vague and generic, using non-descriptive terminology that doesn't convey specific information about the substantial changes made to the codebase. Provide a more specific title that captures the main objectives, such as 'Fix NABSL commands and remove redundant namespace flag test' or 'Refactor NABSL request handling and CLI cleanup'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description covers the main changes and testing instructions, addressing the required template sections with sufficient detail about why changes were made and how to verify them.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Joseph <jvaikath@redhat.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/shared/nabsl_requests.go (1)

36-50: ⚠️ Potential issue | 🟠 Major

Return non-NotFound errors from the UUID lookup instead of silently falling back.

Currently, any Get error triggers a list fallback, which masks auth, network, and permission failures—allowing the function to surface a misleading "request not found" error at the end when the real problem was elsewhere.

Only proceed to the fallback when the error is explicitly a NotFound error. For all other errors, return immediately with proper context.

🔧 Suggested fix
 import (
 	"context"
 	"fmt"
 
 	kbclient "sigs.k8s.io/controller-runtime/pkg/client"
+	"k8s.io/apimachinery/pkg/api/errors"
 
 	nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
 )
@@
 	err := client.Get(ctx, kbclient.ObjectKey{
 		Name:      nameOrUUID,
 		Namespace: adminNamespace,
 	}, &testRequest)
 	if err == nil {
 		return nameOrUUID, nil
 	}
+	if !errors.IsNotFound(err) {
+		return "", fmt.Errorf("failed to get request %q: %w", nameOrUUID, err)
+	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/shared/nabsl_requests.go` around lines 36 - 50, The UUID lookup currently
treats any error from client.Get(ctx, kbclient.ObjectKey{Name: nameOrUUID,
Namespace: adminNamespace}, &testRequest) as a signal to fallback to listing;
change this so only a NotFound error falls through to the list path—if
client.Get returns a non-NotFound error (e.g. network/auth/permission error)
return that error immediately with context (wrap/format it) instead of
proceeding; keep the fallback behavior when the error is explicitly a NotFound
(use the appropriate IsNotFound helper for your imports) and then continue with
the existing client.List logic using requestList and adminNamespace.
🧹 Nitpick comments (1)
cmd/nabsl-request/approve.go (1)

87-89: Minor: Remove leftover empty line.

Line 88 appears to be a leftover from removing the Validate() call. Consider removing the empty line to keep the function body clean.

🔧 Suggested cleanup
 func (o *ApproveOptions) Run(c *cobra.Command, f client.Factory) error {
-
 	adminNS := f.Namespace()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/nabsl-request/approve.go` around lines 87 - 89, The function
ApproveOptions.Run contains an extra blank line between the variable assignment
adminNS := f.Namespace() and surrounding code; remove that leftover empty line
so the function body is compact and the adminNS assignment is directly adjacent
to the next statement.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/nabsl-request/describe.go`:
- Around line 108-184: The code dereferences spec.ObjectStorage without checking
for nil (when reading spec.ObjectStorage.Bucket and spec.ObjectStorage.Prefix),
which can panic for partial/invalid requests; update the block that handles
source.RequestedSpec (the Requested BackupStorageLocation Spec logic for
variable spec := source.RequestedSpec) to first check if spec.ObjectStorage !=
nil before accessing its fields and only print "Object Storage Bucket" and
"Prefix" when ObjectStorage is non-nil; retain printing other spec fields as-is
and ensure the nil check guards both Bucket and Prefix accesses.

---

Outside diff comments:
In `@cmd/shared/nabsl_requests.go`:
- Around line 36-50: The UUID lookup currently treats any error from
client.Get(ctx, kbclient.ObjectKey{Name: nameOrUUID, Namespace: adminNamespace},
&testRequest) as a signal to fallback to listing; change this so only a NotFound
error falls through to the list path—if client.Get returns a non-NotFound error
(e.g. network/auth/permission error) return that error immediately with context
(wrap/format it) instead of proceeding; keep the fallback behavior when the
error is explicitly a NotFound (use the appropriate IsNotFound helper for your
imports) and then continue with the existing client.List logic using requestList
and adminNamespace.

---

Nitpick comments:
In `@cmd/nabsl-request/approve.go`:
- Around line 87-89: The function ApproveOptions.Run contains an extra blank
line between the variable assignment adminNS := f.Namespace() and surrounding
code; remove that leftover empty line so the function body is compact and the
adminNS assignment is directly adjacent to the next statement.

Signed-off-by: Joseph <jvaikath@redhat.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/shared/nabsl_requests.go (1)

43-63: ⚠️ Potential issue | 🔴 Critical

Critical logic bug: Early return on NotFound blocks NABSL name lookup.

The function documentation (lines 29-31) explicitly states it supports two lookup strategies: direct UUID lookup and NABSL name lookup. However, the early return at lines 45-46 when errors.IsNotFound(err) prevents the fallback List operation from executing when a user provides a NABSL name.

When a user provides a NABSL name, the Get call returns NotFound (since request objects are named by UUID), triggering the return at line 46. This bypasses the List operation at lines 49-61 that searches by Status.SourceNonAdminBSL.Name, breaking the documented behavior that all four callers (describe, approve, reject, get) depend on.

The condition at line 45 should be inverted to !errors.IsNotFound(err) so that NotFound errors fall through to the List fallback while actual errors are properly reported.

🐛 Proposed fix
 	if err == nil {
 		return nameOrUUID, nil
-	} else if errors.IsNotFound(err) {
-		return "", fmt.Errorf("request for NABSL %q not found", nameOrUUID)
+	} else if !errors.IsNotFound(err) {
+		// Non-NotFound errors (e.g., network issues) should be reported
+		return "", fmt.Errorf("failed to get request: %w", err)
 	}
 
-	// Fallback:Match NABSL name to UUID
+	// Fallback: Match NABSL name to UUID (also handles case where nameOrUUID wasn't a valid UUID)
 	var requestList nacv1alpha1.NonAdminBackupStorageLocationRequestList
 	err = client.List(ctx, &requestList, kbclient.InNamespace(adminNamespace))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/shared/nabsl_requests.go` around lines 43 - 63, The lookup currently
bails out on errors.IsNotFound(err) and thus never runs the fallback List
search; in the function that resolves nameOrUUID (where client.List, ctx,
adminNamespace and variable requestList of type
nacv1alpha1.NonAdminBackupStorageLocationRequestList are used), change the
conditional so that you return immediately only on success (err == nil) or on
any real error (i.e., when err != nil && !errors.IsNotFound(err)), but allow
NotFound to fall through to the List-based fallback that scans
request.Status.SourceNonAdminBSL.Name and returns the matching request.Name;
this preserves direct UUID success, reports real errors, and lets NABSL-name
lookups proceed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@cmd/shared/nabsl_requests.go`:
- Around line 43-63: The lookup currently bails out on errors.IsNotFound(err)
and thus never runs the fallback List search; in the function that resolves
nameOrUUID (where client.List, ctx, adminNamespace and variable requestList of
type nacv1alpha1.NonAdminBackupStorageLocationRequestList are used), change the
conditional so that you return immediately only on success (err == nil) or on
any real error (i.e., when err != nil && !errors.IsNotFound(err)), but allow
NotFound to fall through to the List-based fallback that scans
request.Status.SourceNonAdminBSL.Name and returns the matching request.Name;
this preserves direct UUID success, reports real errors, and lets NABSL-name
lookups proceed.

@Joeavaikath Joeavaikath merged commit 7d66cd7 into migtools:oadp-dev Feb 25, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants