mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 13:55:20 +00:00
continue rather than return for non-matching restore action label
When iterating over applicable restore actions, if a non-matching label selector is found, velero should continue to the next action rather than returning from the restoreItem func, which ends up preventing the item's restore entirely. Signed-off-by: Scott Seago <sseago@redhat.com>
This commit is contained in:
1
changelogs/unreleased/4890-sseago
Normal file
1
changelogs/unreleased/4890-sseago
Normal file
@@ -0,0 +1 @@
|
||||
continue rather than return for non-matching restore action label
|
||||
@@ -1106,7 +1106,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
||||
|
||||
for _, action := range ctx.getApplicableActions(groupResource, namespace) {
|
||||
if !action.Selector.Matches(labels.Set(obj.GetLabels())) {
|
||||
return warnings, errs
|
||||
continue
|
||||
}
|
||||
|
||||
ctx.log.Infof("Executing item action for %v", &groupResource)
|
||||
|
||||
@@ -1270,6 +1270,11 @@ func (a *pluggableAction) AppliesTo() (velero.ResourceSelector, error) {
|
||||
return a.selector, nil
|
||||
}
|
||||
|
||||
func (a *pluggableAction) addSelector(selector velero.ResourceSelector) *pluggableAction {
|
||||
a.selector = selector
|
||||
return a
|
||||
}
|
||||
|
||||
// TestRestoreActionModifications runs restores with restore item actions that modify resources, and
|
||||
// verifies that that the modified item is correctly created in the API. Verification is done by looking
|
||||
// at the full object in the API.
|
||||
@@ -1335,6 +1340,26 @@ func TestRestoreActionModifications(t *testing.T) {
|
||||
test.Pods(builder.ForPod("ns-1", "pod-1").Result()),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "action with non-matching label selector doesn't prevent restore",
|
||||
restore: defaultRestore().Result(),
|
||||
backup: defaultBackup().Result(),
|
||||
tarball: test.NewTarWriter(t).AddItems("pods", builder.ForPod("ns-1", "pod-1").Result()).Done(),
|
||||
apiResources: []*test.APIResource{test.Pods()},
|
||||
actions: []velero.RestoreItemAction{
|
||||
modifyingActionGetter(func(item *unstructured.Unstructured) {
|
||||
item.SetLabels(map[string]string{"updated": "true"})
|
||||
}).addSelector(velero.ResourceSelector{
|
||||
IncludedResources: []string{
|
||||
"Pod",
|
||||
},
|
||||
LabelSelector: "nonmatching=label",
|
||||
}),
|
||||
},
|
||||
want: []*test.APIResource{
|
||||
test.Pods(builder.ForPod("ns-1", "pod-1").Result()),
|
||||
},
|
||||
},
|
||||
// TODO action that modifies namespace/name - what's the expected behavior?
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user