Skip to content

Commit 49b1fe1

Browse files
committed
Merge branch 'upstream-add-driver-root-flag' into 'master'
Add a flag to specify the root path of the NVIDIA driver installation See merge request nvidia/kubernetes/device-plugin!73
2 parents 2a0888b + fbdff11 commit 49b1fe1

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ a number of customizable values. The most commonly overridden ones are:
142142
deviceListStrategy:
143143
the desired strategy for passing the device list to the underlying runtime
144144
[envvar | volume-mounts] (default "envvar")
145+
nvidiaDriverRoot:
146+
the root path for the NVIDIA driver installation (typical values are '/' or '/run/nvidia/driver')
145147
```
146148

147149
When set to true, the `failOnInitError` flag fails the plugin if an error is

deployments/helm/nvidia-device-plugin/templates/daemonset.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ spec:
6262
- "--pass-device-specs={{ .Values.compatWithCPUManager }}"
6363
- "--fail-on-init-error={{ .Values.failOnInitError }}"
6464
- "--device-list-strategy={{ .Values.deviceListStrategy }}"
65+
- "--nvidia-driver-root={{ .Values.nvidiaDriverRoot }}"
6566
securityContext:
6667
{{- if ne (len .Values.securityContext) 0 }}
6768
{{- toYaml .Values.securityContext | nindent 10 }}

deployments/helm/nvidia-device-plugin/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ compatWithCPUManager: false
33
migStrategy: none
44
failOnInitError: true
55
deviceListStrategy: envvar
6+
nvidiaDriverRoot: "/"
67

78
nameOverride: ""
89
fullnameOverride: ""

main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var failOnInitErrorFlag = flag.Bool(
3838
true,
3939
"fail the plugin if an error is encountered during initialization, otherwise block indefinitely [default: true]\n")
4040

41-
var passDeviceSpecs = flag.Bool(
41+
var passDeviceSpecsFlag = flag.Bool(
4242
"pass-device-specs",
4343
false,
4444
"pass the list of DeviceSpecs to the kubelet on Allocate()")
@@ -49,6 +49,11 @@ var deviceListStrategyFlag = flag.String(
4949
"the desired strategy for passing the device list to the underlying runtime\n"+
5050
"[envvar | volume-mounts]")
5151

52+
var nvidiaDriverRootFlag = flag.String(
53+
"nvidia-driver-root",
54+
"/",
55+
"the root path for the NVIDIA driver installation (typical values are '/' or '/run/nvidia/driver')")
56+
5257
func main() {
5358
flag.Parse()
5459

server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ func (m *NvidiaDevicePlugin) Allocate(ctx context.Context, reqs *pluginapi.Alloc
280280
response.Envs = m.apiEnvs(m.deviceListEnvvar, []string{deviceListAsVolumeMountsContainerPathRoot})
281281
response.Mounts = m.apiMounts(req.DevicesIDs)
282282
}
283-
if *passDeviceSpecs {
284-
response.Devices = m.apiDeviceSpecs(req.DevicesIDs)
283+
if *passDeviceSpecsFlag {
284+
response.Devices = m.apiDeviceSpecs(*nvidiaDriverRootFlag, req.DevicesIDs)
285285
}
286286

287287
responses.ContainerResponses = append(responses.ContainerResponses, &response)
@@ -348,7 +348,7 @@ func (m *NvidiaDevicePlugin) apiMounts(filter []string) []*pluginapi.Mount {
348348
return mounts
349349
}
350350

351-
func (m *NvidiaDevicePlugin) apiDeviceSpecs(filter []string) []*pluginapi.DeviceSpec {
351+
func (m *NvidiaDevicePlugin) apiDeviceSpecs(driverRoot string, filter []string) []*pluginapi.DeviceSpec {
352352
var specs []*pluginapi.DeviceSpec
353353

354354
paths := []string{
@@ -362,7 +362,7 @@ func (m *NvidiaDevicePlugin) apiDeviceSpecs(filter []string) []*pluginapi.Device
362362
if _, err := os.Stat(p); err == nil {
363363
spec := &pluginapi.DeviceSpec{
364364
ContainerPath: p,
365-
HostPath: p,
365+
HostPath: filepath.Join(driverRoot, p),
366366
Permissions: "rw",
367367
}
368368
specs = append(specs, spec)
@@ -374,7 +374,7 @@ func (m *NvidiaDevicePlugin) apiDeviceSpecs(filter []string) []*pluginapi.Device
374374
if d.ID == id {
375375
spec := &pluginapi.DeviceSpec{
376376
ContainerPath: d.Path,
377-
HostPath: d.Path,
377+
HostPath: filepath.Join(driverRoot, d.Path),
378378
Permissions: "rw",
379379
}
380380
specs = append(specs, spec)

0 commit comments

Comments
 (0)