Skip to content

Prompts user to choose when more than one NABSL exists#198

Open
NicholasYancey wants to merge 7 commits into
migtools:oadp-devfrom
NicholasYancey:prompt-multi-nabsl
Open

Prompts user to choose when more than one NABSL exists#198
NicholasYancey wants to merge 7 commits into
migtools:oadp-devfrom
NicholasYancey:prompt-multi-nabsl

Conversation

@NicholasYancey
Copy link
Copy Markdown
Contributor

@NicholasYancey NicholasYancey commented Jun 4, 2026

Why the changes were made

PR #193 added auto-selection when exactly one usable NABSL exists in the namespace. That removed the need to pass --storage-location or set default-nabsl in that case.

When a user has two or more NABSLs in their namespace, the CLI still failed with --storage-location is required error. Users had to know the location name up front or set a default in config. This change helps with if there is more than one NABSL and allows the user to pick one that they want instead of giving an error.

How to test the changes made

Build and install

make build
make install ASSUME_DEFAULT=true

Test (2+ NABSLs)

oc project <namespace>
kubectl oadp client config set default-nabsl=
kubectl oadp nonadmin bsl get
kubectl oadp nonadmin backup create prompt-test-$(date +%s)

bsl get should show 2 or more NABSLs before running backup create.

You should see a numbered NABSL list, then after picking one:

  • Selected storage location:
  • NonAdminBackup request "..." submitted successfully.

Confirm with:

kubectl oadp nonadmin backup describe prompt-test-...

Summary by CodeRabbit

  • New Features

    • Interactive terminal-based selection for storage locations when multiple options exist during non-admin backups.
    • Automatic selection when only one valid storage location exists.
    • Defaulting to configured client storage location when available.
    • Clearer user feedback distinguishing auto-selection from prompted selection; prints a “Selected storage location” message when prompting occurs.
    • Graceful error when prompting isn’t possible (non-terminal).
  • Chores

    • Adjusted build dependency declaration.

@NicholasYancey NicholasYancey self-assigned this Jun 4, 2026
@NicholasYancey NicholasYancey added the enhancement new feature or improvements to existing ones label Jun 4, 2026
@openshift-ci openshift-ci Bot requested review from Joeavaikath and kaovilai June 4, 2026 19:45
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 4, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: NicholasYancey
Once this PR has been reviewed and has the lgtm label, please assign rayfordj for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5943f293-c756-4340-8dbb-006d3d0eb38f

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa4407 and aaa30cb.

📒 Files selected for processing (1)
  • cmd/non-admin/backup/create.go

📝 Walkthrough

Walkthrough

The PR refactors non-admin backup storage location handling in cmd/non-admin/backup/create.go to prefer a Velero config default, auto-select a single usable NonAdminBackupStorageLocation, or prompt interactively (terminal-checked) when multiple usable locations exist; go.mod makes golang.org/x/term a direct requirement.

Changes

Interactive NonAdminBackupStorageLocation Selection

Layer / File(s) Summary
Imports and struct setup
cmd/non-admin/backup/create.go
Adds standard-library imports for interactive input and terminal detection (bufio, io, os, strconv, strings, golang.org/x/term) and a storageLocationPrompted field on CreateOptions.
Complete integration and post-create messaging
cmd/non-admin/backup/create.go
Complete calls resolveStorageLocation(currentNS) instead of inline logic; Run prints existing config-derived and auto-selected messages and an additional "Selected storage location" line when the location was chosen interactively.
Storage location resolution and prompting
cmd/non-admin/backup/create.go
Adds resolveStorageLocation and resolveStorageLocationFromList (config default → list NABSLs → filter Created → auto-select single usable → prompt when multiple). Adds promptForNABSLSelection (requires stdin/stdout terminals, lists numbered options, validates numeric choice) and formatNABSLPhase (phase display fallback).
Module dependency
go.mod
golang.org/x/term v0.41.0 moved from indirect to direct requirement in go.mod.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • migtools/oadp-cli#193: Related auto-selection work for single NABSL; this PR extends with interactive prompting.

Suggested reviewers

  • Joeavaikath
  • kaovilai

Poem

🐇 I hopped through configs, defaults, and rows,

