Commit 79e17e6c authored by x00416946 fisherxu's avatar x00416946 fisherxu Committed by fisherxu

use versioned api in kube-proxy

parent c582a37c
...@@ -41,7 +41,8 @@ import ( ...@@ -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 ( ...@@ -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 ...@@ -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 { ...@@ -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 ...@@ -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
......
...@@ -36,7 +36,6 @@ import ( ...@@ -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) { ...@@ -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) { ...@@ -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,
......
...@@ -24,11 +24,10 @@ import ( ...@@ -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() {} ...@@ -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() { ...@@ -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
......
...@@ -22,25 +22,25 @@ import ( ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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{})
......
...@@ -21,11 +21,11 @@ import ( ...@@ -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 ( ...@@ -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 { ...@@ -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{}) { ...@@ -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{}) { ...@@ -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{}) { ...@@ -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{}) { ...@@ -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{}) { ...@@ -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{}) { ...@@ -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
} }
......
...@@ -24,10 +24,10 @@ import ( ...@@ -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 ...@@ -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 ...@@ -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
} }
......
...@@ -38,7 +38,6 @@ import ( ...@@ -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 { ...@@ -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 { ...@@ -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() { ...@@ -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 ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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),
......
...@@ -30,12 +30,11 @@ import ( ...@@ -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 { ...@@ -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 { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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 ...@@ -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)
} }
......
...@@ -25,11 +25,11 @@ import ( ...@@ -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 ( ...@@ -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 { ...@@ -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 { ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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)
......
...@@ -19,8 +19,8 @@ package proxy ...@@ -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 { ...@@ -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
} }
......
...@@ -17,7 +17,7 @@ limitations under the License. ...@@ -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 { ...@@ -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
......
...@@ -26,8 +26,8 @@ import ( ...@@ -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 { ...@@ -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()
......
...@@ -26,8 +26,8 @@ import ( ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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) { ...@@ -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()
......
...@@ -24,8 +24,7 @@ import ( ...@@ -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) { ...@@ -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
} }
......
...@@ -20,25 +20,25 @@ import ( ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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"},
......
...@@ -32,13 +32,13 @@ import ( ...@@ -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 { ...@@ -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() { ...@@ -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 ...@@ -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 { ...@@ -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 { ...@@ -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 ...@@ -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 { ...@@ -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 { ...@@ -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() { ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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() { ...@@ -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())
} }
......
...@@ -17,7 +17,7 @@ limitations under the License. ...@@ -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 { ...@@ -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)
} }
...@@ -27,11 +27,11 @@ import ( ...@@ -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 { ...@@ -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{} ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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[ ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
} }
......
...@@ -28,9 +28,9 @@ import ( ...@@ -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 { ...@@ -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()
......
...@@ -26,8 +26,8 @@ import ( ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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) { ...@@ -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 ...@@ -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 ...@@ -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()
......
...@@ -30,7 +30,6 @@ import ( ...@@ -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) { ...@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment