Skip to content

Commit 6e35149

Browse files
Merge pull request #54257 from tiran/lister-getbykey
Automatic merge from submit-queue (batch tested with PRs 53194, 54257, 53014). 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>. 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. See openshift/origin#16954 Kubernetes-commit: 4282ab39fc15d8267ceac36398947465867027db
2 parents b6644f7 + 3ddb0be commit 6e35149

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

cmd/lister-gen/generators/lister.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ func (s *$.type|private$Lister) $.type|publicPlural$(namespace string) $.type|pu
322322
var typeLister_NonNamespacedGet = `
323323
// Get retrieves the $.type|public$ from the index for a given name.
324324
func (s *$.type|private$Lister) Get(name string) (*$.type|raw$, error) {
325-
key := &$.type|raw${ObjectMeta: $.objectMeta|raw${Name: name}}
326-
obj, exists, err := s.indexer.Get(key)
325+
obj, exists, err := s.indexer.GetByKey(name)
327326
if err != nil {
328327
return nil, err
329328
}

0 commit comments

Comments
 (0)