Skip to content

Add config support default non-admin storage location#144

Open
Joeavaikath wants to merge 5 commits intomigtools:oadp-devfrom
Joeavaikath:default-storage-location
Open

Add config support default non-admin storage location#144
Joeavaikath wants to merge 5 commits intomigtools:oadp-devfrom
Joeavaikath:default-storage-location

Conversation

@Joeavaikath
Copy link
Contributor

@Joeavaikath Joeavaikath commented Feb 27, 2026

Why the changes were made

  • Adds a new config value nonadmin-default: this allows nonadmin users to specify a default NABSL, allowing them to not specify --storage-location for each nonadmin backup creation
  • Improve output formatting with line breaks and notification around the config value

How to test the changes made

  1. Create a NABSL (eg test-nabsl). A message around setting the config value should be visible.
  2. Set the config value: oc oadp nonadmin client config set default-nabsl=test-nabsl
  3. Run a nonadmin backup: oc oadp nonadmin backup create test-backup

The backup should be created successfully with a message stating that the config value was used for nonadmin backup storage location

Summary by CodeRabbit

  • New Features

    • Support for a configurable default non-admin backup storage location via client config so you no longer must specify it each time.
  • Bug Fixes / UX

    • CLI help now clarifies the storage-location can be overridden by config.
    • Commands now print a clear notice when the default storage location from config is used.
    • Minor wording tweak: references "created requests" and adds a hint to set a default via the client config.
  • Documentation

    • Updated examples and help text to show how to set and use the default storage location.

for non-admin backups

Adds a config value to the Velero client config file to set the default storage location for non-admin backups.
Adds a command output on NABSL creation to inform the user about the default storage location config.

Signed-off-by: Joseph <jvaikath@redhat.com>
If default storage location is set in config, display a message that it is being used.

Signed-off-by: Joseph <jvaikath@redhat.com>
Add line breaks in create output for non-admin backup and NABSL creation.

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

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

Adds support for a default non-admin backup storage location (NABSL) sourced from the Velero client config: new config field/accessor, backup-create command reads and uses that default when no flag is provided, and user-facing messages updated to reflect/configure the default.

Changes

Cohort / File(s) Summary
ClientConfig: default NABSL
cmd/shared/factories.go
Add DefaultNABSL string to ClientConfig (json:"default-nabsl,omitempty") and GetDefaultNABSL() string accessor; minor alignment/formatting adjustments.
Non-admin backup create
cmd/non-admin/backup/create.go
If --storage-location is empty, load default NABSL from client config via getNABSLFromConfig(); add storageLocationFromConfig field to CreateOptions; update flag help and validation message; print notice when default NABSL from config is used.
BSL create output
cmd/non-admin/bsl/create.go
Adjust user-facing printed lines (split formatted prints into plain prints), update wording to reference "created requests", add a hint to set a default NABSL via oc oadp client config, and append a blank line.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Bugfixes #138 — Overlaps changes to non-admin backup/BSL command code and may conflict with CreateOptions/BSL output edits.

Suggested reviewers

  • weshayutin

Poem

🐰 I found a default, tucked in config light,
No more flags to chase in the midnight.
I hop through code, nibble a line,
NABSL set—everything's fine! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding configuration support for a default non-admin storage location to avoid requiring the flag on each command.
Description check ✅ Passed The description includes both required sections with substantive content: clear rationale for the feature and detailed testing steps that match the PR objectives.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@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

🧹 Nitpick comments (1)
cmd/non-admin/bsl/create.go (1)

204-204: Clarify scope as “default non-admin” storage location.

Line 204 says “default” broadly; making it explicit helps avoid confusion with admin backup flows.

✏️ Suggested wording
-fmt.Printf("Use `oc oadp client config set default-nabsl=%s` to set this BSL as the default to avoid specifying the BSL name each time.\n", nabsl.Name)
+fmt.Printf("Use `oc oadp client config set default-nabsl=%s` to set this as the default non-admin BSL and avoid specifying --storage-location each time.\n", nabsl.Name)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/non-admin/bsl/create.go` at line 204, The user-facing message currently
prints a broad "default" which is ambiguous; update the fmt.Printf call that
references nabsl.Name (the line using fmt.Printf("Use `oc oadp client config set
default-nabsl=%s`...")) to explicitly say "default non-admin storage location"
or "default non-admin BSL" so it clarifies scope and avoids confusion with admin
backup flows—replace the wording in that fmt.Printf invocation to include
"non-admin" while preserving the command and nabsl.Name placeholder.
🤖 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/non-admin/backup/create.go`:
- Around line 147-150: The code currently unconditionally sets o.StorageLocation
from getNABSLFromConfig() via defaultNABSL which overwrites an explicit
--storage-location flag; change the logic so you only assign o.StorageLocation =
defaultNABSL when the user did NOT provide a storage location flag (i.e., detect
whether the flag was set and only use getNABSLFromConfig() as a fallback).
Update the related reporting logic that mentions config usage (the message
around where o.StorageLocation is later reported) to only state "using
default-nabsl from config" when the config value was actually used; reference
the identifiers defaultNABSL, getNABSLFromConfig(), and o.StorageLocation to
locate and adjust the conditional assignment and the corresponding log/message.
- Around line 255-264: getNABSLFromConfig currently swallows errors from
shared.ReadVeleroClientConfig and returns "" which hides parse/read failures;
change getNABSLFromConfig to return (string, error), propagate and return any
error from shared.ReadVeleroClientConfig instead of returning an empty string,
and only return the default NABSL when clientConfig is non-nil and
GetDefaultNABSL() is non-empty; update callers of getNABSLFromConfig to handle
the error (e.g., validate and surface the error to the user) rather than relying
on an empty string.

