Skip to content

Commit ac29067

Browse files
committed
use chroot to run modprobe
Signed-off-by: Varun Ramachandra Sekar <[email protected]>
1 parent ed94531 commit ac29067

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

cmd/gpu-kubelet-plugin/vfio-device.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
)
3131

3232
const (
33-
hostNamespaceMount = "/proc/1/ns/mnt"
3433
kernelIommuGroupPath = "/sys/kernel/iommu_groups"
3534
vfioPciModule = "vfio_pci"
3635
vfioPciDriver = "vfio-pci"
@@ -116,7 +115,7 @@ func (vm *VfioPciManager) isVfioPCIModuleLoaded() bool {
116115
}
117116

118117
func (vm *VfioPciManager) loadVfioPciModule() error {
119-
_, err := execCommandInHostNamespace("modprobe", []string{vfioPciModule}) //nolint:gosec
118+
_, err := execCommandWithChroot(vm.driverRoot, "modprobe", []string{vfioPciModule}) //nolint:gosec
120119
if err != nil {
121120
return err
122121
}
@@ -257,10 +256,10 @@ func GetVfioCDIContainerEdits(info *VfioDeviceInfo) *cdiapi.ContainerEdits {
257256
}
258257
}
259258

260-
func execCommandInHostNamespace(cmd string, args []string) ([]byte, error) {
261-
nsenterArgs := []string{"--mount=/proc/1/ns/mnt", cmd}
262-
nsenterArgs = append(nsenterArgs, args...)
263-
return exec.Command("nsenter", nsenterArgs...).CombinedOutput()
259+
func execCommandWithChroot(fsRoot, cmd string, args []string) ([]byte, error) {
260+
chrootArgs := []string{fsRoot, cmd}
261+
chrootArgs = append(chrootArgs, args...)
262+
return exec.Command("chroot", chrootArgs...).CombinedOutput()
264263
}
265264

266265
func execCommand(cmd string, args []string) ([]byte, error) {

deployments/container/Dockerfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ RUN apt-get update && \
4444
git \
4545
gcc-aarch64-linux-gnu \
4646
gcc \
47-
kmod \
48-
lsof \
49-
util-linux
47+
lsof
5048

5149
# Install dependencies for `bash-static` build.
5250
RUN apt-get install -y gpg curl autoconf file
@@ -159,12 +157,7 @@ COPY --from=build /lib/x86_64-linux-gnu/libk5crypto.so.3 /lib/x86_64-linux-
159157
COPY --from=build /lib/x86_64-linux-gnu/libcom_err.so.2 /lib/x86_64-linux-gnu/libcom_err.so.2
160158
COPY --from=build /lib/x86_64-linux-gnu/libkrb5support.so.0 /lib/x86_64-linux-gnu/libkrb5support.so.0
161159
COPY --from=build /lib/x86_64-linux-gnu/libkeyutils.so.1 /lib/x86_64-linux-gnu/libkeyutils.so.1
162-
COPY --from=build /lib/x86_64-linux-gnu/libzstd.so.1 /lib/x86_64-linux-gnu/libzstd.so.1
163-
COPY --from=build /lib/x86_64-linux-gnu/liblzma.so.5 /lib/x86_64-linux-gnu/liblzma.so.5
164-
COPY --from=build /lib/x86_64-linux-gnu/libcrypto.so.3 /lib/x86_64-linux-gnu/libcrypto.so.3
165160
COPY --from=build /usr/bin/lsof /usr/bin/lsof
166-
COPY --from=build /usr/sbin/modprobe /usr/sbin/modprobe
167-
COPY --from=build /usr/bin/nsenter /usr/bin/nsenter
168161
COPY /hack/kubelet-plugin-prestart.sh /usr/bin/kubelet-plugin-prestart.sh
169162
COPY /templates /templates
170163

0 commit comments

Comments
 (0)