Skip to content

Commit 308e75a

Browse files
committed
ensure /lib/modules is available for driver container on SUSE products
This will ensure driver container built by SUSE has access to host kernel modules Signed-off-by: Frederic Crozat <fcrozat@suse.com>
1 parent 83cffd9 commit 308e75a

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

controllers/object_controls.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,28 @@ func transformDriverContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicy
35813581
}
35823582
}
35833583

3584+
// Mount /lib/modules for SLES/SL-Micro
3585+
if release["ID"] == "sles" || release["ID"] == "sl-micro" {
3586+
n.logger.Info("Mounting /lib/modules into the driver container", "OS", release["ID"])
3587+
libModulesVolMount := corev1.VolumeMount{
3588+
Name: "lib-modules",
3589+
MountPath: "/run/host/lib/modules",
3590+
ReadOnly: true,
3591+
}
3592+
driverContainer.VolumeMounts = append(driverContainer.VolumeMounts, libModulesVolMount)
3593+
3594+
libModulesVol := corev1.Volume{
3595+
Name: "lib-modules",
3596+
VolumeSource: corev1.VolumeSource{
3597+
HostPath: &corev1.HostPathVolumeSource{
3598+
Path: "/lib/modules",
3599+
Type: ptr.To(corev1.HostPathDirectory),
3600+
},
3601+
},
3602+
}
3603+
podSpec.Volumes = append(podSpec.Volumes, libModulesVol)
3604+
}
3605+
35843606
// apply proxy and env settings if this is an OpenShift cluster
35853607
if _, ok := release["OPENSHIFT_VERSION"]; ok {
35863608
setContainerEnv(driverContainer, "OPENSHIFT_VERSION", release["OPENSHIFT_VERSION"])

controllers/object_controls_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,3 +1461,53 @@ func TestParseOSReleaseFromFile(t *testing.T) {
14611461
require.True(t, os.IsNotExist(err))
14621462
})
14631463
}
1464+
1465+
// TestDriverSLES tests that the GPU Operator correctly handles SLES-specific configurations
1466+
func TestDriverSLES(t *testing.T) {
1467+
// Backup original parseOSRelease
1468+
originalParseOSRelease := parseOSRelease
1469+
defer func() { parseOSRelease = originalParseOSRelease }()
1470+
1471+
// Mock SLES environment
1472+
parseOSRelease = mockOSRelease("sles", "15.7")
1473+
1474+
cp := getDriverTestInput("default")
1475+
output := getDriverTestOutput("default")
1476+
1477+
ds, err := testDaemonsetCommon(t, cp, "Driver", output["numDaemonsets"].(int))
1478+
if err != nil {
1479+
t.Fatalf("error in testDaemonsetCommon(): %v", err)
1480+
}
1481+
require.NotNil(t, ds)
1482+
1483+
// Check for /lib/modules volume and mount
1484+
foundVolume := false
1485+
for _, vol := range ds.Spec.Template.Spec.Volumes {
1486+
if vol.Name == "lib-modules" {
1487+
foundVolume = true
1488+
require.NotNil(t, vol.HostPath)
1489+
require.Equal(t, "/lib/modules", vol.HostPath.Path)
1490+
}
1491+
}
1492+
require.True(t, foundVolume, "lib-modules volume not found for SLES")
1493+
1494+
foundMount := false
1495+
driverContainer := findContainerByName(ds.Spec.Template.Spec.Containers, "nvidia-driver-ctr")
1496+
require.NotNil(t, driverContainer)
1497+
1498+
for _, mount := range driverContainer.VolumeMounts {
1499+
if mount.Name == "lib-modules" {
1500+
foundMount = true
1501+
require.Equal(t, "/run/host/lib/modules", mount.MountPath)
1502+
require.True(t, mount.ReadOnly)
1503+
}
1504+
}
1505+
require.True(t, foundMount, "lib-modules volume mount not found for SLES")
1506+
1507+
// Cleanup
1508+
err = removeState(&clusterPolicyController, clusterPolicyController.idx-1)
1509+
if err != nil {
1510+
t.Fatalf("error removing state %v:", err)
1511+
}
1512+
clusterPolicyController.idx--
1513+
}

internal/state/driver_volumes.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,28 @@ func (s *stateDriver) getDriverAdditionalConfigs(ctx context.Context, cr *v1alph
203203
additionalCfgs.Volumes = append(additionalCfgs.Volumes, subscriptionVol)
204204
}
205205
}
206+
207+
// Mount /lib/modules for SLES/SL-Micro
208+
if pool.osRelease == "sles" || pool.osRelease == "sl-micro" {
209+
logger.Info("Mounting /lib/modules into the driver container", "OS", pool.osRelease)
210+
libModulesVolMount := corev1.VolumeMount{
211+
Name: "lib-modules",
212+
MountPath: "/run/host/lib/modules",
213+
ReadOnly: true,
214+
}
215+
additionalCfgs.VolumeMounts = append(additionalCfgs.VolumeMounts, libModulesVolMount)
216+
217+
libModulesVol := corev1.Volume{
218+
Name: "lib-modules",
219+
VolumeSource: corev1.VolumeSource{
220+
HostPath: &corev1.HostPathVolumeSource{
221+
Path: "/lib/modules",
222+
Type: ptr.To(corev1.HostPathDirectory),
223+
},
224+
},
225+
}
226+
additionalCfgs.Volumes = append(additionalCfgs.Volumes, libModulesVol)
227+
}
206228
}
207229

208230
// mount any custom kernel module configuration parameters at /drivers

0 commit comments

Comments
 (0)