Merge pull request #51458 from CaoShuFeng/use_map_in_admit

Automatic merge from submit-queue (batch tested with PRs 51310, 51458, 47636). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

remove useless allocation of map

This one-element map is only used for checking api. Remove it and
simplify the code.

**Release note**:
```
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-10-18 20:47:07 -07:00 committed by GitHub
commit 3f2ce7e557

View File

@ -31,7 +31,6 @@ import (
"k8s.io/api/imagepolicy/v1alpha1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
kubeschema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/cache"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/apiserver/pkg/admission"
@ -110,11 +109,7 @@ func (a *imagePolicyWebhook) webhookError(pod *api.Pod, attributes admission.Att
func (a *imagePolicyWebhook) Admit(attributes admission.Attributes) (err error) {
// Ignore all calls to subresources or resources other than pods.
allowedResources := map[kubeschema.GroupResource]bool{
api.Resource("pods"): true,
}
if len(attributes.GetSubresource()) != 0 || !allowedResources[attributes.GetResource().GroupResource()] {
if attributes.GetSubresource() != "" || attributes.GetResource().GroupResource() != api.Resource("pods") {
return nil
}