mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #5033 from mikedanese/lookup-mock
mock LookupIP to speedup nodecontroller_test on some runtimes
This commit is contained in:
commit
b457379108
@ -40,6 +40,11 @@ var (
|
||||
ErrCloudInstance = errors.New("cloud provider doesn't support instances.")
|
||||
)
|
||||
|
||||
var (
|
||||
// aliased to allow mocking in tests
|
||||
lookupIP = net.LookupIP
|
||||
)
|
||||
|
||||
type NodeController struct {
|
||||
cloud cloudprovider.Interface
|
||||
matchRE string
|
||||
@ -285,7 +290,7 @@ func (s *NodeController) PopulateIPs(nodes *api.NodeList) (*api.NodeList, error)
|
||||
if addr != nil {
|
||||
node.Status.HostIP = node.Name
|
||||
} else {
|
||||
addrs, err := net.LookupIP(node.Name)
|
||||
addrs, err := lookupIP(node.Name)
|
||||
if err != nil {
|
||||
glog.Errorf("Can't get ip address of node %s: %v", node.Name, err)
|
||||
} else if len(addrs) == 0 {
|
||||
|
@ -18,6 +18,7 @@ package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"sort"
|
||||
@ -51,6 +52,12 @@ type FakeNodeHandler struct {
|
||||
RequestCount int
|
||||
}
|
||||
|
||||
func init() {
|
||||
lookupIP = func(host string) ([]net.IP, error) {
|
||||
return nil, fmt.Errorf("lookup %v: no such host", host)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *FakeNodeHandler) Nodes() client.NodeInterface {
|
||||
return c
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user