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
18098ca0
Unverified
Commit
18098ca0
authored
Apr 21, 2022
by
Brad Davidson
Committed by
GitHub
Apr 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue with long-running apiserver endpoints watch (#5480)
Use ListWatch helpers to retry when the watch channel is closed. Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
3b1ae9cd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
apiaddresses_controller.go
pkg/etcd/apiaddresses_controller.go
+24
-12
No files found.
pkg/etcd/apiaddresses_controller.go
View file @
18098ca0
...
@@ -10,23 +10,38 @@ import (
...
@@ -10,23 +10,38 @@ import (
v1
"k8s.io/api/core/v1"
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/fields"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
toolswatch
"k8s.io/client-go/tools/watch"
)
)
func
registerEndpointsHandlers
(
ctx
context
.
Context
,
etcd
*
ETCD
)
error
{
func
registerEndpointsHandlers
(
ctx
context
.
Context
,
etcd
*
ETCD
)
{
if
etcd
.
config
.
DisableAPIServer
{
if
etcd
.
config
.
DisableAPIServer
{
return
nil
return
}
}
endpoints
:=
etcd
.
config
.
Runtime
.
Core
.
Core
()
.
V1
()
.
Endpoints
()
endpoints
:=
etcd
.
config
.
Runtime
.
Core
.
Core
()
.
V1
()
.
Endpoints
()
watch
,
err
:=
endpoints
.
Watch
(
metav1
.
NamespaceDefault
,
metav1
.
ListOptions
{
fieldSelector
:=
fields
.
Set
{
metav1
.
ObjectNameField
:
"kubernetes"
}
.
String
()
FieldSelector
:
fields
.
Set
{
"metadata.name"
:
"kubernetes"
}
.
String
(),
lw
:=
&
cache
.
ListWatch
{
ResourceVersion
:
"0"
,
ListFunc
:
func
(
options
metav1
.
ListOptions
)
(
object
runtime
.
Object
,
e
error
)
{
})
options
.
FieldSelector
=
fieldSelector
if
err
!=
nil
{
return
endpoints
.
List
(
metav1
.
NamespaceDefault
,
options
)
return
err
},
WatchFunc
:
func
(
options
metav1
.
ListOptions
)
(
i
watch
.
Interface
,
e
error
)
{
options
.
FieldSelector
=
fieldSelector
return
endpoints
.
Watch
(
metav1
.
NamespaceDefault
,
options
)
},
}
}
_
,
_
,
watch
,
done
:=
toolswatch
.
NewIndexerInformerWatcher
(
lw
,
&
v1
.
Endpoints
{})
go
func
()
{
<-
ctx
.
Done
()
watch
.
Stop
()
<-
done
}()
h
:=
&
handler
{
h
:=
&
handler
{
etcd
:
etcd
,
etcd
:
etcd
,
watch
:
watch
,
watch
:
watch
,
...
@@ -34,8 +49,6 @@ func registerEndpointsHandlers(ctx context.Context, etcd *ETCD) error {
...
@@ -34,8 +49,6 @@ func registerEndpointsHandlers(ctx context.Context, etcd *ETCD) error {
logrus
.
Infof
(
"Starting managed etcd apiserver addresses controller"
)
logrus
.
Infof
(
"Starting managed etcd apiserver addresses controller"
)
go
h
.
watchEndpoints
(
ctx
)
go
h
.
watchEndpoints
(
ctx
)
return
nil
}
}
type
handler
struct
{
type
handler
struct
{
...
@@ -53,8 +66,7 @@ func (h *handler) watchEndpoints(ctx context.Context) {
...
@@ -53,8 +66,7 @@ func (h *handler) watchEndpoints(ctx context.Context) {
case
ev
,
ok
:=
<-
h
.
watch
.
ResultChan
()
:
case
ev
,
ok
:=
<-
h
.
watch
.
ResultChan
()
:
endpoint
,
ok
:=
ev
.
Object
.
(
*
v1
.
Endpoints
)
endpoint
,
ok
:=
ev
.
Object
.
(
*
v1
.
Endpoints
)
if
!
ok
{
if
!
ok
{
logrus
.
Errorf
(
"Failed to watch apiserver addresses: could not convert event object to endpoint: %v"
,
ev
)
logrus
.
Fatalf
(
"Failed to watch apiserver addresses: could not convert event object to endpoint: %v"
,
ev
)
continue
}
}
w
:=
&
bytes
.
Buffer
{}
w
:=
&
bytes
.
Buffer
{}
...
...
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