use versioned api in kube-proxy

pull/8/head
x00416946 fisherxu 2018-08-15 21:51:19 +08:00 committed by fisherxu
parent c582a37cae
commit 79e17e6cd7
31 changed files with 1482 additions and 1513 deletions

View File

@ -41,7 +41,8 @@ import (
"k8s.io/apiserver/pkg/server/routes" "k8s.io/apiserver/pkg/server/routes"
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/apiserver/pkg/util/flag" "k8s.io/apiserver/pkg/util/flag"
clientgoclientset "k8s.io/client-go/kubernetes" informers "k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1" v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
@ -49,8 +50,6 @@ import (
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/apis/componentconfig" "k8s.io/kubernetes/pkg/apis/componentconfig"
api "k8s.io/kubernetes/pkg/apis/core" api "k8s.io/kubernetes/pkg/apis/core"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
"k8s.io/kubernetes/pkg/kubelet/qos" "k8s.io/kubernetes/pkg/kubelet/qos"
"k8s.io/kubernetes/pkg/master/ports" "k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
@ -434,7 +433,7 @@ func createClients(config kubeproxyconfig.ClientConnectionConfiguration, masterO
return nil, nil, err return nil, nil, err
} }
eventClient, err := clientgoclientset.NewForConfig(kubeConfig) eventClient, err := clientset.NewForConfig(kubeConfig)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -550,11 +549,11 @@ func (s *ProxyServer) Run() error {
// Note: RegisterHandler() calls need to happen before creation of Sources because sources // Note: RegisterHandler() calls need to happen before creation of Sources because sources
// only notify on changes, and the initial update (on process start) may be lost if no handlers // only notify on changes, and the initial update (on process start) may be lost if no handlers
// are registered yet. // are registered yet.
serviceConfig := config.NewServiceConfig(informerFactory.Core().InternalVersion().Services(), s.ConfigSyncPeriod) serviceConfig := config.NewServiceConfig(informerFactory.Core().V1().Services(), s.ConfigSyncPeriod)
serviceConfig.RegisterEventHandler(s.ServiceEventHandler) serviceConfig.RegisterEventHandler(s.ServiceEventHandler)
go serviceConfig.Run(wait.NeverStop) go serviceConfig.Run(wait.NeverStop)
endpointsConfig := config.NewEndpointsConfig(informerFactory.Core().InternalVersion().Endpoints(), s.ConfigSyncPeriod) endpointsConfig := config.NewEndpointsConfig(informerFactory.Core().V1().Endpoints(), s.ConfigSyncPeriod)
endpointsConfig.RegisterEventHandler(s.EndpointsEventHandler) endpointsConfig.RegisterEventHandler(s.EndpointsEventHandler)
go endpointsConfig.Run(wait.NeverStop) go endpointsConfig.Run(wait.NeverStop)
@ -600,12 +599,12 @@ func getConntrackMax(config kubeproxyconfig.KubeProxyConntrackConfiguration) (in
func getNodeIP(client clientset.Interface, hostname string) net.IP { func getNodeIP(client clientset.Interface, hostname string) net.IP {
var nodeIP net.IP var nodeIP net.IP
node, err := client.Core().Nodes().Get(hostname, metav1.GetOptions{}) node, err := client.CoreV1().Nodes().Get(hostname, metav1.GetOptions{})
if err != nil { if err != nil {
glog.Warningf("Failed to retrieve node info: %v", err) glog.Warningf("Failed to retrieve node info: %v", err)
return nil return nil
} }
nodeIP, err = utilnode.InternalGetNodeHostIP(node) nodeIP, err = utilnode.GetNodeHostIP(node)
if err != nil { if err != nil {
glog.Warningf("Failed to retrieve node IP: %v", err) glog.Warningf("Failed to retrieve node IP: %v", err)
return nil return nil

View File

@ -36,7 +36,6 @@ import (
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
_ "k8s.io/kubernetes/pkg/client/metrics/prometheus" // for client metric registration _ "k8s.io/kubernetes/pkg/client/metrics/prometheus" // for client metric registration
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing" cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
"k8s.io/kubernetes/pkg/kubelet/cm" "k8s.io/kubernetes/pkg/kubelet/cm"
@ -152,10 +151,6 @@ func run(config *HollowNodeConfig) {
if err != nil { if err != nil {
glog.Fatalf("Failed to create a ClientSet: %v. Exiting.", err) glog.Fatalf("Failed to create a ClientSet: %v. Exiting.", err)
} }
internalClientset, err := internalclientset.NewForConfig(clientConfig)
if err != nil {
glog.Fatalf("Failed to create an internal ClientSet: %v. Exiting.", err)
}
if config.Morph == "kubelet" { if config.Morph == "kubelet" {
cadvisorInterface := &cadvisortest.Fake{ cadvisorInterface := &cadvisortest.Fake{
@ -196,7 +191,7 @@ func run(config *HollowNodeConfig) {
hollowProxy, err := kubemark.NewHollowProxyOrDie( hollowProxy, err := kubemark.NewHollowProxyOrDie(
config.NodeName, config.NodeName,
internalClientset, client,
client.CoreV1(), client.CoreV1(),
iptInterface, iptInterface,
sysctl, sysctl,

View File

@ -24,11 +24,10 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1" v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
proxyapp "k8s.io/kubernetes/cmd/kube-proxy/app" proxyapp "k8s.io/kubernetes/cmd/kube-proxy/app"
api "k8s.io/kubernetes/pkg/apis/core"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
proxyconfig "k8s.io/kubernetes/pkg/proxy/config" proxyconfig "k8s.io/kubernetes/pkg/proxy/config"
"k8s.io/kubernetes/pkg/proxy/iptables" "k8s.io/kubernetes/pkg/proxy/iptables"
@ -51,14 +50,14 @@ func (*FakeProxier) Sync() {}
func (*FakeProxier) SyncLoop() { func (*FakeProxier) SyncLoop() {
select {} select {}
} }
func (*FakeProxier) OnServiceAdd(service *api.Service) {} func (*FakeProxier) OnServiceAdd(service *v1.Service) {}
func (*FakeProxier) OnServiceUpdate(oldService, service *api.Service) {} func (*FakeProxier) OnServiceUpdate(oldService, service *v1.Service) {}
func (*FakeProxier) OnServiceDelete(service *api.Service) {} func (*FakeProxier) OnServiceDelete(service *v1.Service) {}
func (*FakeProxier) OnServiceSynced() {} func (*FakeProxier) OnServiceSynced() {}
func (*FakeProxier) OnEndpointsAdd(endpoints *api.Endpoints) {} func (*FakeProxier) OnEndpointsAdd(endpoints *v1.Endpoints) {}
func (*FakeProxier) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) {} func (*FakeProxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {}
func (*FakeProxier) OnEndpointsDelete(endpoints *api.Endpoints) {} func (*FakeProxier) OnEndpointsDelete(endpoints *v1.Endpoints) {}
func (*FakeProxier) OnEndpointsSynced() {} func (*FakeProxier) OnEndpointsSynced() {}
func NewHollowProxyOrDie( func NewHollowProxyOrDie(
nodeName string, nodeName string,
@ -142,12 +141,12 @@ func (hp *HollowProxy) Run() {
func getNodeIP(client clientset.Interface, hostname string) net.IP { func getNodeIP(client clientset.Interface, hostname string) net.IP {
var nodeIP net.IP var nodeIP net.IP
node, err := client.Core().Nodes().Get(hostname, metav1.GetOptions{}) node, err := client.CoreV1().Nodes().Get(hostname, metav1.GetOptions{})
if err != nil { if err != nil {
glog.Warningf("Failed to retrieve node info: %v", err) glog.Warningf("Failed to retrieve node info: %v", err)
return nil return nil
} }
nodeIP, err = utilnode.InternalGetNodeHostIP(node) nodeIP, err = utilnode.GetNodeHostIP(node)
if err != nil { if err != nil {
glog.Warningf("Failed to retrieve node IP: %v", err) glog.Warningf("Failed to retrieve node IP: %v", err)
return nil return nil

View File

@ -22,25 +22,25 @@ import (
"testing" "testing"
"time" "time"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
informers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
ktesting "k8s.io/client-go/testing" ktesting "k8s.io/client-go/testing"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
) )
func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) {
service1v1 := &api.Service{ service1v1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "s1"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "s1"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 10}}}} Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 10}}}}
service1v2 := &api.Service{ service1v2 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "s1"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "s1"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 20}}}} Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 20}}}}
service2 := &api.Service{ service2 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "s2"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "s2"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 30}}}} Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 30}}}}
// Setup fake api client. // Setup fake api client.
client := fake.NewSimpleClientset() client := fake.NewSimpleClientset()
@ -54,59 +54,59 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, time.Minute) sharedInformers := informers.NewSharedInformerFactory(client, time.Minute)
serviceConfig := NewServiceConfig(sharedInformers.Core().InternalVersion().Services(), time.Minute) serviceConfig := NewServiceConfig(sharedInformers.Core().V1().Services(), time.Minute)
serviceConfig.RegisterEventHandler(handler) serviceConfig.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh) go sharedInformers.Start(stopCh)
go serviceConfig.Run(stopCh) go serviceConfig.Run(stopCh)
// Add the first service // Add the first service
fakeWatch.Add(service1v1) fakeWatch.Add(service1v1)
handler.ValidateServices(t, []*api.Service{service1v1}) handler.ValidateServices(t, []*v1.Service{service1v1})
// Add another service // Add another service
fakeWatch.Add(service2) fakeWatch.Add(service2)
handler.ValidateServices(t, []*api.Service{service1v1, service2}) handler.ValidateServices(t, []*v1.Service{service1v1, service2})
// Modify service1 // Modify service1
fakeWatch.Modify(service1v2) fakeWatch.Modify(service1v2)
handler.ValidateServices(t, []*api.Service{service1v2, service2}) handler.ValidateServices(t, []*v1.Service{service1v2, service2})
// Delete service1 // Delete service1
fakeWatch.Delete(service1v2) fakeWatch.Delete(service1v2)
handler.ValidateServices(t, []*api.Service{service2}) handler.ValidateServices(t, []*v1.Service{service2})
// Delete service2 // Delete service2
fakeWatch.Delete(service2) fakeWatch.Delete(service2)
handler.ValidateServices(t, []*api.Service{}) handler.ValidateServices(t, []*v1.Service{})
} }
func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
endpoints1v1 := &api.Endpoints{ endpoints1v1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e1"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e1"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{ Addresses: []v1.EndpointAddress{
{IP: "1.2.3.4"}, {IP: "1.2.3.4"},
}, },
Ports: []api.EndpointPort{{Port: 8080, Protocol: "TCP"}}, Ports: []v1.EndpointPort{{Port: 8080, Protocol: "TCP"}},
}}, }},
} }
endpoints1v2 := &api.Endpoints{ endpoints1v2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e1"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e1"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{ Addresses: []v1.EndpointAddress{
{IP: "1.2.3.4"}, {IP: "1.2.3.4"},
{IP: "4.3.2.1"}, {IP: "4.3.2.1"},
}, },
Ports: []api.EndpointPort{{Port: 8080, Protocol: "TCP"}}, Ports: []v1.EndpointPort{{Port: 8080, Protocol: "TCP"}},
}}, }},
} }
endpoints2 := &api.Endpoints{ endpoints2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e2"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "e2"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{ Addresses: []v1.EndpointAddress{
{IP: "5.6.7.8"}, {IP: "5.6.7.8"},
}, },
Ports: []api.EndpointPort{{Port: 80, Protocol: "TCP"}}, Ports: []v1.EndpointPort{{Port: 80, Protocol: "TCP"}},
}}, }},
} }
@ -122,37 +122,37 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, time.Minute) sharedInformers := informers.NewSharedInformerFactory(client, time.Minute)
endpointsConfig := NewEndpointsConfig(sharedInformers.Core().InternalVersion().Endpoints(), time.Minute) endpointsConfig := NewEndpointsConfig(sharedInformers.Core().V1().Endpoints(), time.Minute)
endpointsConfig.RegisterEventHandler(handler) endpointsConfig.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh) go sharedInformers.Start(stopCh)
go endpointsConfig.Run(stopCh) go endpointsConfig.Run(stopCh)
// Add the first endpoints // Add the first endpoints
fakeWatch.Add(endpoints1v1) fakeWatch.Add(endpoints1v1)
handler.ValidateEndpoints(t, []*api.Endpoints{endpoints1v1}) handler.ValidateEndpoints(t, []*v1.Endpoints{endpoints1v1})
// Add another endpoints // Add another endpoints
fakeWatch.Add(endpoints2) fakeWatch.Add(endpoints2)
handler.ValidateEndpoints(t, []*api.Endpoints{endpoints1v1, endpoints2}) handler.ValidateEndpoints(t, []*v1.Endpoints{endpoints1v1, endpoints2})
// Modify endpoints1 // Modify endpoints1
fakeWatch.Modify(endpoints1v2) fakeWatch.Modify(endpoints1v2)
handler.ValidateEndpoints(t, []*api.Endpoints{endpoints1v2, endpoints2}) handler.ValidateEndpoints(t, []*v1.Endpoints{endpoints1v2, endpoints2})
// Delete endpoints1 // Delete endpoints1
fakeWatch.Delete(endpoints1v2) fakeWatch.Delete(endpoints1v2)
handler.ValidateEndpoints(t, []*api.Endpoints{endpoints2}) handler.ValidateEndpoints(t, []*v1.Endpoints{endpoints2})
// Delete endpoints2 // Delete endpoints2
fakeWatch.Delete(endpoints2) fakeWatch.Delete(endpoints2)
handler.ValidateEndpoints(t, []*api.Endpoints{}) handler.ValidateEndpoints(t, []*v1.Endpoints{})
} }
func newSvcHandler(t *testing.T, svcs []*api.Service, done func()) ServiceHandler { func newSvcHandler(t *testing.T, svcs []*v1.Service, done func()) ServiceHandler {
shm := &ServiceHandlerMock{ shm := &ServiceHandlerMock{
state: make(map[types.NamespacedName]*api.Service), state: make(map[types.NamespacedName]*v1.Service),
} }
shm.process = func(services []*api.Service) { shm.process = func(services []*v1.Service) {
defer done() defer done()
if !reflect.DeepEqual(services, svcs) { if !reflect.DeepEqual(services, svcs) {
t.Errorf("Unexpected services: %#v, expected: %#v", services, svcs) t.Errorf("Unexpected services: %#v, expected: %#v", services, svcs)
@ -161,11 +161,11 @@ func newSvcHandler(t *testing.T, svcs []*api.Service, done func()) ServiceHandle
return shm return shm
} }
func newEpsHandler(t *testing.T, eps []*api.Endpoints, done func()) EndpointsHandler { func newEpsHandler(t *testing.T, eps []*v1.Endpoints, done func()) EndpointsHandler {
ehm := &EndpointsHandlerMock{ ehm := &EndpointsHandlerMock{
state: make(map[types.NamespacedName]*api.Endpoints), state: make(map[types.NamespacedName]*v1.Endpoints),
} }
ehm.process = func(endpoints []*api.Endpoints) { ehm.process = func(endpoints []*v1.Endpoints) {
defer done() defer done()
if !reflect.DeepEqual(eps, endpoints) { if !reflect.DeepEqual(eps, endpoints) {
t.Errorf("Unexpected endpoints: %#v, expected: %#v", endpoints, eps) t.Errorf("Unexpected endpoints: %#v, expected: %#v", endpoints, eps)
@ -175,18 +175,18 @@ func newEpsHandler(t *testing.T, eps []*api.Endpoints, done func()) EndpointsHan
} }
func TestInitialSync(t *testing.T) { func TestInitialSync(t *testing.T) {
svc1 := &api.Service{ svc1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 10}}}, Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 10}}},
} }
svc2 := &api.Service{ svc2 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 10}}}, Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 10}}},
} }
eps1 := &api.Endpoints{ eps1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
} }
eps2 := &api.Endpoints{ eps2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
} }
@ -198,11 +198,11 @@ func TestInitialSync(t *testing.T) {
client := fake.NewSimpleClientset(svc1, svc2, eps2, eps1) client := fake.NewSimpleClientset(svc1, svc2, eps2, eps1)
sharedInformers := informers.NewSharedInformerFactory(client, 0) sharedInformers := informers.NewSharedInformerFactory(client, 0)
svcConfig := NewServiceConfig(sharedInformers.Core().InternalVersion().Services(), 0) svcConfig := NewServiceConfig(sharedInformers.Core().V1().Services(), 0)
epsConfig := NewEndpointsConfig(sharedInformers.Core().InternalVersion().Endpoints(), 0) epsConfig := NewEndpointsConfig(sharedInformers.Core().V1().Endpoints(), 0)
svcHandler := newSvcHandler(t, []*api.Service{svc2, svc1}, wg.Done) svcHandler := newSvcHandler(t, []*v1.Service{svc2, svc1}, wg.Done)
svcConfig.RegisterEventHandler(svcHandler) svcConfig.RegisterEventHandler(svcHandler)
epsHandler := newEpsHandler(t, []*api.Endpoints{eps2, eps1}, wg.Done) epsHandler := newEpsHandler(t, []*v1.Endpoints{eps2, eps1}, wg.Done)
epsConfig.RegisterEventHandler(epsHandler) epsConfig.RegisterEventHandler(epsHandler)
stopCh := make(chan struct{}) stopCh := make(chan struct{})

View File

@ -21,11 +21,11 @@ import (
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
coreinformers "k8s.io/client-go/informers/core/v1"
listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
api "k8s.io/kubernetes/pkg/apis/core"
coreinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion/core/internalversion"
listers "k8s.io/kubernetes/pkg/client/listers/core/internalversion"
"k8s.io/kubernetes/pkg/controller" "k8s.io/kubernetes/pkg/controller"
) )
@ -34,13 +34,13 @@ import (
type ServiceHandler interface { type ServiceHandler interface {
// OnServiceAdd is called whenever creation of new service object // OnServiceAdd is called whenever creation of new service object
// is observed. // is observed.
OnServiceAdd(service *api.Service) OnServiceAdd(service *v1.Service)
// OnServiceUpdate is called whenever modification of an existing // OnServiceUpdate is called whenever modification of an existing
// service object is observed. // service object is observed.
OnServiceUpdate(oldService, service *api.Service) OnServiceUpdate(oldService, service *v1.Service)
// OnServiceDelete is called whenever deletion of an existing service // OnServiceDelete is called whenever deletion of an existing service
// object is observed. // object is observed.
OnServiceDelete(service *api.Service) OnServiceDelete(service *v1.Service)
// OnServiceSynced is called once all the initial even handlers were // OnServiceSynced is called once all the initial even handlers were
// called and the state is fully propagated to local cache. // called and the state is fully propagated to local cache.
OnServiceSynced() OnServiceSynced()
@ -51,13 +51,13 @@ type ServiceHandler interface {
type EndpointsHandler interface { type EndpointsHandler interface {
// OnEndpointsAdd is called whenever creation of new endpoints object // OnEndpointsAdd is called whenever creation of new endpoints object
// is observed. // is observed.
OnEndpointsAdd(endpoints *api.Endpoints) OnEndpointsAdd(endpoints *v1.Endpoints)
// OnEndpointsUpdate is called whenever modification of an existing // OnEndpointsUpdate is called whenever modification of an existing
// endpoints object is observed. // endpoints object is observed.
OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints)
// OnEndpointsDelete is called whever deletion of an existing endpoints // OnEndpointsDelete is called whever deletion of an existing endpoints
// object is observed. // object is observed.
OnEndpointsDelete(endpoints *api.Endpoints) OnEndpointsDelete(endpoints *v1.Endpoints)
// OnEndpointsSynced is called once all the initial event handlers were // OnEndpointsSynced is called once all the initial event handlers were
// called and the state is fully propagated to local cache. // called and the state is fully propagated to local cache.
OnEndpointsSynced() OnEndpointsSynced()
@ -115,7 +115,7 @@ func (c *EndpointsConfig) Run(stopCh <-chan struct{}) {
} }
func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) { func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) {
endpoints, ok := obj.(*api.Endpoints) endpoints, ok := obj.(*v1.Endpoints)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj))
return return
@ -127,12 +127,12 @@ func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) {
} }
func (c *EndpointsConfig) handleUpdateEndpoints(oldObj, newObj interface{}) { func (c *EndpointsConfig) handleUpdateEndpoints(oldObj, newObj interface{}) {
oldEndpoints, ok := oldObj.(*api.Endpoints) oldEndpoints, ok := oldObj.(*v1.Endpoints)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj))
return return
} }
endpoints, ok := newObj.(*api.Endpoints) endpoints, ok := newObj.(*v1.Endpoints)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj))
return return
@ -144,14 +144,14 @@ func (c *EndpointsConfig) handleUpdateEndpoints(oldObj, newObj interface{}) {
} }
func (c *EndpointsConfig) handleDeleteEndpoints(obj interface{}) { func (c *EndpointsConfig) handleDeleteEndpoints(obj interface{}) {
endpoints, ok := obj.(*api.Endpoints) endpoints, ok := obj.(*v1.Endpoints)
if !ok { if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown) tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj))
return return
} }
if endpoints, ok = tombstone.Obj.(*api.Endpoints); !ok { if endpoints, ok = tombstone.Obj.(*v1.Endpoints); !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj))
return return
} }
@ -215,7 +215,7 @@ func (c *ServiceConfig) Run(stopCh <-chan struct{}) {
} }
func (c *ServiceConfig) handleAddService(obj interface{}) { func (c *ServiceConfig) handleAddService(obj interface{}) {
service, ok := obj.(*api.Service) service, ok := obj.(*v1.Service)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj))
return return
@ -227,12 +227,12 @@ func (c *ServiceConfig) handleAddService(obj interface{}) {
} }
func (c *ServiceConfig) handleUpdateService(oldObj, newObj interface{}) { func (c *ServiceConfig) handleUpdateService(oldObj, newObj interface{}) {
oldService, ok := oldObj.(*api.Service) oldService, ok := oldObj.(*v1.Service)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", oldObj))
return return
} }
service, ok := newObj.(*api.Service) service, ok := newObj.(*v1.Service)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj))
return return
@ -244,14 +244,14 @@ func (c *ServiceConfig) handleUpdateService(oldObj, newObj interface{}) {
} }
func (c *ServiceConfig) handleDeleteService(obj interface{}) { func (c *ServiceConfig) handleDeleteService(obj interface{}) {
service, ok := obj.(*api.Service) service, ok := obj.(*v1.Service)
if !ok { if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown) tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok { if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj))
return return
} }
if service, ok = tombstone.Obj.(*api.Service); !ok { if service, ok = tombstone.Obj.(*v1.Service); !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj)) utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", obj))
return return
} }

View File

@ -23,17 +23,17 @@ import (
"testing" "testing"
"time" "time"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
informers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
ktesting "k8s.io/client-go/testing" ktesting "k8s.io/client-go/testing"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
) )
type sortedServices []*api.Service type sortedServices []*v1.Service
func (s sortedServices) Len() int { func (s sortedServices) Len() int {
return len(s) return len(s)
@ -48,24 +48,24 @@ func (s sortedServices) Less(i, j int) bool {
type ServiceHandlerMock struct { type ServiceHandlerMock struct {
lock sync.Mutex lock sync.Mutex
state map[types.NamespacedName]*api.Service state map[types.NamespacedName]*v1.Service
synced bool synced bool
updated chan []*api.Service updated chan []*v1.Service
process func([]*api.Service) process func([]*v1.Service)
} }
func NewServiceHandlerMock() *ServiceHandlerMock { func NewServiceHandlerMock() *ServiceHandlerMock {
shm := &ServiceHandlerMock{ shm := &ServiceHandlerMock{
state: make(map[types.NamespacedName]*api.Service), state: make(map[types.NamespacedName]*v1.Service),
updated: make(chan []*api.Service, 5), updated: make(chan []*v1.Service, 5),
} }
shm.process = func(services []*api.Service) { shm.process = func(services []*v1.Service) {
shm.updated <- services shm.updated <- services
} }
return shm return shm
} }
func (h *ServiceHandlerMock) OnServiceAdd(service *api.Service) { func (h *ServiceHandlerMock) OnServiceAdd(service *v1.Service) {
h.lock.Lock() h.lock.Lock()
defer h.lock.Unlock() defer h.lock.Unlock()
namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name} namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name}
@ -73,7 +73,7 @@ func (h *ServiceHandlerMock) OnServiceAdd(service *api.Service) {
h.sendServices() h.sendServices()
} }
func (h *ServiceHandlerMock) OnServiceUpdate(oldService, service *api.Service) { func (h *ServiceHandlerMock) OnServiceUpdate(oldService, service *v1.Service) {
h.lock.Lock() h.lock.Lock()
defer h.lock.Unlock() defer h.lock.Unlock()
namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name} namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name}
@ -81,7 +81,7 @@ func (h *ServiceHandlerMock) OnServiceUpdate(oldService, service *api.Service) {
h.sendServices() h.sendServices()
} }
func (h *ServiceHandlerMock) OnServiceDelete(service *api.Service) { func (h *ServiceHandlerMock) OnServiceDelete(service *v1.Service) {
h.lock.Lock() h.lock.Lock()
defer h.lock.Unlock() defer h.lock.Unlock()
namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name} namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name}
@ -100,7 +100,7 @@ func (h *ServiceHandlerMock) sendServices() {
if !h.synced { if !h.synced {
return return
} }
services := make([]*api.Service, 0, len(h.state)) services := make([]*v1.Service, 0, len(h.state))
for _, svc := range h.state { for _, svc := range h.state {
services = append(services, svc) services = append(services, svc)
} }
@ -108,11 +108,11 @@ func (h *ServiceHandlerMock) sendServices() {
h.process(services) h.process(services)
} }
func (h *ServiceHandlerMock) ValidateServices(t *testing.T, expectedServices []*api.Service) { func (h *ServiceHandlerMock) ValidateServices(t *testing.T, expectedServices []*v1.Service) {
// We might get 1 or more updates for N service updates, because we // We might get 1 or more updates for N service updates, because we
// over write older snapshots of services from the producer go-routine // over write older snapshots of services from the producer go-routine
// if the consumer falls behind. // if the consumer falls behind.
var services []*api.Service var services []*v1.Service
for { for {
select { select {
case services = <-h.updated: case services = <-h.updated:
@ -128,7 +128,7 @@ func (h *ServiceHandlerMock) ValidateServices(t *testing.T, expectedServices []*
} }
} }
type sortedEndpoints []*api.Endpoints type sortedEndpoints []*v1.Endpoints
func (s sortedEndpoints) Len() int { func (s sortedEndpoints) Len() int {
return len(s) return len(s)
@ -143,24 +143,24 @@ func (s sortedEndpoints) Less(i, j int) bool {
type EndpointsHandlerMock struct { type EndpointsHandlerMock struct {
lock sync.Mutex lock sync.Mutex
state map[types.NamespacedName]*api.Endpoints state map[types.NamespacedName]*v1.Endpoints
synced bool synced bool
updated chan []*api.Endpoints updated chan []*v1.Endpoints
process func([]*api.Endpoints) process func([]*v1.Endpoints)
} }
func NewEndpointsHandlerMock() *EndpointsHandlerMock { func NewEndpointsHandlerMock() *EndpointsHandlerMock {
ehm := &EndpointsHandlerMock{ ehm := &EndpointsHandlerMock{
state: make(map[types.NamespacedName]*api.Endpoints), state: make(map[types.NamespacedName]*v1.Endpoints),
updated: make(chan []*api.Endpoints, 5), updated: make(chan []*v1.Endpoints, 5),
} }
ehm.process = func(endpoints []*api.Endpoints) { ehm.process = func(endpoints []*v1.Endpoints) {
ehm.updated <- endpoints ehm.updated <- endpoints
} }
return ehm return ehm
} }
func (h *EndpointsHandlerMock) OnEndpointsAdd(endpoints *api.Endpoints) { func (h *EndpointsHandlerMock) OnEndpointsAdd(endpoints *v1.Endpoints) {
h.lock.Lock() h.lock.Lock()
defer h.lock.Unlock() defer h.lock.Unlock()
namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name} namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}
@ -168,7 +168,7 @@ func (h *EndpointsHandlerMock) OnEndpointsAdd(endpoints *api.Endpoints) {
h.sendEndpoints() h.sendEndpoints()
} }
func (h *EndpointsHandlerMock) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) { func (h *EndpointsHandlerMock) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
h.lock.Lock() h.lock.Lock()
defer h.lock.Unlock() defer h.lock.Unlock()
namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name} namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}
@ -176,7 +176,7 @@ func (h *EndpointsHandlerMock) OnEndpointsUpdate(oldEndpoints, endpoints *api.En
h.sendEndpoints() h.sendEndpoints()
} }
func (h *EndpointsHandlerMock) OnEndpointsDelete(endpoints *api.Endpoints) { func (h *EndpointsHandlerMock) OnEndpointsDelete(endpoints *v1.Endpoints) {
h.lock.Lock() h.lock.Lock()
defer h.lock.Unlock() defer h.lock.Unlock()
namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name} namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}
@ -195,7 +195,7 @@ func (h *EndpointsHandlerMock) sendEndpoints() {
if !h.synced { if !h.synced {
return return
} }
endpoints := make([]*api.Endpoints, 0, len(h.state)) endpoints := make([]*v1.Endpoints, 0, len(h.state))
for _, eps := range h.state { for _, eps := range h.state {
endpoints = append(endpoints, eps) endpoints = append(endpoints, eps)
} }
@ -203,11 +203,11 @@ func (h *EndpointsHandlerMock) sendEndpoints() {
h.process(endpoints) h.process(endpoints)
} }
func (h *EndpointsHandlerMock) ValidateEndpoints(t *testing.T, expectedEndpoints []*api.Endpoints) { func (h *EndpointsHandlerMock) ValidateEndpoints(t *testing.T, expectedEndpoints []*v1.Endpoints) {
// We might get 1 or more updates for N endpoint updates, because we // We might get 1 or more updates for N endpoint updates, because we
// over write older snapshots of endpoints from the producer go-routine // over write older snapshots of endpoints from the producer go-routine
// if the consumer falls behind. Unittests will hard timeout in 5m. // if the consumer falls behind. Unittests will hard timeout in 5m.
var endpoints []*api.Endpoints var endpoints []*v1.Endpoints
for { for {
select { select {
case endpoints = <-h.updated: case endpoints = <-h.updated:
@ -233,18 +233,18 @@ func TestNewServiceAddedAndNotified(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, time.Minute) sharedInformers := informers.NewSharedInformerFactory(client, time.Minute)
config := NewServiceConfig(sharedInformers.Core().InternalVersion().Services(), time.Minute) config := NewServiceConfig(sharedInformers.Core().V1().Services(), time.Minute)
handler := NewServiceHandlerMock() handler := NewServiceHandlerMock()
config.RegisterEventHandler(handler) config.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh) go sharedInformers.Start(stopCh)
go config.Run(stopCh) go config.Run(stopCh)
service := &api.Service{ service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 10}}}, Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 10}}},
} }
fakeWatch.Add(service) fakeWatch.Add(service)
handler.ValidateServices(t, []*api.Service{service}) handler.ValidateServices(t, []*v1.Service{service})
} }
func TestServiceAddedRemovedSetAndNotified(t *testing.T) { func TestServiceAddedRemovedSetAndNotified(t *testing.T) {
@ -257,29 +257,29 @@ func TestServiceAddedRemovedSetAndNotified(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, time.Minute) sharedInformers := informers.NewSharedInformerFactory(client, time.Minute)
config := NewServiceConfig(sharedInformers.Core().InternalVersion().Services(), time.Minute) config := NewServiceConfig(sharedInformers.Core().V1().Services(), time.Minute)
handler := NewServiceHandlerMock() handler := NewServiceHandlerMock()
config.RegisterEventHandler(handler) config.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh) go sharedInformers.Start(stopCh)
go config.Run(stopCh) go config.Run(stopCh)
service1 := &api.Service{ service1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 10}}}, Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 10}}},
} }
fakeWatch.Add(service1) fakeWatch.Add(service1)
handler.ValidateServices(t, []*api.Service{service1}) handler.ValidateServices(t, []*v1.Service{service1})
service2 := &api.Service{ service2 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 20}}}, Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 20}}},
} }
fakeWatch.Add(service2) fakeWatch.Add(service2)
services := []*api.Service{service2, service1} services := []*v1.Service{service2, service1}
handler.ValidateServices(t, services) handler.ValidateServices(t, services)
fakeWatch.Delete(service1) fakeWatch.Delete(service1)
services = []*api.Service{service2} services = []*v1.Service{service2}
handler.ValidateServices(t, services) handler.ValidateServices(t, services)
} }
@ -293,7 +293,7 @@ func TestNewServicesMultipleHandlersAddedAndNotified(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, time.Minute) sharedInformers := informers.NewSharedInformerFactory(client, time.Minute)
config := NewServiceConfig(sharedInformers.Core().InternalVersion().Services(), time.Minute) config := NewServiceConfig(sharedInformers.Core().V1().Services(), time.Minute)
handler := NewServiceHandlerMock() handler := NewServiceHandlerMock()
handler2 := NewServiceHandlerMock() handler2 := NewServiceHandlerMock()
config.RegisterEventHandler(handler) config.RegisterEventHandler(handler)
@ -301,18 +301,18 @@ func TestNewServicesMultipleHandlersAddedAndNotified(t *testing.T) {
go sharedInformers.Start(stopCh) go sharedInformers.Start(stopCh)
go config.Run(stopCh) go config.Run(stopCh)
service1 := &api.Service{ service1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 10}}}, Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 10}}},
} }
service2 := &api.Service{ service2 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
Spec: api.ServiceSpec{Ports: []api.ServicePort{{Protocol: "TCP", Port: 20}}}, Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Protocol: "TCP", Port: 20}}},
} }
fakeWatch.Add(service1) fakeWatch.Add(service1)
fakeWatch.Add(service2) fakeWatch.Add(service2)
services := []*api.Service{service2, service1} services := []*v1.Service{service2, service1}
handler.ValidateServices(t, services) handler.ValidateServices(t, services)
handler2.ValidateServices(t, services) handler2.ValidateServices(t, services)
} }
@ -327,7 +327,7 @@ func TestNewEndpointsMultipleHandlersAddedAndNotified(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, time.Minute) sharedInformers := informers.NewSharedInformerFactory(client, time.Minute)
config := NewEndpointsConfig(sharedInformers.Core().InternalVersion().Endpoints(), time.Minute) config := NewEndpointsConfig(sharedInformers.Core().V1().Endpoints(), time.Minute)
handler := NewEndpointsHandlerMock() handler := NewEndpointsHandlerMock()
handler2 := NewEndpointsHandlerMock() handler2 := NewEndpointsHandlerMock()
config.RegisterEventHandler(handler) config.RegisterEventHandler(handler)
@ -335,24 +335,24 @@ func TestNewEndpointsMultipleHandlersAddedAndNotified(t *testing.T) {
go sharedInformers.Start(stopCh) go sharedInformers.Start(stopCh)
go config.Run(stopCh) go config.Run(stopCh)
endpoints1 := &api.Endpoints{ endpoints1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "1.1.1.1"}, {IP: "2.2.2.2"}}, Addresses: []v1.EndpointAddress{{IP: "1.1.1.1"}, {IP: "2.2.2.2"}},
Ports: []api.EndpointPort{{Port: 80}}, Ports: []v1.EndpointPort{{Port: 80}},
}}, }},
} }
endpoints2 := &api.Endpoints{ endpoints2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "3.3.3.3"}, {IP: "4.4.4.4"}}, Addresses: []v1.EndpointAddress{{IP: "3.3.3.3"}, {IP: "4.4.4.4"}},
Ports: []api.EndpointPort{{Port: 80}}, Ports: []v1.EndpointPort{{Port: 80}},
}}, }},
} }
fakeWatch.Add(endpoints1) fakeWatch.Add(endpoints1)
fakeWatch.Add(endpoints2) fakeWatch.Add(endpoints2)
endpoints := []*api.Endpoints{endpoints2, endpoints1} endpoints := []*v1.Endpoints{endpoints2, endpoints1}
handler.ValidateEndpoints(t, endpoints) handler.ValidateEndpoints(t, endpoints)
handler2.ValidateEndpoints(t, endpoints) handler2.ValidateEndpoints(t, endpoints)
} }
@ -367,7 +367,7 @@ func TestNewEndpointsMultipleHandlersAddRemoveSetAndNotified(t *testing.T) {
sharedInformers := informers.NewSharedInformerFactory(client, time.Minute) sharedInformers := informers.NewSharedInformerFactory(client, time.Minute)
config := NewEndpointsConfig(sharedInformers.Core().InternalVersion().Endpoints(), time.Minute) config := NewEndpointsConfig(sharedInformers.Core().V1().Endpoints(), time.Minute)
handler := NewEndpointsHandlerMock() handler := NewEndpointsHandlerMock()
handler2 := NewEndpointsHandlerMock() handler2 := NewEndpointsHandlerMock()
config.RegisterEventHandler(handler) config.RegisterEventHandler(handler)
@ -375,56 +375,56 @@ func TestNewEndpointsMultipleHandlersAddRemoveSetAndNotified(t *testing.T) {
go sharedInformers.Start(stopCh) go sharedInformers.Start(stopCh)
go config.Run(stopCh) go config.Run(stopCh)
endpoints1 := &api.Endpoints{ endpoints1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "1.1.1.1"}, {IP: "2.2.2.2"}}, Addresses: []v1.EndpointAddress{{IP: "1.1.1.1"}, {IP: "2.2.2.2"}},
Ports: []api.EndpointPort{{Port: 80}}, Ports: []v1.EndpointPort{{Port: 80}},
}}, }},
} }
endpoints2 := &api.Endpoints{ endpoints2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "bar"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "3.3.3.3"}, {IP: "4.4.4.4"}}, Addresses: []v1.EndpointAddress{{IP: "3.3.3.3"}, {IP: "4.4.4.4"}},
Ports: []api.EndpointPort{{Port: 80}}, Ports: []v1.EndpointPort{{Port: 80}},
}}, }},
} }
fakeWatch.Add(endpoints1) fakeWatch.Add(endpoints1)
fakeWatch.Add(endpoints2) fakeWatch.Add(endpoints2)
endpoints := []*api.Endpoints{endpoints2, endpoints1} endpoints := []*v1.Endpoints{endpoints2, endpoints1}
handler.ValidateEndpoints(t, endpoints) handler.ValidateEndpoints(t, endpoints)
handler2.ValidateEndpoints(t, endpoints) handler2.ValidateEndpoints(t, endpoints)
// Add one more // Add one more
endpoints3 := &api.Endpoints{ endpoints3 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foobar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foobar"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "5.5.5.5"}, {IP: "6.6.6.6"}}, Addresses: []v1.EndpointAddress{{IP: "5.5.5.5"}, {IP: "6.6.6.6"}},
Ports: []api.EndpointPort{{Port: 80}}, Ports: []v1.EndpointPort{{Port: 80}},
}}, }},
} }
fakeWatch.Add(endpoints3) fakeWatch.Add(endpoints3)
endpoints = []*api.Endpoints{endpoints2, endpoints1, endpoints3} endpoints = []*v1.Endpoints{endpoints2, endpoints1, endpoints3}
handler.ValidateEndpoints(t, endpoints) handler.ValidateEndpoints(t, endpoints)
handler2.ValidateEndpoints(t, endpoints) handler2.ValidateEndpoints(t, endpoints)
// Update the "foo" service with new endpoints // Update the "foo" service with new endpoints
endpoints1v2 := &api.Endpoints{ endpoints1v2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Namespace: "testnamespace", Name: "foo"},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "7.7.7.7"}}, Addresses: []v1.EndpointAddress{{IP: "7.7.7.7"}},
Ports: []api.EndpointPort{{Port: 80}}, Ports: []v1.EndpointPort{{Port: 80}},
}}, }},
} }
fakeWatch.Modify(endpoints1v2) fakeWatch.Modify(endpoints1v2)
endpoints = []*api.Endpoints{endpoints2, endpoints1v2, endpoints3} endpoints = []*v1.Endpoints{endpoints2, endpoints1v2, endpoints3}
handler.ValidateEndpoints(t, endpoints) handler.ValidateEndpoints(t, endpoints)
handler2.ValidateEndpoints(t, endpoints) handler2.ValidateEndpoints(t, endpoints)
// Remove "bar" endpoints // Remove "bar" endpoints
fakeWatch.Delete(endpoints2) fakeWatch.Delete(endpoints2)
endpoints = []*api.Endpoints{endpoints1v2, endpoints3} endpoints = []*v1.Endpoints{endpoints1v2, endpoints3}
handler.ValidateEndpoints(t, endpoints) handler.ValidateEndpoints(t, endpoints)
handler2.ValidateEndpoints(t, endpoints) handler2.ValidateEndpoints(t, endpoints)
} }

View File

@ -24,10 +24,10 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
api "k8s.io/kubernetes/pkg/apis/core"
utilproxy "k8s.io/kubernetes/pkg/proxy/util" utilproxy "k8s.io/kubernetes/pkg/proxy/util"
utilnet "k8s.io/kubernetes/pkg/util/net" utilnet "k8s.io/kubernetes/pkg/util/net"
) )
@ -113,7 +113,7 @@ func NewEndpointChangeTracker(hostname string, makeEndpointInfo makeEndpointFunc
// - pass <oldEndpoints, endpoints> as the <previous, current> pair. // - pass <oldEndpoints, endpoints> as the <previous, current> pair.
// Delete item // Delete item
// - pass <endpoints, nil> as the <previous, current> pair. // - pass <endpoints, nil> as the <previous, current> pair.
func (ect *EndpointChangeTracker) Update(previous, current *api.Endpoints) bool { func (ect *EndpointChangeTracker) Update(previous, current *v1.Endpoints) bool {
endpoints := current endpoints := current
if endpoints == nil { if endpoints == nil {
endpoints = previous endpoints = previous
@ -184,7 +184,7 @@ type EndpointsMap map[ServicePortName][]Endpoint
// This function is used for incremental updated of endpointsMap. // This function is used for incremental updated of endpointsMap.
// //
// NOTE: endpoints object should NOT be modified. // NOTE: endpoints object should NOT be modified.
func (ect *EndpointChangeTracker) endpointsToEndpointsMap(endpoints *api.Endpoints) EndpointsMap { func (ect *EndpointChangeTracker) endpointsToEndpointsMap(endpoints *v1.Endpoints) EndpointsMap {
if endpoints == nil { if endpoints == nil {
return nil return nil
} }

View File

@ -22,21 +22,21 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
api "k8s.io/kubernetes/pkg/apis/core"
) )
func (proxier *FakeProxier) addEndpoints(endpoints *api.Endpoints) { func (proxier *FakeProxier) addEndpoints(endpoints *v1.Endpoints) {
proxier.endpointsChanges.Update(nil, endpoints) proxier.endpointsChanges.Update(nil, endpoints)
} }
func (proxier *FakeProxier) updateEndpoints(oldEndpoints, endpoints *api.Endpoints) { func (proxier *FakeProxier) updateEndpoints(oldEndpoints, endpoints *v1.Endpoints) {
proxier.endpointsChanges.Update(oldEndpoints, endpoints) proxier.endpointsChanges.Update(oldEndpoints, endpoints)
} }
func (proxier *FakeProxier) deleteEndpoints(endpoints *api.Endpoints) { func (proxier *FakeProxier) deleteEndpoints(endpoints *v1.Endpoints) {
proxier.endpointsChanges.Update(endpoints, nil) proxier.endpointsChanges.Update(endpoints, nil)
} }
@ -118,8 +118,8 @@ func TestGetLocalEndpointIPs(t *testing.T) {
} }
} }
func makeTestEndpoints(namespace, name string, eptFunc func(*api.Endpoints)) *api.Endpoints { func makeTestEndpoints(namespace, name string, eptFunc func(*v1.Endpoints)) *v1.Endpoints {
ept := &api.Endpoints{ ept := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Namespace: namespace, Namespace: namespace,
@ -138,24 +138,24 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
newEndpoints *api.Endpoints newEndpoints *v1.Endpoints
expected map[ServicePortName][]*BaseEndpointInfo expected map[ServicePortName][]*BaseEndpointInfo
isIPv6Mode *bool isIPv6Mode *bool
}{ }{
{ {
desc: "nothing", desc: "nothing",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {}), newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {}),
expected: map[ServicePortName][]*BaseEndpointInfo{}, expected: map[ServicePortName][]*BaseEndpointInfo{},
}, },
{ {
desc: "no changes, unnamed port", desc: "no changes, unnamed port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "", Name: "",
Port: 11, Port: 11,
}}, }},
@ -170,13 +170,13 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "no changes, named port", desc: "no changes, named port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "port", Name: "port",
Port: 11, Port: 11,
}}, }},
@ -191,13 +191,13 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "new port", desc: "new port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Port: 11, Port: 11,
}}, }},
}, },
@ -211,20 +211,20 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "remove port", desc: "remove port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {}), newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {}),
expected: map[ServicePortName][]*BaseEndpointInfo{}, expected: map[ServicePortName][]*BaseEndpointInfo{},
}, },
{ {
desc: "new IP and port", desc: "new IP and port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}, { }, {
IP: "2.2.2.2", IP: "2.2.2.2",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p1", Name: "p1",
Port: 11, Port: 11,
}, { }, {
@ -247,13 +247,13 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "remove IP and port", desc: "remove IP and port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p1", Name: "p1",
Port: 11, Port: 11,
}}, }},
@ -268,13 +268,13 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "rename port", desc: "rename port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p2", Name: "p2",
Port: 11, Port: 11,
}}, }},
@ -289,13 +289,13 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "renumber port", desc: "renumber port",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p1", Name: "p1",
Port: 22, Port: 22,
}}, }},
@ -310,15 +310,15 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "should omit IPv6 address in IPv4 mode", desc: "should omit IPv6 address in IPv4 mode",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}, { }, {
IP: "2001:db8:85a3:0:0:8a2e:370:7334", IP: "2001:db8:85a3:0:0:8a2e:370:7334",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p1", Name: "p1",
Port: 11, Port: 11,
}, { }, {
@ -340,15 +340,15 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
}, },
{ {
desc: "should omit IPv4 address in IPv6 mode", desc: "should omit IPv4 address in IPv6 mode",
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) { newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{ ept.Subsets = []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}, { }, {
IP: "2001:db8:85a3:0:0:8a2e:370:7334", IP: "2001:db8:85a3:0:0:8a2e:370:7334",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p1", Name: "p1",
Port: 11, Port: 11,
}, { }, {
@ -396,84 +396,84 @@ func TestEndpointsToEndpointsMap(t *testing.T) {
func TestUpdateEndpointsMap(t *testing.T) { func TestUpdateEndpointsMap(t *testing.T) {
var nodeName = testHostname var nodeName = testHostname
emptyEndpoint := func(ept *api.Endpoints) { emptyEndpoint := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{} ept.Subsets = []v1.EndpointSubset{}
} }
unnamedPort := func(ept *api.Endpoints) { unnamedPort := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Port: 11, Port: 11,
}}, }},
}} }}
} }
unnamedPortLocal := func(ept *api.Endpoints) { unnamedPortLocal := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Port: 11, Port: 11,
}}, }},
}} }}
} }
namedPortLocal := func(ept *api.Endpoints) { namedPortLocal := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}}, }},
}} }}
} }
namedPort := func(ept *api.Endpoints) { namedPort := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}}, }},
}} }}
} }
namedPortRenamed := func(ept *api.Endpoints) { namedPortRenamed := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11-2", Name: "p11-2",
Port: 11, Port: 11,
}}, }},
}} }}
} }
namedPortRenumbered := func(ept *api.Endpoints) { namedPortRenumbered := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 22, Port: 22,
}}, }},
}} }}
} }
namedPortsLocalNoLocal := func(ept *api.Endpoints) { namedPortsLocalNoLocal := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}, { }, {
IP: "1.1.1.2", IP: "1.1.1.2",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}, { }, {
@ -482,52 +482,52 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
}} }}
} }
multipleSubsets := func(ept *api.Endpoints) { multipleSubsets := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}}, }},
}, { }, {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.2", IP: "1.1.1.2",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p12", Name: "p12",
Port: 12, Port: 12,
}}, }},
}} }}
} }
multipleSubsetsWithLocal := func(ept *api.Endpoints) { multipleSubsetsWithLocal := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}}, }},
}, { }, {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.2", IP: "1.1.1.2",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p12", Name: "p12",
Port: 12, Port: 12,
}}, }},
}} }}
} }
multipleSubsetsMultiplePortsLocal := func(ept *api.Endpoints) { multipleSubsetsMultiplePortsLocal := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}, { }, {
@ -535,24 +535,24 @@ func TestUpdateEndpointsMap(t *testing.T) {
Port: 12, Port: 12,
}}, }},
}, { }, {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.3", IP: "1.1.1.3",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p13", Name: "p13",
Port: 13, Port: 13,
}}, }},
}} }}
} }
multipleSubsetsIPsPorts1 := func(ept *api.Endpoints) { multipleSubsetsIPsPorts1 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}, { }, {
IP: "1.1.1.2", IP: "1.1.1.2",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}, { }, {
@ -560,13 +560,13 @@ func TestUpdateEndpointsMap(t *testing.T) {
Port: 12, Port: 12,
}}, }},
}, { }, {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.3", IP: "1.1.1.3",
}, { }, {
IP: "1.1.1.4", IP: "1.1.1.4",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p13", Name: "p13",
Port: 13, Port: 13,
}, { }, {
@ -575,15 +575,15 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
}} }}
} }
multipleSubsetsIPsPorts2 := func(ept *api.Endpoints) { multipleSubsetsIPsPorts2 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "2.2.2.1", IP: "2.2.2.1",
}, { }, {
IP: "2.2.2.2", IP: "2.2.2.2",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p21", Name: "p21",
Port: 21, Port: 21,
}, { }, {
@ -592,81 +592,81 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
}} }}
} }
complexBefore1 := func(ept *api.Endpoints) { complexBefore1 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}}, }},
}} }}
} }
complexBefore2 := func(ept *api.Endpoints) { complexBefore2 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "2.2.2.2", IP: "2.2.2.2",
NodeName: &nodeName, NodeName: &nodeName,
}, { }, {
IP: "2.2.2.22", IP: "2.2.2.22",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p22", Name: "p22",
Port: 22, Port: 22,
}}, }},
}, { }, {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "2.2.2.3", IP: "2.2.2.3",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p23", Name: "p23",
Port: 23, Port: 23,
}}, }},
}} }}
} }
complexBefore4 := func(ept *api.Endpoints) { complexBefore4 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "4.4.4.4", IP: "4.4.4.4",
NodeName: &nodeName, NodeName: &nodeName,
}, { }, {
IP: "4.4.4.5", IP: "4.4.4.5",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p44", Name: "p44",
Port: 44, Port: 44,
}}, }},
}, { }, {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "4.4.4.6", IP: "4.4.4.6",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p45", Name: "p45",
Port: 45, Port: 45,
}}, }},
}} }}
} }
complexAfter1 := func(ept *api.Endpoints) { complexAfter1 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.1", IP: "1.1.1.1",
}, { }, {
IP: "1.1.1.11", IP: "1.1.1.11",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p11", Name: "p11",
Port: 11, Port: 11,
}}, }},
}, { }, {
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "1.1.1.2", IP: "1.1.1.2",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p12", Name: "p12",
Port: 12, Port: 12,
}, { }, {
@ -675,24 +675,24 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
}} }}
} }
complexAfter3 := func(ept *api.Endpoints) { complexAfter3 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "3.3.3.3", IP: "3.3.3.3",
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p33", Name: "p33",
Port: 33, Port: 33,
}}, }},
}} }}
} }
complexAfter4 := func(ept *api.Endpoints) { complexAfter4 := func(ept *v1.Endpoints) {
ept.Subsets = []api.EndpointSubset{{ ept.Subsets = []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{ Addresses: []v1.EndpointAddress{{
IP: "4.4.4.4", IP: "4.4.4.4",
NodeName: &nodeName, NodeName: &nodeName,
}}, }},
Ports: []api.EndpointPort{{ Ports: []v1.EndpointPort{{
Name: "p44", Name: "p44",
Port: 44, Port: 44,
}}, }},
@ -703,8 +703,8 @@ func TestUpdateEndpointsMap(t *testing.T) {
// previousEndpoints and currentEndpoints are used to call appropriate // previousEndpoints and currentEndpoints are used to call appropriate
// handlers OnEndpoints* (based on whether corresponding values are nil // handlers OnEndpoints* (based on whether corresponding values are nil
// or non-nil) and must be of equal length. // or non-nil) and must be of equal length.
previousEndpoints []*api.Endpoints previousEndpoints []*v1.Endpoints
currentEndpoints []*api.Endpoints currentEndpoints []*v1.Endpoints
oldEndpoints map[ServicePortName][]*BaseEndpointInfo oldEndpoints map[ServicePortName][]*BaseEndpointInfo
expectedResult map[ServicePortName][]*BaseEndpointInfo expectedResult map[ServicePortName][]*BaseEndpointInfo
expectedStaleEndpoints []ServiceEndpoint expectedStaleEndpoints []ServiceEndpoint
@ -719,10 +719,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[1]: no change, unnamed port // Case[1]: no change, unnamed port
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", unnamedPort), makeTestEndpoints("ns1", "ep1", unnamedPort),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", unnamedPort), makeTestEndpoints("ns1", "ep1", unnamedPort),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -740,10 +740,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[2]: no change, named port, local // Case[2]: no change, named port, local
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPortLocal), makeTestEndpoints("ns1", "ep1", namedPortLocal),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPortLocal), makeTestEndpoints("ns1", "ep1", namedPortLocal),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -763,10 +763,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
}, },
}, { }, {
// Case[3]: no change, multiple subsets // Case[3]: no change, multiple subsets
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsets), makeTestEndpoints("ns1", "ep1", multipleSubsets),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsets), makeTestEndpoints("ns1", "ep1", multipleSubsets),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -790,10 +790,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[4]: no change, multiple subsets, multiple ports, local // Case[4]: no change, multiple subsets, multiple ports, local
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsetsMultiplePortsLocal), makeTestEndpoints("ns1", "ep1", multipleSubsetsMultiplePortsLocal),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsetsMultiplePortsLocal), makeTestEndpoints("ns1", "ep1", multipleSubsetsMultiplePortsLocal),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -825,11 +825,11 @@ func TestUpdateEndpointsMap(t *testing.T) {
}, },
}, { }, {
// Case[5]: no change, multiple endpoints, subsets, IPs, and ports // Case[5]: no change, multiple endpoints, subsets, IPs, and ports
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsetsIPsPorts1), makeTestEndpoints("ns1", "ep1", multipleSubsetsIPsPorts1),
makeTestEndpoints("ns2", "ep2", multipleSubsetsIPsPorts2), makeTestEndpoints("ns2", "ep2", multipleSubsetsIPsPorts2),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsetsIPsPorts1), makeTestEndpoints("ns1", "ep1", multipleSubsetsIPsPorts1),
makeTestEndpoints("ns2", "ep2", multipleSubsetsIPsPorts2), makeTestEndpoints("ns2", "ep2", multipleSubsetsIPsPorts2),
}, },
@ -893,10 +893,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
}, },
}, { }, {
// Case[6]: add an Endpoints // Case[6]: add an Endpoints
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
nil, nil,
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", unnamedPortLocal), makeTestEndpoints("ns1", "ep1", unnamedPortLocal),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{}, oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{},
@ -914,10 +914,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
}, },
}, { }, {
// Case[7]: remove an Endpoints // Case[7]: remove an Endpoints
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", unnamedPortLocal), makeTestEndpoints("ns1", "ep1", unnamedPortLocal),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
nil, nil,
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -934,10 +934,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[8]: add an IP and port // Case[8]: add an IP and port
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPort), makeTestEndpoints("ns1", "ep1", namedPort),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPortsLocalNoLocal), makeTestEndpoints("ns1", "ep1", namedPortsLocalNoLocal),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -964,10 +964,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
}, },
}, { }, {
// Case[9]: remove an IP and port // Case[9]: remove an IP and port
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPortsLocalNoLocal), makeTestEndpoints("ns1", "ep1", namedPortsLocalNoLocal),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPort), makeTestEndpoints("ns1", "ep1", namedPort),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -999,10 +999,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[10]: add a subset // Case[10]: add a subset
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPort), makeTestEndpoints("ns1", "ep1", namedPort),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsetsWithLocal), makeTestEndpoints("ns1", "ep1", multipleSubsetsWithLocal),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -1027,10 +1027,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
}, },
}, { }, {
// Case[11]: remove a subset // Case[11]: remove a subset
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", multipleSubsets), makeTestEndpoints("ns1", "ep1", multipleSubsets),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPort), makeTestEndpoints("ns1", "ep1", namedPort),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -1054,10 +1054,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[12]: rename a port // Case[12]: rename a port
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPort), makeTestEndpoints("ns1", "ep1", namedPort),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPortRenamed), makeTestEndpoints("ns1", "ep1", namedPortRenamed),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -1080,10 +1080,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[13]: renumber a port // Case[13]: renumber a port
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPort), makeTestEndpoints("ns1", "ep1", namedPort),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", namedPortRenumbered), makeTestEndpoints("ns1", "ep1", namedPortRenumbered),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{ oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{
@ -1104,13 +1104,13 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedHealthchecks: map[types.NamespacedName]int{}, expectedHealthchecks: map[types.NamespacedName]int{},
}, { }, {
// Case[14]: complex add and remove // Case[14]: complex add and remove
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", complexBefore1), makeTestEndpoints("ns1", "ep1", complexBefore1),
makeTestEndpoints("ns2", "ep2", complexBefore2), makeTestEndpoints("ns2", "ep2", complexBefore2),
nil, nil,
makeTestEndpoints("ns4", "ep4", complexBefore4), makeTestEndpoints("ns4", "ep4", complexBefore4),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", complexAfter1), makeTestEndpoints("ns1", "ep1", complexAfter1),
nil, nil,
makeTestEndpoints("ns3", "ep3", complexAfter3), makeTestEndpoints("ns3", "ep3", complexAfter3),
@ -1179,10 +1179,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
}, },
}, { }, {
// Case[15]: change from 0 endpoint address to 1 unnamed port // Case[15]: change from 0 endpoint address to 1 unnamed port
previousEndpoints: []*api.Endpoints{ previousEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", emptyEndpoint), makeTestEndpoints("ns1", "ep1", emptyEndpoint),
}, },
currentEndpoints: []*api.Endpoints{ currentEndpoints: []*v1.Endpoints{
makeTestEndpoints("ns1", "ep1", unnamedPort), makeTestEndpoints("ns1", "ep1", unnamedPort),
}, },
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{}, oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{},

View File

@ -38,7 +38,6 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/proxy/healthcheck" "k8s.io/kubernetes/pkg/proxy/healthcheck"
"k8s.io/kubernetes/pkg/proxy/metrics" "k8s.io/kubernetes/pkg/proxy/metrics"
@ -149,7 +148,7 @@ type serviceInfo struct {
} }
// returns a new proxy.ServicePort which abstracts a serviceInfo // returns a new proxy.ServicePort which abstracts a serviceInfo
func newServiceInfo(port *api.ServicePort, service *api.Service, baseInfo *proxy.BaseServiceInfo) proxy.ServicePort { func newServiceInfo(port *v1.ServicePort, service *v1.Service, baseInfo *proxy.BaseServiceInfo) proxy.ServicePort {
info := &serviceInfo{BaseServiceInfo: baseInfo} info := &serviceInfo{BaseServiceInfo: baseInfo}
// Store the following for performance reasons. // Store the following for performance reasons.
@ -507,17 +506,17 @@ func (proxier *Proxier) isInitialized() bool {
return atomic.LoadInt32(&proxier.initialized) > 0 return atomic.LoadInt32(&proxier.initialized) > 0
} }
func (proxier *Proxier) OnServiceAdd(service *api.Service) { func (proxier *Proxier) OnServiceAdd(service *v1.Service) {
proxier.OnServiceUpdate(nil, service) proxier.OnServiceUpdate(nil, service)
} }
func (proxier *Proxier) OnServiceUpdate(oldService, service *api.Service) { func (proxier *Proxier) OnServiceUpdate(oldService, service *v1.Service) {
if proxier.serviceChanges.Update(oldService, service) && proxier.isInitialized() { if proxier.serviceChanges.Update(oldService, service) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
func (proxier *Proxier) OnServiceDelete(service *api.Service) { func (proxier *Proxier) OnServiceDelete(service *v1.Service) {
proxier.OnServiceUpdate(service, nil) proxier.OnServiceUpdate(service, nil)
} }
@ -532,17 +531,17 @@ func (proxier *Proxier) OnServiceSynced() {
proxier.syncProxyRules() proxier.syncProxyRules()
} }
func (proxier *Proxier) OnEndpointsAdd(endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
proxier.OnEndpointsUpdate(nil, endpoints) proxier.OnEndpointsUpdate(nil, endpoints)
} }
func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
if proxier.endpointsChanges.Update(oldEndpoints, endpoints) && proxier.isInitialized() { if proxier.endpointsChanges.Update(oldEndpoints, endpoints) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
func (proxier *Proxier) OnEndpointsDelete(endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsDelete(endpoints *v1.Endpoints) {
proxier.OnEndpointsUpdate(endpoints, nil) proxier.OnEndpointsUpdate(endpoints, nil)
} }
@ -602,7 +601,7 @@ func servicePortEndpointChainName(servicePortName string, protocol string, endpo
// TODO: move it to util // TODO: move it to util
func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceEndpoint) { func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceEndpoint) {
for _, epSvcPair := range connectionMap { for _, epSvcPair := range connectionMap {
if svcInfo, ok := proxier.serviceMap[epSvcPair.ServicePortName]; ok && svcInfo.GetProtocol() == api.ProtocolUDP { if svcInfo, ok := proxier.serviceMap[epSvcPair.ServicePortName]; ok && svcInfo.GetProtocol() == v1.ProtocolUDP {
endpointIP := utilproxy.IPPart(epSvcPair.Endpoint) endpointIP := utilproxy.IPPart(epSvcPair.Endpoint)
err := conntrack.ClearEntriesForNAT(proxier.exec, svcInfo.ClusterIPString(), endpointIP, v1.ProtocolUDP) err := conntrack.ClearEntriesForNAT(proxier.exec, svcInfo.ClusterIPString(), endpointIP, v1.ProtocolUDP)
if err != nil { if err != nil {
@ -652,7 +651,7 @@ func (proxier *Proxier) syncProxyRules() {
staleServices := serviceUpdateResult.UDPStaleClusterIP staleServices := serviceUpdateResult.UDPStaleClusterIP
// merge stale services gathered from updateEndpointsMap // merge stale services gathered from updateEndpointsMap
for _, svcPortName := range endpointUpdateResult.StaleServiceNames { for _, svcPortName := range endpointUpdateResult.StaleServiceNames {
if svcInfo, ok := proxier.serviceMap[svcPortName]; ok && svcInfo != nil && svcInfo.GetProtocol() == api.ProtocolUDP { if svcInfo, ok := proxier.serviceMap[svcPortName]; ok && svcInfo != nil && svcInfo.GetProtocol() == v1.ProtocolUDP {
glog.V(2).Infof("Stale udp service %v -> %s", svcPortName, svcInfo.ClusterIPString()) glog.V(2).Infof("Stale udp service %v -> %s", svcPortName, svcInfo.ClusterIPString())
staleServices.Insert(svcInfo.ClusterIPString()) staleServices.Insert(svcInfo.ClusterIPString())
} }
@ -869,7 +868,7 @@ func (proxier *Proxier) syncProxyRules() {
Name: proxier.hostname, Name: proxier.hostname,
UID: types.UID(proxier.hostname), UID: types.UID(proxier.hostname),
Namespace: "", Namespace: "",
}, api.EventTypeWarning, err.Error(), msg) }, v1.EventTypeWarning, err.Error(), msg)
glog.Error(msg) glog.Error(msg)
continue continue
} }
@ -1103,7 +1102,7 @@ func (proxier *Proxier) syncProxyRules() {
} }
// First write session affinity rules, if applicable. // First write session affinity rules, if applicable.
if svcInfo.SessionAffinityType == api.ServiceAffinityClientIP { if svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP {
for _, endpointChain := range endpointChains { for _, endpointChain := range endpointChains {
args = append(args[:0], args = append(args[:0],
"-A", string(svcChain), "-A", string(svcChain),
@ -1148,7 +1147,7 @@ func (proxier *Proxier) syncProxyRules() {
"-s", utilproxy.ToCIDR(net.ParseIP(epIP)), "-s", utilproxy.ToCIDR(net.ParseIP(epIP)),
"-j", string(KubeMarkMasqChain))...) "-j", string(KubeMarkMasqChain))...)
// Update client-affinity lists. // Update client-affinity lists.
if svcInfo.SessionAffinityType == api.ServiceAffinityClientIP { if svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP {
args = append(args, "-m", "recent", "--name", string(endpointChain), "--set") args = append(args, "-m", "recent", "--name", string(endpointChain), "--set")
} }
// DNAT to final destination. // DNAT to final destination.
@ -1199,7 +1198,7 @@ func (proxier *Proxier) syncProxyRules() {
writeLine(proxier.natRules, args...) writeLine(proxier.natRules, args...)
} else { } else {
// First write session affinity rules only over local endpoints, if applicable. // First write session affinity rules only over local endpoints, if applicable.
if svcInfo.SessionAffinityType == api.ServiceAffinityClientIP { if svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP {
for _, endpointChain := range localEndpointChains { for _, endpointChain := range localEndpointChains {
writeLine(proxier.natRules, writeLine(proxier.natRules,
"-A", string(svcXlbChain), "-A", string(svcXlbChain),

File diff suppressed because it is too large Load Diff

View File

@ -30,12 +30,11 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
clientv1 "k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/proxy/healthcheck" "k8s.io/kubernetes/pkg/proxy/healthcheck"
"k8s.io/kubernetes/pkg/proxy/metrics" "k8s.io/kubernetes/pkg/proxy/metrics"
@ -397,7 +396,7 @@ type serviceInfo struct {
} }
// returns a new proxy.ServicePort which abstracts a serviceInfo // returns a new proxy.ServicePort which abstracts a serviceInfo
func newServiceInfo(port *api.ServicePort, service *api.Service, baseInfo *proxy.BaseServiceInfo) proxy.ServicePort { func newServiceInfo(port *v1.ServicePort, service *v1.Service, baseInfo *proxy.BaseServiceInfo) proxy.ServicePort {
info := &serviceInfo{BaseServiceInfo: baseInfo} info := &serviceInfo{BaseServiceInfo: baseInfo}
// Store the following for performance reasons. // Store the following for performance reasons.
@ -594,19 +593,19 @@ func (proxier *Proxier) isInitialized() bool {
} }
// OnServiceAdd is called whenever creation of new service object is observed. // OnServiceAdd is called whenever creation of new service object is observed.
func (proxier *Proxier) OnServiceAdd(service *api.Service) { func (proxier *Proxier) OnServiceAdd(service *v1.Service) {
proxier.OnServiceUpdate(nil, service) proxier.OnServiceUpdate(nil, service)
} }
// OnServiceUpdate is called whenever modification of an existing service object is observed. // OnServiceUpdate is called whenever modification of an existing service object is observed.
func (proxier *Proxier) OnServiceUpdate(oldService, service *api.Service) { func (proxier *Proxier) OnServiceUpdate(oldService, service *v1.Service) {
if proxier.serviceChanges.Update(oldService, service) && proxier.isInitialized() { if proxier.serviceChanges.Update(oldService, service) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
// OnServiceDelete is called whenever deletion of an existing service object is observed. // OnServiceDelete is called whenever deletion of an existing service object is observed.
func (proxier *Proxier) OnServiceDelete(service *api.Service) { func (proxier *Proxier) OnServiceDelete(service *v1.Service) {
proxier.OnServiceUpdate(service, nil) proxier.OnServiceUpdate(service, nil)
} }
@ -622,19 +621,19 @@ func (proxier *Proxier) OnServiceSynced() {
} }
// OnEndpointsAdd is called whenever creation of new endpoints object is observed. // OnEndpointsAdd is called whenever creation of new endpoints object is observed.
func (proxier *Proxier) OnEndpointsAdd(endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
proxier.OnEndpointsUpdate(nil, endpoints) proxier.OnEndpointsUpdate(nil, endpoints)
} }
// OnEndpointsUpdate is called whenever modification of an existing endpoints object is observed. // OnEndpointsUpdate is called whenever modification of an existing endpoints object is observed.
func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
if proxier.endpointsChanges.Update(oldEndpoints, endpoints) && proxier.isInitialized() { if proxier.endpointsChanges.Update(oldEndpoints, endpoints) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
// OnEndpointsDelete is called whenever deletion of an existing endpoints object is observed. // OnEndpointsDelete is called whenever deletion of an existing endpoints object is observed.
func (proxier *Proxier) OnEndpointsDelete(endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsDelete(endpoints *v1.Endpoints) {
proxier.OnEndpointsUpdate(endpoints, nil) proxier.OnEndpointsUpdate(endpoints, nil)
} }
@ -678,7 +677,7 @@ func (proxier *Proxier) syncProxyRules() {
staleServices := serviceUpdateResult.UDPStaleClusterIP staleServices := serviceUpdateResult.UDPStaleClusterIP
// merge stale services gathered from updateEndpointsMap // merge stale services gathered from updateEndpointsMap
for _, svcPortName := range endpointUpdateResult.StaleServiceNames { for _, svcPortName := range endpointUpdateResult.StaleServiceNames {
if svcInfo, ok := proxier.serviceMap[svcPortName]; ok && svcInfo != nil && svcInfo.GetProtocol() == api.ProtocolUDP { if svcInfo, ok := proxier.serviceMap[svcPortName]; ok && svcInfo != nil && svcInfo.GetProtocol() == v1.ProtocolUDP {
glog.V(2).Infof("Stale udp service %v -> %s", svcPortName, svcInfo.ClusterIPString()) glog.V(2).Infof("Stale udp service %v -> %s", svcPortName, svcInfo.ClusterIPString())
staleServices.Insert(svcInfo.ClusterIPString()) staleServices.Insert(svcInfo.ClusterIPString())
} }
@ -785,7 +784,7 @@ func (proxier *Proxier) syncProxyRules() {
Scheduler: proxier.ipvsScheduler, Scheduler: proxier.ipvsScheduler,
} }
// Set session affinity flag and timeout for IPVS service // Set session affinity flag and timeout for IPVS service
if svcInfo.SessionAffinityType == api.ServiceAffinityClientIP { if svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP {
serv.Flags |= utilipvs.FlagPersistent serv.Flags |= utilipvs.FlagPersistent
serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds) serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds)
} }
@ -822,12 +821,12 @@ func (proxier *Proxier) syncProxyRules() {
msg := fmt.Sprintf("can't open %s, skipping this externalIP: %v", lp.String(), err) msg := fmt.Sprintf("can't open %s, skipping this externalIP: %v", lp.String(), err)
proxier.recorder.Eventf( proxier.recorder.Eventf(
&clientv1.ObjectReference{ &v1.ObjectReference{
Kind: "Node", Kind: "Node",
Name: proxier.hostname, Name: proxier.hostname,
UID: types.UID(proxier.hostname), UID: types.UID(proxier.hostname),
Namespace: "", Namespace: "",
}, api.EventTypeWarning, err.Error(), msg) }, v1.EventTypeWarning, err.Error(), msg)
glog.Error(msg) glog.Error(msg)
continue continue
} }
@ -856,7 +855,7 @@ func (proxier *Proxier) syncProxyRules() {
Protocol: string(svcInfo.Protocol), Protocol: string(svcInfo.Protocol),
Scheduler: proxier.ipvsScheduler, Scheduler: proxier.ipvsScheduler,
} }
if svcInfo.SessionAffinityType == api.ServiceAffinityClientIP { if svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP {
serv.Flags |= utilipvs.FlagPersistent serv.Flags |= utilipvs.FlagPersistent
serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds) serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds)
} }
@ -957,13 +956,13 @@ func (proxier *Proxier) syncProxyRules() {
Protocol: string(svcInfo.Protocol), Protocol: string(svcInfo.Protocol),
Scheduler: proxier.ipvsScheduler, Scheduler: proxier.ipvsScheduler,
} }
if svcInfo.SessionAffinityType == api.ServiceAffinityClientIP { if svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP {
serv.Flags |= utilipvs.FlagPersistent serv.Flags |= utilipvs.FlagPersistent
serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds) serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds)
} }
if err := proxier.syncService(svcNameString, serv, true); err == nil { if err := proxier.syncService(svcNameString, serv, true); err == nil {
// check if service need skip endpoints that not in same host as kube-proxy // check if service need skip endpoints that not in same host as kube-proxy
onlyLocal := svcInfo.SessionAffinityType == api.ServiceAffinityClientIP && svcInfo.OnlyNodeLocalEndpoints onlyLocal := svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP && svcInfo.OnlyNodeLocalEndpoints
activeIPVSServices[serv.String()] = true activeIPVSServices[serv.String()] = true
activeBindAddrs[serv.Address.String()] = true activeBindAddrs[serv.Address.String()] = true
if err := proxier.syncEndpoint(svcName, onlyLocal, serv); err != nil { if err := proxier.syncEndpoint(svcName, onlyLocal, serv); err != nil {
@ -1013,7 +1012,7 @@ func (proxier *Proxier) syncProxyRules() {
} }
if lp.Protocol == "udp" { if lp.Protocol == "udp" {
isIPv6 := utilnet.IsIPv6(svcInfo.ClusterIP) isIPv6 := utilnet.IsIPv6(svcInfo.ClusterIP)
conntrack.ClearEntriesForPort(proxier.exec, lp.Port, isIPv6, clientv1.ProtocolUDP) conntrack.ClearEntriesForPort(proxier.exec, lp.Port, isIPv6, v1.ProtocolUDP)
} }
replacementPortsMap[lp] = socket replacementPortsMap[lp] = socket
} // We're holding the port, so it's OK to install ipvs rules. } // We're holding the port, so it's OK to install ipvs rules.
@ -1087,7 +1086,7 @@ func (proxier *Proxier) syncProxyRules() {
Protocol: string(svcInfo.Protocol), Protocol: string(svcInfo.Protocol),
Scheduler: proxier.ipvsScheduler, Scheduler: proxier.ipvsScheduler,
} }
if svcInfo.SessionAffinityType == api.ServiceAffinityClientIP { if svcInfo.SessionAffinityType == v1.ServiceAffinityClientIP {
serv.Flags |= utilipvs.FlagPersistent serv.Flags |= utilipvs.FlagPersistent
serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds) serv.Timeout = uint32(svcInfo.StickyMaxAgeSeconds)
} }
@ -1173,7 +1172,7 @@ func (proxier *Proxier) syncProxyRules() {
// Finish housekeeping. // Finish housekeeping.
// TODO: these could be made more consistent. // TODO: these could be made more consistent.
for _, svcIP := range staleServices.UnsortedList() { for _, svcIP := range staleServices.UnsortedList() {
if err := conntrack.ClearEntriesForIP(proxier.exec, svcIP, clientv1.ProtocolUDP); err != nil { if err := conntrack.ClearEntriesForIP(proxier.exec, svcIP, v1.ProtocolUDP); err != nil {
glog.Errorf("Failed to delete stale service IP %s connections, error: %v", svcIP, err) glog.Errorf("Failed to delete stale service IP %s connections, error: %v", svcIP, err)
} }
} }
@ -1418,9 +1417,9 @@ func (proxier *Proxier) getExistingChains(buffer *bytes.Buffer, table utiliptabl
// This assumes the proxier mutex is held // This assumes the proxier mutex is held
func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceEndpoint) { func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceEndpoint) {
for _, epSvcPair := range connectionMap { for _, epSvcPair := range connectionMap {
if svcInfo, ok := proxier.serviceMap[epSvcPair.ServicePortName]; ok && svcInfo.GetProtocol() == api.ProtocolUDP { if svcInfo, ok := proxier.serviceMap[epSvcPair.ServicePortName]; ok && svcInfo.GetProtocol() == v1.ProtocolUDP {
endpointIP := utilproxy.IPPart(epSvcPair.Endpoint) endpointIP := utilproxy.IPPart(epSvcPair.Endpoint)
err := conntrack.ClearEntriesForNAT(proxier.exec, svcInfo.ClusterIPString(), endpointIP, clientv1.ProtocolUDP) err := conntrack.ClearEntriesForNAT(proxier.exec, svcInfo.ClusterIPString(), endpointIP, v1.ProtocolUDP)
if err != nil { if err != nil {
glog.Errorf("Failed to delete %s endpoint connections, error: %v", epSvcPair.ServicePortName.String(), err) glog.Errorf("Failed to delete %s endpoint connections, error: %v", epSvcPair.ServicePortName.String(), err)
} }

File diff suppressed because it is too large Load Diff

View File

@ -25,11 +25,11 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
apiservice "k8s.io/kubernetes/pkg/api/service" apiservice "k8s.io/kubernetes/pkg/api/v1/service"
api "k8s.io/kubernetes/pkg/apis/core"
utilproxy "k8s.io/kubernetes/pkg/proxy/util" utilproxy "k8s.io/kubernetes/pkg/proxy/util"
utilnet "k8s.io/kubernetes/pkg/util/net" utilnet "k8s.io/kubernetes/pkg/util/net"
) )
@ -41,10 +41,10 @@ import (
type BaseServiceInfo struct { type BaseServiceInfo struct {
ClusterIP net.IP ClusterIP net.IP
Port int Port int
Protocol api.Protocol Protocol v1.Protocol
NodePort int NodePort int
LoadBalancerStatus api.LoadBalancerStatus LoadBalancerStatus v1.LoadBalancerStatus
SessionAffinityType api.ServiceAffinity SessionAffinityType v1.ServiceAffinity
StickyMaxAgeSeconds int StickyMaxAgeSeconds int
ExternalIPs []string ExternalIPs []string
LoadBalancerSourceRanges []string LoadBalancerSourceRanges []string
@ -65,7 +65,7 @@ func (info *BaseServiceInfo) ClusterIPString() string {
} }
// GetProtocol is part of ServicePort interface. // GetProtocol is part of ServicePort interface.
func (info *BaseServiceInfo) GetProtocol() api.Protocol { func (info *BaseServiceInfo) GetProtocol() v1.Protocol {
return info.Protocol return info.Protocol
} }
@ -74,13 +74,13 @@ func (info *BaseServiceInfo) GetHealthCheckNodePort() int {
return info.HealthCheckNodePort return info.HealthCheckNodePort
} }
func (sct *ServiceChangeTracker) newBaseServiceInfo(port *api.ServicePort, service *api.Service) *BaseServiceInfo { func (sct *ServiceChangeTracker) newBaseServiceInfo(port *v1.ServicePort, service *v1.Service) *BaseServiceInfo {
onlyNodeLocalEndpoints := false onlyNodeLocalEndpoints := false
if apiservice.RequestsOnlyLocalTraffic(service) { if apiservice.RequestsOnlyLocalTraffic(service) {
onlyNodeLocalEndpoints = true onlyNodeLocalEndpoints = true
} }
var stickyMaxAgeSeconds int var stickyMaxAgeSeconds int
if service.Spec.SessionAffinity == api.ServiceAffinityClientIP { if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
// Kube-apiserver side guarantees SessionAffinityConfig won't be nil when session affinity type is ClientIP // Kube-apiserver side guarantees SessionAffinityConfig won't be nil when session affinity type is ClientIP
stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds) stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds)
} }
@ -128,7 +128,7 @@ func (sct *ServiceChangeTracker) newBaseServiceInfo(port *api.ServicePort, servi
return info return info
} }
type makeServicePortFunc func(*api.ServicePort, *api.Service, *BaseServiceInfo) ServicePort type makeServicePortFunc func(*v1.ServicePort, *v1.Service, *BaseServiceInfo) ServicePort
// serviceChange contains all changes to services that happened since proxy rules were synced. For a single object, // serviceChange contains all changes to services that happened since proxy rules were synced. For a single object,
// changes are accumulated, i.e. previous is state from before applying the changes, // changes are accumulated, i.e. previous is state from before applying the changes,
@ -170,7 +170,7 @@ func NewServiceChangeTracker(makeServiceInfo makeServicePortFunc, isIPv6Mode *bo
// - pass <oldService, service> as the <previous, current> pair. // - pass <oldService, service> as the <previous, current> pair.
// Delete item // Delete item
// - pass <service, nil> as the <previous, current> pair. // - pass <service, nil> as the <previous, current> pair.
func (sct *ServiceChangeTracker) Update(previous, current *api.Service) bool { func (sct *ServiceChangeTracker) Update(previous, current *v1.Service) bool {
svc := current svc := current
if svc == nil { if svc == nil {
svc = previous svc = previous
@ -231,7 +231,7 @@ type ServiceMap map[ServicePortName]ServicePort
// serviceToServiceMap translates a single Service object to a ServiceMap. // serviceToServiceMap translates a single Service object to a ServiceMap.
// //
// NOTE: service object should NOT be modified. // NOTE: service object should NOT be modified.
func (sct *ServiceChangeTracker) serviceToServiceMap(service *api.Service) ServiceMap { func (sct *ServiceChangeTracker) serviceToServiceMap(service *v1.Service) ServiceMap {
if service == nil { if service == nil {
return nil return nil
} }
@ -332,7 +332,7 @@ func (sm *ServiceMap) unmerge(other ServiceMap, UDPStaleClusterIP sets.String) {
info, exists := (*sm)[svcPortName] info, exists := (*sm)[svcPortName]
if exists { if exists {
glog.V(1).Infof("Removing service port %q", svcPortName) glog.V(1).Infof("Removing service port %q", svcPortName)
if info.GetProtocol() == api.ProtocolUDP { if info.GetProtocol() == v1.ProtocolUDP {
UDPStaleClusterIP.Insert(info.ClusterIPString()) UDPStaleClusterIP.Insert(info.ClusterIPString())
} }
delete(*sm, svcPortName) delete(*sm, svcPortName)

View File

@ -22,11 +22,11 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
api "k8s.io/kubernetes/pkg/apis/core"
) )
const testHostname = "test-hostname" const testHostname = "test-hostname"
@ -35,7 +35,7 @@ func makeTestServiceInfo(clusterIP string, port int, protocol string, healthchec
info := &BaseServiceInfo{ info := &BaseServiceInfo{
ClusterIP: net.ParseIP(clusterIP), ClusterIP: net.ParseIP(clusterIP),
Port: port, Port: port,
Protocol: api.Protocol(protocol), Protocol: v1.Protocol(protocol),
} }
if healthcheckNodePort != 0 { if healthcheckNodePort != 0 {
info.HealthCheckNodePort = healthcheckNodePort info.HealthCheckNodePort = healthcheckNodePort
@ -46,22 +46,22 @@ func makeTestServiceInfo(clusterIP string, port int, protocol string, healthchec
return info return info
} }
func makeTestService(namespace, name string, svcFunc func(*api.Service)) *api.Service { func makeTestService(namespace, name string, svcFunc func(*v1.Service)) *v1.Service {
svc := &api.Service{ svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
Namespace: namespace, Namespace: namespace,
Annotations: map[string]string{}, Annotations: map[string]string{},
}, },
Spec: api.ServiceSpec{}, Spec: v1.ServiceSpec{},
Status: api.ServiceStatus{}, Status: v1.ServiceStatus{},
} }
svcFunc(svc) svcFunc(svc)
return svc return svc
} }
func addTestPort(array []api.ServicePort, name string, protocol api.Protocol, port, nodeport int32, targetPort int) []api.ServicePort { func addTestPort(array []v1.ServicePort, name string, protocol v1.Protocol, port, nodeport int32, targetPort int) []v1.ServicePort {
svcPort := api.ServicePort{ svcPort := v1.ServicePort{
Name: name, Name: name,
Protocol: protocol, Protocol: protocol,
Port: port, Port: port,
@ -96,7 +96,7 @@ func TestServiceToServiceMap(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
service *api.Service service *v1.Service
expected map[ServicePortName]*BaseServiceInfo expected map[ServicePortName]*BaseServiceInfo
isIPv6Mode *bool isIPv6Mode *bool
}{ }{
@ -107,25 +107,25 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "headless service", desc: "headless service",
service: makeTestService("ns2", "headless", func(svc *api.Service) { service: makeTestService("ns2", "headless", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = api.ClusterIPNone svc.Spec.ClusterIP = v1.ClusterIPNone
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "rpc", "UDP", 1234, 0, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "rpc", "UDP", 1234, 0, 0)
}), }),
expected: map[ServicePortName]*BaseServiceInfo{}, expected: map[ServicePortName]*BaseServiceInfo{},
}, },
{ {
desc: "headless service without port", desc: "headless service without port",
service: makeTestService("ns2", "headless-without-port", func(svc *api.Service) { service: makeTestService("ns2", "headless-without-port", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = api.ClusterIPNone svc.Spec.ClusterIP = v1.ClusterIPNone
}), }),
expected: map[ServicePortName]*BaseServiceInfo{}, expected: map[ServicePortName]*BaseServiceInfo{},
}, },
{ {
desc: "cluster ip service", desc: "cluster ip service",
service: makeTestService("ns2", "cluster-ip", func(svc *api.Service) { service: makeTestService("ns2", "cluster-ip", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = "172.16.55.4" svc.Spec.ClusterIP = "172.16.55.4"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p1", "UDP", 1234, 4321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p1", "UDP", 1234, 4321, 0)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "UDP", 1235, 5321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "UDP", 1235, 5321, 0)
@ -137,8 +137,8 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "nodeport service", desc: "nodeport service",
service: makeTestService("ns2", "node-port", func(svc *api.Service) { service: makeTestService("ns2", "node-port", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeNodePort svc.Spec.Type = v1.ServiceTypeNodePort
svc.Spec.ClusterIP = "172.16.55.10" svc.Spec.ClusterIP = "172.16.55.10"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port1", "UDP", 345, 678, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port1", "UDP", 345, 678, 0)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port2", "TCP", 344, 677, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port2", "TCP", 344, 677, 0)
@ -150,14 +150,14 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "load balancer service", desc: "load balancer service",
service: makeTestService("ns1", "load-balancer", func(svc *api.Service) { service: makeTestService("ns1", "load-balancer", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeLoadBalancer svc.Spec.Type = v1.ServiceTypeLoadBalancer
svc.Spec.ClusterIP = "172.16.55.11" svc.Spec.ClusterIP = "172.16.55.11"
svc.Spec.LoadBalancerIP = "5.6.7.8" svc.Spec.LoadBalancerIP = "5.6.7.8"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port3", "UDP", 8675, 30061, 7000) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port3", "UDP", 8675, 30061, 7000)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port4", "UDP", 8676, 30062, 7001) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port4", "UDP", 8676, 30062, 7001)
svc.Status.LoadBalancer = api.LoadBalancerStatus{ svc.Status.LoadBalancer = v1.LoadBalancerStatus{
Ingress: []api.LoadBalancerIngress{ Ingress: []v1.LoadBalancerIngress{
{IP: "10.1.2.4"}, {IP: "10.1.2.4"},
}, },
} }
@ -169,18 +169,18 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "load balancer service with only local traffic policy", desc: "load balancer service with only local traffic policy",
service: makeTestService("ns1", "only-local-load-balancer", func(svc *api.Service) { service: makeTestService("ns1", "only-local-load-balancer", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeLoadBalancer svc.Spec.Type = v1.ServiceTypeLoadBalancer
svc.Spec.ClusterIP = "172.16.55.12" svc.Spec.ClusterIP = "172.16.55.12"
svc.Spec.LoadBalancerIP = "5.6.7.8" svc.Spec.LoadBalancerIP = "5.6.7.8"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "portx", "UDP", 8677, 30063, 7002) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "portx", "UDP", 8677, 30063, 7002)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "porty", "UDP", 8678, 30064, 7003) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "porty", "UDP", 8678, 30064, 7003)
svc.Status.LoadBalancer = api.LoadBalancerStatus{ svc.Status.LoadBalancer = v1.LoadBalancerStatus{
Ingress: []api.LoadBalancerIngress{ Ingress: []v1.LoadBalancerIngress{
{IP: "10.1.2.3"}, {IP: "10.1.2.3"},
}, },
} }
svc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal svc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeLocal
svc.Spec.HealthCheckNodePort = 345 svc.Spec.HealthCheckNodePort = 345
}), }),
expected: map[ServicePortName]*BaseServiceInfo{ expected: map[ServicePortName]*BaseServiceInfo{
@ -190,8 +190,8 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "external name service", desc: "external name service",
service: makeTestService("ns2", "external-name", func(svc *api.Service) { service: makeTestService("ns2", "external-name", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeExternalName svc.Spec.Type = v1.ServiceTypeExternalName
svc.Spec.ClusterIP = "172.16.55.4" // Should be ignored svc.Spec.ClusterIP = "172.16.55.4" // Should be ignored
svc.Spec.ExternalName = "foo2.bar.com" svc.Spec.ExternalName = "foo2.bar.com"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "portz", "UDP", 1235, 5321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "portz", "UDP", 1235, 5321, 0)
@ -200,18 +200,18 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "service with ipv6 clusterIP under ipv4 mode, service should be filtered", desc: "service with ipv6 clusterIP under ipv4 mode, service should be filtered",
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "invalidIPv6InIPV4Mode", Name: "invalidIPv6InIPV4Mode",
Namespace: "test", Namespace: "test",
}, },
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: testClusterIPv6, ClusterIP: testClusterIPv6,
Ports: []api.ServicePort{ Ports: []v1.ServicePort{
{ {
Name: "testPort", Name: "testPort",
Port: int32(12345), Port: int32(12345),
Protocol: api.ProtocolTCP, Protocol: v1.ProtocolTCP,
}, },
}, },
}, },
@ -220,18 +220,18 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "service with ipv4 clusterIP under ipv6 mode, service should be filtered", desc: "service with ipv4 clusterIP under ipv6 mode, service should be filtered",
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "invalidIPv4InIPV6Mode", Name: "invalidIPv4InIPV6Mode",
Namespace: "test", Namespace: "test",
}, },
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: testClusterIPv4, ClusterIP: testClusterIPv4,
Ports: []api.ServicePort{ Ports: []v1.ServicePort{
{ {
Name: "testPort", Name: "testPort",
Port: int32(12345), Port: int32(12345),
Protocol: api.ProtocolTCP, Protocol: v1.ProtocolTCP,
}, },
}, },
}, },
@ -240,20 +240,20 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "service with ipv4 configurations under ipv4 mode", desc: "service with ipv4 configurations under ipv4 mode",
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "validIPv4", Name: "validIPv4",
Namespace: "test", Namespace: "test",
}, },
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: testClusterIPv4, ClusterIP: testClusterIPv4,
ExternalIPs: []string{testExternalIPv4}, ExternalIPs: []string{testExternalIPv4},
LoadBalancerSourceRanges: []string{testSourceRangeIPv4}, LoadBalancerSourceRanges: []string{testSourceRangeIPv4},
Ports: []api.ServicePort{ Ports: []v1.ServicePort{
{ {
Name: "testPort", Name: "testPort",
Port: int32(12345), Port: int32(12345),
Protocol: api.ProtocolTCP, Protocol: v1.ProtocolTCP,
}, },
}, },
}, },
@ -268,20 +268,20 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "service with ipv6 configurations under ipv6 mode", desc: "service with ipv6 configurations under ipv6 mode",
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "validIPv6", Name: "validIPv6",
Namespace: "test", Namespace: "test",
}, },
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: testClusterIPv6, ClusterIP: testClusterIPv6,
ExternalIPs: []string{testExternalIPv6}, ExternalIPs: []string{testExternalIPv6},
LoadBalancerSourceRanges: []string{testSourceRangeIPv6}, LoadBalancerSourceRanges: []string{testSourceRangeIPv6},
Ports: []api.ServicePort{ Ports: []v1.ServicePort{
{ {
Name: "testPort", Name: "testPort",
Port: int32(12345), Port: int32(12345),
Protocol: api.ProtocolTCP, Protocol: v1.ProtocolTCP,
}, },
}, },
}, },
@ -296,20 +296,20 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "service with both ipv4 and ipv6 configurations under ipv4 mode, ipv6 fields should be filtered", desc: "service with both ipv4 and ipv6 configurations under ipv4 mode, ipv6 fields should be filtered",
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "filterIPv6InIPV4Mode", Name: "filterIPv6InIPV4Mode",
Namespace: "test", Namespace: "test",
}, },
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: testClusterIPv4, ClusterIP: testClusterIPv4,
ExternalIPs: []string{testExternalIPv4, testExternalIPv6}, ExternalIPs: []string{testExternalIPv4, testExternalIPv6},
LoadBalancerSourceRanges: []string{testSourceRangeIPv4, testSourceRangeIPv6}, LoadBalancerSourceRanges: []string{testSourceRangeIPv4, testSourceRangeIPv6},
Ports: []api.ServicePort{ Ports: []v1.ServicePort{
{ {
Name: "testPort", Name: "testPort",
Port: int32(12345), Port: int32(12345),
Protocol: api.ProtocolTCP, Protocol: v1.ProtocolTCP,
}, },
}, },
}, },
@ -324,20 +324,20 @@ func TestServiceToServiceMap(t *testing.T) {
}, },
{ {
desc: "service with both ipv4 and ipv6 configurations under ipv6 mode, ipv4 fields should be filtered", desc: "service with both ipv4 and ipv6 configurations under ipv6 mode, ipv4 fields should be filtered",
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "filterIPv4InIPV6Mode", Name: "filterIPv4InIPV6Mode",
Namespace: "test", Namespace: "test",
}, },
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: testClusterIPv6, ClusterIP: testClusterIPv6,
ExternalIPs: []string{testExternalIPv4, testExternalIPv6}, ExternalIPs: []string{testExternalIPv4, testExternalIPv6},
LoadBalancerSourceRanges: []string{testSourceRangeIPv4, testSourceRangeIPv6}, LoadBalancerSourceRanges: []string{testSourceRangeIPv4, testSourceRangeIPv6},
Ports: []api.ServicePort{ Ports: []v1.ServicePort{
{ {
Name: "testPort", Name: "testPort",
Port: int32(12345), Port: int32(12345),
Protocol: api.ProtocolTCP, Protocol: v1.ProtocolTCP,
}, },
}, },
}, },
@ -391,21 +391,21 @@ func newFakeProxier() *FakeProxier {
} }
} }
func makeServiceMap(fake *FakeProxier, allServices ...*api.Service) { func makeServiceMap(fake *FakeProxier, allServices ...*v1.Service) {
for i := range allServices { for i := range allServices {
fake.addService(allServices[i]) fake.addService(allServices[i])
} }
} }
func (fake *FakeProxier) addService(service *api.Service) { func (fake *FakeProxier) addService(service *v1.Service) {
fake.serviceChanges.Update(nil, service) fake.serviceChanges.Update(nil, service)
} }
func (fake *FakeProxier) updateService(oldService *api.Service, service *api.Service) { func (fake *FakeProxier) updateService(oldService *v1.Service, service *v1.Service) {
fake.serviceChanges.Update(oldService, service) fake.serviceChanges.Update(oldService, service)
} }
func (fake *FakeProxier) deleteService(service *api.Service) { func (fake *FakeProxier) deleteService(service *v1.Service) {
fake.serviceChanges.Update(service, nil) fake.serviceChanges.Update(service, nil)
} }
@ -413,14 +413,14 @@ func TestUpdateServiceMapHeadless(t *testing.T) {
fp := newFakeProxier() fp := newFakeProxier()
makeServiceMap(fp, makeServiceMap(fp,
makeTestService("ns2", "headless", func(svc *api.Service) { makeTestService("ns2", "headless", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = api.ClusterIPNone svc.Spec.ClusterIP = v1.ClusterIPNone
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "rpc", "UDP", 1234, 0, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "rpc", "UDP", 1234, 0, 0)
}), }),
makeTestService("ns2", "headless-without-port", func(svc *api.Service) { makeTestService("ns2", "headless-without-port", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = api.ClusterIPNone svc.Spec.ClusterIP = v1.ClusterIPNone
}), }),
) )
@ -444,8 +444,8 @@ func TestUpdateServiceTypeExternalName(t *testing.T) {
fp := newFakeProxier() fp := newFakeProxier()
makeServiceMap(fp, makeServiceMap(fp,
makeTestService("ns2", "external-name", func(svc *api.Service) { makeTestService("ns2", "external-name", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeExternalName svc.Spec.Type = v1.ServiceTypeExternalName
svc.Spec.ClusterIP = "172.16.55.4" // Should be ignored svc.Spec.ClusterIP = "172.16.55.4" // Should be ignored
svc.Spec.ExternalName = "foo2.bar.com" svc.Spec.ExternalName = "foo2.bar.com"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "blah", "UDP", 1235, 5321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "blah", "UDP", 1235, 5321, 0)
@ -468,43 +468,43 @@ func TestUpdateServiceTypeExternalName(t *testing.T) {
func TestBuildServiceMapAddRemove(t *testing.T) { func TestBuildServiceMapAddRemove(t *testing.T) {
fp := newFakeProxier() fp := newFakeProxier()
services := []*api.Service{ services := []*v1.Service{
makeTestService("ns2", "cluster-ip", func(svc *api.Service) { makeTestService("ns2", "cluster-ip", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = "172.16.55.4" svc.Spec.ClusterIP = "172.16.55.4"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port1", "UDP", 1234, 4321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port1", "UDP", 1234, 4321, 0)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port2", "UDP", 1235, 5321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port2", "UDP", 1235, 5321, 0)
}), }),
makeTestService("ns2", "node-port", func(svc *api.Service) { makeTestService("ns2", "node-port", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeNodePort svc.Spec.Type = v1.ServiceTypeNodePort
svc.Spec.ClusterIP = "172.16.55.10" svc.Spec.ClusterIP = "172.16.55.10"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port1", "UDP", 345, 678, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port1", "UDP", 345, 678, 0)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port2", "TCP", 344, 677, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "port2", "TCP", 344, 677, 0)
}), }),
makeTestService("ns1", "load-balancer", func(svc *api.Service) { makeTestService("ns1", "load-balancer", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeLoadBalancer svc.Spec.Type = v1.ServiceTypeLoadBalancer
svc.Spec.ClusterIP = "172.16.55.11" svc.Spec.ClusterIP = "172.16.55.11"
svc.Spec.LoadBalancerIP = "5.6.7.8" svc.Spec.LoadBalancerIP = "5.6.7.8"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "foobar", "UDP", 8675, 30061, 7000) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "foobar", "UDP", 8675, 30061, 7000)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "baz", "UDP", 8676, 30062, 7001) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "baz", "UDP", 8676, 30062, 7001)
svc.Status.LoadBalancer = api.LoadBalancerStatus{ svc.Status.LoadBalancer = v1.LoadBalancerStatus{
Ingress: []api.LoadBalancerIngress{ Ingress: []v1.LoadBalancerIngress{
{IP: "10.1.2.4"}, {IP: "10.1.2.4"},
}, },
} }
}), }),
makeTestService("ns1", "only-local-load-balancer", func(svc *api.Service) { makeTestService("ns1", "only-local-load-balancer", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeLoadBalancer svc.Spec.Type = v1.ServiceTypeLoadBalancer
svc.Spec.ClusterIP = "172.16.55.12" svc.Spec.ClusterIP = "172.16.55.12"
svc.Spec.LoadBalancerIP = "5.6.7.8" svc.Spec.LoadBalancerIP = "5.6.7.8"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "foobar2", "UDP", 8677, 30063, 7002) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "foobar2", "UDP", 8677, 30063, 7002)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "baz", "UDP", 8678, 30064, 7003) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "baz", "UDP", 8678, 30064, 7003)
svc.Status.LoadBalancer = api.LoadBalancerStatus{ svc.Status.LoadBalancer = v1.LoadBalancerStatus{
Ingress: []api.LoadBalancerIngress{ Ingress: []v1.LoadBalancerIngress{
{IP: "10.1.2.3"}, {IP: "10.1.2.3"},
}, },
} }
svc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal svc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeLocal
svc.Spec.HealthCheckNodePort = 345 svc.Spec.HealthCheckNodePort = 345
}), }),
} }
@ -534,8 +534,8 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
// Remove some stuff // Remove some stuff
// oneService is a modification of services[0] with removed first port. // oneService is a modification of services[0] with removed first port.
oneService := makeTestService("ns2", "cluster-ip", func(svc *api.Service) { oneService := makeTestService("ns2", "cluster-ip", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = "172.16.55.4" svc.Spec.ClusterIP = "172.16.55.4"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "UDP", 1235, 5321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "UDP", 1235, 5321, 0)
}) })
@ -571,24 +571,24 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
func TestBuildServiceMapServiceUpdate(t *testing.T) { func TestBuildServiceMapServiceUpdate(t *testing.T) {
fp := newFakeProxier() fp := newFakeProxier()
servicev1 := makeTestService("ns1", "svc1", func(svc *api.Service) { servicev1 := makeTestService("ns1", "svc1", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeClusterIP svc.Spec.Type = v1.ServiceTypeClusterIP
svc.Spec.ClusterIP = "172.16.55.4" svc.Spec.ClusterIP = "172.16.55.4"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p1", "UDP", 1234, 4321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p1", "UDP", 1234, 4321, 0)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "TCP", 1235, 5321, 0) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "TCP", 1235, 5321, 0)
}) })
servicev2 := makeTestService("ns1", "svc1", func(svc *api.Service) { servicev2 := makeTestService("ns1", "svc1", func(svc *v1.Service) {
svc.Spec.Type = api.ServiceTypeLoadBalancer svc.Spec.Type = v1.ServiceTypeLoadBalancer
svc.Spec.ClusterIP = "172.16.55.4" svc.Spec.ClusterIP = "172.16.55.4"
svc.Spec.LoadBalancerIP = "5.6.7.8" svc.Spec.LoadBalancerIP = "5.6.7.8"
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p1", "UDP", 1234, 4321, 7002) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p1", "UDP", 1234, 4321, 7002)
svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "TCP", 1235, 5321, 7003) svc.Spec.Ports = addTestPort(svc.Spec.Ports, "p2", "TCP", 1235, 5321, 7003)
svc.Status.LoadBalancer = api.LoadBalancerStatus{ svc.Status.LoadBalancer = v1.LoadBalancerStatus{
Ingress: []api.LoadBalancerIngress{ Ingress: []v1.LoadBalancerIngress{
{IP: "10.1.2.3"}, {IP: "10.1.2.3"},
}, },
} }
svc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal svc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeLocal
svc.Spec.HealthCheckNodePort = 345 svc.Spec.HealthCheckNodePort = 345
}) })

View File

@ -19,8 +19,8 @@ package proxy
import ( import (
"fmt" "fmt"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
api "k8s.io/kubernetes/pkg/apis/core"
) )
// ProxyProvider is the interface provided by proxier implementations. // ProxyProvider is the interface provided by proxier implementations.
@ -51,7 +51,7 @@ type ServicePort interface {
// ClusterIPString returns service cluster IP in string format. // ClusterIPString returns service cluster IP in string format.
ClusterIPString() string ClusterIPString() string
// GetProtocol returns service protocol. // GetProtocol returns service protocol.
GetProtocol() api.Protocol GetProtocol() v1.Protocol
// GetHealthCheckNodePort returns service health check node port if present. If return 0, it means not present. // GetHealthCheckNodePort returns service health check node port if present. If return 0, it means not present.
GetHealthCheckNodePort() int GetHealthCheckNodePort() int
} }

View File

@ -17,7 +17,7 @@ limitations under the License.
package userspace package userspace
import ( import (
api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"net" "net"
) )
@ -27,7 +27,7 @@ type LoadBalancer interface {
// NextEndpoint returns the endpoint to handle a request for the given // NextEndpoint returns the endpoint to handle a request for the given
// service-port and source address. // service-port and source address.
NextEndpoint(service proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error) NextEndpoint(service proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error)
NewService(service proxy.ServicePortName, sessionAffinityType api.ServiceAffinity, stickyMaxAgeSeconds int) error NewService(service proxy.ServicePortName, sessionAffinityType v1.ServiceAffinity, stickyMaxAgeSeconds int) error
DeleteService(service proxy.ServicePortName) DeleteService(service proxy.ServicePortName)
CleanupStaleStickySessions(service proxy.ServicePortName) CleanupStaleStickySessions(service proxy.ServicePortName)
ServiceHasEndpoints(service proxy.ServicePortName) bool ServiceHasEndpoints(service proxy.ServicePortName) bool

View File

@ -28,14 +28,12 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
utilnet "k8s.io/apimachinery/pkg/util/net"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/core/helper"
"k8s.io/kubernetes/pkg/proxy"
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/proxy"
utilproxy "k8s.io/kubernetes/pkg/proxy/util" utilproxy "k8s.io/kubernetes/pkg/proxy/util"
"k8s.io/kubernetes/pkg/util/conntrack" "k8s.io/kubernetes/pkg/util/conntrack"
"k8s.io/kubernetes/pkg/util/iptables" "k8s.io/kubernetes/pkg/util/iptables"
@ -57,12 +55,12 @@ type ServiceInfo struct {
isAliveAtomic int32 // Only access this with atomic ops isAliveAtomic int32 // Only access this with atomic ops
portal portal portal portal
protocol api.Protocol protocol v1.Protocol
proxyPort int proxyPort int
socket ProxySocket socket ProxySocket
nodePort int nodePort int
loadBalancerStatus api.LoadBalancerStatus loadBalancerStatus v1.LoadBalancerStatus
sessionAffinityType api.ServiceAffinity sessionAffinityType v1.ServiceAffinity
stickyMaxAgeSeconds int stickyMaxAgeSeconds int
// Deprecated, but required for back-compat (including e2e) // Deprecated, but required for back-compat (including e2e)
externalIPs []string externalIPs []string
@ -91,7 +89,7 @@ func logTimeout(err error) bool {
} }
// ProxySocketFunc is a function which constructs a ProxySocket from a protocol, ip, and port // ProxySocketFunc is a function which constructs a ProxySocket from a protocol, ip, and port
type ProxySocketFunc func(protocol api.Protocol, ip net.IP, port int) (ProxySocket, error) type ProxySocketFunc func(protocol v1.Protocol, ip net.IP, port int) (ProxySocket, error)
// Proxier is a simple proxy for TCP connections between a localhost:lport // Proxier is a simple proxy for TCP connections between a localhost:lport
// and services that provide the actual implementations. // and services that provide the actual implementations.
@ -121,7 +119,7 @@ var _ proxy.ProxyProvider = &Proxier{}
type portMapKey struct { type portMapKey struct {
ip string ip string
port int port int
protocol api.Protocol protocol v1.Protocol
} }
func (k *portMapKey) String() string { func (k *portMapKey) String() string {
@ -364,7 +362,7 @@ func (proxier *Proxier) setServiceInfo(service proxy.ServicePortName, info *Serv
// addServiceOnPort starts listening for a new service, returning the ServiceInfo. // addServiceOnPort starts listening for a new service, returning the ServiceInfo.
// Pass proxyPort=0 to allocate a random port. The timeout only applies to UDP // Pass proxyPort=0 to allocate a random port. The timeout only applies to UDP
// connections, for now. // connections, for now.
func (proxier *Proxier) addServiceOnPort(service proxy.ServicePortName, protocol api.Protocol, proxyPort int, timeout time.Duration) (*ServiceInfo, error) { func (proxier *Proxier) addServiceOnPort(service proxy.ServicePortName, protocol v1.Protocol, proxyPort int, timeout time.Duration) (*ServiceInfo, error) {
sock, err := proxier.makeProxySocket(protocol, proxier.listenIP, proxyPort) sock, err := proxier.makeProxySocket(protocol, proxier.listenIP, proxyPort)
if err != nil { if err != nil {
return nil, err return nil, err
@ -386,7 +384,7 @@ func (proxier *Proxier) addServiceOnPort(service proxy.ServicePortName, protocol
proxyPort: portNum, proxyPort: portNum,
protocol: protocol, protocol: protocol,
socket: sock, socket: sock,
sessionAffinityType: api.ServiceAffinityNone, // default sessionAffinityType: v1.ServiceAffinityNone, // default
} }
proxier.setServiceInfo(service, si) proxier.setServiceInfo(service, si)
@ -401,7 +399,7 @@ func (proxier *Proxier) addServiceOnPort(service proxy.ServicePortName, protocol
return si, nil return si, nil
} }
func (proxier *Proxier) mergeService(service *api.Service) sets.String { func (proxier *Proxier) mergeService(service *v1.Service) sets.String {
if service == nil { if service == nil {
return nil return nil
} }
@ -451,7 +449,7 @@ func (proxier *Proxier) mergeService(service *api.Service) sets.String {
info.nodePort = int(servicePort.NodePort) info.nodePort = int(servicePort.NodePort)
info.sessionAffinityType = service.Spec.SessionAffinity info.sessionAffinityType = service.Spec.SessionAffinity
// Kube-apiserver side guarantees SessionAffinityConfig won't be nil when session affinity type is ClientIP // Kube-apiserver side guarantees SessionAffinityConfig won't be nil when session affinity type is ClientIP
if service.Spec.SessionAffinity == api.ServiceAffinityClientIP { if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
info.stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds) info.stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds)
} }
@ -466,7 +464,7 @@ func (proxier *Proxier) mergeService(service *api.Service) sets.String {
return existingPorts return existingPorts
} }
func (proxier *Proxier) unmergeService(service *api.Service, existingPorts sets.String) { func (proxier *Proxier) unmergeService(service *v1.Service, existingPorts sets.String) {
if service == nil { if service == nil {
return return
} }
@ -493,7 +491,7 @@ func (proxier *Proxier) unmergeService(service *api.Service, existingPorts sets.
continue continue
} }
if proxier.serviceMap[serviceName].protocol == api.ProtocolUDP { if proxier.serviceMap[serviceName].protocol == v1.ProtocolUDP {
staleUDPServices.Insert(proxier.serviceMap[serviceName].portal.ip.String()) staleUDPServices.Insert(proxier.serviceMap[serviceName].portal.ip.String())
} }
@ -512,23 +510,23 @@ func (proxier *Proxier) unmergeService(service *api.Service, existingPorts sets.
} }
} }
func (proxier *Proxier) OnServiceAdd(service *api.Service) { func (proxier *Proxier) OnServiceAdd(service *v1.Service) {
_ = proxier.mergeService(service) _ = proxier.mergeService(service)
} }
func (proxier *Proxier) OnServiceUpdate(oldService, service *api.Service) { func (proxier *Proxier) OnServiceUpdate(oldService, service *v1.Service) {
existingPorts := proxier.mergeService(service) existingPorts := proxier.mergeService(service)
proxier.unmergeService(oldService, existingPorts) proxier.unmergeService(oldService, existingPorts)
} }
func (proxier *Proxier) OnServiceDelete(service *api.Service) { func (proxier *Proxier) OnServiceDelete(service *v1.Service) {
proxier.unmergeService(service, sets.NewString()) proxier.unmergeService(service, sets.NewString())
} }
func (proxier *Proxier) OnServiceSynced() { func (proxier *Proxier) OnServiceSynced() {
} }
func sameConfig(info *ServiceInfo, service *api.Service, port *api.ServicePort) bool { func sameConfig(info *ServiceInfo, service *v1.Service, port *v1.ServicePort) bool {
if info.protocol != port.Protocol || info.portal.port != int(port.Port) || info.nodePort != int(port.NodePort) { if info.protocol != port.Protocol || info.portal.port != int(port.Port) || info.nodePort != int(port.NodePort) {
return false return false
} }
@ -587,7 +585,7 @@ func (proxier *Proxier) openPortal(service proxy.ServicePortName, info *ServiceI
return nil return nil
} }
func (proxier *Proxier) openOnePortal(portal portal, protocol api.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) error { func (proxier *Proxier) openOnePortal(portal portal, protocol v1.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) error {
if local, err := utilproxy.IsLocalIP(portal.ip.String()); err != nil { if local, err := utilproxy.IsLocalIP(portal.ip.String()); err != nil {
return fmt.Errorf("can't determine if IP %s is local, assuming not: %v", portal.ip, err) return fmt.Errorf("can't determine if IP %s is local, assuming not: %v", portal.ip, err)
} else if local { } else if local {
@ -646,7 +644,7 @@ func (proxier *Proxier) openOnePortal(portal portal, protocol api.Protocol, prox
// Marks a port as being owned by a particular service, or returns error if already claimed. // Marks a port as being owned by a particular service, or returns error if already claimed.
// Idempotent: reclaiming with the same owner is not an error // Idempotent: reclaiming with the same owner is not an error
func (proxier *Proxier) claimNodePort(ip net.IP, port int, protocol api.Protocol, owner proxy.ServicePortName) error { func (proxier *Proxier) claimNodePort(ip net.IP, port int, protocol v1.Protocol, owner proxy.ServicePortName) error {
proxier.portMapMutex.Lock() proxier.portMapMutex.Lock()
defer proxier.portMapMutex.Unlock() defer proxier.portMapMutex.Unlock()
@ -679,7 +677,7 @@ func (proxier *Proxier) claimNodePort(ip net.IP, port int, protocol api.Protocol
// Release a claim on a port. Returns an error if the owner does not match the claim. // Release a claim on a port. Returns an error if the owner does not match the claim.
// Tolerates release on an unclaimed port, to simplify . // Tolerates release on an unclaimed port, to simplify .
func (proxier *Proxier) releaseNodePort(ip net.IP, port int, protocol api.Protocol, owner proxy.ServicePortName) error { func (proxier *Proxier) releaseNodePort(ip net.IP, port int, protocol v1.Protocol, owner proxy.ServicePortName) error {
proxier.portMapMutex.Lock() proxier.portMapMutex.Lock()
defer proxier.portMapMutex.Unlock() defer proxier.portMapMutex.Unlock()
@ -698,7 +696,7 @@ func (proxier *Proxier) releaseNodePort(ip net.IP, port int, protocol api.Protoc
return nil return nil
} }
func (proxier *Proxier) openNodePort(nodePort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) error { func (proxier *Proxier) openNodePort(nodePort int, protocol v1.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) error {
// TODO: Do we want to allow containers to access public services? Probably yes. // TODO: Do we want to allow containers to access public services? Probably yes.
// TODO: We could refactor this to be the same code as portal, but with IP == nil // TODO: We could refactor this to be the same code as portal, but with IP == nil
@ -764,7 +762,7 @@ func (proxier *Proxier) closePortal(service proxy.ServicePortName, info *Service
return utilerrors.NewAggregate(el) return utilerrors.NewAggregate(el)
} }
func (proxier *Proxier) closeOnePortal(portal portal, protocol api.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) []error { func (proxier *Proxier) closeOnePortal(portal portal, protocol v1.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) []error {
el := []error{} el := []error{}
if local, err := utilproxy.IsLocalIP(portal.ip.String()); err != nil { if local, err := utilproxy.IsLocalIP(portal.ip.String()); err != nil {
@ -807,7 +805,7 @@ func (proxier *Proxier) closeOnePortal(portal portal, protocol api.Protocol, pro
return el return el
} }
func (proxier *Proxier) closeNodePort(nodePort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) []error { func (proxier *Proxier) closeNodePort(nodePort int, protocol v1.Protocol, proxyIP net.IP, proxyPort int, name proxy.ServicePortName) []error {
el := []error{} el := []error{}
// Handle traffic from containers. // Handle traffic from containers.
@ -949,7 +947,7 @@ var zeroIPv6 = net.ParseIP("::")
var localhostIPv6 = net.ParseIP("::1") var localhostIPv6 = net.ParseIP("::1")
// Build a slice of iptables args that are common to from-container and from-host portal rules. // Build a slice of iptables args that are common to from-container and from-host portal rules.
func iptablesCommonPortalArgs(destIP net.IP, addPhysicalInterfaceMatch bool, addDstLocalMatch bool, destPort int, protocol api.Protocol, service proxy.ServicePortName) []string { func iptablesCommonPortalArgs(destIP net.IP, addPhysicalInterfaceMatch bool, addDstLocalMatch bool, destPort int, protocol v1.Protocol, service proxy.ServicePortName) []string {
// This list needs to include all fields as they are eventually spit out // This list needs to include all fields as they are eventually spit out
// by iptables-save. This is because some systems do not support the // by iptables-save. This is because some systems do not support the
// 'iptables -C' arg, and so fall back on parsing iptables-save output. // 'iptables -C' arg, and so fall back on parsing iptables-save output.
@ -982,7 +980,7 @@ func iptablesCommonPortalArgs(destIP net.IP, addPhysicalInterfaceMatch bool, add
} }
// Build a slice of iptables args for a from-container portal rule. // Build a slice of iptables args for a from-container portal rule.
func (proxier *Proxier) iptablesContainerPortalArgs(destIP net.IP, addPhysicalInterfaceMatch bool, addDstLocalMatch bool, destPort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string { func (proxier *Proxier) iptablesContainerPortalArgs(destIP net.IP, addPhysicalInterfaceMatch bool, addDstLocalMatch bool, destPort int, protocol v1.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string {
args := iptablesCommonPortalArgs(destIP, addPhysicalInterfaceMatch, addDstLocalMatch, destPort, protocol, service) args := iptablesCommonPortalArgs(destIP, addPhysicalInterfaceMatch, addDstLocalMatch, destPort, protocol, service)
// This is tricky. // This is tricky.
@ -1029,7 +1027,7 @@ func (proxier *Proxier) iptablesContainerPortalArgs(destIP net.IP, addPhysicalIn
} }
// Build a slice of iptables args for a from-host portal rule. // Build a slice of iptables args for a from-host portal rule.
func (proxier *Proxier) iptablesHostPortalArgs(destIP net.IP, addDstLocalMatch bool, destPort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string { func (proxier *Proxier) iptablesHostPortalArgs(destIP net.IP, addDstLocalMatch bool, destPort int, protocol v1.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string {
args := iptablesCommonPortalArgs(destIP, false, addDstLocalMatch, destPort, protocol, service) args := iptablesCommonPortalArgs(destIP, false, addDstLocalMatch, destPort, protocol, service)
// This is tricky. // This is tricky.
@ -1064,7 +1062,7 @@ func (proxier *Proxier) iptablesHostPortalArgs(destIP net.IP, addDstLocalMatch b
// Build a slice of iptables args for a from-host public-port rule. // Build a slice of iptables args for a from-host public-port rule.
// See iptablesHostPortalArgs // See iptablesHostPortalArgs
// TODO: Should we just reuse iptablesHostPortalArgs? // TODO: Should we just reuse iptablesHostPortalArgs?
func (proxier *Proxier) iptablesHostNodePortArgs(nodePort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string { func (proxier *Proxier) iptablesHostNodePortArgs(nodePort int, protocol v1.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string {
args := iptablesCommonPortalArgs(nil, false, false, nodePort, protocol, service) args := iptablesCommonPortalArgs(nil, false, false, nodePort, protocol, service)
if proxyIP.Equal(zeroIPv4) || proxyIP.Equal(zeroIPv6) { if proxyIP.Equal(zeroIPv4) || proxyIP.Equal(zeroIPv6) {
@ -1076,7 +1074,7 @@ func (proxier *Proxier) iptablesHostNodePortArgs(nodePort int, protocol api.Prot
} }
// Build a slice of iptables args for an from-non-local public-port rule. // Build a slice of iptables args for an from-non-local public-port rule.
func (proxier *Proxier) iptablesNonLocalNodePortArgs(nodePort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string { func (proxier *Proxier) iptablesNonLocalNodePortArgs(nodePort int, protocol v1.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string {
args := iptablesCommonPortalArgs(nil, false, false, proxyPort, protocol, service) args := iptablesCommonPortalArgs(nil, false, false, proxyPort, protocol, service)
args = append(args, "-m", "state", "--state", "NEW", "-j", "ACCEPT") args = append(args, "-m", "state", "--state", "NEW", "-j", "ACCEPT")
return args return args

View File

@ -29,10 +29,10 @@ import (
"testing" "testing"
"time" "time"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
ipttest "k8s.io/kubernetes/pkg/util/iptables/testing" ipttest "k8s.io/kubernetes/pkg/util/iptables/testing"
"k8s.io/utils/exec" "k8s.io/utils/exec"
@ -228,11 +228,11 @@ func waitForNumProxyClients(t *testing.T, s *ServiceInfo, want int, timeout time
func TestTCPProxy(t *testing.T) { func TestTCPProxy(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -255,11 +255,11 @@ func TestTCPProxy(t *testing.T) {
func TestUDPProxy(t *testing.T) { func TestUDPProxy(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -282,11 +282,11 @@ func TestUDPProxy(t *testing.T) {
func TestUDPProxyTimeout(t *testing.T) { func TestUDPProxyTimeout(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -314,18 +314,18 @@ func TestMultiPortProxy(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
serviceP := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-p"}, Port: "p"} serviceP := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-p"}, Port: "p"}
serviceQ := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-q"}, Port: "q"} serviceQ := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-q"}, Port: "q"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Protocol: "TCP", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Protocol: "TCP", Port: tcpServerPort}},
}}, }},
}) })
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceQ.Name, Namespace: serviceQ.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceQ.Name, Namespace: serviceQ.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "q", Protocol: "UDP", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "q", Protocol: "UDP", Port: udpServerPort}},
}}, }},
}) })
@ -366,9 +366,9 @@ func TestMultiPortOnServiceAdd(t *testing.T) {
} }
waitForNumProxyLoops(t, p, 0) waitForNumProxyLoops(t, p, 0)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: 80, Port: 80,
Protocol: "TCP", Protocol: "TCP",
@ -413,11 +413,11 @@ func stopProxyByName(proxier *Proxier, service proxy.ServicePortName) error {
func TestTCPProxyStop(t *testing.T) { func TestTCPProxyStop(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -457,11 +457,11 @@ func TestTCPProxyStop(t *testing.T) {
func TestUDPProxyStop(t *testing.T) { func TestUDPProxyStop(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -495,11 +495,11 @@ func TestUDPProxyStop(t *testing.T) {
func TestTCPProxyUpdateDelete(t *testing.T) { func TestTCPProxyUpdateDelete(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -522,9 +522,9 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "TCP", Protocol: "TCP",
@ -539,11 +539,11 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
func TestUDPProxyUpdateDelete(t *testing.T) { func TestUDPProxyUpdateDelete(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -566,9 +566,9 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "UDP", Protocol: "UDP",
@ -583,11 +583,11 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
func TestTCPProxyUpdateDeleteUpdate(t *testing.T) { func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
endpoint := &api.Endpoints{ endpoint := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
} }
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
@ -611,9 +611,9 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "TCP", Protocol: "TCP",
@ -626,9 +626,9 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
// need to add endpoint here because it got clean up during service delete // need to add endpoint here because it got clean up during service delete
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "TCP", Protocol: "TCP",
@ -645,11 +645,11 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
func TestUDPProxyUpdateDeleteUpdate(t *testing.T) { func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
endpoint := &api.Endpoints{ endpoint := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
} }
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
@ -673,9 +673,9 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "UDP", Protocol: "UDP",
@ -688,9 +688,9 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
// need to add endpoint here because it got clean up during service delete // need to add endpoint here because it got clean up during service delete
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "UDP", Protocol: "UDP",
@ -707,11 +707,11 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
func TestTCPProxyUpdatePort(t *testing.T) { func TestTCPProxyUpdatePort(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -730,9 +730,9 @@ func TestTCPProxyUpdatePort(t *testing.T) {
testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort) testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort)
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: 99, Port: 99,
Protocol: "TCP", Protocol: "TCP",
@ -755,11 +755,11 @@ func TestTCPProxyUpdatePort(t *testing.T) {
func TestUDPProxyUpdatePort(t *testing.T) { func TestUDPProxyUpdatePort(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -777,9 +777,9 @@ func TestUDPProxyUpdatePort(t *testing.T) {
} }
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: 99, Port: 99,
Protocol: "UDP", Protocol: "UDP",
@ -800,11 +800,11 @@ func TestUDPProxyUpdatePort(t *testing.T) {
func TestProxyUpdatePublicIPs(t *testing.T) { func TestProxyUpdatePublicIPs(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -823,10 +823,10 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort) testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort)
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
Ports: []api.ServicePort{{ Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.portal.port), Port: int32(svcInfo.portal.port),
Protocol: "TCP", Protocol: "TCP",
@ -852,11 +852,11 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
func TestProxyUpdatePortal(t *testing.T) { func TestProxyUpdatePortal(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
endpoint := &api.Endpoints{ endpoint := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
} }
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
@ -876,18 +876,18 @@ func TestProxyUpdatePortal(t *testing.T) {
testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort) testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort)
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
svcv0 := &api.Service{ svcv0 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "TCP", Protocol: "TCP",
}}}, }}},
} }
svcv1 := &api.Service{ svcv1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "TCP", Protocol: "TCP",
@ -899,9 +899,9 @@ func TestProxyUpdatePortal(t *testing.T) {
t.Fatalf("service with empty ClusterIP should not be included in the proxy") t.Fatalf("service with empty ClusterIP should not be included in the proxy")
} }
svcv2 := &api.Service{ svcv2 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "None", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "None", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "TCP", Protocol: "TCP",
@ -913,9 +913,9 @@ func TestProxyUpdatePortal(t *testing.T) {
t.Fatalf("service with 'None' as ClusterIP should not be included in the proxy") t.Fatalf("service with 'None' as ClusterIP should not be included in the proxy")
} }
svcv3 := &api.Service{ svcv3 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "1.2.3.4", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.proxyPort), Port: int32(svcInfo.proxyPort),
Protocol: "TCP", Protocol: "TCP",

View File

@ -26,8 +26,8 @@ import (
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
) )
@ -45,7 +45,7 @@ type ProxySocket interface {
ListenPort() int ListenPort() int
} }
func newProxySocket(protocol api.Protocol, ip net.IP, port int) (ProxySocket, error) { func newProxySocket(protocol v1.Protocol, ip net.IP, port int) (ProxySocket, error) {
host := "" host := ""
if ip != nil { if ip != nil {
host = ip.String() host = ip.String()

View File

@ -26,8 +26,8 @@ import (
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/util/slice" "k8s.io/kubernetes/pkg/util/slice"
) )
@ -46,7 +46,7 @@ type affinityState struct {
} }
type affinityPolicy struct { type affinityPolicy struct {
affinityType api.ServiceAffinity affinityType v1.ServiceAffinity
affinityMap map[string]*affinityState // map client IP -> affinity info affinityMap map[string]*affinityState // map client IP -> affinity info
ttlSeconds int ttlSeconds int
} }
@ -66,7 +66,7 @@ type balancerState struct {
affinity affinityPolicy affinity affinityPolicy
} }
func newAffinityPolicy(affinityType api.ServiceAffinity, ttlSeconds int) *affinityPolicy { func newAffinityPolicy(affinityType v1.ServiceAffinity, ttlSeconds int) *affinityPolicy {
return &affinityPolicy{ return &affinityPolicy{
affinityType: affinityType, affinityType: affinityType,
affinityMap: make(map[string]*affinityState), affinityMap: make(map[string]*affinityState),
@ -81,7 +81,7 @@ func NewLoadBalancerRR() *LoadBalancerRR {
} }
} }
func (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType api.ServiceAffinity, ttlSeconds int) error { func (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType v1.ServiceAffinity, ttlSeconds int) error {
glog.V(4).Infof("LoadBalancerRR NewService %q", svcPort) glog.V(4).Infof("LoadBalancerRR NewService %q", svcPort)
lb.lock.Lock() lb.lock.Lock()
defer lb.lock.Unlock() defer lb.lock.Unlock()
@ -90,9 +90,9 @@ func (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType
} }
// This assumes that lb.lock is already held. // This assumes that lb.lock is already held.
func (lb *LoadBalancerRR) newServiceInternal(svcPort proxy.ServicePortName, affinityType api.ServiceAffinity, ttlSeconds int) *balancerState { func (lb *LoadBalancerRR) newServiceInternal(svcPort proxy.ServicePortName, affinityType v1.ServiceAffinity, ttlSeconds int) *balancerState {
if ttlSeconds == 0 { if ttlSeconds == 0 {
ttlSeconds = int(api.DefaultClientIPServiceAffinitySeconds) //default to 3 hours if not specified. Should 0 be unlimited instead???? ttlSeconds = int(v1.DefaultClientIPServiceAffinitySeconds) //default to 3 hours if not specified. Should 0 be unlimited instead????
} }
if _, exists := lb.services[svcPort]; !exists { if _, exists := lb.services[svcPort]; !exists {
@ -114,7 +114,7 @@ func (lb *LoadBalancerRR) DeleteService(svcPort proxy.ServicePortName) {
// return true if this service is using some form of session affinity. // return true if this service is using some form of session affinity.
func isSessionAffinity(affinity *affinityPolicy) bool { func isSessionAffinity(affinity *affinityPolicy) bool {
// Should never be empty string, but checking for it to be safe. // Should never be empty string, but checking for it to be safe.
if affinity.affinityType == "" || affinity.affinityType == api.ServiceAffinityNone { if affinity.affinityType == "" || affinity.affinityType == v1.ServiceAffinityNone {
return false return false
} }
return true return true
@ -245,7 +245,7 @@ func (lb *LoadBalancerRR) updateAffinityMap(svcPort proxy.ServicePortName, newEn
// buildPortsToEndpointsMap builds a map of portname -> all ip:ports for that // buildPortsToEndpointsMap builds a map of portname -> all ip:ports for that
// portname. Expode Endpoints.Subsets[*] into this structure. // portname. Expode Endpoints.Subsets[*] into this structure.
func buildPortsToEndpointsMap(endpoints *api.Endpoints) map[string][]hostPortPair { func buildPortsToEndpointsMap(endpoints *v1.Endpoints) map[string][]hostPortPair {
portsToEndpoints := map[string][]hostPortPair{} portsToEndpoints := map[string][]hostPortPair{}
for i := range endpoints.Subsets { for i := range endpoints.Subsets {
ss := &endpoints.Subsets[i] ss := &endpoints.Subsets[i]
@ -261,7 +261,7 @@ func buildPortsToEndpointsMap(endpoints *api.Endpoints) map[string][]hostPortPai
return portsToEndpoints return portsToEndpoints
} }
func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *api.Endpoints) { func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *v1.Endpoints) {
portsToEndpoints := buildPortsToEndpointsMap(endpoints) portsToEndpoints := buildPortsToEndpointsMap(endpoints)
lb.lock.Lock() lb.lock.Lock()
@ -279,7 +279,7 @@ func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *api.Endpoints) {
// To be safe we will call it here. A new service will only be created // To be safe we will call it here. A new service will only be created
// if one does not already exist. The affinity will be updated // if one does not already exist. The affinity will be updated
// later, once NewService is called. // later, once NewService is called.
state = lb.newServiceInternal(svcPort, api.ServiceAffinity(""), 0) state = lb.newServiceInternal(svcPort, v1.ServiceAffinity(""), 0)
state.endpoints = slice.ShuffleStrings(newEndpoints) state.endpoints = slice.ShuffleStrings(newEndpoints)
// Reset the round-robin index. // Reset the round-robin index.
@ -288,7 +288,7 @@ func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *api.Endpoints) {
} }
} }
func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) { func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
portsToEndpoints := buildPortsToEndpointsMap(endpoints) portsToEndpoints := buildPortsToEndpointsMap(endpoints)
oldPortsToEndpoints := buildPortsToEndpointsMap(oldEndpoints) oldPortsToEndpoints := buildPortsToEndpointsMap(oldEndpoints)
registeredEndpoints := make(map[proxy.ServicePortName]bool) registeredEndpoints := make(map[proxy.ServicePortName]bool)
@ -313,7 +313,7 @@ func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoin
// To be safe we will call it here. A new service will only be created // To be safe we will call it here. A new service will only be created
// if one does not already exist. The affinity will be updated // if one does not already exist. The affinity will be updated
// later, once NewService is called. // later, once NewService is called.
state = lb.newServiceInternal(svcPort, api.ServiceAffinity(""), 0) state = lb.newServiceInternal(svcPort, v1.ServiceAffinity(""), 0)
state.endpoints = slice.ShuffleStrings(newEndpoints) state.endpoints = slice.ShuffleStrings(newEndpoints)
// Reset the round-robin index. // Reset the round-robin index.
@ -343,7 +343,7 @@ func (lb *LoadBalancerRR) resetService(svcPort proxy.ServicePortName) {
} }
} }
func (lb *LoadBalancerRR) OnEndpointsDelete(endpoints *api.Endpoints) { func (lb *LoadBalancerRR) OnEndpointsDelete(endpoints *v1.Endpoints) {
portsToEndpoints := buildPortsToEndpointsMap(endpoints) portsToEndpoints := buildPortsToEndpointsMap(endpoints)
lb.lock.Lock() lb.lock.Lock()

View File

@ -20,9 +20,9 @@ import (
"net" "net"
"testing" "testing"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
) )
@ -104,11 +104,11 @@ func TestLoadBalanceWorksWithSingleEndpoint(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}},
Ports: []api.EndpointPort{{Name: "p", Port: 40}}, Ports: []v1.EndpointPort{{Name: "p", Port: 40}},
}}, }},
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
@ -141,11 +141,11 @@ func TestLoadBalanceWorksWithMultipleEndpoints(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Name: "p", Port: 1}, {Name: "p", Port: 2}, {Name: "p", Port: 3}}, Ports: []v1.EndpointPort{{Name: "p", Port: 1}, {Name: "p", Port: 2}, {Name: "p", Port: 3}},
}}, }},
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
@ -168,16 +168,16 @@ func TestLoadBalanceWorksWithMultipleEndpointsMultiplePorts(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}},
Ports: []api.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 2}}, Ports: []v1.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 2}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint3"}},
Ports: []api.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 4}}, Ports: []v1.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 4}},
}, },
}, },
} }
@ -210,20 +210,20 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpointsv1 := &api.Endpoints{ endpointsv1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}},
Ports: []api.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 10}}, Ports: []v1.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 10}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint2"}},
Ports: []api.EndpointPort{{Name: "p", Port: 2}, {Name: "q", Port: 20}}, Ports: []v1.EndpointPort{{Name: "p", Port: 2}, {Name: "q", Port: 20}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint3"}},
Ports: []api.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 30}}, Ports: []v1.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 30}},
}, },
}, },
} }
@ -249,16 +249,16 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
// Then update the configuration with one fewer endpoints, make sure // Then update the configuration with one fewer endpoints, make sure
// we start in the beginning again // we start in the beginning again
endpointsv2 := &api.Endpoints{ endpointsv2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint4"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint4"}},
Ports: []api.EndpointPort{{Name: "p", Port: 4}, {Name: "q", Port: 40}}, Ports: []v1.EndpointPort{{Name: "p", Port: 4}, {Name: "q", Port: 40}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint5"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint5"}},
Ports: []api.EndpointPort{{Name: "p", Port: 5}, {Name: "q", Port: 50}}, Ports: []v1.EndpointPort{{Name: "p", Port: 5}, {Name: "q", Port: 50}},
}, },
}, },
} }
@ -283,7 +283,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
expectEndpoint(t, loadBalancer, serviceQ, shuffledEndpoints[1], nil) expectEndpoint(t, loadBalancer, serviceQ, shuffledEndpoints[1], nil)
// Clear endpoints // Clear endpoints
endpointsv3 := &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, Subsets: nil} endpointsv3 := &v1.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, Subsets: nil}
loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3) loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3)
endpoint, err = loadBalancer.NextEndpoint(serviceP, nil, false) endpoint, err = loadBalancer.NextEndpoint(serviceP, nil, false)
@ -300,21 +300,21 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints1 := &api.Endpoints{ endpoints1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: fooServiceP.Name, Namespace: fooServiceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: fooServiceP.Name, Namespace: fooServiceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}, {IP: "endpoint3"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}, {IP: "endpoint3"}},
Ports: []api.EndpointPort{{Name: "p", Port: 123}}, Ports: []v1.EndpointPort{{Name: "p", Port: 123}},
}, },
}, },
} }
endpoints2 := &api.Endpoints{ endpoints2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: barServiceP.Name, Namespace: barServiceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: barServiceP.Name, Namespace: barServiceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint4"}, {IP: "endpoint5"}, {IP: "endpoint6"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint4"}, {IP: "endpoint5"}, {IP: "endpoint6"}},
Ports: []api.EndpointPort{{Name: "p", Port: 456}}, Ports: []v1.EndpointPort{{Name: "p", Port: 456}},
}, },
}, },
} }
@ -357,13 +357,13 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
} }
// Call NewService() before OnEndpointsUpdate() // Call NewService() before OnEndpointsUpdate()
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint1"}}, Ports: []v1.EndpointPort{{Port: 1}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint2"}}, Ports: []v1.EndpointPort{{Port: 2}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Ports: []api.EndpointPort{{Port: 3}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint3"}}, Ports: []v1.EndpointPort{{Port: 3}}},
}, },
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
@ -413,15 +413,15 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) {
} }
// Call OnEndpointsUpdate() before NewService() // Call OnEndpointsUpdate() before NewService()
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint1"}}, Ports: []v1.EndpointPort{{Port: 1}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint2"}}, Ports: []v1.EndpointPort{{Port: 2}}},
}, },
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0} client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}
client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0} client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0}
@ -473,13 +473,13 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpointsv1 := &api.Endpoints{ endpointsv1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}},
}, },
}, },
} }
@ -494,12 +494,12 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
expectEndpoint(t, loadBalancer, service, shuffledEndpoints[2], client3) expectEndpoint(t, loadBalancer, service, shuffledEndpoints[2], client3)
client3Endpoint := shuffledEndpoints[2] client3Endpoint := shuffledEndpoints[2]
endpointsv2 := &api.Endpoints{ endpointsv2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}},
}, },
}, },
} }
@ -516,12 +516,12 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
expectEndpoint(t, loadBalancer, service, client2Endpoint, client2) expectEndpoint(t, loadBalancer, service, client2Endpoint, client2)
expectEndpoint(t, loadBalancer, service, client3Endpoint, client3) expectEndpoint(t, loadBalancer, service, client3Endpoint, client3)
endpointsv3 := &api.Endpoints{ endpointsv3 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 4}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 4}},
}, },
}, },
} }
@ -546,13 +546,13 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpointsv1 := &api.Endpoints{ endpointsv1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}},
}, },
}, },
} }
@ -567,12 +567,12 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2) expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2)
// Then update the configuration with one fewer endpoints, make sure // Then update the configuration with one fewer endpoints, make sure
// we start in the beginning again // we start in the beginning again
endpointsv2 := &api.Endpoints{ endpointsv2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 4}, {Port: 5}}, Ports: []v1.EndpointPort{{Port: 4}, {Port: 5}},
}, },
}, },
} }
@ -586,7 +586,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2) expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2)
// Clear endpoints // Clear endpoints
endpointsv3 := &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, Subsets: nil} endpointsv3 := &v1.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, Subsets: nil}
loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3) loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3)
endpoint, err = loadBalancer.NextEndpoint(service, nil, false) endpoint, err = loadBalancer.NextEndpoint(service, nil, false)
@ -605,24 +605,24 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
loadBalancer.NewService(fooService, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(fooService, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints1 := &api.Endpoints{ endpoints1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: fooService.Name, Namespace: fooService.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: fooService.Name, Namespace: fooService.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}},
}, },
}, },
} }
barService := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "bar"}, Port: ""} barService := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "bar"}, Port: ""}
loadBalancer.NewService(barService, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(barService, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints2 := &api.Endpoints{ endpoints2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: barService.Name, Namespace: barService.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: barService.Name, Namespace: barService.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 4}, {Port: 5}}, Ports: []v1.EndpointPort{{Port: 4}, {Port: 5}},
}, },
}, },
} }
@ -674,13 +674,13 @@ func TestStickyLoadBalanceWorksWithEndpointFails(t *testing.T) {
} }
// Call NewService() before OnEndpointsUpdate() // Call NewService() before OnEndpointsUpdate()
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint1"}}, Ports: []v1.EndpointPort{{Port: 1}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint2"}}, Ports: []v1.EndpointPort{{Port: 2}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Ports: []api.EndpointPort{{Port: 3}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint3"}}, Ports: []v1.EndpointPort{{Port: 3}}},
}, },
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)

View File

@ -24,8 +24,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
api "k8s.io/kubernetes/pkg/apis/core" helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/apis/core/helper"
utilnet "k8s.io/kubernetes/pkg/util/net" utilnet "k8s.io/kubernetes/pkg/util/net"
"github.com/golang/glog" "github.com/golang/glog"
@ -60,14 +59,14 @@ func IsLocalIP(ip string) (bool, error) {
return false, nil return false, nil
} }
func ShouldSkipService(svcName types.NamespacedName, service *api.Service) bool { func ShouldSkipService(svcName types.NamespacedName, service *v1.Service) bool {
// if ClusterIP is "None" or empty, skip proxying // if ClusterIP is "None" or empty, skip proxying
if !helper.IsServiceIPSet(service) { if !helper.IsServiceIPSet(service) {
glog.V(3).Infof("Skipping service %s due to clusterIP = %q", svcName, service.Spec.ClusterIP) glog.V(3).Infof("Skipping service %s due to clusterIP = %q", svcName, service.Spec.ClusterIP)
return true return true
} }
// Even if ClusterIP is set, ServiceTypeExternalName services don't get proxied // Even if ClusterIP is set, ServiceTypeExternalName services don't get proxied
if service.Spec.Type == api.ServiceTypeExternalName { if service.Spec.Type == v1.ServiceTypeExternalName {
glog.V(3).Infof("Skipping service %s due to Type=ExternalName", svcName) glog.V(3).Infof("Skipping service %s due to Type=ExternalName", svcName)
return true return true
} }

View File

@ -20,25 +20,25 @@ import (
"net" "net"
"testing" "testing"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
api "k8s.io/kubernetes/pkg/apis/core"
fake "k8s.io/kubernetes/pkg/proxy/util/testing" fake "k8s.io/kubernetes/pkg/proxy/util/testing"
) )
func TestShouldSkipService(t *testing.T) { func TestShouldSkipService(t *testing.T) {
testCases := []struct { testCases := []struct {
service *api.Service service *v1.Service
svcName types.NamespacedName svcName types.NamespacedName
shouldSkip bool shouldSkip bool
}{ }{
{ {
// Cluster IP is None // Cluster IP is None
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: api.ClusterIPNone, ClusterIP: v1.ClusterIPNone,
}, },
}, },
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"}, svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
@ -46,9 +46,9 @@ func TestShouldSkipService(t *testing.T) {
}, },
{ {
// Cluster IP is empty // Cluster IP is empty
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: "", ClusterIP: "",
}, },
}, },
@ -57,11 +57,11 @@ func TestShouldSkipService(t *testing.T) {
}, },
{ {
// ExternalName type service // ExternalName type service
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: "1.2.3.4", ClusterIP: "1.2.3.4",
Type: api.ServiceTypeExternalName, Type: v1.ServiceTypeExternalName,
}, },
}, },
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"}, svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
@ -69,11 +69,11 @@ func TestShouldSkipService(t *testing.T) {
}, },
{ {
// ClusterIP type service with ClusterIP set // ClusterIP type service with ClusterIP set
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: "1.2.3.4", ClusterIP: "1.2.3.4",
Type: api.ServiceTypeClusterIP, Type: v1.ServiceTypeClusterIP,
}, },
}, },
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"}, svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
@ -81,11 +81,11 @@ func TestShouldSkipService(t *testing.T) {
}, },
{ {
// NodePort type service with ClusterIP set // NodePort type service with ClusterIP set
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: "1.2.3.4", ClusterIP: "1.2.3.4",
Type: api.ServiceTypeNodePort, Type: v1.ServiceTypeNodePort,
}, },
}, },
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"}, svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
@ -93,11 +93,11 @@ func TestShouldSkipService(t *testing.T) {
}, },
{ {
// LoadBalancer type service with ClusterIP set // LoadBalancer type service with ClusterIP set
service: &api.Service{ service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
ClusterIP: "1.2.3.4", ClusterIP: "1.2.3.4",
Type: api.ServiceTypeLoadBalancer, Type: v1.ServiceTypeLoadBalancer,
}, },
}, },
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"}, svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},

View File

@ -32,13 +32,13 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
apiservice "k8s.io/kubernetes/pkg/api/service" apiservice "k8s.io/kubernetes/pkg/api/v1/service"
api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/apis/core/helper"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/proxy/healthcheck" "k8s.io/kubernetes/pkg/proxy/healthcheck"
"k8s.io/kubernetes/pkg/util/async" "k8s.io/kubernetes/pkg/util/async"
@ -86,11 +86,11 @@ type loadBalancerIngressInfo struct {
type serviceInfo struct { type serviceInfo struct {
clusterIP net.IP clusterIP net.IP
port int port int
protocol api.Protocol protocol v1.Protocol
nodePort int nodePort int
targetPort int targetPort int
loadBalancerStatus api.LoadBalancerStatus loadBalancerStatus v1.LoadBalancerStatus
sessionAffinityType api.ServiceAffinity sessionAffinityType v1.ServiceAffinity
stickyMaxAgeSeconds int stickyMaxAgeSeconds int
externalIPs []*externalIPInfo externalIPs []*externalIPInfo
loadBalancerIngressIPs []*loadBalancerIngressInfo loadBalancerIngressIPs []*loadBalancerIngressInfo
@ -156,7 +156,7 @@ func (ep *endpointsInfo) Cleanup() {
} }
// returns a new serviceInfo struct // returns a new serviceInfo struct
func newServiceInfo(svcPortName proxy.ServicePortName, port *api.ServicePort, service *api.Service) *serviceInfo { func newServiceInfo(svcPortName proxy.ServicePortName, port *v1.ServicePort, service *v1.Service) *serviceInfo {
onlyNodeLocalEndpoints := false onlyNodeLocalEndpoints := false
if apiservice.RequestsOnlyLocalTraffic(service) { if apiservice.RequestsOnlyLocalTraffic(service) {
onlyNodeLocalEndpoints = true onlyNodeLocalEndpoints = true
@ -164,7 +164,7 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *api.ServicePort, se
// set default session sticky max age 180min=10800s // set default session sticky max age 180min=10800s
stickyMaxAgeSeconds := 10800 stickyMaxAgeSeconds := 10800
if service.Spec.SessionAffinity == api.ServiceAffinityClientIP { if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
// Kube-apiserver side guarantees SessionAffinityConfig won't be nil when session affinity type is ClientIP // Kube-apiserver side guarantees SessionAffinityConfig won't be nil when session affinity type is ClientIP
stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds) stickyMaxAgeSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds)
} }
@ -243,7 +243,7 @@ func newEndpointsChangeMap(hostname string) endpointsChangeMap {
} }
} }
func (ecm *endpointsChangeMap) update(namespacedName *types.NamespacedName, previous, current *api.Endpoints) bool { func (ecm *endpointsChangeMap) update(namespacedName *types.NamespacedName, previous, current *v1.Endpoints) bool {
ecm.lock.Lock() ecm.lock.Lock()
defer ecm.lock.Unlock() defer ecm.lock.Unlock()
@ -266,7 +266,7 @@ func newServiceChangeMap() serviceChangeMap {
} }
} }
func (scm *serviceChangeMap) update(namespacedName *types.NamespacedName, previous, current *api.Service) bool { func (scm *serviceChangeMap) update(namespacedName *types.NamespacedName, previous, current *v1.Service) bool {
scm.lock.Lock() scm.lock.Lock()
defer scm.lock.Unlock() defer scm.lock.Unlock()
@ -309,7 +309,7 @@ func (sm *proxyServiceMap) unmerge(other proxyServiceMap, existingPorts, staleSe
info, exists := (*sm)[svcPortName] info, exists := (*sm)[svcPortName]
if exists { if exists {
glog.V(1).Infof("Removing service port %q", svcPortName) glog.V(1).Infof("Removing service port %q", svcPortName)
if info.protocol == api.ProtocolUDP { if info.protocol == v1.ProtocolUDP {
staleServices.Insert(info.clusterIP.String()) staleServices.Insert(info.clusterIP.String())
} }
info.cleanupAllPolicies(curEndpoints[svcPortName]) info.cleanupAllPolicies(curEndpoints[svcPortName])
@ -421,11 +421,11 @@ func (lp *localPort) String() string {
return fmt.Sprintf("%q (%s:%d/%s)", lp.desc, lp.ip, lp.port, lp.protocol) return fmt.Sprintf("%q (%s:%d/%s)", lp.desc, lp.ip, lp.port, lp.protocol)
} }
func Enum(p api.Protocol) uint16 { func Enum(p v1.Protocol) uint16 {
if p == api.ProtocolTCP { if p == v1.ProtocolTCP {
return 6 return 6
} }
if p == api.ProtocolUDP { if p == v1.ProtocolUDP {
return 17 return 17
} }
return 0 return 0
@ -697,21 +697,21 @@ func (proxier *Proxier) isInitialized() bool {
return atomic.LoadInt32(&proxier.initialized) > 0 return atomic.LoadInt32(&proxier.initialized) > 0
} }
func (proxier *Proxier) OnServiceAdd(service *api.Service) { func (proxier *Proxier) OnServiceAdd(service *v1.Service) {
namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name} namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name}
if proxier.serviceChanges.update(&namespacedName, nil, service) && proxier.isInitialized() { if proxier.serviceChanges.update(&namespacedName, nil, service) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
func (proxier *Proxier) OnServiceUpdate(oldService, service *api.Service) { func (proxier *Proxier) OnServiceUpdate(oldService, service *v1.Service) {
namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name} namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name}
if proxier.serviceChanges.update(&namespacedName, oldService, service) && proxier.isInitialized() { if proxier.serviceChanges.update(&namespacedName, oldService, service) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
func (proxier *Proxier) OnServiceDelete(service *api.Service) { func (proxier *Proxier) OnServiceDelete(service *v1.Service) {
namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name} namespacedName := types.NamespacedName{Namespace: service.Namespace, Name: service.Name}
if proxier.serviceChanges.update(&namespacedName, service, nil) && proxier.isInitialized() { if proxier.serviceChanges.update(&namespacedName, service, nil) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
@ -728,14 +728,14 @@ func (proxier *Proxier) OnServiceSynced() {
proxier.syncProxyRules() proxier.syncProxyRules()
} }
func shouldSkipService(svcName types.NamespacedName, service *api.Service) bool { func shouldSkipService(svcName types.NamespacedName, service *v1.Service) bool {
// if ClusterIP is "None" or empty, skip proxying // if ClusterIP is "None" or empty, skip proxying
if !helper.IsServiceIPSet(service) { if !helper.IsServiceIPSet(service) {
glog.V(3).Infof("Skipping service %s due to clusterIP = %q", svcName, service.Spec.ClusterIP) glog.V(3).Infof("Skipping service %s due to clusterIP = %q", svcName, service.Spec.ClusterIP)
return true return true
} }
// Even if ClusterIP is set, ServiceTypeExternalName services don't get proxied // Even if ClusterIP is set, ServiceTypeExternalName services don't get proxied
if service.Spec.Type == api.ServiceTypeExternalName { if service.Spec.Type == v1.ServiceTypeExternalName {
glog.V(3).Infof("Skipping service %s due to Type=ExternalName", svcName) glog.V(3).Infof("Skipping service %s due to Type=ExternalName", svcName)
return true return true
} }
@ -772,21 +772,21 @@ func (proxier *Proxier) updateServiceMap() (result updateServiceMapResult) {
return result return result
} }
func (proxier *Proxier) OnEndpointsAdd(endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name} namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}
if proxier.endpointsChanges.update(&namespacedName, nil, endpoints) && proxier.isInitialized() { if proxier.endpointsChanges.update(&namespacedName, nil, endpoints) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name} namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}
if proxier.endpointsChanges.update(&namespacedName, oldEndpoints, endpoints) && proxier.isInitialized() { if proxier.endpointsChanges.update(&namespacedName, oldEndpoints, endpoints) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
} }
} }
func (proxier *Proxier) OnEndpointsDelete(endpoints *api.Endpoints) { func (proxier *Proxier) OnEndpointsDelete(endpoints *v1.Endpoints) {
namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name} namespacedName := types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}
if proxier.endpointsChanges.update(&namespacedName, endpoints, nil) && proxier.isInitialized() { if proxier.endpointsChanges.update(&namespacedName, endpoints, nil) && proxier.isInitialized() {
proxier.syncRunner.Run() proxier.syncRunner.Run()
@ -852,7 +852,7 @@ func getLocalIPs(endpointsMap proxyEndpointsMap) map[types.NamespacedName]sets.S
// This function is used for incremental updated of endpointsMap. // This function is used for incremental updated of endpointsMap.
// //
// NOTE: endpoints object should NOT be modified. // NOTE: endpoints object should NOT be modified.
func endpointsToEndpointsMap(endpoints *api.Endpoints, hostname string) proxyEndpointsMap { func endpointsToEndpointsMap(endpoints *v1.Endpoints, hostname string) proxyEndpointsMap {
if endpoints == nil { if endpoints == nil {
return nil return nil
} }
@ -897,7 +897,7 @@ func endpointsToEndpointsMap(endpoints *api.Endpoints, hostname string) proxyEnd
// Translates single Service object to proxyServiceMap. // Translates single Service object to proxyServiceMap.
// //
// NOTE: service object should NOT be modified. // NOTE: service object should NOT be modified.
func serviceToServiceMap(service *api.Service) proxyServiceMap { func serviceToServiceMap(service *v1.Service) proxyServiceMap {
if service == nil { if service == nil {
return nil return nil
} }
@ -941,7 +941,7 @@ func (proxier *Proxier) syncProxyRules() {
staleServices := serviceUpdateResult.staleServices staleServices := serviceUpdateResult.staleServices
// merge stale services gathered from updateEndpointsMap // merge stale services gathered from updateEndpointsMap
for svcPortName := range endpointUpdateResult.staleServiceNames { for svcPortName := range endpointUpdateResult.staleServiceNames {
if svcInfo, ok := proxier.serviceMap[svcPortName]; ok && svcInfo != nil && svcInfo.protocol == api.ProtocolUDP { if svcInfo, ok := proxier.serviceMap[svcPortName]; ok && svcInfo != nil && svcInfo.protocol == v1.ProtocolUDP {
glog.V(2).Infof("Stale udp service %v -> %s", svcPortName, svcInfo.clusterIP.String()) glog.V(2).Infof("Stale udp service %v -> %s", svcPortName, svcInfo.clusterIP.String())
staleServices.Insert(svcInfo.clusterIP.String()) staleServices.Insert(svcInfo.clusterIP.String())
} }

View File

@ -17,7 +17,7 @@ limitations under the License.
package winuserspace package winuserspace
import ( import (
api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"net" "net"
) )
@ -27,7 +27,7 @@ type LoadBalancer interface {
// NextEndpoint returns the endpoint to handle a request for the given // NextEndpoint returns the endpoint to handle a request for the given
// service-port and source address. // service-port and source address.
NextEndpoint(service proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error) NextEndpoint(service proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error)
NewService(service proxy.ServicePortName, sessionAffinityType api.ServiceAffinity, stickyMaxAgeMinutes int) error NewService(service proxy.ServicePortName, sessionAffinityType v1.ServiceAffinity, stickyMaxAgeMinutes int) error
DeleteService(service proxy.ServicePortName) DeleteService(service proxy.ServicePortName)
CleanupStaleStickySessions(service proxy.ServicePortName) CleanupStaleStickySessions(service proxy.ServicePortName)
} }

View File

@ -27,11 +27,11 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
utilnet "k8s.io/apimachinery/pkg/util/net" utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/apis/core/helper"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/util/netsh" "k8s.io/kubernetes/pkg/util/netsh"
) )
@ -47,12 +47,12 @@ type portal struct {
type serviceInfo struct { type serviceInfo struct {
isAliveAtomic int32 // Only access this with atomic ops isAliveAtomic int32 // Only access this with atomic ops
portal portal portal portal
protocol api.Protocol protocol v1.Protocol
socket proxySocket socket proxySocket
timeout time.Duration timeout time.Duration
activeClients *clientCache activeClients *clientCache
dnsClients *dnsClientCache dnsClients *dnsClientCache
sessionAffinityType api.ServiceAffinity sessionAffinityType v1.ServiceAffinity
} }
func (info *serviceInfo) setAlive(b bool) { func (info *serviceInfo) setAlive(b bool) {
@ -100,7 +100,7 @@ var _ proxy.ProxyProvider = &Proxier{}
type portMapKey struct { type portMapKey struct {
ip string ip string
port int port int
protocol api.Protocol protocol v1.Protocol
} }
func (k *portMapKey) String() string { func (k *portMapKey) String() string {
@ -223,7 +223,7 @@ func (proxier *Proxier) setServiceInfo(service ServicePortPortalName, info *serv
// addServicePortPortal starts listening for a new service, returning the serviceInfo. // addServicePortPortal starts listening for a new service, returning the serviceInfo.
// The timeout only applies to UDP connections, for now. // The timeout only applies to UDP connections, for now.
func (proxier *Proxier) addServicePortPortal(servicePortPortalName ServicePortPortalName, protocol api.Protocol, listenIP string, port int, timeout time.Duration) (*serviceInfo, error) { func (proxier *Proxier) addServicePortPortal(servicePortPortalName ServicePortPortalName, protocol v1.Protocol, listenIP string, port int, timeout time.Duration) (*serviceInfo, error) {
var serviceIP net.IP var serviceIP net.IP
if listenIP != allAvailableInterfaces { if listenIP != allAvailableInterfaces {
if serviceIP = net.ParseIP(listenIP); serviceIP == nil { if serviceIP = net.ParseIP(listenIP); serviceIP == nil {
@ -255,7 +255,7 @@ func (proxier *Proxier) addServicePortPortal(servicePortPortalName ServicePortPo
timeout: timeout, timeout: timeout,
activeClients: newClientCache(), activeClients: newClientCache(),
dnsClients: newDNSClientCache(), dnsClients: newDNSClientCache(),
sessionAffinityType: api.ServiceAffinityNone, // default sessionAffinityType: v1.ServiceAffinityNone, // default
} }
proxier.setServiceInfo(servicePortPortalName, si) proxier.setServiceInfo(servicePortPortalName, si)
@ -288,7 +288,7 @@ func (proxier *Proxier) closeServicePortPortal(servicePortPortalName ServicePort
} }
// getListenIPPortMap returns a slice of all listen IPs for a service. // getListenIPPortMap returns a slice of all listen IPs for a service.
func getListenIPPortMap(service *api.Service, listenPort int, nodePort int) map[string]int { func getListenIPPortMap(service *v1.Service, listenPort int, nodePort int) map[string]int {
listenIPPortMap := make(map[string]int) listenIPPortMap := make(map[string]int)
listenIPPortMap[service.Spec.ClusterIP] = listenPort listenIPPortMap[service.Spec.ClusterIP] = listenPort
@ -307,7 +307,7 @@ func getListenIPPortMap(service *api.Service, listenPort int, nodePort int) map[
return listenIPPortMap return listenIPPortMap
} }
func (proxier *Proxier) mergeService(service *api.Service) map[ServicePortPortalName]bool { func (proxier *Proxier) mergeService(service *v1.Service) map[ServicePortPortalName]bool {
if service == nil { if service == nil {
return nil return nil
} }
@ -361,7 +361,7 @@ func (proxier *Proxier) mergeService(service *api.Service) map[ServicePortPortal
Port: servicePort.Name, Port: servicePort.Name,
} }
timeoutSeconds := 0 timeoutSeconds := 0
if service.Spec.SessionAffinity == api.ServiceAffinityClientIP { if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
timeoutSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds) timeoutSeconds = int(*service.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds)
} }
proxier.loadBalancer.NewService(servicePortName, service.Spec.SessionAffinity, timeoutSeconds) proxier.loadBalancer.NewService(servicePortName, service.Spec.SessionAffinity, timeoutSeconds)
@ -371,7 +371,7 @@ func (proxier *Proxier) mergeService(service *api.Service) map[ServicePortPortal
return existingPortPortals return existingPortPortals
} }
func (proxier *Proxier) unmergeService(service *api.Service, existingPortPortals map[ServicePortPortalName]bool) { func (proxier *Proxier) unmergeService(service *v1.Service, existingPortPortals map[ServicePortPortalName]bool) {
if service == nil { if service == nil {
return return
} }
@ -428,23 +428,23 @@ func (proxier *Proxier) unmergeService(service *api.Service, existingPortPortals
} }
} }
func (proxier *Proxier) OnServiceAdd(service *api.Service) { func (proxier *Proxier) OnServiceAdd(service *v1.Service) {
_ = proxier.mergeService(service) _ = proxier.mergeService(service)
} }
func (proxier *Proxier) OnServiceUpdate(oldService, service *api.Service) { func (proxier *Proxier) OnServiceUpdate(oldService, service *v1.Service) {
existingPortPortals := proxier.mergeService(service) existingPortPortals := proxier.mergeService(service)
proxier.unmergeService(oldService, existingPortPortals) proxier.unmergeService(oldService, existingPortPortals)
} }
func (proxier *Proxier) OnServiceDelete(service *api.Service) { func (proxier *Proxier) OnServiceDelete(service *v1.Service) {
proxier.unmergeService(service, map[ServicePortPortalName]bool{}) proxier.unmergeService(service, map[ServicePortPortalName]bool{})
} }
func (proxier *Proxier) OnServiceSynced() { func (proxier *Proxier) OnServiceSynced() {
} }
func sameConfig(info *serviceInfo, service *api.Service, protocol api.Protocol, listenPort int) bool { func sameConfig(info *serviceInfo, service *v1.Service, protocol v1.Protocol, listenPort int) bool {
return info.protocol == protocol && info.portal.port == listenPort && info.sessionAffinityType == service.Spec.SessionAffinity return info.protocol == protocol && info.portal.port == listenPort && info.sessionAffinityType == service.Spec.SessionAffinity
} }

View File

@ -29,10 +29,10 @@ import (
"testing" "testing"
"time" "time"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
netshtest "k8s.io/kubernetes/pkg/util/netsh/testing" netshtest "k8s.io/kubernetes/pkg/util/netsh/testing"
) )
@ -241,11 +241,11 @@ func getPortNum(t *testing.T, addr string) int {
func TestTCPProxy(t *testing.T) { func TestTCPProxy(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -268,11 +268,11 @@ func TestTCPProxy(t *testing.T) {
func TestUDPProxy(t *testing.T) { func TestUDPProxy(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -295,11 +295,11 @@ func TestUDPProxy(t *testing.T) {
func TestUDPProxyTimeout(t *testing.T) { func TestUDPProxyTimeout(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -327,18 +327,18 @@ func TestMultiPortProxy(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
serviceP := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-p"}, Port: "p"} serviceP := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-p"}, Port: "p"}
serviceQ := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-q"}, Port: "q"} serviceQ := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo-q"}, Port: "q"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Protocol: "TCP", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Protocol: "TCP", Port: tcpServerPort}},
}}, }},
}) })
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceQ.Name, Namespace: serviceQ.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceQ.Name, Namespace: serviceQ.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "q", Protocol: "UDP", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "q", Protocol: "UDP", Port: udpServerPort}},
}}, }},
}) })
@ -379,9 +379,9 @@ func TestMultiPortOnServiceAdd(t *testing.T) {
} }
waitForNumProxyLoops(t, p, 0) waitForNumProxyLoops(t, p, 0)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Spec: api.ServiceSpec{ClusterIP: "0.0.0.0", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "0.0.0.0", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: 0, Port: 0,
Protocol: "TCP", Protocol: "TCP",
@ -430,11 +430,11 @@ func stopProxyByName(proxier *Proxier, service ServicePortPortalName) error {
func TestTCPProxyStop(t *testing.T) { func TestTCPProxyStop(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -474,11 +474,11 @@ func TestTCPProxyStop(t *testing.T) {
func TestUDPProxyStop(t *testing.T) { func TestUDPProxyStop(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -512,11 +512,11 @@ func TestUDPProxyStop(t *testing.T) {
func TestTCPProxyUpdateDelete(t *testing.T) { func TestTCPProxyUpdateDelete(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -540,9 +540,9 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(getPortNum(t, svcInfo.socket.Addr().String())), Port: int32(getPortNum(t, svcInfo.socket.Addr().String())),
Protocol: "TCP", Protocol: "TCP",
@ -557,11 +557,11 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
func TestUDPProxyUpdateDelete(t *testing.T) { func TestUDPProxyUpdateDelete(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name}, ObjectMeta: metav1.ObjectMeta{Namespace: service.Namespace, Name: service.Name},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -584,9 +584,9 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(getPortNum(t, svcInfo.socket.Addr().String())), Port: int32(getPortNum(t, svcInfo.socket.Addr().String())),
Protocol: "UDP", Protocol: "UDP",
@ -601,11 +601,11 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
func TestTCPProxyUpdateDeleteUpdate(t *testing.T) { func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
endpoint := &api.Endpoints{ endpoint := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
} }
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
@ -629,9 +629,9 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(getPortNum(t, svcInfo.socket.Addr().String())), Port: int32(getPortNum(t, svcInfo.socket.Addr().String())),
Protocol: "TCP", Protocol: "TCP",
@ -644,9 +644,9 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
// need to add endpoint here because it got clean up during service delete // need to add endpoint here because it got clean up during service delete
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(getPortNum(t, svcInfo.socket.Addr().String())), Port: int32(getPortNum(t, svcInfo.socket.Addr().String())),
Protocol: "TCP", Protocol: "TCP",
@ -663,11 +663,11 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
func TestUDPProxyUpdateDeleteUpdate(t *testing.T) { func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
endpoint := &api.Endpoints{ endpoint := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
} }
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
@ -691,9 +691,9 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
conn.Close() conn.Close()
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceDelete(&api.Service{ p.OnServiceDelete(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(getPortNum(t, svcInfo.socket.Addr().String())), Port: int32(getPortNum(t, svcInfo.socket.Addr().String())),
Protocol: "UDP", Protocol: "UDP",
@ -706,9 +706,9 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
// need to add endpoint here because it got clean up during service delete // need to add endpoint here because it got clean up during service delete
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(getPortNum(t, svcInfo.socket.Addr().String())), Port: int32(getPortNum(t, svcInfo.socket.Addr().String())),
Protocol: "UDP", Protocol: "UDP",
@ -725,11 +725,11 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
func TestTCPProxyUpdatePort(t *testing.T) { func TestTCPProxyUpdatePort(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -748,9 +748,9 @@ func TestTCPProxyUpdatePort(t *testing.T) {
testEchoTCP(t, "127.0.0.1", getPortNum(t, svcInfo.socket.Addr().String())) testEchoTCP(t, "127.0.0.1", getPortNum(t, svcInfo.socket.Addr().String()))
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: 0, Port: 0,
Protocol: "TCP", Protocol: "TCP",
@ -773,11 +773,11 @@ func TestTCPProxyUpdatePort(t *testing.T) {
func TestUDPProxyUpdatePort(t *testing.T) { func TestUDPProxyUpdatePort(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: udpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: udpServerPort}},
}}, }},
}) })
@ -795,9 +795,9 @@ func TestUDPProxyUpdatePort(t *testing.T) {
} }
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: 0, Port: 0,
Protocol: "UDP", Protocol: "UDP",
@ -818,11 +818,11 @@ func TestUDPProxyUpdatePort(t *testing.T) {
func TestProxyUpdatePublicIPs(t *testing.T) { func TestProxyUpdatePublicIPs(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
lb.OnEndpointsAdd(&api.Endpoints{ lb.OnEndpointsAdd(&v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
}) })
@ -841,10 +841,10 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
testEchoTCP(t, "127.0.0.1", getPortNum(t, svcInfo.socket.Addr().String())) testEchoTCP(t, "127.0.0.1", getPortNum(t, svcInfo.socket.Addr().String()))
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
p.OnServiceAdd(&api.Service{ p.OnServiceAdd(&v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ Spec: v1.ServiceSpec{
Ports: []api.ServicePort{{ Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.portal.port), Port: int32(svcInfo.portal.port),
Protocol: "TCP", Protocol: "TCP",
@ -870,11 +870,11 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
func TestProxyUpdatePortal(t *testing.T) { func TestProxyUpdatePortal(t *testing.T) {
lb := NewLoadBalancerRR() lb := NewLoadBalancerRR()
service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"} service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "echo"}, Port: "p"}
endpoint := &api.Endpoints{ endpoint := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}}, Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
Ports: []api.EndpointPort{{Name: "p", Port: tcpServerPort}}, Ports: []v1.EndpointPort{{Name: "p", Port: tcpServerPort}},
}}, }},
} }
lb.OnEndpointsAdd(endpoint) lb.OnEndpointsAdd(endpoint)
@ -894,18 +894,18 @@ func TestProxyUpdatePortal(t *testing.T) {
testEchoTCP(t, "127.0.0.1", getPortNum(t, svcInfo.socket.Addr().String())) testEchoTCP(t, "127.0.0.1", getPortNum(t, svcInfo.socket.Addr().String()))
waitForNumProxyLoops(t, p, 1) waitForNumProxyLoops(t, p, 1)
svcv0 := &api.Service{ svcv0 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.portal.port), Port: int32(svcInfo.portal.port),
Protocol: "TCP", Protocol: "TCP",
}}}, }}},
} }
svcv1 := &api.Service{ svcv1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.portal.port), Port: int32(svcInfo.portal.port),
Protocol: "TCP", Protocol: "TCP",
@ -918,9 +918,9 @@ func TestProxyUpdatePortal(t *testing.T) {
t.Fatalf("service with empty ClusterIP should not be included in the proxy") t.Fatalf("service with empty ClusterIP should not be included in the proxy")
} }
svcv2 := &api.Service{ svcv2 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: "None", Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: "None", Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(getPortNum(t, svcInfo.socket.Addr().String())), Port: int32(getPortNum(t, svcInfo.socket.Addr().String())),
Protocol: "TCP", Protocol: "TCP",
@ -932,9 +932,9 @@ func TestProxyUpdatePortal(t *testing.T) {
t.Fatalf("service with 'None' as ClusterIP should not be included in the proxy") t.Fatalf("service with 'None' as ClusterIP should not be included in the proxy")
} }
svcv3 := &api.Service{ svcv3 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Spec: api.ServiceSpec{ClusterIP: listenIP, Ports: []api.ServicePort{{ Spec: v1.ServiceSpec{ClusterIP: listenIP, Ports: []v1.ServicePort{{
Name: "p", Name: "p",
Port: int32(svcInfo.portal.port), Port: int32(svcInfo.portal.port),
Protocol: "TCP", Protocol: "TCP",

View File

@ -28,9 +28,9 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"github.com/miekg/dns" "github.com/miekg/dns"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/runtime"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/util/ipconfig" "k8s.io/kubernetes/pkg/util/ipconfig"
"k8s.io/utils/exec" "k8s.io/utils/exec"
@ -78,7 +78,7 @@ type proxySocket interface {
ListenPort() int ListenPort() int
} }
func newProxySocket(protocol api.Protocol, ip net.IP, port int) (proxySocket, error) { func newProxySocket(protocol v1.Protocol, ip net.IP, port int) (proxySocket, error) {
host := "" host := ""
if ip != nil { if ip != nil {
host = ip.String() host = ip.String()

View File

@ -26,8 +26,8 @@ import (
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
"k8s.io/kubernetes/pkg/util/slice" "k8s.io/kubernetes/pkg/util/slice"
) )
@ -46,7 +46,7 @@ type affinityState struct {
} }
type affinityPolicy struct { type affinityPolicy struct {
affinityType api.ServiceAffinity affinityType v1.ServiceAffinity
affinityMap map[string]*affinityState // map client IP -> affinity info affinityMap map[string]*affinityState // map client IP -> affinity info
ttlSeconds int ttlSeconds int
} }
@ -66,7 +66,7 @@ type balancerState struct {
affinity affinityPolicy affinity affinityPolicy
} }
func newAffinityPolicy(affinityType api.ServiceAffinity, ttlSeconds int) *affinityPolicy { func newAffinityPolicy(affinityType v1.ServiceAffinity, ttlSeconds int) *affinityPolicy {
return &affinityPolicy{ return &affinityPolicy{
affinityType: affinityType, affinityType: affinityType,
affinityMap: make(map[string]*affinityState), affinityMap: make(map[string]*affinityState),
@ -81,7 +81,7 @@ func NewLoadBalancerRR() *LoadBalancerRR {
} }
} }
func (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType api.ServiceAffinity, ttlSeconds int) error { func (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType v1.ServiceAffinity, ttlSeconds int) error {
glog.V(4).Infof("LoadBalancerRR NewService %q", svcPort) glog.V(4).Infof("LoadBalancerRR NewService %q", svcPort)
lb.lock.Lock() lb.lock.Lock()
defer lb.lock.Unlock() defer lb.lock.Unlock()
@ -90,9 +90,9 @@ func (lb *LoadBalancerRR) NewService(svcPort proxy.ServicePortName, affinityType
} }
// This assumes that lb.lock is already held. // This assumes that lb.lock is already held.
func (lb *LoadBalancerRR) newServiceInternal(svcPort proxy.ServicePortName, affinityType api.ServiceAffinity, ttlSeconds int) *balancerState { func (lb *LoadBalancerRR) newServiceInternal(svcPort proxy.ServicePortName, affinityType v1.ServiceAffinity, ttlSeconds int) *balancerState {
if ttlSeconds == 0 { if ttlSeconds == 0 {
ttlSeconds = int(api.DefaultClientIPServiceAffinitySeconds) //default to 3 hours if not specified. Should 0 be unlimited instead???? ttlSeconds = int(v1.DefaultClientIPServiceAffinitySeconds) //default to 3 hours if not specified. Should 0 be unlimited instead????
} }
if _, exists := lb.services[svcPort]; !exists { if _, exists := lb.services[svcPort]; !exists {
@ -114,7 +114,7 @@ func (lb *LoadBalancerRR) DeleteService(svcPort proxy.ServicePortName) {
// return true if this service is using some form of session affinity. // return true if this service is using some form of session affinity.
func isSessionAffinity(affinity *affinityPolicy) bool { func isSessionAffinity(affinity *affinityPolicy) bool {
// Should never be empty string, but checking for it to be safe. // Should never be empty string, but checking for it to be safe.
if affinity.affinityType == "" || affinity.affinityType == api.ServiceAffinityNone { if affinity.affinityType == "" || affinity.affinityType == v1.ServiceAffinityNone {
return false return false
} }
return true return true
@ -235,7 +235,7 @@ func (lb *LoadBalancerRR) updateAffinityMap(svcPort proxy.ServicePortName, newEn
// buildPortsToEndpointsMap builds a map of portname -> all ip:ports for that // buildPortsToEndpointsMap builds a map of portname -> all ip:ports for that
// portname. Explode Endpoints.Subsets[*] into this structure. // portname. Explode Endpoints.Subsets[*] into this structure.
func buildPortsToEndpointsMap(endpoints *api.Endpoints) map[string][]hostPortPair { func buildPortsToEndpointsMap(endpoints *v1.Endpoints) map[string][]hostPortPair {
portsToEndpoints := map[string][]hostPortPair{} portsToEndpoints := map[string][]hostPortPair{}
for i := range endpoints.Subsets { for i := range endpoints.Subsets {
ss := &endpoints.Subsets[i] ss := &endpoints.Subsets[i]
@ -251,7 +251,7 @@ func buildPortsToEndpointsMap(endpoints *api.Endpoints) map[string][]hostPortPai
return portsToEndpoints return portsToEndpoints
} }
func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *api.Endpoints) { func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *v1.Endpoints) {
portsToEndpoints := buildPortsToEndpointsMap(endpoints) portsToEndpoints := buildPortsToEndpointsMap(endpoints)
lb.lock.Lock() lb.lock.Lock()
@ -269,7 +269,7 @@ func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *api.Endpoints) {
// To be safe we will call it here. A new service will only be created // To be safe we will call it here. A new service will only be created
// if one does not already exist. The affinity will be updated // if one does not already exist. The affinity will be updated
// later, once NewService is called. // later, once NewService is called.
state = lb.newServiceInternal(svcPort, api.ServiceAffinity(""), 0) state = lb.newServiceInternal(svcPort, v1.ServiceAffinity(""), 0)
state.endpoints = slice.ShuffleStrings(newEndpoints) state.endpoints = slice.ShuffleStrings(newEndpoints)
// Reset the round-robin index. // Reset the round-robin index.
@ -278,7 +278,7 @@ func (lb *LoadBalancerRR) OnEndpointsAdd(endpoints *api.Endpoints) {
} }
} }
func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoints) { func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
portsToEndpoints := buildPortsToEndpointsMap(endpoints) portsToEndpoints := buildPortsToEndpointsMap(endpoints)
oldPortsToEndpoints := buildPortsToEndpointsMap(oldEndpoints) oldPortsToEndpoints := buildPortsToEndpointsMap(oldEndpoints)
registeredEndpoints := make(map[proxy.ServicePortName]bool) registeredEndpoints := make(map[proxy.ServicePortName]bool)
@ -303,7 +303,7 @@ func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoin
// To be safe we will call it here. A new service will only be created // To be safe we will call it here. A new service will only be created
// if one does not already exist. The affinity will be updated // if one does not already exist. The affinity will be updated
// later, once NewService is called. // later, once NewService is called.
state = lb.newServiceInternal(svcPort, api.ServiceAffinity(""), 0) state = lb.newServiceInternal(svcPort, v1.ServiceAffinity(""), 0)
state.endpoints = slice.ShuffleStrings(newEndpoints) state.endpoints = slice.ShuffleStrings(newEndpoints)
// Reset the round-robin index. // Reset the round-robin index.
@ -325,7 +325,7 @@ func (lb *LoadBalancerRR) OnEndpointsUpdate(oldEndpoints, endpoints *api.Endpoin
} }
} }
func (lb *LoadBalancerRR) OnEndpointsDelete(endpoints *api.Endpoints) { func (lb *LoadBalancerRR) OnEndpointsDelete(endpoints *v1.Endpoints) {
portsToEndpoints := buildPortsToEndpointsMap(endpoints) portsToEndpoints := buildPortsToEndpointsMap(endpoints)
lb.lock.Lock() lb.lock.Lock()

View File

@ -20,9 +20,9 @@ import (
"net" "net"
"testing" "testing"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/proxy" "k8s.io/kubernetes/pkg/proxy"
) )
@ -104,11 +104,11 @@ func TestLoadBalanceWorksWithSingleEndpoint(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}},
Ports: []api.EndpointPort{{Name: "p", Port: 40}}, Ports: []v1.EndpointPort{{Name: "p", Port: 40}},
}}, }},
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
@ -141,11 +141,11 @@ func TestLoadBalanceWorksWithMultipleEndpoints(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Name: "p", Port: 1}, {Name: "p", Port: 2}, {Name: "p", Port: 3}}, Ports: []v1.EndpointPort{{Name: "p", Port: 1}, {Name: "p", Port: 2}, {Name: "p", Port: 3}},
}}, }},
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
@ -168,16 +168,16 @@ func TestLoadBalanceWorksWithMultipleEndpointsMultiplePorts(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}},
Ports: []api.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 2}}, Ports: []v1.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 2}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint3"}},
Ports: []api.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 4}}, Ports: []v1.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 4}},
}, },
}, },
} }
@ -210,20 +210,20 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpointsv1 := &api.Endpoints{ endpointsv1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}},
Ports: []api.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 10}}, Ports: []v1.EndpointPort{{Name: "p", Port: 1}, {Name: "q", Port: 10}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint2"}},
Ports: []api.EndpointPort{{Name: "p", Port: 2}, {Name: "q", Port: 20}}, Ports: []v1.EndpointPort{{Name: "p", Port: 2}, {Name: "q", Port: 20}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint3"}},
Ports: []api.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 30}}, Ports: []v1.EndpointPort{{Name: "p", Port: 3}, {Name: "q", Port: 30}},
}, },
}, },
} }
@ -249,16 +249,16 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
// Then update the configuration with one fewer endpoints, make sure // Then update the configuration with one fewer endpoints, make sure
// we start in the beginning again // we start in the beginning again
endpointsv2 := &api.Endpoints{ endpointsv2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint4"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint4"}},
Ports: []api.EndpointPort{{Name: "p", Port: 4}, {Name: "q", Port: 40}}, Ports: []v1.EndpointPort{{Name: "p", Port: 4}, {Name: "q", Port: 40}},
}, },
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint5"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint5"}},
Ports: []api.EndpointPort{{Name: "p", Port: 5}, {Name: "q", Port: 50}}, Ports: []v1.EndpointPort{{Name: "p", Port: 5}, {Name: "q", Port: 50}},
}, },
}, },
} }
@ -283,7 +283,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
expectEndpoint(t, loadBalancer, serviceQ, shuffledEndpoints[1], nil) expectEndpoint(t, loadBalancer, serviceQ, shuffledEndpoints[1], nil)
// Clear endpoints // Clear endpoints
endpointsv3 := &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, Subsets: nil} endpointsv3 := &v1.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, Subsets: nil}
loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3) loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3)
endpoint, err = loadBalancer.NextEndpoint(serviceP, nil, false) endpoint, err = loadBalancer.NextEndpoint(serviceP, nil, false)
@ -300,21 +300,21 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
endpoints1 := &api.Endpoints{ endpoints1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: fooServiceP.Name, Namespace: fooServiceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: fooServiceP.Name, Namespace: fooServiceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}, {IP: "endpoint3"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint1"}, {IP: "endpoint2"}, {IP: "endpoint3"}},
Ports: []api.EndpointPort{{Name: "p", Port: 123}}, Ports: []v1.EndpointPort{{Name: "p", Port: 123}},
}, },
}, },
} }
endpoints2 := &api.Endpoints{ endpoints2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: barServiceP.Name, Namespace: barServiceP.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: barServiceP.Name, Namespace: barServiceP.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint4"}, {IP: "endpoint5"}, {IP: "endpoint6"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint4"}, {IP: "endpoint5"}, {IP: "endpoint6"}},
Ports: []api.EndpointPort{{Name: "p", Port: 456}}, Ports: []v1.EndpointPort{{Name: "p", Port: 456}},
}, },
}, },
} }
@ -357,13 +357,13 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
} }
// Call NewService() before OnEndpointsUpdate() // Call NewService() before OnEndpointsUpdate()
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint1"}}, Ports: []v1.EndpointPort{{Port: 1}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint2"}}, Ports: []v1.EndpointPort{{Port: 2}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Ports: []api.EndpointPort{{Port: 3}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint3"}}, Ports: []v1.EndpointPort{{Port: 3}}},
}, },
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
@ -413,15 +413,15 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) {
} }
// Call OnEndpointsUpdate() before NewService() // Call OnEndpointsUpdate() before NewService()
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint1"}}, Ports: []v1.EndpointPort{{Port: 1}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint2"}}, Ports: []v1.EndpointPort{{Port: 2}}},
}, },
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0} client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}
client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0} client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0}
@ -473,13 +473,13 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpointsv1 := &api.Endpoints{ endpointsv1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}},
}, },
}, },
} }
@ -494,12 +494,12 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
expectEndpoint(t, loadBalancer, service, shuffledEndpoints[2], client3) expectEndpoint(t, loadBalancer, service, shuffledEndpoints[2], client3)
client3Endpoint := shuffledEndpoints[2] client3Endpoint := shuffledEndpoints[2]
endpointsv2 := &api.Endpoints{ endpointsv2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}},
}, },
}, },
} }
@ -516,12 +516,12 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
expectEndpoint(t, loadBalancer, service, client2Endpoint, client2) expectEndpoint(t, loadBalancer, service, client2Endpoint, client2)
expectEndpoint(t, loadBalancer, service, client3Endpoint, client3) expectEndpoint(t, loadBalancer, service, client3Endpoint, client3)
endpointsv3 := &api.Endpoints{ endpointsv3 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 4}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 4}},
}, },
}, },
} }
@ -546,13 +546,13 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpointsv1 := &api.Endpoints{ endpointsv1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}},
}, },
}, },
} }
@ -567,12 +567,12 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2) expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2)
// Then update the configuration with one fewer endpoints, make sure // Then update the configuration with one fewer endpoints, make sure
// we start in the beginning again // we start in the beginning again
endpointsv2 := &api.Endpoints{ endpointsv2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 4}, {Port: 5}}, Ports: []v1.EndpointPort{{Port: 4}, {Port: 5}},
}, },
}, },
} }
@ -586,7 +586,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2) expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2)
// Clear endpoints // Clear endpoints
endpointsv3 := &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, Subsets: nil} endpointsv3 := &v1.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, Subsets: nil}
loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3) loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3)
endpoint, err = loadBalancer.NextEndpoint(service, nil, false) endpoint, err = loadBalancer.NextEndpoint(service, nil, false)
@ -605,24 +605,24 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
if err == nil || len(endpoint) != 0 { if err == nil || len(endpoint) != 0 {
t.Errorf("Didn't fail with non-existent service") t.Errorf("Didn't fail with non-existent service")
} }
loadBalancer.NewService(fooService, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(fooService, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints1 := &api.Endpoints{ endpoints1 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: fooService.Name, Namespace: fooService.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: fooService.Name, Namespace: fooService.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}}, Ports: []v1.EndpointPort{{Port: 1}, {Port: 2}, {Port: 3}},
}, },
}, },
} }
barService := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "bar"}, Port: ""} barService := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "bar"}, Port: ""}
loadBalancer.NewService(barService, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(barService, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints2 := &api.Endpoints{ endpoints2 := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: barService.Name, Namespace: barService.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: barService.Name, Namespace: barService.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{ {
Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Addresses: []v1.EndpointAddress{{IP: "endpoint"}},
Ports: []api.EndpointPort{{Port: 4}, {Port: 5}}, Ports: []v1.EndpointPort{{Port: 4}, {Port: 5}},
}, },
}, },
} }
@ -674,13 +674,13 @@ func TestStickyLoadBalanceWorksWithEndpointFails(t *testing.T) {
} }
// Call NewService() before OnEndpointsUpdate() // Call NewService() before OnEndpointsUpdate()
loadBalancer.NewService(service, api.ServiceAffinityClientIP, int(api.DefaultClientIPServiceAffinitySeconds)) loadBalancer.NewService(service, v1.ServiceAffinityClientIP, int(v1.DefaultClientIPServiceAffinitySeconds))
endpoints := &api.Endpoints{ endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
Subsets: []api.EndpointSubset{ Subsets: []v1.EndpointSubset{
{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint1"}}, Ports: []v1.EndpointPort{{Port: 1}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint2"}}, Ports: []v1.EndpointPort{{Port: 2}}},
{Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Ports: []api.EndpointPort{{Port: 3}}}, {Addresses: []v1.EndpointAddress{{IP: "endpoint3"}}, Ports: []v1.EndpointPort{{Port: 3}}},
}, },
} }
loadBalancer.OnEndpointsAdd(endpoints) loadBalancer.OnEndpointsAdd(endpoints)

View File

@ -30,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1" v1core "k8s.io/client-go/kubernetes/typed/core/v1"
api "k8s.io/kubernetes/pkg/apis/core"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis" kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
) )
@ -92,24 +91,6 @@ func GetNodeHostIP(node *v1.Node) (net.IP, error) {
return nil, fmt.Errorf("host IP unknown; known addresses: %v", addresses) return nil, fmt.Errorf("host IP unknown; known addresses: %v", addresses)
} }
// InternalGetNodeHostIP returns the provided node's IP, based on the priority:
// 1. NodeInternalIP
// 2. NodeExternalIP
func InternalGetNodeHostIP(node *api.Node) (net.IP, error) {
addresses := node.Status.Addresses
addressMap := make(map[api.NodeAddressType][]api.NodeAddress)
for i := range addresses {
addressMap[addresses[i].Type] = append(addressMap[addresses[i].Type], addresses[i])
}
if addresses, ok := addressMap[api.NodeInternalIP]; ok {
return net.ParseIP(addresses[0].Address), nil
}
if addresses, ok := addressMap[api.NodeExternalIP]; ok {
return net.ParseIP(addresses[0].Address), nil
}
return nil, fmt.Errorf("host IP unknown; known addresses: %v", addresses)
}
// GetZoneKey is a helper function that builds a string identifier that is unique per failure-zone; // GetZoneKey is a helper function that builds a string identifier that is unique per failure-zone;
// it returns empty-string for no zone. // it returns empty-string for no zone.
func GetZoneKey(node *v1.Node) string { func GetZoneKey(node *v1.Node) string {