mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-16 16:21:11 +00:00
Allow Action's Matches function to specify a subresource.
In other parts of the system (notably in RBAC rules), the "resource/subresource" notation is common to specify an explicit subresource. This makes this notation available to tests that use the `Matches` function on client actions as well. Backwards compatibility is kept by ignoring the `Subresource` field if no specific subresource is defined in the resource string itself. Kubernetes-commit: 47277f281eb0e7d484555e4d210b0ddb42974793
This commit is contained in:
parent
1ae532aad6
commit
1133cbffc1
@ -439,8 +439,18 @@ func (a ActionImpl) GetSubresource() string {
|
||||
return a.Subresource
|
||||
}
|
||||
func (a ActionImpl) Matches(verb, resource string) bool {
|
||||
// Stay backwards compatible.
|
||||
if !strings.Contains(resource, "/") {
|
||||
return strings.EqualFold(verb, a.Verb) &&
|
||||
strings.EqualFold(resource, a.Resource.Resource)
|
||||
}
|
||||
|
||||
parts := strings.SplitN(resource, "/", 2)
|
||||
topresource, subresource := parts[0], parts[1]
|
||||
|
||||
return strings.EqualFold(verb, a.Verb) &&
|
||||
strings.EqualFold(resource, a.Resource.Resource)
|
||||
strings.EqualFold(topresource, a.Resource.Resource) &&
|
||||
strings.EqualFold(subresource, a.Subresource)
|
||||
}
|
||||
func (a ActionImpl) DeepCopy() Action {
|
||||
ret := a
|
||||
|
Loading…
Reference in New Issue
Block a user