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
185eb5e2
Commit
185eb5e2
authored
Jun 16, 2015
by
Saad Ali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9912 from justinsb/loadbalancer_logic
servicecontroller: last state applied to LB vs last state seen
parents
9f60f3ce
1561fce8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
servicecontroller.go
pkg/cloudprovider/servicecontroller/servicecontroller.go
+14
-7
servicecontroller_test.go
...cloudprovider/servicecontroller/servicecontroller_test.go
+1
-1
No files found.
pkg/cloudprovider/servicecontroller/servicecontroller.go
View file @
185eb5e2
...
@@ -52,7 +52,11 @@ const (
...
@@ -52,7 +52,11 @@ const (
)
)
type
cachedService
struct
{
type
cachedService
struct
{
service
*
api
.
Service
// The last-known state of the service
lastState
*
api
.
Service
// The state as successfully applied to the load balancer
appliedState
*
api
.
Service
// Ensures only one goroutine can operate on this service at any given time.
// Ensures only one goroutine can operate on this service at any given time.
mu
sync
.
Mutex
mu
sync
.
Mutex
}
}
...
@@ -191,8 +195,8 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
...
@@ -191,8 +195,8 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"Service %s not in cache even though the watcher thought it was. Ignoring the deletion."
,
key
),
notRetryable
return
fmt
.
Errorf
(
"Service %s not in cache even though the watcher thought it was. Ignoring the deletion."
,
key
),
notRetryable
}
}
service
=
cachedService
.
servic
e
service
=
cachedService
.
lastStat
e
delta
.
Object
=
cachedService
.
servic
e
delta
.
Object
=
cachedService
.
lastStat
e
namespacedName
=
types
.
NamespacedName
{
service
.
Namespace
,
service
.
Name
}
namespacedName
=
types
.
NamespacedName
{
service
.
Namespace
,
service
.
Name
}
}
else
{
}
else
{
namespacedName
.
Namespace
=
service
.
Namespace
namespacedName
.
Namespace
=
service
.
Namespace
...
@@ -206,6 +210,9 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
...
@@ -206,6 +210,9 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
cachedService
.
mu
.
Lock
()
cachedService
.
mu
.
Lock
()
defer
cachedService
.
mu
.
Unlock
()
defer
cachedService
.
mu
.
Unlock
()
// Update the cached service (used above for populating synthetic deletes)
cachedService
.
lastState
=
service
// TODO: Handle added, updated, and sync differently?
// TODO: Handle added, updated, and sync differently?
switch
delta
.
Type
{
switch
delta
.
Type
{
case
cache
.
Added
:
case
cache
.
Added
:
...
@@ -213,7 +220,7 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
...
@@ -213,7 +220,7 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
case
cache
.
Updated
:
case
cache
.
Updated
:
fallthrough
fallthrough
case
cache
.
Sync
:
case
cache
.
Sync
:
err
,
retry
:=
s
.
createLoadBalancerIfNeeded
(
namespacedName
,
service
,
cachedService
.
servic
e
)
err
,
retry
:=
s
.
createLoadBalancerIfNeeded
(
namespacedName
,
service
,
cachedService
.
appliedStat
e
)
if
err
!=
nil
{
if
err
!=
nil
{
s
.
eventRecorder
.
Event
(
service
,
"creating loadbalancer failed"
,
err
.
Error
())
s
.
eventRecorder
.
Event
(
service
,
"creating loadbalancer failed"
,
err
.
Error
())
return
err
,
retry
return
err
,
retry
...
@@ -222,7 +229,7 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
...
@@ -222,7 +229,7 @@ func (s *ServiceController) processDelta(delta *cache.Delta) (error, bool) {
// NOTE: Since we update the cached service if and only if we successully
// NOTE: Since we update the cached service if and only if we successully
// processed it, a cached service being nil implies that it hasn't yet
// processed it, a cached service being nil implies that it hasn't yet
// been successfully processed.
// been successfully processed.
cachedService
.
servic
e
=
service
cachedService
.
appliedStat
e
=
service
s
.
cache
.
set
(
namespacedName
.
String
(),
cachedService
)
s
.
cache
.
set
(
namespacedName
.
String
(),
cachedService
)
case
cache
.
Deleted
:
case
cache
.
Deleted
:
err
:=
s
.
balancer
.
EnsureTCPLoadBalancerDeleted
(
s
.
loadBalancerName
(
service
),
s
.
zone
.
Region
)
err
:=
s
.
balancer
.
EnsureTCPLoadBalancerDeleted
(
s
.
loadBalancerName
(
service
),
s
.
zone
.
Region
)
...
@@ -609,10 +616,10 @@ func (s *ServiceController) updateLoadBalancerHosts(services []*cachedService, h
...
@@ -609,10 +616,10 @@ func (s *ServiceController) updateLoadBalancerHosts(services []*cachedService, h
// with by the load balancer reconciler. We can trust the load balancer
// with by the load balancer reconciler. We can trust the load balancer
// reconciler to ensure the service's load balancer is created to target
// reconciler to ensure the service's load balancer is created to target
// the correct nodes.
// the correct nodes.
if
service
.
servic
e
==
nil
{
if
service
.
appliedStat
e
==
nil
{
return
return
}
}
if
err
:=
s
.
lockedUpdateLoadBalancerHosts
(
service
.
servic
e
,
hosts
);
err
!=
nil
{
if
err
:=
s
.
lockedUpdateLoadBalancerHosts
(
service
.
appliedStat
e
,
hosts
);
err
!=
nil
{
glog
.
Errorf
(
"External error while updating TCP load balancer: %v."
,
err
)
glog
.
Errorf
(
"External error while updating TCP load balancer: %v."
,
err
)
servicesToRetry
=
append
(
servicesToRetry
,
service
)
servicesToRetry
=
append
(
servicesToRetry
,
service
)
}
}
...
...
pkg/cloudprovider/servicecontroller/servicecontroller_test.go
View file @
185eb5e2
...
@@ -206,7 +206,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
...
@@ -206,7 +206,7 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
var
services
[]
*
cachedService
var
services
[]
*
cachedService
for
_
,
service
:=
range
item
.
services
{
for
_
,
service
:=
range
item
.
services
{
services
=
append
(
services
,
&
cachedService
{
servic
e
:
service
})
services
=
append
(
services
,
&
cachedService
{
lastState
:
service
,
appliedStat
e
:
service
})
}
}
if
err
:=
controller
.
updateLoadBalancerHosts
(
services
,
hosts
);
err
!=
nil
{
if
err
:=
controller
.
updateLoadBalancerHosts
(
services
,
hosts
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
...
...
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