---

Nitpick comments:
In `@cmd/non-admin/bsl/create.go`:
- Line 204: The user-facing message currently prints a broad "default" which is
ambiguous; update the fmt.Printf call that references nabsl.Name (the line using
fmt.Printf("Use `oc oadp client config set default-nabsl=%s`...")) to explicitly
say "default non-admin storage location" or "default non-admin BSL" so it
clarifies scope and avoids confusion with admin backup flows—replace the wording
in that fmt.Printf invocation to include "non-admin" while preserving the
command and nabsl.Name placeholder.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d66cd7 and d06aba6.

📒 Files selected for processing (3)
  • cmd/non-admin/backup/create.go
  • cmd/non-admin/bsl/create.go
  • cmd/shared/factories.go

Comment on lines +255 to +264
func getNABSLFromConfig() string {
clientConfig, err := shared.ReadVeleroClientConfig()
if err == nil && clientConfig != nil {
defaultNABSL := clientConfig.GetDefaultNABSL()
if defaultNABSL != "" {
return defaultNABSL
}
}
return ""
}
Copy link

@coderabbitai coderabbitai bot Feb 27, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Don’t hide config read/parse errors.

Lines 255-264 return "" on error, which masks real failures and later produces a generic validation message instead of actionable feedback.

💡 Proposed fix
-func getNABSLFromConfig() string {
+func getNABSLFromConfig() (string, error) {
 	clientConfig, err := shared.ReadVeleroClientConfig()
-	if err == nil && clientConfig != nil {
-		defaultNABSL := clientConfig.GetDefaultNABSL()
-		if defaultNABSL != "" {
-			return defaultNABSL
-		}
+	if err != nil {
+		return "", fmt.Errorf("failed to read Velero client config: %w", err)
 	}
-	return ""
+	if clientConfig == nil {
+		return "", nil
+	}
+	return clientConfig.GetDefaultNABSL(), nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/non-admin/backup/create.go` around lines 255 - 264, getNABSLFromConfig
currently swallows errors from shared.ReadVeleroClientConfig and returns ""
which hides parse/read failures; change getNABSLFromConfig to return (string,
error), propagate and return any error from shared.ReadVeleroClientConfig
instead of returning an empty string, and only return the default NABSL when
clientConfig is non-nil and GetDefaultNABSL() is non-empty; update callers of
getNABSLFromConfig to handle the error (e.g., validate and surface the error to
the user) rather than relying on an empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No config reading is kind of straightforward

Copy link

Choose a reason for hiding this comment

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

@Joeavaikath, understood. I'll leave the config reading as-is since it handles the straightforward case adequately.


✏️ Learnings added
Learnt from: Joeavaikath
Repo: migtools/oadp-cli PR: 144
File: cmd/non-admin/backup/create.go:260-269
Timestamp: 2026-02-27T19:32:59.144Z
Learning: In the oadp-cli project, for the getNABSLFromConfig() function in cmd/non-admin/backup/create.go, returning an empty string on config read errors is acceptable because config reading is straightforward and doesn't require explicit error propagation.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

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

🤖 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/non-admin/backup/create.go`:
- Around line 64-66: Update the example to use the non-admin command path and
remove the misleading “all backups” scope: replace the comment line "# Set
default storage location for all backups." with wording that indicates this is
for non-admin backup flows, and change the example command string "oc oadp
client config set default-nabsl=my-nabsl" to the non-admin variant (e.g. "oc
oadp non-admin client config set default-nabsl=my-nabsl") so the example
reflects the non-admin scope used by this feature.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d06aba6 and 4deb38e.

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

Comment on lines +64 to +66
# Set default storage location for all backups.
oc oadp client config set default-nabsl=my-nabsl

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the example command scope/path for default-nabsl.

This example currently reads as global (“all backups”) and uses oc oadp client ..., while this feature is for non-admin backup flows. Updating this avoids copy/paste confusion.

💡 Proposed fix
-  # Set default storage location for all backups.
-  oc oadp client config set default-nabsl=my-nabsl
+  # Set default storage location for non-admin backups.
+  oc oadp nonadmin client config set default-nabsl=my-nabsl
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Set default storage location for all backups.
oc oadp client config set default-nabsl=my-nabsl
# Set default storage location for non-admin backups.
oc oadp nonadmin client config set default-nabsl=my-nabsl
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/non-admin/backup/create.go` around lines 64 - 66, Update the example to
use the non-admin command path and remove the misleading “all backups” scope:
replace the comment line "# Set default storage location for all backups." with
wording that indicates this is for non-admin backup flows, and change the
example command string "oc oadp client config set default-nabsl=my-nabsl" to the
non-admin variant (e.g. "oc oadp non-admin client config set
default-nabsl=my-nabsl") so the example reflects the non-admin scope used by
this feature.

// Storage location validation
if o.StorageLocation == "" {
return fmt.Errorf("--storage-location is required")
return fmt.Errorf("--storage-location is required (can be set via flag or config 'default-nabsl')")
Copy link
Member

Choose a reason for hiding this comment

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

I think it could be clarified a bit more how to set this config? or we wanna keep this short?

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.

Allow non-admin users to set a default nabsl to avoid specifying --storage-location each time

2 participants