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
066549b4
Unverified
Commit
066549b4
authored
May 16, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #77892 from mikedanese/pluginwatcher
simplify pluginwatcher close by removing waitgroup
parents
730bc968
531a50c7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
22 deletions
+10
-22
plugin_watcher.go
pkg/kubelet/util/pluginwatcher/plugin_watcher.go
+10
-22
No files found.
pkg/kubelet/util/pluginwatcher/plugin_watcher.go
View file @
066549b4
...
@@ -39,10 +39,10 @@ import (
...
@@ -39,10 +39,10 @@ import (
type
Watcher
struct
{
type
Watcher
struct
{
path
string
path
string
deprecatedPath
string
deprecatedPath
string
stopCh
chan
interface
{}
stopCh
chan
struct
{}
stopped
chan
struct
{}
fs
utilfs
.
Filesystem
fs
utilfs
.
Filesystem
fsWatcher
*
fsnotify
.
Watcher
fsWatcher
*
fsnotify
.
Watcher
wg
sync
.
WaitGroup
mutex
sync
.
Mutex
mutex
sync
.
Mutex
handlers
map
[
string
]
PluginHandler
handlers
map
[
string
]
PluginHandler
...
@@ -88,7 +88,8 @@ func (w *Watcher) getHandler(pluginType string) (PluginHandler, bool) {
...
@@ -88,7 +88,8 @@ func (w *Watcher) getHandler(pluginType string) (PluginHandler, bool) {
// Start watches for the creation of plugin sockets at the path
// Start watches for the creation of plugin sockets at the path
func
(
w
*
Watcher
)
Start
()
error
{
func
(
w
*
Watcher
)
Start
()
error
{
klog
.
V
(
2
)
.
Infof
(
"Plugin Watcher Start at %s"
,
w
.
path
)
klog
.
V
(
2
)
.
Infof
(
"Plugin Watcher Start at %s"
,
w
.
path
)
w
.
stopCh
=
make
(
chan
interface
{})
w
.
stopCh
=
make
(
chan
struct
{})
w
.
stopped
=
make
(
chan
struct
{})
// Creating the directory to be watched if it doesn't exist yet,
// Creating the directory to be watched if it doesn't exist yet,
// and walks through the directory to discover the existing plugins.
// and walks through the directory to discover the existing plugins.
...
@@ -104,22 +105,20 @@ func (w *Watcher) Start() error {
...
@@ -104,22 +105,20 @@ func (w *Watcher) Start() error {
// Traverse plugin dir and add filesystem watchers before starting the plugin processing goroutine.
// Traverse plugin dir and add filesystem watchers before starting the plugin processing goroutine.
if
err
:=
w
.
traversePluginDir
(
w
.
path
);
err
!=
nil
{
if
err
:=
w
.
traversePluginDir
(
w
.
path
);
err
!=
nil
{
w
.
Stop
()
w
.
fsWatcher
.
Close
()
return
fmt
.
Errorf
(
"failed to traverse plugin socket path %q, err: %v"
,
w
.
path
,
err
)
return
fmt
.
Errorf
(
"failed to traverse plugin socket path %q, err: %v"
,
w
.
path
,
err
)
}
}
// Traverse deprecated plugin dir, if specified.
// Traverse deprecated plugin dir, if specified.
if
len
(
w
.
deprecatedPath
)
!=
0
{
if
len
(
w
.
deprecatedPath
)
!=
0
{
if
err
:=
w
.
traversePluginDir
(
w
.
deprecatedPath
);
err
!=
nil
{
if
err
:=
w
.
traversePluginDir
(
w
.
deprecatedPath
);
err
!=
nil
{
w
.
Stop
()
w
.
fsWatcher
.
Close
()
return
fmt
.
Errorf
(
"failed to traverse deprecated plugin socket path %q, err: %v"
,
w
.
deprecatedPath
,
err
)
return
fmt
.
Errorf
(
"failed to traverse deprecated plugin socket path %q, err: %v"
,
w
.
deprecatedPath
,
err
)
}
}
}
}
w
.
wg
.
Add
(
1
)
go
func
()
{
go
func
(
fsWatcher
*
fsnotify
.
Watcher
)
{
defer
close
(
w
.
stopped
)
defer
w
.
wg
.
Done
()
for
{
for
{
select
{
select
{
case
event
:=
<-
fsWatcher
.
Events
:
case
event
:=
<-
fsWatcher
.
Events
:
...
@@ -135,17 +134,15 @@ func (w *Watcher) Start() error {
...
@@ -135,17 +134,15 @@ func (w *Watcher) Start() error {
klog
.
Errorf
(
"error %v when handling delete event: %s"
,
err
,
event
)
klog
.
Errorf
(
"error %v when handling delete event: %s"
,
err
,
event
)
}
}
}
}
continue
case
err
:=
<-
fsWatcher
.
Errors
:
case
err
:=
<-
fsWatcher
.
Errors
:
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Errorf
(
"fsWatcher received error: %v"
,
err
)
klog
.
Errorf
(
"fsWatcher received error: %v"
,
err
)
}
}
continue
case
<-
w
.
stopCh
:
case
<-
w
.
stopCh
:
return
return
}
}
}
}
}(
fsWatcher
)
}()
return
nil
return
nil
}
}
...
@@ -154,18 +151,9 @@ func (w *Watcher) Start() error {
...
@@ -154,18 +151,9 @@ func (w *Watcher) Start() error {
func
(
w
*
Watcher
)
Stop
()
error
{
func
(
w
*
Watcher
)
Stop
()
error
{
close
(
w
.
stopCh
)
close
(
w
.
stopCh
)
c
:=
make
(
chan
struct
{})
var
once
sync
.
Once
closeFunc
:=
func
()
{
close
(
c
)
}
go
func
()
{
defer
once
.
Do
(
closeFunc
)
w
.
wg
.
Wait
()
}()
select
{
select
{
case
<-
c
:
case
<-
w
.
stopped
:
case
<-
time
.
After
(
11
*
time
.
Second
)
:
case
<-
time
.
After
(
11
*
time
.
Second
)
:
once
.
Do
(
closeFunc
)
return
fmt
.
Errorf
(
"timeout on stopping watcher"
)
return
fmt
.
Errorf
(
"timeout on stopping watcher"
)
}
}
...
...
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