-
Notifications
You must be signed in to change notification settings - Fork 12
Fix OADP-7562: handle wildcard in scoped excluded cluster resources #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: oadp-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
| "context" | ||
| "errors" | ||
| "reflect" | ||
| "slices" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" | ||
|
|
@@ -705,11 +706,18 @@ func (r *NonAdminBackupReconciler) createVeleroBackupAndSyncWithNonAdminBackup(c | |
|
|
||
| if haveNewResourceFilterParameters { | ||
| // Use the new-style exclusion list | ||
| backupSpec.ExcludedNamespaceScopedResources = append(backupSpec.ExcludedNamespaceScopedResources, | ||
| alwaysExcludedNamespacedResources...) | ||
| backupSpec.ExcludedClusterScopedResources = append(backupSpec.ExcludedClusterScopedResources, | ||
| alwaysExcludedClusterResources...) | ||
| } else { | ||
| // Skip appending when wildcard '*' is already present, as it already | ||
| // excludes everything and mixing '*' with specific items causes Velero | ||
| // FailedValidation. | ||
| if !slices.Contains(backupSpec.ExcludedNamespaceScopedResources, constant.WildcardString) { | ||
| backupSpec.ExcludedNamespaceScopedResources = append(backupSpec.ExcludedNamespaceScopedResources, | ||
| alwaysExcludedNamespacedResources...) | ||
| } | ||
| if !slices.Contains(backupSpec.ExcludedClusterScopedResources, constant.WildcardString) { | ||
| backupSpec.ExcludedClusterScopedResources = append(backupSpec.ExcludedClusterScopedResources, | ||
| alwaysExcludedClusterResources...) | ||
| } | ||
|
Comment on lines
+709
to
+719
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check if the old-style ExcludedResources field also supports wildcards in Velero
# and find all similar append patterns that might need the same fix
# Find other places where resources are appended to exclusion lists without wildcard check
rg -n -A3 -B3 'ExcludedResources\s*=\s*append' --type=go
# Check Velero documentation/validation for wildcard handling in ExcludedResources
rg -n 'ExcludedResources.*\*' --type=goRepository: migtools/oadp-non-admin Length of output: 1363 🏁 Script executed: # Get context around the fallback path in backup controller
sed -n '700,730p' internal/controller/nonadminbackup_controller.goRepository: migtools/oadp-non-admin Length of output: 1556 🏁 Script executed: # Get context around the restore controller append
sed -n '340,360p' internal/controller/nonadminrestore_controller.goRepository: migtools/oadp-non-admin Length of output: 873 🏁 Script executed: # Check if there are any tests or comments that mention ExcludedResources wildcard behavior
rg -i 'excludedresources.*wildcard|wildcard.*excludedresources' --type=go -C 3Repository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Search for ExcludedResources field definitions or usage patterns to understand its purpose
rg -n 'ExcludedResources' --type=go | head -20Repository: migtools/oadp-non-admin Length of output: 1038 🏁 Script executed: # Find the definition of alwaysExcludedNamespacedResources and alwaysExcludedClusterResources
rg -n 'alwaysExcluded(Namespaced|Cluster)Resources\s*[=:]' --type=go -A 10Repository: migtools/oadp-non-admin Length of output: 1312 🏁 Script executed: # Check if there are any constants or variables that might contain wildcards
rg -n 'alwaysExcluded' --type=goRepository: migtools/oadp-non-admin Length of output: 637 🏁 Script executed: # Look for Velero API types to understand ExcludedResources field
rg -n 'type.*Spec.*struct' --type=go | grep -i backup | head -5Repository: migtools/oadp-non-admin Length of output: 359 🏁 Script executed: # Check if there are any Velero imports or comments that explain ExcludedResources behavior
rg -n 'velerov1\.(Backup|Restore)' --type=go -B 2 -A 2 | head -40Repository: migtools/oadp-non-admin Length of output: 3473 🏁 Script executed: # Look for test cases that show ExcludedResources behavior with wildcards
rg -n 'ExcludedResources.*\*|"\*".*ExcludedResources' --type=go -B 2 -A 2Repository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Check if the code has any other wildcard validation patterns
rg -n 'slices.Contains.*\*' --type=go -B 2 -A 2Repository: migtools/oadp-non-admin Length of output: 1078 🏁 Script executed: # Verify the actual risk: check if user can set ExcludedResources to "*"
rg -n 'ExcludedResources\s*:' --type=go | grep -v '//'Repository: migtools/oadp-non-admin Length of output: 254 🏁 Script executed: # Check the actual BackupSpec and RestoreSpec type definitions to confirm ExcludedResources is user-provided
fd -t f -e go -x grep -l 'type.*BackupSpec\|type.*RestoreSpec' {} \; 2>/dev/null | head -10Repository: migtools/oadp-non-admin Length of output: 197 🏁 Script executed: # Verify if there are any tests that show user setting ExcludedResources with "*"
rg -n 'ExcludedResources.*=.*\[\]string' --type=go -A 3 | head -30Repository: migtools/oadp-non-admin Length of output: 889 🏁 Script executed: # Check NonAdminBackupSpec to see if it embeds BackupSpec
sed -n '27,100p' api/v1alpha1/nonadminbackup_types.goRepository: migtools/oadp-non-admin Length of output: 2728 🏁 Script executed: # Check if ExcludedResources is user-configurable by looking at how it's populated
rg -n 'backupSpec.ExcludedResources\s*=' --type=go -B 3 -A 1Repository: migtools/oadp-non-admin Length of output: 723 🏁 Script executed: # Look for where ExcludedResources might be set by users (in API or spec parsing)
rg -n 'ExcludedResources' --type=go | grep -v 'append\|test\|//'Repository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Check if there's any existing pattern for checking wildcards in ExcludedResources
rg -n 'Contains.*ExcludedResources' --type=go -B 2 -A 2Repository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Check the actual field definitions in Velero's BackupSpec to understand ExcludedResources
# Since we can't access Velero directly, look for any documentation or comments in this repo
rg -n 'ExcludedResources' --type=go -B 5 | grep -E 'type|struct|comment|//' | head -20Repository: migtools/oadp-non-admin Length of output: 166 🏁 Script executed: # Look at how the backup is created with ExcludedResources to understand the risk
sed -n '697,730p' internal/controller/nonadminbackup_controller.goRepository: migtools/oadp-non-admin Length of output: 1645 🏁 Script executed: # Check if there's any validation or comment about the wildcard behavior being specific to scoped fields
rg -n 'wildcard|Wildcard|\*' --type=go -B 2 -A 2 | grep -A 2 -B 2 'scoped\|Scoped' | head -30Repository: migtools/oadp-non-admin Length of output: 2519 🏁 Script executed: # Verify if the test actually shows the wildcard behavior being a Velero validation issue
sed -n '1549,1575p' internal/controller/nonadminbackup_controller_test.goRepository: migtools/oadp-non-admin Length of output: 1092 🏁 Script executed: # Check what validation errors Velero throws when mixing wildcards with specific items
# Look for any error handling or validation in the test files
rg -n 'FailedValidation' --type=go -B 3 -A 3Repository: migtools/oadp-non-admin Length of output: 868 🏁 Script executed: # Understand the user flow: can a user actually set ExcludedResources to "*" in the old-style path?
# Check if there are any examples in tests showing user setting this
rg -n 'BackupSpec.*{' --type=go -A 20 | grep -A 15 'ExcludedResources'Repository: migtools/oadp-non-admin Length of output: 156 🏁 Script executed: # Check if there's any documentation about when ExcludedResources vs scoped resources are used
sed -n '697,710p' internal/controller/nonadminbackup_controller.goRepository: migtools/oadp-non-admin Length of output: 787 🏁 Script executed: # Search for any comments or issues related to the old-style path wildcard handling
rg -n 'old-style|fallback' --type=go -B 3 -A 3 | grep -i 'wildcard\|exclude' -B 3 -A 3Repository: migtools/oadp-non-admin Length of output: 724 🏁 Script executed: # Check if there are tests for the fallback path with ExcludedResources containing wildcards
rg -n 'Should not append default excluded resources' --type=go -A 30 | grep -B 30 'ExcludedResources'Repository: migtools/oadp-non-admin Length of output: 49 Add wildcard guard to old-style fallback path and restore controller. The new-style scoped fields correctly prevent appending specific resources when Add wildcard checks before appending in both locations:
🤖 Prompt for AI Agents |
||
| } else if !slices.Contains(backupSpec.ExcludedResources, constant.WildcardString) { | ||
| // Fallback to the old-style exclusion list | ||
| backupSpec.ExcludedResources = append(backupSpec.ExcludedResources, | ||
| alwaysExcludedNamespacedResources...) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ( | |
| "context" | ||
| "errors" | ||
| "reflect" | ||
| "slices" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" | ||
|
|
@@ -348,8 +349,10 @@ func (r *NonAdminRestoreReconciler) createVeleroRestore(ctx context.Context, log | |
| } | ||
| } | ||
|
|
||
| restoreSpec.ExcludedResources = append(restoreSpec.ExcludedResources, | ||
| "volumesnapshotclasses") | ||
| if !slices.Contains(restoreSpec.ExcludedResources, constant.WildcardString) { | ||
| restoreSpec.ExcludedResources = append(restoreSpec.ExcludedResources, | ||
| "volumesnapshotclasses") | ||
| } | ||
|
Comment on lines
+352
to
+355
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check if there are tests covering the wildcard exclusion scenario for restores
# Search for test cases involving ExcludedResources with wildcard in restore controller tests
rg -n -C5 'ExcludedResources.*\*|"\*"' internal/controller/nonadminrestore_controller_test.go
# Also check if there's any wildcard-related test naming
rg -n 'wildcard|Wildcard' internal/controller/nonadminrestore_controller_test.goRepository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Check the implementation at lines 352-355
cat -n internal/controller/nonadminrestore_controller.go | sed -n '350,360p'Repository: migtools/oadp-non-admin Length of output: 479 🏁 Script executed: # Check the test file structure and the mentioned lines 369-370
wc -l internal/controller/nonadminrestore_controller_test.go
head -n 1 internal/controller/nonadminrestore_controller_test.goRepository: migtools/oadp-non-admin Length of output: 128 🏁 Script executed: # Look at the test file around lines 369-370 to see what's being tested
sed -n '365,380p' internal/controller/nonadminrestore_controller_test.goRepository: migtools/oadp-non-admin Length of output: 779 🏁 Script executed: # Search for any test setup with wildcard patterns in ExcludedResources across the entire test file
rg -n 'ExcludedResources' internal/controller/nonadminrestore_controller_test.goRepository: migtools/oadp-non-admin Length of output: 143 🏁 Script executed: # Look for scenario setup that might include wildcard configurations
rg -n 'scenario\.|WildcardString' internal/controller/nonadminrestore_controller_test.goRepository: migtools/oadp-non-admin Length of output: 1682 🏁 Script executed: # Check what WildcardString constant is defined as
rg -n 'WildcardString.*=' internal/pkg/constant/ | head -5Repository: migtools/oadp-non-admin Length of output: 129 🏁 Script executed: # Look for any scenario definitions in the test file to understand test structure
sed -n '1,150p' internal/controller/nonadminrestore_controller_test.go | grep -A2 'type.*scenario\|var.*scenario' | head -20Repository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Find where WildcardString is defined
rg -n 'WildcardString' --type go | head -10Repository: migtools/oadp-non-admin Length of output: 821 🏁 Script executed: # Look at the test scenarios structure - search for test case definitions
sed -n '80,200p' internal/controller/nonadminrestore_controller_test.goRepository: migtools/oadp-non-admin Length of output: 5489 🏁 Script executed: # Search for test scenario definitions in the test file
rg -n 'nonAdminRestoreFullReconcileScenario\{' internal/controller/nonadminrestore_controller_test.go -A 15 | head -100Repository: migtools/oadp-non-admin Length of output: 2266 🏁 Script executed: # Look for all test entry definitions with Entry() to see if any test the wildcard scenario
rg -n 'ginkgo.Entry' internal/controller/nonadminrestore_controller_test.go -B 2 -A 8 | head -150Repository: migtools/oadp-non-admin Length of output: 1917 🏁 Script executed: # Look at the test scenario structures to see if any include ExcludedResources with wildcard
sed -n '451,610p' internal/controller/nonadminrestore_controller_test.go | grep -C 10 'ExcludedResources'Repository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Search for all test scenario definitions to find if wildcard is tested
rg -n 'ginkgo.Entry.*"Should' internal/controller/nonadminrestore_controller_test.goRepository: migtools/oadp-non-admin Length of output: 638 🏁 Script executed: # Get more details on what test scenarios exist and their structure
sed -n '451,625p' internal/controller/nonadminrestore_controller_test.go | head -200Repository: migtools/oadp-non-admin Length of output: 5120 🏁 Script executed: # Check if there's any test that explicitly uses wildcard in ExcludedResources for restore tests
rg -n '\*' internal/controller/nonadminrestore_controller_test.go | grep -i 'exclude\|resource' | head -10Repository: migtools/oadp-non-admin Length of output: 49 🏁 Script executed: # Look at the backup controller to see if it has similar tests and if wildcard scenarios are tested there
rg -n 'wildcard\|WildcardString' internal/controller/nonadminbackup_controller_test.go -B 2 -A 2Repository: migtools/oadp-non-admin Length of output: 49 Confirm test coverage gap: add test case for wildcard exclusion scenario. The implementation correctly prevents appending 🤖 Prompt for AI Agents |
||
|
|
||
| veleroRestore = &velerov1.Restore{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: migtools/oadp-non-admin
Length of output: 736
🏁 Script executed:
Repository: migtools/oadp-non-admin
Length of output: 1531
🏁 Script executed:
Repository: migtools/oadp-non-admin
Length of output: 4242
🌐 Web query:
Velero VolumeGroupSnapshotLabelKey release version when added💡 Result:
The VolumeGroupSnapshotLabelKey feature, which allows customizing the label key used by Velero to group PVCs for VolumeGroupSnapshots (default: velero.io/volume-group), was added in Velero v1.17.0. It is configurable via the Backup spec field volumeGroupSnapshotLabelKey, the server flag --volume-group-snapshot-label-key, or defaults to velero.io/volume-group.
Citations:
CRITICAL: Test case references a non-existent BackupSpec field in current Velero version.
The
VolumeGroupSnapshotLabelKeyfield was added in Velero v1.17.0, but this project uses v1.14.0. The test case at lines 381-385 will fail when the completeness check (lines 460-475) attempts to validate the field against the actualvelerov1.BackupSpecstruct via reflection. The field does not exist in v1.14.0's BackupSpec.Either upgrade Velero to v1.17.0 or later, or remove this test case.
🤖 Prompt for AI Agents