Skip to content

Non-admin Restore for OADP CLI#113

Open
Joeavaikath wants to merge 3 commits intomigtools:oadp-devfrom
Joeavaikath:nar-phase1
Open

Non-admin Restore for OADP CLI#113
Joeavaikath wants to merge 3 commits intomigtools:oadp-devfrom
Joeavaikath:nar-phase1

Conversation

@Joeavaikath
Copy link
Contributor

Why the changes were made

This PR completes Phase 2 of the non-admin restore commands implementation, adding
describe, logs, and delete functionality to match the feature parity with non-admin
backup commands.

Phase 1 (already merged) provided create and get commands for non-admin restores.
Phase 2 adds the remaining essential operations:

  • describe - Enables users to view detailed restore information including status,
    progress, and configuration. The --details flag provides access to RestoreResults,
    RestoreItemOperations, and RestoreResourceList via NonAdminDownloadRequest.

  • logs - Allows users to troubleshoot restore operations by streaming logs directly
    from the CLI, essential for debugging failed or in-progress restores.

  • delete - Provides safe deletion of restore resources with confirmation prompts and
    batch deletion support via --all flag.

These commands follow the same patterns established by the backup commands, ensuring
consistency across the CLI. All commands support both noun-verb (restore describe) and
verb-noun (describe restore) orderings, making the UX flexible and intuitive.

How to test the changes made

Prerequisites

# Build the CLI
go build -o oadp .

# Run unit tests
go test ./cmd/non-admin/restore/... -v

# Verify all 51 tests pass

1. Test Describe Command

Basic describe (no download requests):
# Noun-verb order
./oadp nonadmin restore describe my-restore

# Verb-noun order
./oadp nonadmin describe restore my-restore

# Shorthand
./oadp na restore describe my-restore

Verify output shows:
- Name, Namespace, Labels, Annotations
- Phase (color-coded: green=Completed, yellow=InProgress, red=Failed)
- Source backup name
- Namespace mappings
- Included/excluded resources
- Restore PVs setting
- Progress (TotalItems, ItemsRestored)

Describe with details flag:
./oadp nonadmin restore describe my-restore --details

Verify additional output includes:
- Resource List (grouped by GVK)
- Restore Results (errors/warnings)
- Restore Item Operations

With custom timeout:
./oadp nonadmin restore describe my-restore --details --request-timeout=30m

2. Test Logs Command

Stream restore logs:
# Noun-verb order
./oadp nonadmin restore logs my-restore

# Verb-noun order
./oadp nonadmin logs restore my-restore

# Shorthand
./oadp na logs restore my-restore

Verify:
- Logs stream to stdout
- Gzip content is automatically decompressed
- Progress dots appear while waiting for download URL

With timeout:
./oadp nonadmin restore logs my-restore --request-timeout=15m

3. Test Delete Command

Delete single restore (with confirmation):
./oadp nonadmin restore delete my-restore
# Should prompt: "Are you sure you want to delete restore 'my-restore'? (y/N):"

Delete multiple restores:
./oadp nonadmin restore delete restore1 restore2 restore3
# Should prompt: "Are you sure you want to delete these 3 restores? (y/N):"

Delete with --confirm flag (skip prompt):
./oadp nonadmin restore delete my-restore --confirm

Delete all restores in namespace:
./oadp nonadmin restore delete --all
# Should prompt: "Are you sure you want to delete ALL N restore(s) in namespace 'X'? (y/N):"

Verb-noun order:
./oadp nonadmin delete restore my-restore --confirm
./oadp na delete restore my-restore --confirm

Verify after deletion:
kubectl get nonadminrestore -n <namespace>
# Deleted restores should be removed

4. Test Help Text

Verify all commands appear:
./oadp nonadmin restore --help
# Should list: create, get, describe, logs, delete

Verify flags:
# Describe flags
./oadp nonadmin restore describe --help | grep -E "(--details|--request-timeout)"

# Logs flags
./oadp nonadmin restore logs --help | grep "--request-timeout"

# Delete flags
./oadp nonadmin restore delete --help | grep -E "(--confirm|--all)"

Verify examples use correct format:
./oadp nonadmin restore describe --help | grep "kubectl oadp"
./oadp nonadmin restore logs --help | grep "kubectl oadp"
./oadp nonadmin restore delete --help | grep "kubectl oadp"

5. Test Verb-Noun Ordering

Verify both orderings work:
# These should all work and show appropriate help
./oadp nonadmin describe restore --help
./oadp nonadmin logs restore --help
./oadp nonadmin delete restore --help

# Examples should appear in verb command help
./oadp nonadmin describe --help | grep "restore"
./oadp nonadmin logs --help | grep "restore"
./oadp nonadmin delete --help | grep "restore"

6. Error Handling Tests

Non-existent restore:
./oadp nonadmin restore describe does-not-exist
# Should show: "NonAdminRestore \"does-not-exist\" not found"

Missing arguments:
./oadp nonadmin restore logs
# Should show: "accepts 1 arg(s), received 0"

./oadp nonadmin restore delete
# Should show: "at least one restore name is required, or use --all"

Conflicting flags:
./oadp nonadmin restore delete my-restore --all
# Should show: "accepts 0 arg(s), received 1" (when --all is set, no names allowed)

Expected Results

✅ All commands work with both noun-verb and verb-noun orderings
✅ Shorthand na works for all commands
✅ Help text shows all flags and uses kubectl oadp prefix in examples
✅ Describe command shows restore-specific fields (not backup snapshots)
✅ Logs stream correctly with gzip auto-detection
✅ Delete command prompts for confirmation unless --confirm is used
✅ All 51 unit tests pass
✅ Error messages are user-friendly

Joeavaikath and others added 2 commits February 4, 2026 13:01
Add create and get subcommands for non-admin restores following the
established pattern from backup commands. Phase 1 provides core
functionality for creating restores from backups and viewing restore
status, enabling users to perform restore operations through both
noun-verb and verb-noun command syntax.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Joseph <jvaikath@redhat.com>
Add three new commands to complete the non-admin restore functionality:

- describe: Display detailed restore information with optional --details flag
  for RestoreResults, RestoreItemOperations, and RestoreResourceList
- logs: Stream restore operation logs using NonAdminDownloadRequest
- delete: Delete restore CRs with --confirm and --all flags

All commands support both noun-verb (restore describe) and verb-noun
(describe restore) orderings, work with 'na' shorthand, and use the
'kubectl oadp' prefix in examples.

Key features:
- --details flag for additional restore information (describe only)
- --request-timeout flag for download operations (describe and logs)
- --confirm flag to skip confirmation prompts (delete only)
- --all flag to delete all restores in namespace (delete only)
- Color-coded phase display (green/yellow/red)
- Restore-specific fields: backup name, namespace mappings, restore PVs
- Comprehensive test coverage with 51 passing tests

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Joseph <jvaikath@redhat.com>
@Joeavaikath Joeavaikath changed the title Nar phase1 Non-admin Restore for OADP CLI Feb 4, 2026
@Joeavaikath Joeavaikath linked an issue Feb 4, 2026 that may be closed by this pull request
Signed-off-by: Joseph <jvaikath@redhat.com>
Comment on lines +73 to +93
type CreateOptions struct {
Name string
BackupName string
IncludeNamespaces flag.StringArray
ExcludeNamespaces flag.StringArray
IncludeResources flag.StringArray
ExcludeResources flag.StringArray
NamespaceMappings flag.Map
Labels flag.Map
Annotations flag.Map
Selector flag.LabelSelector
OrSelector flag.OrLabelSelector
RestoreVolumes flag.OptionalBool
PreserveNodePorts flag.OptionalBool
IncludeClusterResources flag.OptionalBool
ExistingResourcePolicy string
ItemOperationTimeout time.Duration
ResourceModifierConfigMap string
client kbclient.WithWatch
currentNamespace string
}
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, I tried importing "github.com/vmware-tanzu/velero/pkg/cmd/cli/restore"

type CreateOptions struct {
	restore.CreateOptions
	Name                      string
	client                    kbclient.WithWatch
	currentNamespace          string
}

func NewCreateOptions() *CreateOptions {
	return &CreateOptions{
		CreateOptions: restore.CreateOptions{
			Labels: flag.NewMap(),
			Annotations:       flag.NewMap(),
			NamespaceMappings: flag.NewMap(),
		},
	}
}

Seems to compile. Could be anti-pattern tho..

Anyway this would add writesparsefiles and other settings which is in non-admin CRD. Thoughts on why some settings are missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NAR crud Support

2 participants