Skip to content

Auto select when only one NABSL exists#193

Open
NicholasYancey wants to merge 1 commit into
migtools:oadp-devfrom
NicholasYancey:auto-select-nabsl
Open

Auto select when only one NABSL exists#193
NicholasYancey wants to merge 1 commit into
migtools:oadp-devfrom
NicholasYancey:auto-select-nabsl

Conversation

@NicholasYancey
Copy link
Copy Markdown
Contributor

@NicholasYancey NicholasYancey commented May 29, 2026

Why the changes were made

  • When a user has only one NABSL in their namespace, they don't need to specify --storage-location flag since
    there is only one valid option.

How to test the changes made

  • Check only one NABSL exists: oc oadp nonadmin bsl get
  • Create a nonadmin backup without a --storage-location flag: oc oadp nonadmin backup create test-backup
  • The new changes should auto-select the storage location with the only NABSL name available.

Expected output:
Auto-selected storage location: (only NABSL in namespace)
NonAdminBackup request "test-backup" submitted successfully.

Summary by CodeRabbit

  • New Features

    • Auto-selects a non-admin backup storage location when exactly one usable location exists in the current namespace, and displays an "Auto-selected storage location" message with a warning about future placement changes.
  • Bug Fixes

    • Defers config-based storage location lookup until after the current namespace is determined for more accurate resolution.

Review Change Stack

@NicholasYancey NicholasYancey self-assigned this May 29, 2026
@NicholasYancey NicholasYancey added the enhancement new feature or improvements to existing ones label May 29, 2026
@openshift-ci openshift-ci Bot requested review from kaovilai and mpryc May 29, 2026 15:37
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c3963622-9f58-45b6-bf0d-deab128c488d

📥 Commits

Reviewing files that changed from the base of the PR and between 98f3406 and 28bde6a.

📒 Files selected for processing (1)
  • cmd/non-admin/backup/create.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/non-admin/backup/create.go

📝 Walkthrough

Walkthrough

CreateOptions.Complete now defers config default lookup until after the Kubernetes client and namespace are available; if StorageLocation remains unset, it lists NonAdminBackupStorageLocation in the current namespace, filters to NonAdminPhaseCreated, and auto-selects when exactly one usable NABSL exists.

Changes

Storage Location Resolution

Layer / File(s) Summary
NABSL config lookup and auto-selection
cmd/non-admin/backup/create.go
CreateOptions adds a storageLocationAutoSelected field. Config-derived default NABSL lookup is moved to run after Kubernetes client creation and namespace determination. If StorageLocation remains unset, the command lists NonAdminBackupStorageLocation objects in the current namespace, filters to NonAdminPhaseCreated, and auto-selects StorageLocation only when exactly one usable NABSL exists; Run prints an auto-selection info/warning when applicable.

🎯 3 (Moderate) | ⏱️ ~20 minutes

A rabbit hops through configs with K8s in tow,
Finds storage by namespace where single blossoms grow,
One NABSL stands — chosen with a cheer,
A gentle warning whispered, future ones may steer,
Hoppity backup, safe and clear! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: auto-selecting a NonAdminBackupStorageLocation when only one exists in the namespace.
Description check ✅ Passed The pull request description includes all required sections: explanation of why changes were made and detailed testing instructions with expected output.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

🤖 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 176-189: The auto-select message is printed in Complete
(fmt.Printf in the block that sets o.StorageLocation using nabslList) which
breaks -o yaml/json output; change CreateOptions to add a boolean flag (e.g.,
storageLocationAutoSelected bool) set to true inside Complete when you
auto-select o.StorageLocation from nabslList, remove the fmt.Printf from
Complete, and then in Run—after the PrintWithFormat early return and alongside
the existing storageLocationFromConfig handling—emit the user-facing message
about auto-selection if storageLocationAutoSelected is true so the message is
suppressed for formatted output.
🪄 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: d11b8f22-d7a8-491f-934c-6bdf1df95fed

📥 Commits

