Skip to content

Commit

Permalink
Use networking to hold network related pkgs
Browse files Browse the repository at this point in the history
Change names of unclear methods

Use net as pkg name for short
  • Loading branch information
resouer committed Jan 15, 2016
1 parent 33c72db commit 936a11e
Show file tree
Hide file tree
Showing 43 changed files with 687 additions and 626 deletions.
3 changes: 2 additions & 1 deletion cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/volume/empty_dir"
Expand Down Expand Up @@ -153,7 +154,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
}

// The caller of master.New should guarantee pulicAddress is properly set
hostIP, err := util.ValidPublicAddrForMaster(publicAddress)
hostIP, err := utilnet.ChooseBindAddress(publicAddress)
if err != nil {
glog.Fatalf("Unable to find suitable network address.error='%v' . "+
"Fail to get a valid public address for master.", err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/kube-apiserver/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
"k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"

"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -76,7 +77,7 @@ type APIServer struct {
ServiceAccountKeyFile string
ServiceAccountLookup bool
ServiceClusterIPRange net.IPNet // TODO: make this a list
ServiceNodePortRange util.PortRange
ServiceNodePortRange utilnet.PortRange
StorageVersions string
TokenAuthFile string
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
"k8s.io/kubernetes/pkg/serviceaccount"
"k8s.io/kubernetes/pkg/storage"
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"
)

// NewAPIServerCommand creates a *cobra.Command object with default parameters
Expand Down Expand Up @@ -164,9 +164,9 @@ func Run(s *options.APIServer) error {

// If advertise-address is not specified, use bind-address. If bind-address
// is not usable (unset, 0.0.0.0, or loopback), we will use the host's default
// interface as valid public addr for master (see: util#ValidPublicAddrForMaster)
// interface as valid public addr for master (see: util/net#ValidPublicAddrForMaster)
if s.AdvertiseAddress == nil || s.AdvertiseAddress.IsUnspecified() {
hostIP, err := util.ValidPublicAddrForMaster(s.BindAddress)
hostIP, err := utilnet.ChooseBindAddress(s.BindAddress)
if err != nil {
glog.Fatalf("Unable to find suitable network address.error='%v' . "+
"Try to set the AdvertiseAddress directly or provide a valid BindAddress to fix this.", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kube-proxy/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/kubelet/qos"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"

"github.com/spf13/pflag"
)
Expand All @@ -42,7 +42,7 @@ type ProxyServerConfig struct {
ResourceContainer string
Master string
Kubeconfig string
PortRange util.PortRange
PortRange utilnet.PortRange
HostnameOverride string
ProxyMode string
IptablesSyncPeriod time.Duration
Expand Down
3 changes: 2 additions & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"k8s.io/kubernetes/pkg/util"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/flushwriter"
utilnet "k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/util/wsstream"
"k8s.io/kubernetes/pkg/version"

Expand All @@ -61,7 +62,7 @@ func monitorFilter(action, resource string) restful.FilterFunction {
reqStart := time.Now()
chain.ProcessFilter(req, res)
httpCode := res.StatusCode()
metrics.Monitor(&action, &resource, util.GetClient(req.Request), &httpCode, reqStart)
metrics.Monitor(&action, &resource, utilnet.GetHTTPClient(req.Request), &httpCode, reqStart)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/apiserver/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
"k8s.io/kubernetes/pkg/apiserver/metrics"
"k8s.io/kubernetes/pkg/httplog"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/httpstream"
"k8s.io/kubernetes/pkg/util/net"
proxyutil "k8s.io/kubernetes/pkg/util/proxy"

"github.com/golang/glog"
Expand All @@ -56,7 +56,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var apiResource string
var httpCode int
reqStart := time.Now()
defer metrics.Monitor(&verb, &apiResource, util.GetClient(req), &httpCode, reqStart)
defer metrics.Monitor(&verb, &apiResource, net.GetHTTPClient(req), &httpCode, reqStart)

requestInfo, err := r.requestInfoResolver.GetRequestInfo(req)
if err != nil || !requestInfo.IsResourceRequest {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apiserver/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"k8s.io/kubernetes/pkg/probe"
httpprober "k8s.io/kubernetes/pkg/probe/http"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"
"time"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func (server *Server) DoServerCheck(prober httpprober.HTTPProber) (probe.Result,
if server.EnableHTTPS {
scheme = "https"
}
url := util.FormatURL(scheme, server.Addr, server.Port, server.Path)
url := utilnet.FormatURL(scheme, server.Addr, server.Port, server.Path)

result, data, err := prober.Probe(url, probeTimeOut)

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/chaosclient/chaosclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"reflect"
"runtime"

"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/net"
)

// chaosrt provides the ability to perform simulations of HTTP client failures
Expand Down Expand Up @@ -88,7 +88,7 @@ func (rt *chaosrt) RoundTrip(req *http.Request) (*http.Response, error) {
return rt.rt.RoundTrip(req)
}

var _ = util.RoundTripperWrapper(&chaosrt{})
var _ = net.RoundTripperWrapper(&chaosrt{})

func (rt *chaosrt) WrappedRoundTripper() http.RoundTripper {
return rt.rt
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/unversioned/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/watch"
watchjson "k8s.io/kubernetes/pkg/watch/json"
Expand Down Expand Up @@ -637,7 +637,7 @@ func (r *Request) Watch() (watch.Interface, error) {
if err != nil {
// The watch stream mechanism handles many common partial data errors, so closed
// connections can be retried in many cases.
if util.IsProbableEOF(err) {
if net.IsProbableEOF(err) {
return watch.NewEmptyWatch(), nil
}
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/unversioned/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package unversioned

import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/watch"
)

Expand Down Expand Up @@ -103,7 +103,7 @@ func (c *services) ProxyGet(scheme, name, port, path string, params map[string]s
Prefix("proxy").
Namespace(c.ns).
Resource("services").
Name(util.JoinSchemeNamePort(scheme, name, port)).
Name(net.JoinSchemeNamePort(scheme, name, port)).
Suffix(path)
for k, v := range params {
request = request.Param(k, v)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/providers/mesos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"golang.org/x/net/context"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"
)

const defaultClusterName = "mesos"
Expand Down Expand Up @@ -111,7 +111,7 @@ func newMesosClient(
md detector.Master,
mesosHttpClientTimeout, stateCacheTTL time.Duration) (*mesosClient, error) {

tr := util.SetTransportDefaults(&http.Transport{})
tr := utilnet.SetTransportDefaults(&http.Transport{})
httpClient := &http.Client{
Transport: tr,
Timeout: mesosHttpClientTimeout,
Expand Down
9 changes: 5 additions & 4 deletions pkg/genericapiserver/genericapiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/ui"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/util/sets"

systemd "github.com/coreos/go-systemd/daemon"
Expand Down Expand Up @@ -212,7 +213,7 @@ type Config struct {
ServiceReadWriteIP net.IP

// The range of ports to be assigned to services with type=NodePort or greater
ServiceNodePortRange util.PortRange
ServiceNodePortRange utilnet.PortRange

// Used to customize default proxy dial/tls options
ProxyDialer apiserver.ProxyDialerFunc
Expand All @@ -237,7 +238,7 @@ type Config struct {
type GenericAPIServer struct {
// "Inputs", Copied from Config
ServiceClusterIPRange *net.IPNet
ServiceNodePortRange util.PortRange
ServiceNodePortRange utilnet.PortRange
cacheTimeout time.Duration
MinRequestTimeout time.Duration

Expand Down Expand Up @@ -319,7 +320,7 @@ func setDefaults(c *Config) {
// We should probably allow this for clouds that don't require NodePort to do load-balancing (GCE)
// but then that breaks the strict nestedness of ServiceType.
// Review post-v1
defaultServiceNodePortRange := util.PortRange{Base: 30000, Size: 2768}
defaultServiceNodePortRange := utilnet.PortRange{Base: 30000, Size: 2768}
c.ServiceNodePortRange = defaultServiceNodePortRange
glog.Infof("Node port range unspecified. Defaulting to %v.", c.ServiceNodePortRange)
}
Expand Down Expand Up @@ -454,7 +455,7 @@ func NewHandlerContainer(mux *http.ServeMux) *restful.Container {
func (s *GenericAPIServer) init(c *Config) {

if c.ProxyDialer != nil || c.ProxyTLSClientConfig != nil {
s.ProxyTransport = util.SetTransportDefaults(&http.Transport{
s.ProxyTransport = utilnet.SetTransportDefaults(&http.Transport{
Dial: c.ProxyDialer,
TLSClientConfig: c.ProxyTLSClientConfig,
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/genericapiserver/genericapiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apiserver"
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestNew(t *testing.T) {
assert.Equal(s.ServiceReadWriteIP, config.ServiceReadWriteIP)

// These functions should point to the same memory location
serverDialer, _ := util.Dialer(s.ProxyTransport)
serverDialer, _ := utilnet.Dialer(s.ProxyTransport)
serverDialerFunc := fmt.Sprintf("%p", serverDialer)
configDialerFunc := fmt.Sprintf("%p", config.ProxyDialer)
assert.Equal(serverDialerFunc, configDialerFunc)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/client/kubelet_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/client/transport"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util"
utilnet "k8s.io/kubernetes/pkg/util/net"
)

type KubeletClientConfig struct {
Expand Down Expand Up @@ -71,7 +71,7 @@ func MakeTransport(config *KubeletClientConfig) (http.RoundTripper, error) {

rt := http.DefaultTransport
if config.Dial != nil || tlsConfig != nil {
rt = util.SetTransportDefaults(&http.Transport{
rt = utilnet.SetTransportDefaults(&http.Transport{
Dial: config.Dial,
TLSClientConfig: tlsConfig,
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
utilerrors "k8s.io/kubernetes/pkg/util/errors"
kubeio "k8s.io/kubernetes/pkg/util/io"
"k8s.io/kubernetes/pkg/util/mount"
utilnet "k8s.io/kubernetes/pkg/util/net"
nodeutil "k8s.io/kubernetes/pkg/util/node"
"k8s.io/kubernetes/pkg/util/oom"
"k8s.io/kubernetes/pkg/util/procfs"
Expand Down Expand Up @@ -2677,7 +2678,7 @@ func (kl *Kubelet) setNodeAddress(node *api.Node) error {
}

if len(node.Status.Addresses) == 0 {
ip, err := util.ChooseHostInterface()
ip, err := utilnet.ChooseHostInterface()
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/master/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net"
"time"

"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/endpoints"
"k8s.io/kubernetes/pkg/api/errors"
Expand All @@ -32,8 +33,7 @@ import (
portallocatorcontroller "k8s.io/kubernetes/pkg/registry/service/portallocator/controller"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"

"github.com/golang/glog"
utilnet "k8s.io/kubernetes/pkg/util/net"
)

// Controller is the controller manager for the core bootstrap Kubernetes controller
Expand All @@ -51,7 +51,7 @@ type Controller struct {

ServiceNodePortRegistry service.RangeRegistry
ServiceNodePortInterval time.Duration
ServiceNodePortRange util.PortRange
ServiceNodePortRange utilnet.PortRange

EndpointRegistry endpoint.Registry
EndpointInterval time.Duration
Expand Down
7 changes: 4 additions & 3 deletions pkg/master/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
apiutil "k8s.io/kubernetes/pkg/api/util"
utilnet "k8s.io/kubernetes/pkg/util/net"

"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/genericapiserver"
"k8s.io/kubernetes/pkg/kubelet/client"
Expand All @@ -44,7 +46,6 @@ import (
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
"k8s.io/kubernetes/pkg/storage/etcd/etcdtest"
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/intstr"

"github.com/emicklei/go-restful"
Expand Down Expand Up @@ -110,7 +111,7 @@ func TestNew(t *testing.T) {
assert.Equal(master.ServiceReadWriteIP, config.ServiceReadWriteIP)

// These functions should point to the same memory location
masterDialer, _ := util.Dialer(master.ProxyTransport)
masterDialer, _ := utilnet.Dialer(master.ProxyTransport)
masterDialerFunc := fmt.Sprintf("%p", masterDialer)
configDialerFunc := fmt.Sprintf("%p", config.ProxyDialer)
assert.Equal(masterDialerFunc, configDialerFunc)
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestNewBootstrapController(t *testing.T) {
master, etcdserver, _, assert := setUp(t)
defer etcdserver.Terminate(t)

portRange := util.PortRange{Base: 10, Size: 10}
portRange := utilnet.PortRange{Base: 10, Size: 10}

master.namespaceRegistry = namespace.NewRegistry(nil)
master.serviceRegistry = registrytest.NewServiceRegistry()
Expand Down
7 changes: 4 additions & 3 deletions pkg/proxy/userspace/port_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/net"
)

var (
Expand Down Expand Up @@ -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{}
}
Expand All @@ -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")
}
Expand Down
Loading

0 comments on commit 936a11e

Please sign in to comment.