Skip to content

Nabsl enforce#29

Merged
Joeavaikath merged 9 commits into
migtools:mainfrom
Joeavaikath:nabsl-enforce
Jul 22, 2025
Merged

Nabsl enforce#29
Joeavaikath merged 9 commits into
migtools:mainfrom
Joeavaikath:nabsl-enforce

Conversation

@Joeavaikath
Copy link
Copy Markdown
Contributor

@Joeavaikath Joeavaikath commented Jul 18, 2025

Add get command and enforce storage location validation for NonAdminBackup

Overview

This PR adds two key enhancements to the NonAdminBackup functionality:

  1. New get command for listing and retrieving NonAdminBackup resources
  2. Storage location validation requiring valid NABSL reference for backup creation

Changes

1. New Command: kubectl oadp nonadmin backup get

  • List all NABs: kubectl oadp nonadmin backup get
  • Get specific NAB: kubectl oadp nonadmin backup get <backup-name>
  • Output formats: Supports table format (default), with YAML/JSON planned for future iterations

2. Enhanced Backup Create Validation

  • Required storage location: --storage-location parameter is now mandatory
  • Force flag option: --force flag allows bypassing validation to use admin defaults
  • Clear error messages: Specific guidance about NABSL requirements

Features

Get Command Features

Clean table output with columns:

  • NAME - Backup name (30 chars wide)
  • STATUS - Current backup status from NAB phase
  • CREATED - Human-readable creation timestamp
  • AGE - Time since creation (e.g., 23d, 15h, 45m)

Proper integration into existing command structure
Namespace-aware - automatically uses current kubectl context namespace
Error handling for missing backups and empty namespaces

Validation Features

Enforced best practices - requires explicit storage location reference
Force flag escape hatch - allows admin override when needed
Clear error messaging - guides users to provide valid NABSL or use force
Updated examples - all documentation shows proper usage patterns

Usage Examples

Get Command

# List all non-admin backups in current namespace
kubectl oadp nonadmin backup get

# Get details for a specific backup
kubectl oadp nonadmin backup get my-backup

# Show help and examples
kubectl oadp nonadmin backup get --help

Create Command (Updated)

# Create backup with required storage location
kubectl oadp nonadmin backup create backup1 --storage-location my-nabsl

# Create with specific resource types
kubectl oadp nonadmin backup create backup2 --include-resources deployments,services --storage-location my-nabsl

# Force creation with admin defaults (no storage location specified)
kubectl oadp nonadmin backup create backup3 --force

Sample Output

Get Command Output

NAME                           STATUS          CREATED              AGE       
example                        Created         2025-06-25 10:16:40  23d       
example2                       Created         2025-07-03 13:20:12  15d       
test3                          Created         2025-06-25 13:21:11  23d       

Validation Error

$ kubectl oadp nonadmin backup create test-backup
Error: a valid NonAdminBackupStorageLocation must be provided via --storage-location, or use --force to create with admin defaults

Files Changed

  • cmd/non-admin/backup/get.go - New get command implementation
  • cmd/non-admin/backup/backup.go - Added get command to backup subcommand
  • cmd/non-admin/backup/create.go - Added storage location validation and force flag

Testing

Get Command

  • Command appears in help output
  • Lists NABs correctly when present
  • Handles empty namespaces gracefully
  • Retrieves specific NABs by name
  • Proper error messages for missing backups
  • Table formatting displays correctly

Validation

  • Backup create fails without storage location
  • Force flag bypasses validation successfully
  • Clear error messages guide users
  • Updated examples show proper usage
  • Success messages indicate when force is used

Future Enhancements

  • YAML/JSON output format support for get command (scheme registration needs refinement)
  • Label selectors and filtering options for get command
  • Wide output format with additional columns
  • Enhanced validation for storage location existence

Dependencies

  • Builds on existing NonAdminBackup CRD from github.com/migtools/oadp-non-admin
  • Uses established patterns from other backup commands (create, describe, delete, logs)
  • Follows kubectl-style validation and force flag patterns

These enhancements improve the OADP CLI user experience by:

  1. Providing familiar kubectl get-style interface for viewing NonAdminBackup resources
  2. Enforcing best practices by requiring explicit storage location references
  3. Maintaining flexibility with force flag for advanced users
  4. Improving error guidance for common configuration issues

✨ Major improvements:
- Convert oadp.yaml to environment variable template
- Replace complex Python regex with clean envsubst
- Much more readable and maintainable approach
- Robust error handling and validation
- Template uses ${VERSION}, ${LINUX_AMD64_SHA}, etc.

🔧 Technical benefits:
- No more fragile regex string replacement
- Standard environment variable substitution
- Easier to debug and modify
- Less code, more reliable
🎯 Perfect for krew index submission:
- Generate oadp.yaml directly (not oadp-final.yaml)
- Release artifact is ready to drop into krew index
- No renaming needed - matches krew convention exactly
- Clean workflow: template → envsubst → oadp.yaml
- Removed the backup storage location (BSL) command from the non-admin command set.
- Introduced a new 'get' command for listing and retrieving non-admin backups.
- Updated the create command examples to include a storage location option and added a force flag for creation without specifying a storage location.
- Enhanced output messages to indicate when defaults are used during backup creation.
Comment thread cmd/non-admin/backup/get.go
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.

No major blockers.

Suggestions for Improvement

  1. Add unit tests for:
    - Table formatting functions
    - Age calculation logic
    - Validation logic for storage location
    - Get command with various scenarios
  2. Consider adding:
    - --selector flag for filtering backups in get command
    - Sort options for the backup list
    - More output formats beyond table/yaml/json
  3. Documentation:
    - Update README with new command examples
    - Add inline comments for exported functions
  4. Code organization:
    - Extract common client setup/scheme registration into shared utilities
    - Consider a common package for formatting helpers

@kaovilai kaovilai requested a review from Copilot July 22, 2025 17:52
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 adds a new get command for NonAdminBackup resources and enforces storage location validation for backup creation. The get command provides kubectl-style listing and retrieval of backups with clean table output, while the validation enhancement requires users to specify a valid NonAdminBackupStorageLocation or use a force flag for admin defaults.

  • Adds new kubectl oadp nonadmin backup get command with table format output
  • Enforces storage location validation during backup creation with --storage-location parameter
  • Introduces shared client utilities for consistent scheme management across commands

Reviewed Changes

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

Show a summary per file
File Description
cmd/shared/client.go New shared utilities for client creation and namespace handling
cmd/non-admin/backup/get.go New get command implementation with table formatting
cmd/non-admin/backup/create.go Added storage location validation and force flag with user prompts
cmd/non-admin/backup/backup.go Added get command to backup subcommand structure
cmd/non-admin/backup/nonadminbackup_builder.go Removed duplicate getCurrentNamespace function
cmd/non-admin/backup/describe.go Refactored to use shared client utilities
cmd/non-admin/backup/delete.go Updated to use shared client creation
cmd/non-admin/backup/logs.go Updated to use shared scheme utilities

Comment thread cmd/non-admin/bsl/bsl.go
Comment thread cmd/non-admin/backup/get.go Outdated
Comment thread cmd/shared/client.go Outdated
Comment thread cmd/non-admin/backup/create.go Outdated
Comment thread cmd/non-admin/backup/get.go
Comment thread cmd/non-admin/nonadmin.go
@Joeavaikath Joeavaikath merged commit ae2f564 into migtools:main Jul 22, 2025
10 checks passed
@Joeavaikath Joeavaikath deleted the nabsl-enforce branch February 19, 2026 15:11
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.

3 participants