Skip to content

Commit d755563

Browse files
authored
Merge pull request #479 from klueska/conditionally-mount-host-dev
Conditionally mount the host's /dev over the container's /dev
2 parents 20db628 + 9797d24 commit d755563

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

cmd/compute-domain-kubelet-plugin/nvlib.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
nvidiaCapsDeviceName = "nvidia-caps"
4444
nvidiaCapsImexChannelsDeviceName = "nvidia-caps-imex-channels"
4545
nvidiaCapFabricImexMgmtPath = "/proc/driver/nvidia/capabilities/fabric-imex-mgmt"
46+
hostDevContainerPath = "/host/dev"
4647
)
4748

4849
type deviceLib struct {
@@ -89,6 +90,10 @@ func newDeviceLib(driverRoot root) (*deviceLib, error) {
8990
return nil, fmt.Errorf("error recursively unmounting %s: %w", procDriverNvidiaPath, err)
9091
}
9192

93+
if err := d.conditionallyBindMountHostDev(); err != nil {
94+
return nil, fmt.Errorf("error conditionally bind mounting host dev: %w", err)
95+
}
96+
9297
return &d, nil
9398
}
9499

@@ -418,3 +423,27 @@ func (l deviceLib) unmountRecursively(root string) error {
418423

419424
return helper(root)
420425
}
426+
427+
// conditionallyBindMountHostDev bind mounts hostDevContainerPath over /dev when devRoot is "/".
428+
// Introduced to address the issues described in https://github.com/NVIDIA/k8s-dra-driver-gpu/issues/477.
429+
// TODO: Revisit with a more comprehensive solution as proposed in https://github.com/NVIDIA/k8s-dra-driver-gpu/pull/307.
430+
func (l deviceLib) conditionallyBindMountHostDev() error {
431+
// If devRoot != "/" then we don't need to do the mount
432+
if l.devRoot != "/" {
433+
return nil
434+
}
435+
436+
// Get a reference to the mount executable.
437+
mountExecutable, err := exec.LookPath("mount")
438+
if err != nil {
439+
return fmt.Errorf("error looking up mount executable: %w", err)
440+
}
441+
mounter := mount.New(mountExecutable)
442+
443+
// Bind mount hostDevContainerPath over /dev
444+
if err := mounter.Mount(hostDevContainerPath, "/dev", "", []string{"bind"}); err != nil {
445+
return fmt.Errorf("failed to bind mount %s over /dev: %w", hostDevContainerPath, err)
446+
}
447+
448+
return nil
449+
}

deployments/helm/nvidia-dra-driver-gpu/templates/kubeletplugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ spec:
149149
# TODO: make this more surgical, see discussion in
150150
# https://github.com/NVIDIA/k8s-dra-driver-gpu/pull/307.
151151
- name: host-dev
152-
mountPath: /dev
152+
mountPath: /host/dev
153153
{{- end }}
154154
{{- if .Values.resources.gpus.enabled }}
155155
- name: gpus

0 commit comments

Comments
 (0)