Merge pull request #4890 from sseago/restoreitemaction-label-fix

continue rather than return for non-matching restore action label
pull/4899/head
Wenkai Yin(尹文开) 2022-05-09 14:34:03 +08:00 committed by GitHub
commit 1d8d2bdb4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -0,0 +1 @@
continue rather than return for non-matching restore action label

View File

@ -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)

View File

@ -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?
}