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
8dd1d27c
Commit
8dd1d27c
authored
Aug 12, 2018
by
Renaud Gaubert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated the device manager pluginwatcher handler
parent
78b55eb5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
137 additions
and
121 deletions
+137
-121
container_manager.go
pkg/kubelet/cm/container_manager.go
+5
-1
container_manager_linux.go
pkg/kubelet/cm/container_manager_linux.go
+2
-2
container_manager_stub.go
pkg/kubelet/cm/container_manager_stub.go
+2
-4
manager.go
pkg/kubelet/cm/devicemanager/manager.go
+83
-67
manager_stub.go
pkg/kubelet/cm/devicemanager/manager_stub.go
+3
-5
manager_test.go
pkg/kubelet/cm/devicemanager/manager_test.go
+40
-40
types.go
pkg/kubelet/cm/devicemanager/types.go
+1
-1
kubelet.go
pkg/kubelet/kubelet.go
+1
-1
No files found.
pkg/kubelet/cm/container_manager.go
View file @
8dd1d27c
...
@@ -95,7 +95,11 @@ type ContainerManager interface {
...
@@ -95,7 +95,11 @@ type ContainerManager interface {
// GetPodCgroupRoot returns the cgroup which contains all pods.
// GetPodCgroupRoot returns the cgroup which contains all pods.
GetPodCgroupRoot
()
string
GetPodCgroupRoot
()
string
GetPluginRegistrationHandlerCallback
()
pluginwatcher
.
RegisterCallbackFn
// GetPluginRegistrationHandler returns a plugin registration handler
// The pluginwatcher's Handlers allow to have a single module for handling
// registration.
GetPluginRegistrationHandler
()
pluginwatcher
.
PluginHandler
}
}
type
NodeConfig
struct
{
type
NodeConfig
struct
{
...
...
pkg/kubelet/cm/container_manager_linux.go
View file @
8dd1d27c
...
@@ -605,8 +605,8 @@ func (cm *containerManagerImpl) Start(node *v1.Node,
...
@@ -605,8 +605,8 @@ func (cm *containerManagerImpl) Start(node *v1.Node,
return
nil
return
nil
}
}
func
(
cm
*
containerManagerImpl
)
GetPluginRegistrationHandler
Callback
()
pluginwatcher
.
RegisterCallbackFn
{
func
(
cm
*
containerManagerImpl
)
GetPluginRegistrationHandler
()
pluginwatcher
.
PluginHandler
{
return
cm
.
deviceManager
.
GetWatcher
Callback
()
return
cm
.
deviceManager
.
GetWatcher
Handler
()
}
}
// TODO: move the GetResources logic to PodContainerManager.
// TODO: move the GetResources logic to PodContainerManager.
...
...
pkg/kubelet/cm/container_manager_stub.go
View file @
8dd1d27c
...
@@ -77,10 +77,8 @@ func (cm *containerManagerStub) GetCapacity() v1.ResourceList {
...
@@ -77,10 +77,8 @@ func (cm *containerManagerStub) GetCapacity() v1.ResourceList {
return
c
return
c
}
}
func
(
cm
*
containerManagerStub
)
GetPluginRegistrationHandlerCallback
()
pluginwatcher
.
RegisterCallbackFn
{
func
(
cm
*
containerManagerStub
)
GetPluginRegistrationHandler
()
pluginwatcher
.
PluginHandler
{
return
func
(
name
string
,
endpoint
string
,
versions
[]
string
,
sockPath
string
)
(
chan
bool
,
error
)
{
return
nil
return
nil
,
nil
}
}
}
func
(
cm
*
containerManagerStub
)
GetDevicePluginResourceCapacity
()
(
v1
.
ResourceList
,
v1
.
ResourceList
,
[]
string
)
{
func
(
cm
*
containerManagerStub
)
GetDevicePluginResourceCapacity
()
(
v1
.
ResourceList
,
v1
.
ResourceList
,
[]
string
)
{
...
...
pkg/kubelet/cm/devicemanager/manager.go
View file @
8dd1d27c
This diff is collapsed.
Click to expand it.
pkg/kubelet/cm/devicemanager/manager_stub.go
View file @
8dd1d27c
...
@@ -57,9 +57,7 @@ func (h *ManagerStub) GetCapacity() (v1.ResourceList, v1.ResourceList, []string)
...
@@ -57,9 +57,7 @@ func (h *ManagerStub) GetCapacity() (v1.ResourceList, v1.ResourceList, []string)
return
nil
,
nil
,
[]
string
{}
return
nil
,
nil
,
[]
string
{}
}
}
// GetWatcherCallback returns plugin watcher callback
// GetWatcherHandler returns plugin watcher interface
func
(
h
*
ManagerStub
)
GetWatcherCallback
()
pluginwatcher
.
RegisterCallbackFn
{
func
(
h
*
ManagerStub
)
GetWatcherHandler
()
pluginwatcher
.
PluginHandler
{
return
func
(
name
string
,
endpoint
string
,
versions
[]
string
,
sockPath
string
)
(
chan
bool
,
error
)
{
return
nil
return
nil
,
nil
}
}
}
pkg/kubelet/cm/devicemanager/manager_test.go
View file @
8dd1d27c
...
@@ -249,9 +249,10 @@ func setupDevicePlugin(t *testing.T, devs []*pluginapi.Device, pluginSocketName
...
@@ -249,9 +249,10 @@ func setupDevicePlugin(t *testing.T, devs []*pluginapi.Device, pluginSocketName
func
setupPluginWatcher
(
pluginSocketName
string
,
m
Manager
)
*
pluginwatcher
.
Watcher
{
func
setupPluginWatcher
(
pluginSocketName
string
,
m
Manager
)
*
pluginwatcher
.
Watcher
{
w
:=
pluginwatcher
.
NewWatcher
(
filepath
.
Dir
(
pluginSocketName
))
w
:=
pluginwatcher
.
NewWatcher
(
filepath
.
Dir
(
pluginSocketName
))
w
.
AddHandler
(
watcherapi
.
DevicePlugin
,
m
.
GetWatcher
Callback
())
w
.
AddHandler
(
watcherapi
.
DevicePlugin
,
m
.
GetWatcher
Handler
())
w
.
Start
()
w
.
Start
()
return
&
w
return
w
}
}
func
setup
(
t
*
testing
.
T
,
devs
[]
*
pluginapi
.
Device
,
callback
monitorCallback
,
socketName
string
,
pluginSocketName
string
)
(
Manager
,
<-
chan
interface
{},
*
Stub
)
{
func
setup
(
t
*
testing
.
T
,
devs
[]
*
pluginapi
.
Device
,
callback
monitorCallback
,
socketName
string
,
pluginSocketName
string
)
(
Manager
,
<-
chan
interface
{},
*
Stub
)
{
...
@@ -295,7 +296,7 @@ func TestUpdateCapacityAllocatable(t *testing.T) {
...
@@ -295,7 +296,7 @@ func TestUpdateCapacityAllocatable(t *testing.T) {
// Expects capacity for resource1 to be 2.
// Expects capacity for resource1 to be 2.
resourceName1
:=
"domain1.com/resource1"
resourceName1
:=
"domain1.com/resource1"
e1
:=
&
endpointImpl
{}
e1
:=
&
endpointImpl
{}
testManager
.
endpoints
[
resourceName1
]
=
e
1
testManager
.
endpoints
[
resourceName1
]
=
e
ndpointInfo
{
e
:
e1
,
opts
:
nil
}
callback
(
resourceName1
,
devs
)
callback
(
resourceName1
,
devs
)
capacity
,
allocatable
,
removedResources
:=
testManager
.
GetCapacity
()
capacity
,
allocatable
,
removedResources
:=
testManager
.
GetCapacity
()
resource1Capacity
,
ok
:=
capacity
[
v1
.
ResourceName
(
resourceName1
)]
resource1Capacity
,
ok
:=
capacity
[
v1
.
ResourceName
(
resourceName1
)]
...
@@ -345,7 +346,7 @@ func TestUpdateCapacityAllocatable(t *testing.T) {
...
@@ -345,7 +346,7 @@ func TestUpdateCapacityAllocatable(t *testing.T) {
// Tests adding another resource.
// Tests adding another resource.
resourceName2
:=
"resource2"
resourceName2
:=
"resource2"
e2
:=
&
endpointImpl
{}
e2
:=
&
endpointImpl
{}
testManager
.
endpoints
[
resourceName2
]
=
e
2
testManager
.
endpoints
[
resourceName2
]
=
e
ndpointInfo
{
e
:
e2
,
opts
:
nil
}
callback
(
resourceName2
,
devs
)
callback
(
resourceName2
,
devs
)
capacity
,
allocatable
,
removedResources
=
testManager
.
GetCapacity
()
capacity
,
allocatable
,
removedResources
=
testManager
.
GetCapacity
()
as
.
Equal
(
2
,
len
(
capacity
))
as
.
Equal
(
2
,
len
(
capacity
))
...
@@ -456,7 +457,7 @@ func TestCheckpoint(t *testing.T) {
...
@@ -456,7 +457,7 @@ func TestCheckpoint(t *testing.T) {
ckm
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
tmpDir
)
ckm
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
tmpDir
)
as
.
Nil
(
err
)
as
.
Nil
(
err
)
testManager
:=
&
ManagerImpl
{
testManager
:=
&
ManagerImpl
{
endpoints
:
make
(
map
[
string
]
endpoint
),
endpoints
:
make
(
map
[
string
]
endpoint
Info
),
healthyDevices
:
make
(
map
[
string
]
sets
.
String
),
healthyDevices
:
make
(
map
[
string
]
sets
.
String
),
unhealthyDevices
:
make
(
map
[
string
]
sets
.
String
),
unhealthyDevices
:
make
(
map
[
string
]
sets
.
String
),
allocatedDevices
:
make
(
map
[
string
]
sets
.
String
),
allocatedDevices
:
make
(
map
[
string
]
sets
.
String
),
...
@@ -577,7 +578,7 @@ func makePod(limits v1.ResourceList) *v1.Pod {
...
@@ -577,7 +578,7 @@ func makePod(limits v1.ResourceList) *v1.Pod {
}
}
}
}
func
getTestManager
(
tmpDir
string
,
activePods
ActivePodsFunc
,
testRes
[]
TestResource
,
opts
map
[
string
]
*
pluginapi
.
DevicePluginOptions
)
(
*
ManagerImpl
,
error
)
{
func
getTestManager
(
tmpDir
string
,
activePods
ActivePodsFunc
,
testRes
[]
TestResource
)
(
*
ManagerImpl
,
error
)
{
monitorCallback
:=
func
(
resourceName
string
,
devices
[]
pluginapi
.
Device
)
{}
monitorCallback
:=
func
(
resourceName
string
,
devices
[]
pluginapi
.
Device
)
{}
ckm
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
tmpDir
)
ckm
,
err
:=
checkpointmanager
.
NewCheckpointManager
(
tmpDir
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -589,41 +590,45 @@ func getTestManager(tmpDir string, activePods ActivePodsFunc, testRes []TestReso
...
@@ -589,41 +590,45 @@ func getTestManager(tmpDir string, activePods ActivePodsFunc, testRes []TestReso
healthyDevices
:
make
(
map
[
string
]
sets
.
String
),
healthyDevices
:
make
(
map
[
string
]
sets
.
String
),
unhealthyDevices
:
make
(
map
[
string
]
sets
.
String
),
unhealthyDevices
:
make
(
map
[
string
]
sets
.
String
),
allocatedDevices
:
make
(
map
[
string
]
sets
.
String
),
allocatedDevices
:
make
(
map
[
string
]
sets
.
String
),
endpoints
:
make
(
map
[
string
]
endpoint
),
endpoints
:
make
(
map
[
string
]
endpointInfo
),
pluginOpts
:
opts
,
podDevices
:
make
(
podDevices
),
podDevices
:
make
(
podDevices
),
activePods
:
activePods
,
activePods
:
activePods
,
sourcesReady
:
&
sourcesReadyStub
{},
sourcesReady
:
&
sourcesReadyStub
{},
checkpointManager
:
ckm
,
checkpointManager
:
ckm
,
}
}
for
_
,
res
:=
range
testRes
{
for
_
,
res
:=
range
testRes
{
testManager
.
healthyDevices
[
res
.
resourceName
]
=
sets
.
NewString
()
testManager
.
healthyDevices
[
res
.
resourceName
]
=
sets
.
NewString
()
for
_
,
dev
:=
range
res
.
devs
{
for
_
,
dev
:=
range
res
.
devs
{
testManager
.
healthyDevices
[
res
.
resourceName
]
.
Insert
(
dev
)
testManager
.
healthyDevices
[
res
.
resourceName
]
.
Insert
(
dev
)
}
}
if
res
.
resourceName
==
"domain1.com/resource1"
{
if
res
.
resourceName
==
"domain1.com/resource1"
{
testManager
.
endpoints
[
res
.
resourceName
]
=
&
MockEndpoint
{
testManager
.
endpoints
[
res
.
resourceName
]
=
endpointInfo
{
allocateFunc
:
allocateStubFunc
(),
e
:
&
MockEndpoint
{
allocateFunc
:
allocateStubFunc
()},
opts
:
nil
,
}
}
}
}
if
res
.
resourceName
==
"domain2.com/resource2"
{
if
res
.
resourceName
==
"domain2.com/resource2"
{
testManager
.
endpoints
[
res
.
resourceName
]
=
&
MockEndpoint
{
testManager
.
endpoints
[
res
.
resourceName
]
=
endpointInfo
{
allocateFunc
:
func
(
devs
[]
string
)
(
*
pluginapi
.
AllocateResponse
,
error
)
{
e
:
&
MockEndpoint
{
resp
:=
new
(
pluginapi
.
ContainerAllocateResponse
)
allocateFunc
:
func
(
devs
[]
string
)
(
*
pluginapi
.
AllocateResponse
,
error
)
{
resp
.
Envs
=
make
(
map
[
string
]
string
)
resp
:=
new
(
pluginapi
.
ContainerAllocateResponse
)
for
_
,
dev
:=
range
devs
{
resp
.
Envs
=
make
(
map
[
string
]
string
)
switch
dev
{
for
_
,
dev
:=
range
devs
{
case
"dev3"
:
switch
dev
{
resp
.
Envs
[
"key2"
]
=
"val2"
case
"dev3"
:
resp
.
Envs
[
"key2"
]
=
"val2"
case
"dev4"
:
resp
.
Envs
[
"key2"
]
=
"val3"
case
"dev4"
:
resp
.
Envs
[
"key2"
]
=
"val3"
}
}
}
}
resps
:=
new
(
pluginapi
.
AllocateResponse
)
resps
:=
new
(
pluginapi
.
AllocateResponse
)
resps
.
ContainerResponses
=
append
(
resps
.
ContainerResponses
,
resp
)
resps
.
ContainerResponses
=
append
(
resps
.
ContainerResponses
,
resp
)
return
resps
,
nil
return
resps
,
nil
},
},
},
opts
:
nil
,
}
}
}
}
}
}
...
@@ -669,10 +674,7 @@ func TestPodContainerDeviceAllocation(t *testing.T) {
...
@@ -669,10 +674,7 @@ func TestPodContainerDeviceAllocation(t *testing.T) {
as
.
Nil
(
err
)
as
.
Nil
(
err
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
nodeInfo
:=
getTestNodeInfo
(
v1
.
ResourceList
{})
nodeInfo
:=
getTestNodeInfo
(
v1
.
ResourceList
{})
pluginOpts
:=
make
(
map
[
string
]
*
pluginapi
.
DevicePluginOptions
)
testManager
,
err
:=
getTestManager
(
tmpDir
,
podsStub
.
getActivePods
,
testResources
)
pluginOpts
[
res1
.
resourceName
]
=
nil
pluginOpts
[
res2
.
resourceName
]
=
nil
testManager
,
err
:=
getTestManager
(
tmpDir
,
podsStub
.
getActivePods
,
testResources
,
pluginOpts
)
as
.
Nil
(
err
)
as
.
Nil
(
err
)
testPods
:=
[]
*
v1
.
Pod
{
testPods
:=
[]
*
v1
.
Pod
{
...
@@ -767,10 +769,8 @@ func TestInitContainerDeviceAllocation(t *testing.T) {
...
@@ -767,10 +769,8 @@ func TestInitContainerDeviceAllocation(t *testing.T) {
tmpDir
,
err
:=
ioutil
.
TempDir
(
""
,
"checkpoint"
)
tmpDir
,
err
:=
ioutil
.
TempDir
(
""
,
"checkpoint"
)
as
.
Nil
(
err
)
as
.
Nil
(
err
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
pluginOpts
:=
make
(
map
[
string
]
*
pluginapi
.
DevicePluginOptions
)
pluginOpts
[
res1
.
resourceName
]
=
nil
testManager
,
err
:=
getTestManager
(
tmpDir
,
podsStub
.
getActivePods
,
testResources
)
pluginOpts
[
res2
.
resourceName
]
=
nil
testManager
,
err
:=
getTestManager
(
tmpDir
,
podsStub
.
getActivePods
,
testResources
,
pluginOpts
)
as
.
Nil
(
err
)
as
.
Nil
(
err
)
podWithPluginResourcesInInitContainers
:=
&
v1
.
Pod
{
podWithPluginResourcesInInitContainers
:=
&
v1
.
Pod
{
...
@@ -904,18 +904,18 @@ func TestDevicePreStartContainer(t *testing.T) {
...
@@ -904,18 +904,18 @@ func TestDevicePreStartContainer(t *testing.T) {
as
.
Nil
(
err
)
as
.
Nil
(
err
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
nodeInfo
:=
getTestNodeInfo
(
v1
.
ResourceList
{})
nodeInfo
:=
getTestNodeInfo
(
v1
.
ResourceList
{})
pluginOpts
:=
make
(
map
[
string
]
*
pluginapi
.
DevicePluginOptions
)
pluginOpts
[
res1
.
resourceName
]
=
&
pluginapi
.
DevicePluginOptions
{
PreStartRequired
:
true
}
testManager
,
err
:=
getTestManager
(
tmpDir
,
podsStub
.
getActivePods
,
[]
TestResource
{
res1
}
,
pluginOpts
)
testManager
,
err
:=
getTestManager
(
tmpDir
,
podsStub
.
getActivePods
,
[]
TestResource
{
res1
})
as
.
Nil
(
err
)
as
.
Nil
(
err
)
ch
:=
make
(
chan
[]
string
,
1
)
ch
:=
make
(
chan
[]
string
,
1
)
testManager
.
endpoints
[
res1
.
resourceName
]
=
&
MockEndpoint
{
testManager
.
endpoints
[
res1
.
resourceName
]
=
endpointInfo
{
initChan
:
ch
,
e
:
&
MockEndpoint
{
allocateFunc
:
allocateStubFunc
(),
initChan
:
ch
,
allocateFunc
:
allocateStubFunc
(),
},
opts
:
&
pluginapi
.
DevicePluginOptions
{
PreStartRequired
:
true
},
}
}
pod
:=
makePod
(
v1
.
ResourceList
{
pod
:=
makePod
(
v1
.
ResourceList
{
v1
.
ResourceName
(
res1
.
resourceName
)
:
res1
.
resourceQuantity
})
v1
.
ResourceName
(
res1
.
resourceName
)
:
res1
.
resourceQuantity
})
activePods
:=
[]
*
v1
.
Pod
{}
activePods
:=
[]
*
v1
.
Pod
{}
...
...
pkg/kubelet/cm/devicemanager/types.go
View file @
8dd1d27c
...
@@ -53,7 +53,7 @@ type Manager interface {
...
@@ -53,7 +53,7 @@ type Manager interface {
// GetCapacity returns the amount of available device plugin resource capacity, resource allocatable
// GetCapacity returns the amount of available device plugin resource capacity, resource allocatable
// and inactive device plugin resources previously registered on the node.
// and inactive device plugin resources previously registered on the node.
GetCapacity
()
(
v1
.
ResourceList
,
v1
.
ResourceList
,
[]
string
)
GetCapacity
()
(
v1
.
ResourceList
,
v1
.
ResourceList
,
[]
string
)
GetWatcher
Callback
()
watcher
.
RegisterCallbackFn
GetWatcher
Handler
()
watcher
.
PluginHandler
}
}
// DeviceRunContainerOptions contains the combined container runtime settings to consume its allocated devices.
// DeviceRunContainerOptions contains the combined container runtime settings to consume its allocated devices.
...
...
pkg/kubelet/kubelet.go
View file @
8dd1d27c
...
@@ -1367,7 +1367,7 @@ func (kl *Kubelet) initializeRuntimeDependentModules() {
...
@@ -1367,7 +1367,7 @@ func (kl *Kubelet) initializeRuntimeDependentModules() {
// Adding Registration Callback function for CSI Driver
// Adding Registration Callback function for CSI Driver
kl
.
pluginWatcher
.
AddHandler
(
"CSIPlugin"
,
pluginwatcher
.
PluginHandler
(
csi
.
PluginHandler
))
kl
.
pluginWatcher
.
AddHandler
(
"CSIPlugin"
,
pluginwatcher
.
PluginHandler
(
csi
.
PluginHandler
))
// Adding Registration Callback function for Device Manager
// Adding Registration Callback function for Device Manager
kl
.
pluginWatcher
.
AddHandler
(
pluginwatcherapi
.
DevicePlugin
,
kl
.
containerManager
.
GetPluginRegistrationHandler
Callback
())
kl
.
pluginWatcher
.
AddHandler
(
pluginwatcherapi
.
DevicePlugin
,
kl
.
containerManager
.
GetPluginRegistrationHandler
())
// Start the plugin watcher
// Start the plugin watcher
glog
.
V
(
4
)
.
Infof
(
"starting watcher"
)
glog
.
V
(
4
)
.
Infof
(
"starting watcher"
)
if
err
:=
kl
.
pluginWatcher
.
Start
();
err
!=
nil
{
if
err
:=
kl
.
pluginWatcher
.
Start
();
err
!=
nil
{
...
...
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