Merge pull request #3000 from Shell32-Natsu/res-select

fix namespace will match all empty namespace
This commit is contained in:
Kubernetes Prow Robot
2020-09-21 13:07:52 -07:00
committed by GitHub
2 changed files with 14 additions and 2 deletions

View File

@@ -530,7 +530,7 @@ func (m *resWrangler) Select(s types.Selector) ([]*resource.Resource, error) {
// matches the namespace when namespace is not empty in the selector // matches the namespace when namespace is not empty in the selector
// It first tries to match with the original namespace // It first tries to match with the original namespace
// then matches with the current namespace // then matches with the current namespace
if r.GetNamespace() != "" { if s.Namespace != "" {
matched := ns.MatchString(orgId.EffectiveNamespace()) matched := ns.MatchString(orgId.EffectiveNamespace())
if !matched { if !matched {
matched = ns.MatchString(curId.EffectiveNamespace()) matched = ns.MatchString(curId.EffectiveNamespace())
@@ -543,7 +543,7 @@ func (m *resWrangler) Select(s types.Selector) ([]*resource.Resource, error) {
// matches the name when name is not empty in the selector // matches the name when name is not empty in the selector
// It first tries to match with the original name // It first tries to match with the original name
// then matches with the current name // then matches with the current name
if r.GetName() != "" { if s.Name != "" {
matched := nm.MatchString(orgId.Name) matched := nm.MatchString(orgId.Name)
if !matched { if !matched {
matched = nm.MatchString(curId.Name) matched = nm.MatchString(curId.Name)

View File

@@ -164,6 +164,18 @@ func TestFindPatchTargets(t *testing.T) {
}, },
count: 2, count: 2,
}, },
{
target: types.Selector{
Namespace: "NotMatched",
},
count: 0,
},
{
target: types.Selector{
Namespace: "ns1",
},
count: 1,
},
} }
for _, testcase := range testcases { for _, testcase := range testcases {
actual, err := rm.Select(testcase.target) actual, err := rm.Select(testcase.target)