Skip to content

Commit

Permalink
Merge pull request #16986 from enj/enj/i/rbac_memory/16954
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

UPSTREAM: 54257: Use GetByKey() in typeLister_NonNamespacedGet

The Get() function of non-namespace lister passes a temporary object to indexer.Get() in order to fetch the actual object from the indexer. This may cause Go to allocate the temporary object on the heap instead of the stack, as it is passed into interfaces. For non-namespaced objects, Get(&Type{ObjectMeta: v1.ObjectMeta{Name: name}}) should be equivalent to GetByKey(name).

This could be the root cause of excessive allocations, e.g. in tests clusterRoleLister.Get() has trigger 4 billion allocations.

Signed-off-by: Christian Heimes <[email protected]>
Signed-off-by: Monis Khan <[email protected]>

Fixes #16954

/assign @deads2k @simo5
  • Loading branch information
openshift-merge-robot authored Oct 23, 2017
2 parents c0ea123 + 6b4f948 commit 50389c0
Show file tree
Hide file tree
Showing 81 changed files with 81 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
authorization "github.com/openshift/origin/pkg/authorization/apis/authorization"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterPolicyLister) List(selector labels.Selector) (ret []*authorizati

// Get retrieves the ClusterPolicy from the index for a given name.
func (s *clusterPolicyLister) Get(name string) (*authorization.ClusterPolicy, error) {
key := &authorization.ClusterPolicy{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
authorization "github.com/openshift/origin/pkg/authorization/apis/authorization"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterPolicyBindingLister) List(selector labels.Selector) (ret []*auth

// Get retrieves the ClusterPolicyBinding from the index for a given name.
func (s *clusterPolicyBindingLister) Get(name string) (*authorization.ClusterPolicyBinding, error) {
key := &authorization.ClusterPolicyBinding{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
authorization "github.com/openshift/origin/pkg/authorization/apis/authorization"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterRoleLister) List(selector labels.Selector) (ret []*authorization

// Get retrieves the ClusterRole from the index for a given name.
func (s *clusterRoleLister) Get(name string) (*authorization.ClusterRole, error) {
key := &authorization.ClusterRole{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
authorization "github.com/openshift/origin/pkg/authorization/apis/authorization"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterRoleBindingLister) List(selector labels.Selector) (ret []*author

// Get retrieves the ClusterRoleBinding from the index for a given name.
func (s *clusterRoleBindingLister) Get(name string) (*authorization.ClusterRoleBinding, error) {
key := &authorization.ClusterRoleBinding{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/authorization/apis/authorization/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterPolicyLister) List(selector labels.Selector) (ret []*v1.ClusterP

// Get retrieves the ClusterPolicy from the index for a given name.
func (s *clusterPolicyLister) Get(name string) (*v1.ClusterPolicy, error) {
key := &v1.ClusterPolicy{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/authorization/apis/authorization/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterPolicyBindingLister) List(selector labels.Selector) (ret []*v1.C

// Get retrieves the ClusterPolicyBinding from the index for a given name.
func (s *clusterPolicyBindingLister) Get(name string) (*v1.ClusterPolicyBinding, error) {
key := &v1.ClusterPolicyBinding{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/authorization/apis/authorization/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterRoleLister) List(selector labels.Selector) (ret []*v1.ClusterRol

// Get retrieves the ClusterRole from the index for a given name.
func (s *clusterRoleLister) Get(name string) (*v1.ClusterRole, error) {
key := &v1.ClusterRole{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/authorization/apis/authorization/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterRoleBindingLister) List(selector labels.Selector) (ret []*v1.Clu

// Get retrieves the ClusterRoleBinding from the index for a given name.
func (s *clusterRoleBindingLister) Get(name string) (*v1.ClusterRoleBinding, error) {
key := &v1.ClusterRoleBinding{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/image/generated/listers/image/internalversion/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
image "github.com/openshift/origin/pkg/image/apis/image"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *imageLister) List(selector labels.Selector) (ret []*image.Image, err er

// Get retrieves the Image from the index for a given name.
func (s *imageLister) Get(name string) (*image.Image, error) {
key := &image.Image{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/image/generated/listers/image/v1/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/image/apis/image/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *imageLister) List(selector labels.Selector) (ret []*v1.Image, err error

// Get retrieves the Image from the index for a given name.
func (s *imageLister) Get(name string) (*v1.Image, error) {
key := &v1.Image{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
network "github.com/openshift/origin/pkg/network/apis/network"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterNetworkLister) List(selector labels.Selector) (ret []*network.Cl

// Get retrieves the ClusterNetwork from the index for a given name.
func (s *clusterNetworkLister) Get(name string) (*network.ClusterNetwork, error) {
key := &network.ClusterNetwork{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
network "github.com/openshift/origin/pkg/network/apis/network"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *hostSubnetLister) List(selector labels.Selector) (ret []*network.HostSu

// Get retrieves the HostSubnet from the index for a given name.
func (s *hostSubnetLister) Get(name string) (*network.HostSubnet, error) {
key := &network.HostSubnet{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
network "github.com/openshift/origin/pkg/network/apis/network"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *netNamespaceLister) List(selector labels.Selector) (ret []*network.NetN

// Get retrieves the NetNamespace from the index for a given name.
func (s *netNamespaceLister) Get(name string) (*network.NetNamespace, error) {
key := &network.NetNamespace{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/network/generated/listers/network/v1/clusternetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/network/apis/network/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *clusterNetworkLister) List(selector labels.Selector) (ret []*v1.Cluster

// Get retrieves the ClusterNetwork from the index for a given name.
func (s *clusterNetworkLister) Get(name string) (*v1.ClusterNetwork, error) {
key := &v1.ClusterNetwork{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/network/generated/listers/network/v1/hostsubnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/network/apis/network/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *hostSubnetLister) List(selector labels.Selector) (ret []*v1.HostSubnet,

// Get retrieves the HostSubnet from the index for a given name.
func (s *hostSubnetLister) Get(name string) (*v1.HostSubnet, error) {
key := &v1.HostSubnet{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/network/generated/listers/network/v1/netnamespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/network/apis/network/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *netNamespaceLister) List(selector labels.Selector) (ret []*v1.NetNamesp

// Get retrieves the NetNamespace from the index for a given name.
func (s *netNamespaceLister) Get(name string) (*v1.NetNamespace, error) {
key := &v1.NetNamespace{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
oauth "github.com/openshift/origin/pkg/oauth/apis/oauth"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *oAuthAccessTokenLister) List(selector labels.Selector) (ret []*oauth.OA

// Get retrieves the OAuthAccessToken from the index for a given name.
func (s *oAuthAccessTokenLister) Get(name string) (*oauth.OAuthAccessToken, error) {
key := &oauth.OAuthAccessToken{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
oauth "github.com/openshift/origin/pkg/oauth/apis/oauth"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *oAuthAuthorizeTokenLister) List(selector labels.Selector) (ret []*oauth

// Get retrieves the OAuthAuthorizeToken from the index for a given name.
func (s *oAuthAuthorizeTokenLister) Get(name string) (*oauth.OAuthAuthorizeToken, error) {
key := &oauth.OAuthAuthorizeToken{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
oauth "github.com/openshift/origin/pkg/oauth/apis/oauth"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *oAuthClientLister) List(selector labels.Selector) (ret []*oauth.OAuthCl

// Get retrieves the OAuthClient from the index for a given name.
func (s *oAuthClientLister) Get(name string) (*oauth.OAuthClient, error) {
key := &oauth.OAuthClient{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package internalversion
import (
oauth "github.com/openshift/origin/pkg/oauth/apis/oauth"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *oAuthClientAuthorizationLister) List(selector labels.Selector) (ret []*

// Get retrieves the OAuthClientAuthorization from the index for a given name.
func (s *oAuthClientAuthorizationLister) Get(name string) (*oauth.OAuthClientAuthorization, error) {
key := &oauth.OAuthClientAuthorization{ObjectMeta: v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/oauth/generated/listers/oauth/v1/oauthaccesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/oauth/apis/oauth/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *oAuthAccessTokenLister) List(selector labels.Selector) (ret []*v1.OAuth

// Get retrieves the OAuthAccessToken from the index for a given name.
func (s *oAuthAccessTokenLister) Get(name string) (*v1.OAuthAccessToken, error) {
key := &v1.OAuthAccessToken{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/oauth/generated/listers/oauth/v1/oauthauthorizetoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package v1
import (
v1 "github.com/openshift/origin/pkg/oauth/apis/oauth/v1"
"k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -39,8 +38,7 @@ func (s *oAuthAuthorizeTokenLister) List(selector labels.Selector) (ret []*v1.OA

// Get retrieves the OAuthAuthorizeToken from the index for a given name.
func (s *oAuthAuthorizeTokenLister) Get(name string) (*v1.OAuthAuthorizeToken, error) {
key := &v1.OAuthAuthorizeToken{ObjectMeta: meta_v1.ObjectMeta{Name: name}}
obj, exists, err := s.indexer.Get(key)
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 50389c0

Please sign in to comment.