mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-07-19 22:42:44 +00:00
Merge pull request #9989 from adam-jian-zhang/fix-globalExcludes-lookup
fix globalExcludes lookup
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Fix globalExcludes lookup, it should be lookup against lower case
|
||||
@@ -552,7 +552,9 @@ func resolveRestoreNamespacedFilterPolicies(
|
||||
// Build a quick lookup map for globally excluded resources
|
||||
globalExcludes := make(map[string]bool)
|
||||
for _, ex := range excludedResources {
|
||||
globalExcludes[ex] = true
|
||||
// We lowercase the excluded resources here because the kinds in the resource filters
|
||||
// are lowercased during resolution, and we want to ensure case-insensitive matching.
|
||||
globalExcludes[strings.ToLower(ex)] = true
|
||||
}
|
||||
|
||||
for _, policy := range policies {
|
||||
|
||||
@@ -2,9 +2,11 @@ package restore
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
logrustest "github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -283,3 +285,48 @@ func TestResolveRestoreClusterScopedFilterPolicy_Validation(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "ambiguous policy: duplicate kind")
|
||||
}
|
||||
|
||||
func TestResolveRestoreNamespacedFilterPolicies_GlobalExcludesWarning(t *testing.T) {
|
||||
log, hook := logrustest.NewNullLogger()
|
||||
helper := test.NewFakeDiscoveryHelper(true, nil)
|
||||
|
||||
policies := []resourcepolicies.NamespacedFilterPolicy{
|
||||
{
|
||||
Namespaces: []string{"ns-1"},
|
||||
ResourceFilters: []resourcepolicies.ResourceFilter{
|
||||
{
|
||||
Kinds: []string{"ConfigMaps"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
excludedResources := []string{"ConfigMaps"} // Same case
|
||||
_, _, err := resolveRestoreNamespacedFilterPolicies(policies, excludedResources, helper, log)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check if a warning was emitted
|
||||
found := false
|
||||
for _, entry := range hook.Entries {
|
||||
if entry.Level == logrus.WarnLevel && strings.Contains(entry.Message, "namespacedFilterPolicies entry lists a kind that is globally excluded") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
require.True(t, found, "expected warning about globally excluded resource")
|
||||
|
||||
hook.Reset()
|
||||
|
||||
excludedResourcesDiffCase := []string{"configmaps"} // Different case
|
||||
_, _, err = resolveRestoreNamespacedFilterPolicies(policies, excludedResourcesDiffCase, helper, log)
|
||||
require.NoError(t, err)
|
||||
|
||||
found = false
|
||||
for _, entry := range hook.Entries {
|
||||
if entry.Level == logrus.WarnLevel && strings.Contains(entry.Message, "namespacedFilterPolicies entry lists a kind that is globally excluded") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
require.True(t, found, "expected warning about globally excluded resource even if case differs")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user