When one stood ready, I quietly chose,
When many beckoned beneath terminal light,
I asked with numbers — pick one tonight,
Now backups march on, tidy and bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: prompting users to choose from multiple NABSLs, which is the primary objective of this PR.
Description check ✅ Passed The description includes both required sections: 'Why the changes were made' explains the motivation and context from PR #193, and 'How to test the changes made' provides detailed build, setup, and verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@NicholasYancey NicholasYancey linked an issue Jun 4, 2026 that may be closed by this pull request
Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/non-admin/backup/create.go`:
- Around line 316-340: The interactive prompt sends its menu to the provided out
writer (and the call site passes os.Stdout) but only checks stdin for a TTY, so
prompts can be written into redirected stdout; update promptForNABSLSelection
(and the call that passes os.Stdout) to either write interactive UI to stderr
(use os.Stderr when in a terminal) or first verify that out is a terminal and
refuse to prompt otherwise; specifically change the menu/Prompt writes
(fmt.Fprintln/Fprintf to out) to target the terminal stream (stderr) or add a
terminal check on out (term.IsTerminal on out's FD) and return an error if not a
TTY so prompting is never written into redirected stdout. Ensure references:
promptForNABSLSelection, the caller that passes os.Stdout, and the menu printing
lines are updated accordingly.
- Around line 305-323: The function resolveStorageLocationFromList should first
filter the incoming items slice to only include those with Status.Phase ==
nacv1alpha1.NonAdminPhaseCreated, then make decisions from that filtered slice:
if the filtered slice is empty return an explicit error, if it has exactly one
set o.StorageLocation and o.storageLocationAutoSelected = true, and if it has
more than one call promptForNABSLSelection to set o.StorageLocation and
o.storageLocationPrompted = true; update control flow so you never prompt with
unusable NABSLs and you fail early when no usable NABSLs exist.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aad0fde4-186e-442c-9065-4a8adc482db6

📥 Commits

Reviewing files that changed from the base of the PR and between e02116a and 33192ac.

📒 Files selected for processing (1)
  • cmd/non-admin/backup/create.go

Comment thread cmd/non-admin/backup/create.go Outdated
Comment thread cmd/non-admin/backup/create.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the non-admin backup creation flow by adding an interactive selection prompt for --storage-location when multiple NonAdminBackupStorageLocations (NABSLs) exist, reducing the need for users to know/set the location name ahead of time.

Changes:

  • Adds terminal-based prompting to choose a NABSL when more than one is present.
  • Refactors storage-location resolution into helper methods and adds user feedback for prompted vs auto-selected cases.
  • Adds golang.org/x/term as a direct dependency for terminal detection.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
go.mod Adds golang.org/x/term as a direct dependency to support interactive terminal prompting.
cmd/non-admin/backup/create.go Implements interactive NABSL selection and refactors storage-location resolution/output messaging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/non-admin/backup/create.go Outdated
Comment thread cmd/non-admin/backup/create.go Outdated
Comment on lines +335 to +337
for i, nabsl := range items {
fmt.Fprintf(out, " %d) %s (%s)\n", i+1, nabsl.Name, formatNABSLPhase(&nabsl))
}
consistent with pr migtools#193, only uses usable nabsl

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
cmd/non-admin/backup/create.go (1)

315-317: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Return an explicit error when no usable NABSL exists.

When usable is empty, returning nil falls through to a later generic --storage-location is required error instead of reporting that no Created NABSL is currently usable in the namespace.

Suggested fix
 	switch len(usable) {
 	case 0:
-		return nil
+		return fmt.Errorf("no usable NonAdminBackupStorageLocations found; create one or wait until one reaches Created, or specify --storage-location explicitly")
 	case 1:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/non-admin/backup/create.go` around lines 315 - 317, The switch handling
the length of the usable slice currently returns nil for case 0 which masks the
real problem; change the case 0 branch to return an explicit error (e.g., using
fmt.Errorf) that states no usable NABSL exists/has phase "Created" in the target
namespace so callers see a clear message instead of the later generic
"--storage-location is required" error; update the case 0 in the function that
inspects the usable variable (and reference the namespace/name variables used
nearby) to return that descriptive error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/non-admin/backup/create.go`:
- Line 331: There is an extra unmatched closing brace (`}`) at the end of the
file that causes a compilation error; remove that trailing `}` so the function
and file braces are balanced (inspect the end of the create.go source around the
end of the command constructor/handler such as the Create command or its RunE
function to confirm proper brace pairing and delete the dangling brace).

---

Duplicate comments:
In `@cmd/non-admin/backup/create.go`:
- Around line 315-317: The switch handling the length of the usable slice
currently returns nil for case 0 which masks the real problem; change the case 0
branch to return an explicit error (e.g., using fmt.Errorf) that states no
usable NABSL exists/has phase "Created" in the target namespace so callers see a
clear message instead of the later generic "--storage-location is required"
error; update the case 0 in the function that inspects the usable variable (and
reference the namespace/name variables used nearby) to return that descriptive
error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d7c3f6a-ebb1-4b19-a94e-418440275c55

📥 Commits

Reviewing files that changed from the base of the PR and between 33192ac and 4fa4407.

📒 Files selected for processing (2)
  • cmd/non-admin/backup/create.go
  • go.mod

Comment thread cmd/non-admin/backup/create.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement new feature or improvements to existing ones

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prompt user to choose NABSL when more than one exists

2 participants