Use networking to hold network related pkgs

Change names of unclear methods

Use net as pkg name for short
This commit is contained in:
Harry Zhang
2016-01-06 23:56:41 +08:00
committed by harry
parent 33c72db59c
commit 936a11e775
43 changed files with 687 additions and 626 deletions

View File

@@ -24,6 +24,7 @@ import (
"time"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/net"
)
var (
@@ -52,7 +53,7 @@ func (r *randomAllocator) Release(_ int) {
// newPortAllocator builds PortAllocator for a given PortRange. If the PortRange is empty
// then a random port allocator is returned; otherwise, a new range-based allocator
// is returned.
func newPortAllocator(r util.PortRange) PortAllocator {
func newPortAllocator(r net.PortRange) PortAllocator {
if r.Base == 0 {
return &randomAllocator{}
}
@@ -66,14 +67,14 @@ const (
)
type rangeAllocator struct {
util.PortRange
net.PortRange
ports chan int
used big.Int
lock sync.Mutex
rand *rand.Rand
}
func newPortRangeAllocator(r util.PortRange) PortAllocator {
func newPortRangeAllocator(r net.PortRange) PortAllocator {
if r.Base == 0 || r.Size == 0 {
panic("illegal argument: may not specify an empty port range")
}

View File

@@ -20,11 +20,11 @@ import (
"reflect"
"testing"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/net"
)
func TestRangeAllocatorEmpty(t *testing.T) {
r := &util.PortRange{}
r := &net.PortRange{}
r.Set("0-0")
defer func() {
if rv := recover(); rv == nil {
@@ -35,7 +35,7 @@ func TestRangeAllocatorEmpty(t *testing.T) {
}
func TestRangeAllocatorFullyAllocated(t *testing.T) {
r := &util.PortRange{}
r := &net.PortRange{}
r.Set("1-1")
a := newPortRangeAllocator(*r)
p, err := a.AllocateNext()
@@ -67,7 +67,7 @@ func TestRangeAllocatorFullyAllocated(t *testing.T) {
}
func TestRangeAllocator_RandomishAllocation(t *testing.T) {
r := &util.PortRange{}
r := &net.PortRange{}
r.Set("1-100")
a := newPortRangeAllocator(*r)

View File

@@ -30,6 +30,8 @@ import (
"k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/iptables"
)
@@ -137,12 +139,12 @@ func IsProxyLocked(err error) bool {
// if iptables fails to update or acquire the initial lock. Once a proxier is
// created, it will keep iptables up to date in the background and will not
// terminate if a particular iptables call fails.
func NewProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables.Interface, pr util.PortRange, syncPeriod, udpIdleTimeout time.Duration) (*Proxier, error) {
func NewProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables.Interface, pr utilnet.PortRange, syncPeriod, udpIdleTimeout time.Duration) (*Proxier, error) {
if listenIP.Equal(localhostIPv4) || listenIP.Equal(localhostIPv6) {
return nil, ErrProxyOnLocalhost
}
hostIP, err := util.ChooseHostInterface()
hostIP, err := utilnet.ChooseHostInterface()
if err != nil {
return nil, fmt.Errorf("failed to select a host interface: %v", err)
}
@@ -161,7 +163,7 @@ func NewProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables.In
func createProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables.Interface, hostIP net.IP, proxyPorts PortAllocator, syncPeriod, udpIdleTimeout time.Duration) (*Proxier, error) {
// convenient to pass nil for tests..
if proxyPorts == nil {
proxyPorts = newPortAllocator(util.PortRange{})
proxyPorts = newPortAllocator(utilnet.PortRange{})
}
// Set up the iptables foundations we need.
if err := iptablesInit(iptables); err != nil {