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
34dccc5d
Commit
34dccc5d
authored
Sep 15, 2017
by
Jiaying Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes some races in deviceplugin manager_test.go and manager.go.
parent
98ed5dd8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
device_plugin_stub.go
pkg/kubelet/deviceplugin/device_plugin_stub.go
+2
-1
manager.go
pkg/kubelet/deviceplugin/manager.go
+3
-0
manager_test.go
pkg/kubelet/deviceplugin/manager_test.go
+11
-3
No files found.
pkg/kubelet/deviceplugin/device_plugin_stub.go
View file @
34dccc5d
...
@@ -70,7 +70,7 @@ func (m *Stub) Start() error {
...
@@ -70,7 +70,7 @@ func (m *Stub) Start() error {
// Wait till grpc server is ready.
// Wait till grpc server is ready.
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
services
:=
m
.
server
.
GetServiceInfo
()
services
:=
m
.
server
.
GetServiceInfo
()
if
len
(
services
)
>
0
{
if
len
(
services
)
>
1
{
break
break
}
}
time
.
Sleep
(
1
*
time
.
Second
)
time
.
Sleep
(
1
*
time
.
Second
)
...
@@ -83,6 +83,7 @@ func (m *Stub) Start() error {
...
@@ -83,6 +83,7 @@ func (m *Stub) Start() error {
// Stop stops the gRPC server
// Stop stops the gRPC server
func
(
m
*
Stub
)
Stop
()
error
{
func
(
m
*
Stub
)
Stop
()
error
{
m
.
server
.
Stop
()
m
.
server
.
Stop
()
close
(
m
.
stop
)
return
m
.
cleanup
()
return
m
.
cleanup
()
}
}
...
...
pkg/kubelet/deviceplugin/manager.go
View file @
34dccc5d
...
@@ -189,9 +189,12 @@ func (m *ManagerImpl) Register(ctx context.Context,
...
@@ -189,9 +189,12 @@ func (m *ManagerImpl) Register(ctx context.Context,
// Stop is the function that can stop the gRPC server.
// Stop is the function that can stop the gRPC server.
func
(
m
*
ManagerImpl
)
Stop
()
error
{
func
(
m
*
ManagerImpl
)
Stop
()
error
{
m
.
mutex
.
Lock
()
defer
m
.
mutex
.
Unlock
()
for
_
,
e
:=
range
m
.
endpoints
{
for
_
,
e
:=
range
m
.
endpoints
{
e
.
stop
()
e
.
stop
()
}
}
m
.
server
.
Stop
()
m
.
server
.
Stop
()
return
nil
return
nil
}
}
...
...
pkg/kubelet/deviceplugin/manager_test.go
View file @
34dccc5d
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
deviceplugin
package
deviceplugin
import
(
import
(
"sync/atomic"
"testing"
"testing"
"time"
"time"
...
@@ -40,7 +41,8 @@ func TestNewManagerImpl(t *testing.T) {
...
@@ -40,7 +41,8 @@ func TestNewManagerImpl(t *testing.T) {
}
}
func
TestNewManagerImplStart
(
t
*
testing
.
T
)
{
func
TestNewManagerImplStart
(
t
*
testing
.
T
)
{
setup
(
t
,
[]
*
pluginapi
.
Device
{},
func
(
n
string
,
a
,
u
,
r
[]
*
pluginapi
.
Device
)
{})
m
,
p
:=
setup
(
t
,
[]
*
pluginapi
.
Device
{},
func
(
n
string
,
a
,
u
,
r
[]
*
pluginapi
.
Device
)
{})
cleanup
(
t
,
m
,
p
)
}
}
// Tests that the device plugin manager correctly handles registration and re-registration by
// Tests that the device plugin manager correctly handles registration and re-registration by
...
@@ -54,9 +56,11 @@ func TestDevicePluginReRegistration(t *testing.T) {
...
@@ -54,9 +56,11 @@ func TestDevicePluginReRegistration(t *testing.T) {
callbackCount
:=
0
callbackCount
:=
0
callbackChan
:=
make
(
chan
int
)
callbackChan
:=
make
(
chan
int
)
var
stopping
int32
stopping
=
0
callback
:=
func
(
n
string
,
a
,
u
,
r
[]
*
pluginapi
.
Device
)
{
callback
:=
func
(
n
string
,
a
,
u
,
r
[]
*
pluginapi
.
Device
)
{
// Should be called twice, one for each plugin.
// Should be called twice, one for each plugin
registration, till we are stopping
.
if
callbackCount
>
1
{
if
callbackCount
>
1
&&
atomic
.
LoadInt32
(
&
stopping
)
<=
0
{
t
.
FailNow
()
t
.
FailNow
()
}
}
callbackCount
++
callbackCount
++
...
@@ -80,6 +84,10 @@ func TestDevicePluginReRegistration(t *testing.T) {
...
@@ -80,6 +84,10 @@ func TestDevicePluginReRegistration(t *testing.T) {
require
.
Equal
(
t
,
2
,
len
(
devices2
[
testResourceName
]),
"Devices shouldn't change."
)
require
.
Equal
(
t
,
2
,
len
(
devices2
[
testResourceName
]),
"Devices shouldn't change."
)
// Wait long enough to catch unexpected callbacks.
// Wait long enough to catch unexpected callbacks.
time
.
Sleep
(
5
*
time
.
Second
)
time
.
Sleep
(
5
*
time
.
Second
)
atomic
.
StoreInt32
(
&
stopping
,
1
)
cleanup
(
t
,
m
,
p1
)
p2
.
Stop
()
}
}
func
setup
(
t
*
testing
.
T
,
devs
[]
*
pluginapi
.
Device
,
callback
MonitorCallback
)
(
Manager
,
*
Stub
)
{
func
setup
(
t
*
testing
.
T
,
devs
[]
*
pluginapi
.
Device
,
callback
MonitorCallback
)
(
Manager
,
*
Stub
)
{
...
...
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