Skip to content

Commit bca516f

Browse files
authored
Merge pull request kubernetes#87687 from markusthoemmes/action-match-subresource
Allow Action's Matches function to specify a subresource.
2 parents fc90261 + 47277f2 commit bca516f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

staging/src/k8s.io/client-go/testing/actions.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,18 @@ func (a ActionImpl) GetSubresource() string {
439439
return a.Subresource
440440
}
441441
func (a ActionImpl) Matches(verb, resource string) bool {
442+
// Stay backwards compatible.
443+
if !strings.Contains(resource, "/") {
444+
return strings.EqualFold(verb, a.Verb) &&
445+
strings.EqualFold(resource, a.Resource.Resource)
446+
}
447+
448+
parts := strings.SplitN(resource, "/", 2)
449+
topresource, subresource := parts[0], parts[1]
450+
442451
return strings.EqualFold(verb, a.Verb) &&
443-
strings.EqualFold(resource, a.Resource.Resource)
452+
strings.EqualFold(topresource, a.Resource.Resource) &&
453+
strings.EqualFold(subresource, a.Subresource)
444454
}
445455
func (a ActionImpl) DeepCopy() Action {
446456
ret := a

0 commit comments

Comments
 (0)