Reviewing files that changed from the base of the PR and between 21c2e9c and 98f3406.

📒 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
Comment on lines +176 to +189
// Auto-select NABSL if exactly one exists in the namespace
if o.StorageLocation == "" {
nabslList := &nacv1alpha1.NonAdminBackupStorageLocationList{}
if err := o.client.List(context.TODO(), nabslList, &kbclient.ListOptions{
Namespace: currentNS,
}); err != nil {
return fmt.Errorf("failed to list NonAdminBackupStorageLocations: %w", err)
}

if len(nabslList.Items) == 1 {
o.StorageLocation = nabslList.Items[0].Name
fmt.Printf("Auto-selected storage location: %s (only NABSL in namespace)\n", o.StorageLocation)
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

feels like you could reuse the first if o.StorageLocation == "" { from line 168

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed, used the same if statement instead of using 2

@NicholasYancey NicholasYancey force-pushed the auto-select-nabsl branch 2 times, most recently from 9f48cd2 to 29f1a7d Compare May 29, 2026 16:10
@kaovilai kaovilai requested a review from Copilot May 29, 2026 16:12
Copy link
Copy Markdown
Member

@kaovilai kaovilai left a comment

Choose a reason for hiding this comment

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

Should we add a warning that, if the user creates another non-admin BackupStorageLocation in the future, the backups may not go to the same location?

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 updates non-admin backup creation so the CLI can resolve a storage location automatically when the user does not pass --storage-location.

Changes:

  • Adds tracking for auto-selected storage locations.
  • Moves default NABSL lookup after namespace/client setup.
  • Lists NABSLs in the current namespace and auto-selects when exactly one exists.

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

Comment thread cmd/non-admin/backup/create.go Outdated
Comment on lines +183 to +185
if len(nabslList.Items) == 1 {
o.StorageLocation = nabslList.Items[0].Name
o.storageLocationAutoSelected = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like a legitimate concern. We only want approved NABSLs, not pendin or rejected ones
Can we confirm that a pending/approved/rejected NABSL does not create an NABSL whatsoever to cause this issue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed, checks for usable storage locations first

Comment on lines +183 to +194
// Filter to only approved/created NABSLs (exclude pending/rejected)
var usableNABSLs []nacv1alpha1.NonAdminBackupStorageLocation
for _, nabsl := range nabslList.Items {
if nabsl.Status.Phase == nacv1alpha1.NonAdminPhaseCreated {
usableNABSLs = append(usableNABSLs, nabsl)
}
}

if len(usableNABSLs) == 1 {
o.StorageLocation = usableNABSLs[0].Name
o.storageLocationAutoSelected = true
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is microoptimization but for consideration. no array allocation

var usableCount int
var selectedName string

for _, nabsl := range nabslList.Items {
	if nabsl.Status.Phase == nacv1alpha1.NonAdminPhaseCreated {
		usableCount++
		if usableCount == 1 {
			selectedName = nabsl.Name
		} else {
			break
		}
	}
}

if usableCount == 1 {
	o.StorageLocation = selectedName
	o.storageLocationAutoSelected = true
}

Copy link
Copy Markdown
Member

@kaovilai kaovilai left a comment

Choose a reason for hiding this comment

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

will see if others wants this

@NicholasYancey NicholasYancey removed the request for review from mpryc June 1, 2026 15:05
Comment thread cmd/non-admin/backup/create.go Outdated
Comment on lines +183 to +185
if len(nabslList.Items) == 1 {
o.StorageLocation = nabslList.Items[0].Name
o.storageLocationAutoSelected = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like a legitimate concern. We only want approved NABSLs, not pendin or rejected ones
Can we confirm that a pending/approved/rejected NABSL does not create an NABSL whatsoever to cause this issue

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Joeavaikath, NicholasYancey

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved enhancement new feature or improvements to existing ones

Projects

None yet

Development

Successfully merging this pull request may close these issues.

if nonadmin: true && only 1 nabsl in namespace use that as default.

4 participants