Kubelet#GetNode now uses GetNodeInfo instead of List

Both GetNode and the cache.ListWatch listfunc in the
kubelet package call List unnecessary.

GetNodeInfo is sufficient for GetNode and makes looping
through a list of nodes to check for a matching name
unnecessary.

resolves #13476
pull/6/head
Bobby Abbott 2015-09-09 16:40:53 -07:00
parent 1313e3b14e
commit 9a5f43e16d
2 changed files with 12 additions and 14 deletions

View File

@ -206,7 +206,11 @@ func NewMainKubelet(
fieldSelector := fields.Set{client.ObjectNameField: nodeName}.AsSelector()
listWatch := &cache.ListWatch{
ListFunc: func() (runtime.Object, error) {
return kubeClient.Nodes().List(labels.Everything(), fieldSelector)
obj, err := kubeClient.Nodes().Get(nodeName)
if err != nil {
return nil, err
}
return &api.NodeList{Items: []api.Node{*obj}}, nil
},
WatchFunc: func(resourceVersion string) (watch.Interface, error) {
return kubeClient.Nodes().Watch(labels.Everything(), fieldSelector, resourceVersion)
@ -713,17 +717,7 @@ func (kl *Kubelet) GetNode() (*api.Node, error) {
if kl.standaloneMode {
return nil, errors.New("no node entry for kubelet in standalone mode")
}
l, err := kl.nodeLister.List()
if err != nil {
return nil, errors.New("cannot list nodes")
}
nodeName := kl.nodeName
for _, n := range l.Items {
if n.Name == nodeName {
return &n, nil
}
}
return nil, fmt.Errorf("node %v not found", nodeName)
return kl.nodeLister.GetNodeInfo(kl.nodeName)
}
// Starts garbage collection threads.

View File

@ -18,7 +18,6 @@ package kubelet
import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
@ -966,7 +965,12 @@ type testNodeLister struct {
}
func (ls testNodeLister) GetNodeInfo(id string) (*api.Node, error) {
return nil, errors.New("not implemented")
for _, node := range ls.nodes {
if node.Name == id {
return &node, nil
}
}
return nil, fmt.Errorf("Node with name: %s does not exist", id)
}
func (ls testNodeLister) List() (api.NodeList, error) {