mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 13:55:20 +00:00
bug fix: don't remove unresolvable includes from includes-excludes lists (#2462)
* bug fix: don't remove unresolvable includes from includes-excludes lists Signed-off-by: Steve Kriss <krisss@vmware.com> * changelog Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
@@ -142,7 +142,10 @@ func getResourceIncludesExcludes(helper discovery.Helper, includes, excludes []s
|
||||
func(item string) string {
|
||||
gvr, _, err := helper.ResourceFor(schema.ParseGroupResource(item).WithVersion(""))
|
||||
if err != nil {
|
||||
return ""
|
||||
// If we can't resolve it, return it as-is. This prevents the generated
|
||||
// includes-excludes list from including *everything*, if none of the includes
|
||||
// can be resolved. ref. https://github.com/vmware-tanzu/velero/issues/2461
|
||||
return item
|
||||
}
|
||||
|
||||
gr := gvr.GroupResource()
|
||||
|
||||
@@ -543,6 +543,23 @@ func TestBackupResourceFiltering(t *testing.T) {
|
||||
"resources/pods/namespaces/zoo/raz.json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "when all included resources are unresolvable, nothing is included",
|
||||
backup: defaultBackup().
|
||||
IncludedResources("unresolvable-1", "unresolvable-2").
|
||||
Result(),
|
||||
apiResources: []*test.APIResource{
|
||||
test.Pods(
|
||||
builder.ForPod("foo", "bar").Result(),
|
||||
builder.ForPod("zoo", "raz").Result(),
|
||||
),
|
||||
test.Deployments(
|
||||
builder.ForDeployment("foo", "bar").Result(),
|
||||
builder.ForDeployment("zoo", "raz").Result(),
|
||||
),
|
||||
},
|
||||
want: []string{},
|
||||
},
|
||||
{
|
||||
name: "unresolvable excluded resources are ignored",
|
||||
backup: defaultBackup().
|
||||
@@ -563,6 +580,29 @@ func TestBackupResourceFiltering(t *testing.T) {
|
||||
"resources/pods/namespaces/zoo/raz.json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "when all excluded resources are unresolvable, nothing is excluded",
|
||||
backup: defaultBackup().
|
||||
IncludedResources("*").
|
||||
ExcludedResources("unresolvable-1", "unresolvable-2").
|
||||
Result(),
|
||||
apiResources: []*test.APIResource{
|
||||
test.Pods(
|
||||
builder.ForPod("foo", "bar").Result(),
|
||||
builder.ForPod("zoo", "raz").Result(),
|
||||
),
|
||||
test.Deployments(
|
||||
builder.ForDeployment("foo", "bar").Result(),
|
||||
builder.ForDeployment("zoo", "raz").Result(),
|
||||
),
|
||||
},
|
||||
want: []string{
|
||||
"resources/pods/namespaces/foo/bar.json",
|
||||
"resources/pods/namespaces/zoo/raz.json",
|
||||
"resources/deployments.apps/namespaces/foo/bar.json",
|
||||
"resources/deployments.apps/namespaces/zoo/raz.json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "terminating resources are not backed up",
|
||||
backup: defaultBackup().Result(),
|
||||
@@ -1101,6 +1141,26 @@ func TestBackupActionsRunForCorrectItems(t *testing.T) {
|
||||
new(recordResourcesAction).ForNamespace("ns-2").ForResource("pods"): nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "action with a selector that has unresolvable resources doesn't run for any resources",
|
||||
backup: defaultBackup().
|
||||
Result(),
|
||||
apiResources: []*test.APIResource{
|
||||
test.Pods(
|
||||
builder.ForPod("ns-1", "pod-1").Result(),
|
||||
),
|
||||
test.PVCs(
|
||||
builder.ForPersistentVolumeClaim("ns-2", "pvc-2").Result(),
|
||||
),
|
||||
test.PVs(
|
||||
builder.ForPersistentVolume("pv-1").Result(),
|
||||
builder.ForPersistentVolume("pv-2").Result(),
|
||||
),
|
||||
},
|
||||
actions: map[*recordResourcesAction][]string{
|
||||
new(recordResourcesAction).ForResource("unresolvable"): nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2017 the Velero contributors.
|
||||
Copyright 2017, 2020 the Velero contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -172,6 +172,12 @@ func GenerateIncludesExcludes(includes, excludes []string, mapFunc func(string)
|
||||
}
|
||||
|
||||
for _, item := range excludes {
|
||||
// wildcards are invalid for excludes,
|
||||
// so ignore them.
|
||||
if item == "*" {
|
||||
continue
|
||||
}
|
||||
|
||||
key := mapFunc(item)
|
||||
if key == "" {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user