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
2992477c
Commit
2992477c
authored
Apr 03, 2023
by
Brad Davidson
Committed by
Brad Davidson
Apr 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debounce kubernetes service endpoint updates
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
ece4d8e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
16 deletions
+46
-16
tunnel.go
pkg/agent/tunnel/tunnel.go
+46
-16
No files found.
pkg/agent/tunnel/tunnel.go
View file @
2992477c
...
...
@@ -35,6 +35,10 @@ import (
"k8s.io/kubernetes/pkg/cluster/ports"
)
var
(
endpointDebounceDelay
=
time
.
Second
)
type
agentTunnel
struct
{
client
kubernetes
.
Interface
cidrs
cidranger
.
Ranger
...
...
@@ -306,9 +310,14 @@ func (a *agentTunnel) watchEndpoints(ctx context.Context, apiServerReady <-chan
<-
done
}()
var
cancelUpdate
context
.
CancelFunc
for
{
select
{
case
<-
ctx
.
Done
()
:
if
cancelUpdate
!=
nil
{
cancelUpdate
()
}
return
case
ev
,
ok
:=
<-
watch
.
ResultChan
()
:
endpoint
,
ok
:=
ev
.
Object
.
(
*
v1
.
Endpoints
)
...
...
@@ -317,28 +326,49 @@ func (a *agentTunnel) watchEndpoints(ctx context.Context, apiServerReady <-chan
continue
}
newAddresses
:=
util
.
GetAddresses
(
endpoint
)
if
reflect
.
DeepEqual
(
newAddresses
,
proxy
.
SupervisorAddresses
())
{
continue
if
cancelUpdate
!=
nil
{
cancelUpdate
()
}
proxy
.
Update
(
newAddresses
)
validEndpoint
:=
map
[
string
]
bool
{}
var
debounceCtx
context
.
Context
debounceCtx
,
cancelUpdate
=
context
.
WithCancel
(
ctx
)
// When joining the cluster, the apiserver adds, removes, and then readds itself to
// the endpoint list several times. This causes a bit of thrashing if we react to
// endpoint changes immediately. Instead, perform the endpoint update in a
// goroutine that sleeps for a short period before checking for changes and updating
// the proxy addresses. If another update occurs, the previous update operation
// will be cancelled and a new one queued.
go
func
()
{
select
{
case
<-
time
.
After
(
endpointDebounceDelay
)
:
case
<-
debounceCtx
.
Done
()
:
return
}
for
_
,
address
:=
range
proxy
.
SupervisorAddresses
()
{
validEndpoint
[
address
]
=
true
if
_
,
ok
:=
disconnect
[
address
];
!
ok
{
disconnect
[
address
]
=
a
.
connect
(
ctx
,
nil
,
address
,
tlsConfig
)
newAddresses
:=
util
.
GetAddresses
(
endpoint
)
if
reflect
.
DeepEqual
(
newAddresses
,
proxy
.
SupervisorAddresses
())
{
return
}
}
proxy
.
Update
(
newAddresses
)
for
address
,
cancel
:=
range
disconnect
{
if
!
validEndpoint
[
address
]
{
cancel
()
delete
(
disconnect
,
address
)
logrus
.
Infof
(
"Stopped tunnel to %s"
,
address
)
validEndpoint
:=
map
[
string
]
bool
{}
for
_
,
address
:=
range
proxy
.
SupervisorAddresses
()
{
validEndpoint
[
address
]
=
true
if
_
,
ok
:=
disconnect
[
address
];
!
ok
{
disconnect
[
address
]
=
a
.
connect
(
ctx
,
nil
,
address
,
tlsConfig
)
}
}
}
for
address
,
cancel
:=
range
disconnect
{
if
!
validEndpoint
[
address
]
{
cancel
()
delete
(
disconnect
,
address
)
logrus
.
Infof
(
"Stopped tunnel to %s"
,
address
)
}
}
}()
}
}
}
...
...
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