Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c5e221dc
Commit
c5e221dc
authored
Aug 10, 2015
by
Alex Robinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12440 from BenTheElder/proxy_config_handler_refactor
Refactor `pkg/proxy/config`'s ServiceConfigHandler and EndpointsConfigHandler.
parents
72db1230
6bbf2aaa
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
62 deletions
+62
-62
config.go
pkg/proxy/config/config.go
+6
-6
config_test.go
pkg/proxy/config/config_test.go
+2
-2
types.go
pkg/proxy/types.go
+2
-2
proxier.go
pkg/proxy/userspace/proxier.go
+1
-1
proxier_test.go
pkg/proxy/userspace/proxier_test.go
+27
-27
roundrobin.go
pkg/proxy/userspace/roundrobin.go
+3
-3
roundrobin_test.go
pkg/proxy/userspace/roundrobin_test.go
+21
-21
No files found.
pkg/proxy/config/config.go
View file @
c5e221dc
...
@@ -57,17 +57,17 @@ type EndpointsUpdate struct {
...
@@ -57,17 +57,17 @@ type EndpointsUpdate struct {
// ServiceConfigHandler is an abstract interface of objects which receive update notifications for the set of services.
// ServiceConfigHandler is an abstract interface of objects which receive update notifications for the set of services.
type
ServiceConfigHandler
interface
{
type
ServiceConfigHandler
interface
{
// OnUpdate gets called when a configuration has been changed by one of the sources.
// On
Service
Update gets called when a configuration has been changed by one of the sources.
// This is the union of all the configuration sources.
// This is the union of all the configuration sources.
OnUpdate
(
services
[]
api
.
Service
)
On
Service
Update
(
services
[]
api
.
Service
)
}
}
// EndpointsConfigHandler is an abstract interface of objects which receive update notifications for the set of endpoints.
// EndpointsConfigHandler is an abstract interface of objects which receive update notifications for the set of endpoints.
type
EndpointsConfigHandler
interface
{
type
EndpointsConfigHandler
interface
{
// OnUpdate gets called when endpoints configuration is changed for a given
// On
Endpoints
Update gets called when endpoints configuration is changed for a given
// service on any of the configuration sources. An example is when a new
// service on any of the configuration sources. An example is when a new
// service comes up, or when containers come up or down for an existing service.
// service comes up, or when containers come up or down for an existing service.
OnUpdate
(
endpoints
[]
api
.
Endpoints
)
On
Endpoints
Update
(
endpoints
[]
api
.
Endpoints
)
}
}
// EndpointsConfig tracks a set of endpoints configurations.
// EndpointsConfig tracks a set of endpoints configurations.
...
@@ -91,7 +91,7 @@ func NewEndpointsConfig() *EndpointsConfig {
...
@@ -91,7 +91,7 @@ func NewEndpointsConfig() *EndpointsConfig {
func
(
c
*
EndpointsConfig
)
RegisterHandler
(
handler
EndpointsConfigHandler
)
{
func
(
c
*
EndpointsConfig
)
RegisterHandler
(
handler
EndpointsConfigHandler
)
{
c
.
bcaster
.
Add
(
config
.
ListenerFunc
(
func
(
instance
interface
{})
{
c
.
bcaster
.
Add
(
config
.
ListenerFunc
(
func
(
instance
interface
{})
{
handler
.
OnUpdate
(
instance
.
([]
api
.
Endpoints
))
handler
.
On
Endpoints
Update
(
instance
.
([]
api
.
Endpoints
))
}))
}))
}
}
...
@@ -189,7 +189,7 @@ func NewServiceConfig() *ServiceConfig {
...
@@ -189,7 +189,7 @@ func NewServiceConfig() *ServiceConfig {
func
(
c
*
ServiceConfig
)
RegisterHandler
(
handler
ServiceConfigHandler
)
{
func
(
c
*
ServiceConfig
)
RegisterHandler
(
handler
ServiceConfigHandler
)
{
c
.
bcaster
.
Add
(
config
.
ListenerFunc
(
func
(
instance
interface
{})
{
c
.
bcaster
.
Add
(
config
.
ListenerFunc
(
func
(
instance
interface
{})
{
handler
.
OnUpdate
(
instance
.
([]
api
.
Service
))
handler
.
On
Service
Update
(
instance
.
([]
api
.
Service
))
}))
}))
}
}
...
...
pkg/proxy/config/config_test.go
View file @
c5e221dc
...
@@ -57,7 +57,7 @@ func NewServiceHandlerMock() *ServiceHandlerMock {
...
@@ -57,7 +57,7 @@ func NewServiceHandlerMock() *ServiceHandlerMock {
return
&
ServiceHandlerMock
{
services
:
make
([]
api
.
Service
,
0
)}
return
&
ServiceHandlerMock
{
services
:
make
([]
api
.
Service
,
0
)}
}
}
func
(
h
*
ServiceHandlerMock
)
OnUpdate
(
services
[]
api
.
Service
)
{
func
(
h
*
ServiceHandlerMock
)
On
Service
Update
(
services
[]
api
.
Service
)
{
sort
.
Sort
(
sortedServices
(
services
))
sort
.
Sort
(
sortedServices
(
services
))
h
.
services
=
services
h
.
services
=
services
h
.
updated
.
Done
()
h
.
updated
.
Done
()
...
@@ -95,7 +95,7 @@ func NewEndpointsHandlerMock() *EndpointsHandlerMock {
...
@@ -95,7 +95,7 @@ func NewEndpointsHandlerMock() *EndpointsHandlerMock {
return
&
EndpointsHandlerMock
{
endpoints
:
make
([]
api
.
Endpoints
,
0
)}
return
&
EndpointsHandlerMock
{
endpoints
:
make
([]
api
.
Endpoints
,
0
)}
}
}
func
(
h
*
EndpointsHandlerMock
)
OnUpdate
(
endpoints
[]
api
.
Endpoints
)
{
func
(
h
*
EndpointsHandlerMock
)
On
Endpoints
Update
(
endpoints
[]
api
.
Endpoints
)
{
sort
.
Sort
(
sortedEndpoints
(
endpoints
))
sort
.
Sort
(
sortedEndpoints
(
endpoints
))
h
.
endpoints
=
endpoints
h
.
endpoints
=
endpoints
h
.
updated
.
Done
()
h
.
updated
.
Done
()
...
...
pkg/proxy/types.go
View file @
c5e221dc
...
@@ -25,10 +25,10 @@ import (
...
@@ -25,10 +25,10 @@ import (
// ProxyProvider is the interface provided by proxier implementations.
// ProxyProvider is the interface provided by proxier implementations.
type
ProxyProvider
interface
{
type
ProxyProvider
interface
{
// OnUpdate manages the active set of service proxies.
// On
Service
Update manages the active set of service proxies.
// Active service proxies are reinitialized if found in the update set or
// Active service proxies are reinitialized if found in the update set or
// removed if missing from the update set.
// removed if missing from the update set.
OnUpdate
(
services
[]
api
.
Service
)
On
Service
Update
(
services
[]
api
.
Service
)
// SyncLoop runs periodic work.
// SyncLoop runs periodic work.
// This is expected to run as a goroutine or as the main loop of the app.
// This is expected to run as a goroutine or as the main loop of the app.
// It does not return.
// It does not return.
...
...
pkg/proxy/userspace/proxier.go
View file @
c5e221dc
...
@@ -265,7 +265,7 @@ const udpIdleTimeout = 1 * time.Second
...
@@ -265,7 +265,7 @@ const udpIdleTimeout = 1 * time.Second
// OnUpdate manages the active set of service proxies.
// OnUpdate manages the active set of service proxies.
// Active service proxies are reinitialized if found in the update set or
// Active service proxies are reinitialized if found in the update set or
// shutdown if missing from the update set.
// shutdown if missing from the update set.
func
(
proxier
*
Proxier
)
OnUpdate
(
services
[]
api
.
Service
)
{
func
(
proxier
*
Proxier
)
On
Service
Update
(
services
[]
api
.
Service
)
{
glog
.
V
(
4
)
.
Infof
(
"Received update notice: %+v"
,
services
)
glog
.
V
(
4
)
.
Infof
(
"Received update notice: %+v"
,
services
)
activeServices
:=
make
(
map
[
proxy
.
ServicePortName
]
bool
)
// use a map as a set
activeServices
:=
make
(
map
[
proxy
.
ServicePortName
]
bool
)
// use a map as a set
for
i
:=
range
services
{
for
i
:=
range
services
{
...
...
pkg/proxy/userspace/proxier_test.go
View file @
c5e221dc
...
@@ -213,7 +213,7 @@ func waitForNumProxyLoops(t *testing.T, p *Proxier, want int32) {
...
@@ -213,7 +213,7 @@ func waitForNumProxyLoops(t *testing.T, p *Proxier, want int32) {
func
TestTCPProxy
(
t
*
testing
.
T
)
{
func
TestTCPProxy
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -240,7 +240,7 @@ func TestTCPProxy(t *testing.T) {
...
@@ -240,7 +240,7 @@ func TestTCPProxy(t *testing.T) {
func
TestUDPProxy
(
t
*
testing
.
T
)
{
func
TestUDPProxy
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -268,7 +268,7 @@ func TestMultiPortProxy(t *testing.T) {
...
@@ -268,7 +268,7 @@ func TestMultiPortProxy(t *testing.T) {
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
serviceP
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo-p"
},
"p"
}
serviceP
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo-p"
},
"p"
}
serviceQ
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo-q"
},
"q"
}
serviceQ
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo-q"
},
"q"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
serviceP
.
Name
,
Namespace
:
serviceP
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
serviceP
.
Name
,
Namespace
:
serviceP
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"127.0.0.1"
}},
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"127.0.0.1"
}},
...
@@ -303,7 +303,7 @@ func TestMultiPortProxy(t *testing.T) {
...
@@ -303,7 +303,7 @@ func TestMultiPortProxy(t *testing.T) {
waitForNumProxyLoops
(
t
,
p
,
2
)
waitForNumProxyLoops
(
t
,
p
,
2
)
}
}
func
TestMultiPortOnUpdate
(
t
*
testing
.
T
)
{
func
TestMultiPortOn
Service
Update
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
serviceP
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
serviceP
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
serviceQ
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"q"
}
serviceQ
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"q"
}
...
@@ -315,7 +315,7 @@ func TestMultiPortOnUpdate(t *testing.T) {
...
@@ -315,7 +315,7 @@ func TestMultiPortOnUpdate(t *testing.T) {
}
}
waitForNumProxyLoops
(
t
,
p
,
0
)
waitForNumProxyLoops
(
t
,
p
,
0
)
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
serviceP
.
Name
,
Namespace
:
serviceP
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
serviceP
.
Name
,
Namespace
:
serviceP
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
@@ -362,7 +362,7 @@ func stopProxyByName(proxier *Proxier, service proxy.ServicePortName) error {
...
@@ -362,7 +362,7 @@ func stopProxyByName(proxier *Proxier, service proxy.ServicePortName) error {
func
TestTCPProxyStop
(
t
*
testing
.
T
)
{
func
TestTCPProxyStop
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -400,7 +400,7 @@ func TestTCPProxyStop(t *testing.T) {
...
@@ -400,7 +400,7 @@ func TestTCPProxyStop(t *testing.T) {
func
TestUDPProxyStop
(
t
*
testing
.
T
)
{
func
TestUDPProxyStop
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -438,7 +438,7 @@ func TestUDPProxyStop(t *testing.T) {
...
@@ -438,7 +438,7 @@ func TestUDPProxyStop(t *testing.T) {
func
TestTCPProxyUpdateDelete
(
t
*
testing
.
T
)
{
func
TestTCPProxyUpdateDelete
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -465,7 +465,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
...
@@ -465,7 +465,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
conn
.
Close
()
conn
.
Close
()
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{})
p
.
On
Service
Update
([]
api
.
Service
{})
if
err
:=
waitForClosedPortTCP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
if
err
:=
waitForClosedPortTCP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
...
@@ -475,7 +475,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
...
@@ -475,7 +475,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
func
TestUDPProxyUpdateDelete
(
t
*
testing
.
T
)
{
func
TestUDPProxyUpdateDelete
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
service
.
Namespace
,
Name
:
service
.
Name
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -502,7 +502,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
...
@@ -502,7 +502,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
conn
.
Close
()
conn
.
Close
()
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{})
p
.
On
Service
Update
([]
api
.
Service
{})
if
err
:=
waitForClosedPortUDP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
if
err
:=
waitForClosedPortUDP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
...
@@ -512,7 +512,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
...
@@ -512,7 +512,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
func
TestTCPProxyUpdateDeleteUpdate
(
t
*
testing
.
T
)
{
func
TestTCPProxyUpdateDeleteUpdate
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -539,13 +539,13 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
...
@@ -539,13 +539,13 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
conn
.
Close
()
conn
.
Close
()
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{})
p
.
On
Service
Update
([]
api
.
Service
{})
if
err
:=
waitForClosedPortTCP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
if
err
:=
waitForClosedPortTCP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
waitForNumProxyLoops
(
t
,
p
,
0
)
waitForNumProxyLoops
(
t
,
p
,
0
)
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
@@ -564,7 +564,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
...
@@ -564,7 +564,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
func
TestUDPProxyUpdateDeleteUpdate
(
t
*
testing
.
T
)
{
func
TestUDPProxyUpdateDeleteUpdate
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -591,13 +591,13 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
...
@@ -591,13 +591,13 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
conn
.
Close
()
conn
.
Close
()
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{})
p
.
On
Service
Update
([]
api
.
Service
{})
if
err
:=
waitForClosedPortUDP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
if
err
:=
waitForClosedPortUDP
(
p
,
svcInfo
.
proxyPort
);
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
waitForNumProxyLoops
(
t
,
p
,
0
)
waitForNumProxyLoops
(
t
,
p
,
0
)
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
@@ -616,7 +616,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
...
@@ -616,7 +616,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
func
TestTCPProxyUpdatePort
(
t
*
testing
.
T
)
{
func
TestTCPProxyUpdatePort
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -639,7 +639,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
...
@@ -639,7 +639,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
testEchoTCP
(
t
,
"127.0.0.1"
,
svcInfo
.
proxyPort
)
testEchoTCP
(
t
,
"127.0.0.1"
,
svcInfo
.
proxyPort
)
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
@@ -664,7 +664,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
...
@@ -664,7 +664,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
func
TestUDPProxyUpdatePort
(
t
*
testing
.
T
)
{
func
TestUDPProxyUpdatePort
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -686,7 +686,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
...
@@ -686,7 +686,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
}
}
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
@@ -709,7 +709,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
...
@@ -709,7 +709,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
func
TestProxyUpdatePublicIPs
(
t
*
testing
.
T
)
{
func
TestProxyUpdatePublicIPs
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -732,7 +732,7 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
...
@@ -732,7 +732,7 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
testEchoTCP
(
t
,
"127.0.0.1"
,
svcInfo
.
proxyPort
)
testEchoTCP
(
t
,
"127.0.0.1"
,
svcInfo
.
proxyPort
)
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Ports
:
[]
api
.
ServicePort
{{
...
@@ -761,7 +761,7 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
...
@@ -761,7 +761,7 @@ func TestProxyUpdatePublicIPs(t *testing.T) {
func
TestProxyUpdatePortal
(
t
*
testing
.
T
)
{
func
TestProxyUpdatePortal
(
t
*
testing
.
T
)
{
lb
:=
NewLoadBalancerRR
()
lb
:=
NewLoadBalancerRR
()
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"echo"
},
"p"
}
lb
.
OnUpdate
([]
api
.
Endpoints
{
lb
.
On
Endpoints
Update
([]
api
.
Endpoints
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
[]
api
.
EndpointSubset
{{
Subsets
:
[]
api
.
EndpointSubset
{{
...
@@ -784,7 +784,7 @@ func TestProxyUpdatePortal(t *testing.T) {
...
@@ -784,7 +784,7 @@ func TestProxyUpdatePortal(t *testing.T) {
testEchoTCP
(
t
,
"127.0.0.1"
,
svcInfo
.
proxyPort
)
testEchoTCP
(
t
,
"127.0.0.1"
,
svcInfo
.
proxyPort
)
waitForNumProxyLoops
(
t
,
p
,
1
)
waitForNumProxyLoops
(
t
,
p
,
1
)
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
""
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
""
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
@@ -797,7 +797,7 @@ func TestProxyUpdatePortal(t *testing.T) {
...
@@ -797,7 +797,7 @@ func TestProxyUpdatePortal(t *testing.T) {
t
.
Fatalf
(
"service with empty ClusterIP should not be included in the proxy"
)
t
.
Fatalf
(
"service with empty ClusterIP should not be included in the proxy"
)
}
}
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"None"
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"None"
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
@@ -810,7 +810,7 @@ func TestProxyUpdatePortal(t *testing.T) {
...
@@ -810,7 +810,7 @@ func TestProxyUpdatePortal(t *testing.T) {
t
.
Fatalf
(
"service with 'None' as ClusterIP should not be included in the proxy"
)
t
.
Fatalf
(
"service with 'None' as ClusterIP should not be included in the proxy"
)
}
}
p
.
OnUpdate
([]
api
.
Service
{{
p
.
On
Service
Update
([]
api
.
Service
{{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Spec
:
api
.
ServiceSpec
{
ClusterIP
:
"1.2.3.4"
,
Ports
:
[]
api
.
ServicePort
{{
Name
:
"p"
,
Name
:
"p"
,
...
...
pkg/proxy/userspace/roundrobin.go
View file @
c5e221dc
...
@@ -223,10 +223,10 @@ func (lb *LoadBalancerRR) updateAffinityMap(svcPort proxy.ServicePortName, newEn
...
@@ -223,10 +223,10 @@ func (lb *LoadBalancerRR) updateAffinityMap(svcPort proxy.ServicePortName, newEn
}
}
}
}
// OnUpdate manages the registered service endpoints.
// On
Endpoints
Update manages the registered service endpoints.
// Registered endpoints are updated if found in the update set or
// Registered endpoints are updated if found in the update set or
// unregistered if missing from the update set.
// unregistered if missing from the update set.
func
(
lb
*
LoadBalancerRR
)
OnUpdate
(
allEndpoints
[]
api
.
Endpoints
)
{
func
(
lb
*
LoadBalancerRR
)
On
Endpoints
Update
(
allEndpoints
[]
api
.
Endpoints
)
{
registeredEndpoints
:=
make
(
map
[
proxy
.
ServicePortName
]
bool
)
registeredEndpoints
:=
make
(
map
[
proxy
.
ServicePortName
]
bool
)
lb
.
lock
.
Lock
()
lb
.
lock
.
Lock
()
defer
lb
.
lock
.
Unlock
()
defer
lb
.
lock
.
Unlock
()
...
@@ -262,7 +262,7 @@ func (lb *LoadBalancerRR) OnUpdate(allEndpoints []api.Endpoints) {
...
@@ -262,7 +262,7 @@ func (lb *LoadBalancerRR) OnUpdate(allEndpoints []api.Endpoints) {
if
!
exists
||
state
==
nil
||
len
(
curEndpoints
)
!=
len
(
newEndpoints
)
||
!
slicesEquiv
(
slice
.
CopyStrings
(
curEndpoints
),
newEndpoints
)
{
if
!
exists
||
state
==
nil
||
len
(
curEndpoints
)
!=
len
(
newEndpoints
)
||
!
slicesEquiv
(
slice
.
CopyStrings
(
curEndpoints
),
newEndpoints
)
{
glog
.
V
(
1
)
.
Infof
(
"LoadBalancerRR: Setting endpoints for %s to %+v"
,
svcPort
,
newEndpoints
)
glog
.
V
(
1
)
.
Infof
(
"LoadBalancerRR: Setting endpoints for %s to %+v"
,
svcPort
,
newEndpoints
)
lb
.
updateAffinityMap
(
svcPort
,
newEndpoints
)
lb
.
updateAffinityMap
(
svcPort
,
newEndpoints
)
// OnUpdate can be called without NewService being called externally.
// On
Endpoints
Update can be called without NewService being called externally.
// 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.
...
...
pkg/proxy/userspace/roundrobin_test.go
View file @
c5e221dc
...
@@ -67,7 +67,7 @@ func TestFilterWorks(t *testing.T) {
...
@@ -67,7 +67,7 @@ func TestFilterWorks(t *testing.T) {
func
TestLoadBalanceFailsWithNoEndpoints
(
t
*
testing
.
T
)
{
func
TestLoadBalanceFailsWithNoEndpoints
(
t
*
testing
.
T
)
{
loadBalancer
:=
NewLoadBalancerRR
()
loadBalancer
:=
NewLoadBalancerRR
()
var
endpoints
[]
api
.
Endpoints
var
endpoints
[]
api
.
Endpoints
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"foo"
},
"does-not-exist"
}
service
:=
proxy
.
ServicePortName
{
types
.
NamespacedName
{
"testnamespace"
,
"foo"
},
"does-not-exist"
}
endpoint
,
err
:=
loadBalancer
.
NextEndpoint
(
service
,
nil
)
endpoint
,
err
:=
loadBalancer
.
NextEndpoint
(
service
,
nil
)
if
err
==
nil
{
if
err
==
nil
{
...
@@ -103,7 +103,7 @@ func TestLoadBalanceWorksWithSingleEndpoint(t *testing.T) {
...
@@ -103,7 +103,7 @@ func TestLoadBalanceWorksWithSingleEndpoint(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Name
:
"p"
,
Port
:
40
}},
Ports
:
[]
api
.
EndpointPort
{{
Name
:
"p"
,
Port
:
40
}},
}},
}},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
"endpoint1:40"
,
nil
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
"endpoint1:40"
,
nil
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
"endpoint1:40"
,
nil
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
"endpoint1:40"
,
nil
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
"endpoint1:40"
,
nil
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
"endpoint1:40"
,
nil
)
...
@@ -141,7 +141,7 @@ func TestLoadBalanceWorksWithMultipleEndpoints(t *testing.T) {
...
@@ -141,7 +141,7 @@ func TestLoadBalanceWorksWithMultipleEndpoints(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Name
:
"p"
,
Port
:
1
},
{
Name
:
"p"
,
Port
:
2
},
{
Name
:
"p"
,
Port
:
3
}},
Ports
:
[]
api
.
EndpointPort
{{
Name
:
"p"
,
Port
:
1
},
{
Name
:
"p"
,
Port
:
2
},
{
Name
:
"p"
,
Port
:
3
}},
}},
}},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
:=
loadBalancer
.
services
[
service
]
.
endpoints
shuffledEndpoints
:=
loadBalancer
.
services
[
service
]
.
endpoints
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint:1"
,
"endpoint:2"
,
"endpoint:3"
)
{
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint:1"
,
"endpoint:2"
,
"endpoint:3"
)
{
...
@@ -175,7 +175,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsMultiplePorts(t *testing.T) {
...
@@ -175,7 +175,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsMultiplePorts(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
:=
loadBalancer
.
services
[
serviceP
]
.
endpoints
shuffledEndpoints
:=
loadBalancer
.
services
[
serviceP
]
.
endpoints
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint1:1"
,
"endpoint2:1"
,
"endpoint3:3"
)
{
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint1:1"
,
"endpoint2:1"
,
"endpoint3:3"
)
{
...
@@ -222,7 +222,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
...
@@ -222,7 +222,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
:=
loadBalancer
.
services
[
serviceP
]
.
endpoints
shuffledEndpoints
:=
loadBalancer
.
services
[
serviceP
]
.
endpoints
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint1:1"
,
"endpoint2:2"
,
"endpoint3:3"
)
{
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint1:1"
,
"endpoint2:2"
,
"endpoint3:3"
)
{
...
@@ -257,7 +257,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
...
@@ -257,7 +257,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
=
loadBalancer
.
services
[
serviceP
]
.
endpoints
shuffledEndpoints
=
loadBalancer
.
services
[
serviceP
]
.
endpoints
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint4:4"
,
"endpoint5:5"
)
{
if
!
stringsInSlice
(
shuffledEndpoints
,
"endpoint4:4"
,
"endpoint5:5"
)
{
...
@@ -279,7 +279,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
...
@@ -279,7 +279,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
// Clear endpoints
// Clear endpoints
endpoints
[
0
]
=
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
serviceP
.
Name
,
Namespace
:
serviceP
.
Namespace
},
Subsets
:
nil
}
endpoints
[
0
]
=
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
serviceP
.
Name
,
Namespace
:
serviceP
.
Namespace
},
Subsets
:
nil
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
serviceP
,
nil
)
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
serviceP
,
nil
)
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
...
@@ -314,7 +314,7 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
...
@@ -314,7 +314,7 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledFooEndpoints
:=
loadBalancer
.
services
[
fooServiceP
]
.
endpoints
shuffledFooEndpoints
:=
loadBalancer
.
services
[
fooServiceP
]
.
endpoints
expectEndpoint
(
t
,
loadBalancer
,
fooServiceP
,
shuffledFooEndpoints
[
0
],
nil
)
expectEndpoint
(
t
,
loadBalancer
,
fooServiceP
,
shuffledFooEndpoints
[
0
],
nil
)
expectEndpoint
(
t
,
loadBalancer
,
fooServiceP
,
shuffledFooEndpoints
[
1
],
nil
)
expectEndpoint
(
t
,
loadBalancer
,
fooServiceP
,
shuffledFooEndpoints
[
1
],
nil
)
...
@@ -330,7 +330,7 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
...
@@ -330,7 +330,7 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
expectEndpoint
(
t
,
loadBalancer
,
barServiceP
,
shuffledBarEndpoints
[
1
],
nil
)
expectEndpoint
(
t
,
loadBalancer
,
barServiceP
,
shuffledBarEndpoints
[
1
],
nil
)
// Then update the configuration by removing foo
// Then update the configuration by removing foo
loadBalancer
.
OnUpdate
(
endpoints
[
1
:
])
loadBalancer
.
On
Endpoints
Update
(
endpoints
[
1
:
])
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
fooServiceP
,
nil
)
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
fooServiceP
,
nil
)
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
t
.
Errorf
(
"Didn't fail with non-existent service"
)
t
.
Errorf
(
"Didn't fail with non-existent service"
)
...
@@ -351,7 +351,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
...
@@ -351,7 +351,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
t
.
Errorf
(
"Didn't fail with non-existent service"
)
t
.
Errorf
(
"Didn't fail with non-existent service"
)
}
}
// Call NewService() before OnUpdate()
// Call NewService() before On
Endpoints
Update()
loadBalancer
.
NewService
(
service
,
api
.
ServiceAffinityClientIP
,
0
)
loadBalancer
.
NewService
(
service
,
api
.
ServiceAffinityClientIP
,
0
)
endpoints
:=
make
([]
api
.
Endpoints
,
1
)
endpoints
:=
make
([]
api
.
Endpoints
,
1
)
endpoints
[
0
]
=
api
.
Endpoints
{
endpoints
[
0
]
=
api
.
Endpoints
{
...
@@ -362,7 +362,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
...
@@ -362,7 +362,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"endpoint3"
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
3
}}},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"endpoint3"
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
3
}}},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
client1
:=
&
net
.
TCPAddr
{
IP
:
net
.
IPv4
(
127
,
0
,
0
,
1
),
Port
:
0
}
client1
:=
&
net
.
TCPAddr
{
IP
:
net
.
IPv4
(
127
,
0
,
0
,
1
),
Port
:
0
}
client2
:=
&
net
.
TCPAddr
{
IP
:
net
.
IPv4
(
127
,
0
,
0
,
2
),
Port
:
0
}
client2
:=
&
net
.
TCPAddr
{
IP
:
net
.
IPv4
(
127
,
0
,
0
,
2
),
Port
:
0
}
...
@@ -408,7 +408,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) {
...
@@ -408,7 +408,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) {
t
.
Errorf
(
"Didn't fail with non-existent service"
)
t
.
Errorf
(
"Didn't fail with non-existent service"
)
}
}
// Call OnUpdate() before NewService()
// Call On
Endpoints
Update() before NewService()
endpoints
:=
make
([]
api
.
Endpoints
,
1
)
endpoints
:=
make
([]
api
.
Endpoints
,
1
)
endpoints
[
0
]
=
api
.
Endpoints
{
endpoints
[
0
]
=
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
...
@@ -417,7 +417,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) {
...
@@ -417,7 +417,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) {
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"endpoint2"
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
2
}}},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"endpoint2"
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
2
}}},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
loadBalancer
.
NewService
(
service
,
api
.
ServiceAffinityClientIP
,
0
)
loadBalancer
.
NewService
(
service
,
api
.
ServiceAffinityClientIP
,
0
)
client1
:=
&
net
.
TCPAddr
{
IP
:
net
.
IPv4
(
127
,
0
,
0
,
1
),
Port
:
0
}
client1
:=
&
net
.
TCPAddr
{
IP
:
net
.
IPv4
(
127
,
0
,
0
,
1
),
Port
:
0
}
...
@@ -481,7 +481,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
...
@@ -481,7 +481,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
:=
loadBalancer
.
services
[
service
]
.
endpoints
shuffledEndpoints
:=
loadBalancer
.
services
[
service
]
.
endpoints
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
client1Endpoint
:=
shuffledEndpoints
[
0
]
client1Endpoint
:=
shuffledEndpoints
[
0
]
...
@@ -501,7 +501,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
...
@@ -501,7 +501,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
=
loadBalancer
.
services
[
service
]
.
endpoints
shuffledEndpoints
=
loadBalancer
.
services
[
service
]
.
endpoints
if
client1Endpoint
==
"endpoint:3"
{
if
client1Endpoint
==
"endpoint:3"
{
client1Endpoint
=
shuffledEndpoints
[
0
]
client1Endpoint
=
shuffledEndpoints
[
0
]
...
@@ -523,7 +523,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
...
@@ -523,7 +523,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
=
loadBalancer
.
services
[
service
]
.
endpoints
shuffledEndpoints
=
loadBalancer
.
services
[
service
]
.
endpoints
expectEndpoint
(
t
,
loadBalancer
,
service
,
client1Endpoint
,
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
client1Endpoint
,
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
client2Endpoint
,
client2
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
client2Endpoint
,
client2
)
...
@@ -555,7 +555,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
...
@@ -555,7 +555,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
:=
loadBalancer
.
services
[
service
]
.
endpoints
shuffledEndpoints
:=
loadBalancer
.
services
[
service
]
.
endpoints
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
...
@@ -575,7 +575,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
...
@@ -575,7 +575,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledEndpoints
=
loadBalancer
.
services
[
service
]
.
endpoints
shuffledEndpoints
=
loadBalancer
.
services
[
service
]
.
endpoints
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
0
],
client1
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
1
],
client2
)
expectEndpoint
(
t
,
loadBalancer
,
service
,
shuffledEndpoints
[
1
],
client2
)
...
@@ -586,7 +586,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
...
@@ -586,7 +586,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
// Clear endpoints
// Clear endpoints
endpoints
[
0
]
=
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
nil
}
endpoints
[
0
]
=
api
.
Endpoints
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
},
Subsets
:
nil
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
service
,
nil
)
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
service
,
nil
)
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
...
@@ -626,7 +626,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
...
@@ -626,7 +626,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
},
},
},
},
}
}
loadBalancer
.
OnUpdate
(
endpoints
)
loadBalancer
.
On
Endpoints
Update
(
endpoints
)
shuffledFooEndpoints
:=
loadBalancer
.
services
[
fooService
]
.
endpoints
shuffledFooEndpoints
:=
loadBalancer
.
services
[
fooService
]
.
endpoints
expectEndpoint
(
t
,
loadBalancer
,
fooService
,
shuffledFooEndpoints
[
0
],
client1
)
expectEndpoint
(
t
,
loadBalancer
,
fooService
,
shuffledFooEndpoints
[
0
],
client1
)
...
@@ -648,7 +648,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
...
@@ -648,7 +648,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
expectEndpoint
(
t
,
loadBalancer
,
barService
,
shuffledBarEndpoints
[
1
],
client2
)
expectEndpoint
(
t
,
loadBalancer
,
barService
,
shuffledBarEndpoints
[
1
],
client2
)
// Then update the configuration by removing foo
// Then update the configuration by removing foo
loadBalancer
.
OnUpdate
(
endpoints
[
1
:
])
loadBalancer
.
On
Endpoints
Update
(
endpoints
[
1
:
])
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
fooService
,
nil
)
endpoint
,
err
=
loadBalancer
.
NextEndpoint
(
fooService
,
nil
)
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
if
err
==
nil
||
len
(
endpoint
)
!=
0
{
t
.
Errorf
(
"Didn't fail with non-existent service"
)
t
.
Errorf
(
"Didn't fail with non-existent service"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment