mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-05-01 12:55:46 +00:00
fix bugs in finding applicable restore item actions
Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
1
changelogs/unreleased/1607-skriss
Normal file
1
changelogs/unreleased/1607-skriss
Normal file
@@ -0,0 +1 @@
|
||||
bug fix: respect namespace selector when determining which restore item actions to run
|
||||
@@ -262,9 +262,8 @@ func (kr *kubernetesRestorer) Restore(
|
||||
log: log,
|
||||
fileSystem: kr.fileSystem,
|
||||
},
|
||||
applicableActions: make(map[schema.GroupResource][]resolvedAction),
|
||||
resourceClients: make(map[resourceClientKey]client.Dynamic),
|
||||
restoredItems: make(map[velero.ResourceIdentifier]struct{}),
|
||||
resourceClients: make(map[resourceClientKey]client.Dynamic),
|
||||
restoredItems: make(map[velero.ResourceIdentifier]struct{}),
|
||||
}
|
||||
|
||||
return restoreCtx.execute()
|
||||
@@ -351,7 +350,6 @@ type context struct {
|
||||
volumeSnapshots []*volume.Snapshot
|
||||
resourceTerminatingTimeout time.Duration
|
||||
extractor *backupExtractor
|
||||
applicableActions map[schema.GroupResource][]resolvedAction
|
||||
resourceClients map[resourceClientKey]client.Dynamic
|
||||
restoredItems map[velero.ResourceIdentifier]struct{}
|
||||
}
|
||||
@@ -589,10 +587,6 @@ func addToResult(r *Result, ns string, e error) {
|
||||
}
|
||||
|
||||
func (ctx *context) getApplicableActions(groupResource schema.GroupResource, namespace string) []resolvedAction {
|
||||
if actions, ok := ctx.applicableActions[groupResource]; ok {
|
||||
return actions
|
||||
}
|
||||
|
||||
var actions []resolvedAction
|
||||
for _, action := range ctx.actions {
|
||||
if !action.resourceIncludesExcludes.ShouldInclude(groupResource.String()) {
|
||||
@@ -603,10 +597,13 @@ func (ctx *context) getApplicableActions(groupResource schema.GroupResource, nam
|
||||
continue
|
||||
}
|
||||
|
||||
if namespace == "" && !action.namespaceIncludesExcludes.IncludeEverything() {
|
||||
continue
|
||||
}
|
||||
|
||||
actions = append(actions, action)
|
||||
}
|
||||
|
||||
ctx.applicableActions[groupResource] = actions
|
||||
return actions
|
||||
}
|
||||
|
||||
|
||||
@@ -1059,6 +1059,34 @@ func TestRestoreActionsRunForCorrectItems(t *testing.T) {
|
||||
new(recordResourcesAction).ForResource("persistentvolumes"): {"pv-1", "pv-2"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "single action with a namespace selector runs only for resources in that namespace",
|
||||
restore: defaultRestore().Restore(),
|
||||
backup: defaultBackup().Backup(),
|
||||
tarball: newTarWriter(t).
|
||||
addItems("pods", test.NewPod("ns-1", "pod-1"), test.NewPod("ns-2", "pod-2")).
|
||||
addItems("persistentvolumeclaims", test.NewPVC("ns-1", "pvc-1"), test.NewPVC("ns-2", "pvc-2")).
|
||||
addItems("persistentvolumes", test.NewPV("pv-1"), test.NewPV("pv-2")).
|
||||
done(),
|
||||
apiResources: []*test.APIResource{test.Pods(), test.PVCs(), test.PVs()},
|
||||
actions: map[*recordResourcesAction][]string{
|
||||
new(recordResourcesAction).ForNamespace("ns-1"): {"ns-1/pod-1", "ns-1/pvc-1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "single action with a resource and namespace selector runs only for matching resources in that namespace",
|
||||
restore: defaultRestore().Restore(),
|
||||
backup: defaultBackup().Backup(),
|
||||
tarball: newTarWriter(t).
|
||||
addItems("pods", test.NewPod("ns-1", "pod-1"), test.NewPod("ns-2", "pod-2")).
|
||||
addItems("persistentvolumeclaims", test.NewPVC("ns-1", "pvc-1"), test.NewPVC("ns-2", "pvc-2")).
|
||||
addItems("persistentvolumes", test.NewPV("pv-1"), test.NewPV("pv-2")).
|
||||
done(),
|
||||
apiResources: []*test.APIResource{test.Pods(), test.PVCs(), test.PVs()},
|
||||
actions: map[*recordResourcesAction][]string{
|
||||
new(recordResourcesAction).ForNamespace("ns-1").ForResource("pods"): {"ns-1/pod-1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple actions, each with a different resource selector using short name, run for matching resources",
|
||||
restore: defaultRestore().Restore(),
|
||||
|
||||
@@ -337,14 +337,13 @@ status:
|
||||
Name: "my-restore",
|
||||
},
|
||||
},
|
||||
backup: backup,
|
||||
log: velerotest.NewLogger(),
|
||||
pvsToProvision: sets.NewString(),
|
||||
pvRestorer: pvRestorer,
|
||||
namespaceClient: nsClient,
|
||||
applicableActions: make(map[schema.GroupResource][]resolvedAction),
|
||||
resourceClients: make(map[resourceClientKey]pkgclient.Dynamic),
|
||||
restoredItems: make(map[velero.ResourceIdentifier]struct{}),
|
||||
backup: backup,
|
||||
log: velerotest.NewLogger(),
|
||||
pvsToProvision: sets.NewString(),
|
||||
pvRestorer: pvRestorer,
|
||||
namespaceClient: nsClient,
|
||||
resourceClients: make(map[resourceClientKey]pkgclient.Dynamic),
|
||||
restoredItems: make(map[velero.ResourceIdentifier]struct{}),
|
||||
}
|
||||
|
||||
if test.haveSnapshot {
|
||||
|
||||
Reference in New Issue
Block a user