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
e0f89a32
Commit
e0f89a32
authored
Oct 31, 2016
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CRI: Add devices implementation and moves GPU to devices
parent
c53fee77
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
10 deletions
+89
-10
docker_container.go
pkg/kubelet/dockershim/docker_container.go
+11
-1
docker_manager.go
pkg/kubelet/dockertools/docker_manager.go
+9
-9
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+18
-0
kubelet_pods_test.go
pkg/kubelet/kubelet_pods_test.go
+34
-0
kuberuntime_container.go
pkg/kubelet/kuberuntime/kuberuntime_container.go
+17
-0
No files found.
pkg/kubelet/dockershim/docker_container.go
View file @
e0f89a32
...
...
@@ -162,13 +162,23 @@ func (ds *dockerService) CreateContainer(podSandboxID string, config *runtimeApi
CPUShares
:
rOpts
.
GetCpuShares
(),
CPUQuota
:
rOpts
.
GetCpuQuota
(),
CPUPeriod
:
rOpts
.
GetCpuPeriod
(),
// TODO: Need to set devices.
}
hc
.
OomScoreAdj
=
int
(
rOpts
.
GetOomScoreAdj
())
}
// Note: ShmSize is handled in kube_docker_client.go
}
// Set devices for container.
devices
:=
make
([]
dockercontainer
.
DeviceMapping
,
len
(
config
.
Devices
))
for
i
,
device
:=
range
config
.
Devices
{
devices
[
i
]
=
dockercontainer
.
DeviceMapping
{
PathOnHost
:
device
.
GetHostPath
(),
PathInContainer
:
device
.
GetContainerPath
(),
CgroupPermissions
:
device
.
GetPermissions
(),
}
}
hc
.
Resources
.
Devices
=
devices
var
err
error
hc
.
SecurityOpt
,
err
=
getContainerSecurityOpts
(
config
.
Metadata
.
GetName
(),
sandboxConfig
,
ds
.
seccompProfileRoot
)
if
err
!=
nil
{
...
...
pkg/kubelet/dockertools/docker_manager.go
View file @
e0f89a32
...
...
@@ -619,7 +619,6 @@ func (dm *DockerManager) runContainer(
memoryLimit
:=
container
.
Resources
.
Limits
.
Memory
()
.
Value
()
cpuRequest
:=
container
.
Resources
.
Requests
.
Cpu
()
cpuLimit
:=
container
.
Resources
.
Limits
.
Cpu
()
nvidiaGPULimit
:=
container
.
Resources
.
Limits
.
NvidiaGPU
()
var
cpuShares
int64
// If request is not specified, but limit is, we want request to default to limit.
// API server does this for new containers, but we repeat this logic in Kubelet
...
...
@@ -631,17 +630,18 @@ func (dm *DockerManager) runContainer(
// of CPU shares.
cpuShares
=
milliCPUToShares
(
cpuRequest
.
MilliValue
())
}
var
devices
[]
dockercontainer
.
DeviceMapping
if
nvidiaGPULimit
.
Value
()
!=
0
{
// Experimental. For now, we hardcode /dev/nvidia0 no matter what the user asks for
// (we only support one device per node).
devices
=
[]
dockercontainer
.
DeviceMapping
{
{
PathOnHost
:
"/dev/nvidia0"
,
PathInContainer
:
"/dev/nvidia0"
,
CgroupPermissions
:
"mrw"
}
,
{
PathOnHost
:
"/dev/nvidiactl"
,
PathInContainer
:
"/dev/nvidiactl"
,
CgroupPermissions
:
"mrw"
}
,
{
PathOnHost
:
"/dev/nvidia-uvm"
,
PathInContainer
:
"/dev/nvidia-uvm"
,
CgroupPermissions
:
"mrw"
}
,
// Set devices for container.
devices
:=
make
([]
dockercontainer
.
DeviceMapping
,
len
(
opts
.
Devices
))
for
i
,
device
:=
range
opts
.
Devices
{
devices
[
i
]
=
dockercontainer
.
DeviceMapping
{
PathOnHost
:
device
.
PathOnHost
,
PathInContainer
:
device
.
PathInContainer
,
CgroupPermissions
:
device
.
Permissions
,
}
}
binds
:=
makeMountBindings
(
opts
.
Mounts
)
// The reason we create and mount the log file in here (not in kubelet) is because
// the file's location depends on the ID of the container, and we need to create and
// mount the file before actually starting the container.
...
...
pkg/kubelet/kubelet_pods.go
View file @
e0f89a32
...
...
@@ -74,6 +74,23 @@ func (kl *Kubelet) getActivePods() []*api.Pod {
return
activePods
}
// makeDevices determines the devices for the given container.
// Experimental. For now, we hardcode /dev/nvidia0 no matter what the user asks for
// (we only support one device per node).
// TODO: add support for more than 1 GPU after #28216.
func
makeDevices
(
container
*
api
.
Container
)
[]
kubecontainer
.
DeviceInfo
{
nvidiaGPULimit
:=
container
.
Resources
.
Limits
.
NvidiaGPU
()
if
nvidiaGPULimit
.
Value
()
!=
0
{
return
[]
kubecontainer
.
DeviceInfo
{
{
PathOnHost
:
"/dev/nvidia0"
,
PathInContainer
:
"/dev/nvidia0"
,
Permissions
:
"mrw"
},
{
PathOnHost
:
"/dev/nvidiactl"
,
PathInContainer
:
"/dev/nvidiactl"
,
Permissions
:
"mrw"
},
{
PathOnHost
:
"/dev/nvidia-uvm"
,
PathInContainer
:
"/dev/nvidia-uvm"
,
Permissions
:
"mrw"
},
}
}
return
nil
}
// makeMounts determines the mount points for the given container.
func
makeMounts
(
pod
*
api
.
Pod
,
podDir
string
,
container
*
api
.
Container
,
hostName
,
hostDomain
,
podIP
string
,
podVolumes
kubecontainer
.
VolumeMap
)
([]
kubecontainer
.
Mount
,
error
)
{
// Kubernetes only mounts on /etc/hosts if :
...
...
@@ -252,6 +269,7 @@ func (kl *Kubelet) GenerateRunContainerOptions(pod *api.Pod, container *api.Cont
volumes
:=
kl
.
volumeManager
.
GetMountedVolumesForPod
(
podName
)
opts
.
PortMappings
=
makePortMappings
(
container
)
opts
.
Devices
=
makeDevices
(
container
)
opts
.
Mounts
,
err
=
makeMounts
(
pod
,
kl
.
getPodDir
(
pod
.
UID
),
container
,
hostname
,
hostDomainName
,
podIP
,
volumes
)
if
err
!=
nil
{
...
...
pkg/kubelet/kubelet_pods_test.go
View file @
e0f89a32
...
...
@@ -28,6 +28,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/apimachinery/registered"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
containertest
"k8s.io/kubernetes/pkg/kubelet/container/testing"
...
...
@@ -1262,3 +1263,36 @@ func TestGetHostPortConflicts(t *testing.T) {
pods
=
append
(
pods
,
expected
)
assert
.
True
(
t
,
hasHostPortConflicts
(
pods
),
"Should have port conflicts"
)
}
func
TestMakeDevices
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
container
*
api
.
Container
devices
[]
kubecontainer
.
DeviceInfo
test
string
}{
{
test
:
"no device"
,
container
:
&
api
.
Container
{},
devices
:
nil
,
},
{
test
:
"gpu"
,
container
:
&
api
.
Container
{
Resources
:
api
.
ResourceRequirements
{
Limits
:
map
[
api
.
ResourceName
]
resource
.
Quantity
{
api
.
ResourceNvidiaGPU
:
resource
.
MustParse
(
"1000"
),
},
},
},
devices
:
[]
kubecontainer
.
DeviceInfo
{
{
PathOnHost
:
"/dev/nvidia0"
,
PathInContainer
:
"/dev/nvidia0"
,
Permissions
:
"mrw"
},
{
PathOnHost
:
"/dev/nvidiactl"
,
PathInContainer
:
"/dev/nvidiactl"
,
Permissions
:
"mrw"
},
{
PathOnHost
:
"/dev/nvidia-uvm"
,
PathInContainer
:
"/dev/nvidia-uvm"
,
Permissions
:
"mrw"
},
},
},
}
for
_
,
test
:=
range
testCases
{
assert
.
Equal
(
t
,
test
.
devices
,
makeDevices
(
test
.
container
),
"[test %q]"
,
test
.
test
)
}
}
pkg/kubelet/kuberuntime/kuberuntime_container.go
View file @
e0f89a32
...
...
@@ -151,6 +151,7 @@ func (m *kubeGenericRuntimeManager) generateContainerConfig(container *api.Conta
Labels
:
newContainerLabels
(
container
,
pod
),
Annotations
:
newContainerAnnotations
(
container
,
pod
,
restartCount
),
Mounts
:
m
.
makeMounts
(
opts
,
container
,
podHasSELinuxLabel
),
Devices
:
makeDevices
(
opts
),
LogPath
:
&
containerLogsPath
,
Stdin
:
&
container
.
Stdin
,
StdinOnce
:
&
container
.
StdinOnce
,
...
...
@@ -251,6 +252,22 @@ func (m *kubeGenericRuntimeManager) generateLinuxContainerConfig(container *api.
return
linuxConfig
}
// makeDevices generates container devices for kubelet runtime api.
func
makeDevices
(
opts
*
kubecontainer
.
RunContainerOptions
)
[]
*
runtimeApi
.
Device
{
devices
:=
make
([]
*
runtimeApi
.
Device
,
len
(
opts
.
Devices
))
for
idx
:=
range
opts
.
Devices
{
device
:=
opts
.
Devices
[
idx
]
devices
[
idx
]
=
&
runtimeApi
.
Device
{
HostPath
:
&
device
.
PathOnHost
,
ContainerPath
:
&
device
.
PathInContainer
,
Permissions
:
&
device
.
Permissions
,
}
}
return
devices
}
// makeMounts generates container volume mounts for kubelet runtime api.
func
(
m
*
kubeGenericRuntimeManager
)
makeMounts
(
opts
*
kubecontainer
.
RunContainerOptions
,
container
*
api
.
Container
,
podHasSELinuxLabel
bool
)
[]
*
runtimeApi
.
Mount
{
volumeMounts
:=
[]
*
runtimeApi
.
Mount
{}
...
...
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