Merge pull request #4890 from sseago/restoreitemaction-label-fix
continue rather than return for non-matching restore action labelpull/4899/head
commit
1d8d2bdb4f
|
@ -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?
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue