Skip to content

Commit 314729a

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 290b075 commit 314729a

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
@@ -3571,6 +3571,28 @@ func transformDriverContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicy
35713571
}
35723572
}
35733573

3574+
// Mount /lib/modules for SLES/SL-Micro
3575+
if release["ID"] == "sles" || release["ID"] == "sl-micro" {
3576+
n.logger.Info("Mounting /lib/modules into the driver container", "OS", release["ID"])
3577+
libModulesVolMount := corev1.VolumeMount{
3578+
Name: "lib-modules",
3579+
MountPath: "/run/host/lib/modules",
3580+
ReadOnly: true,
3581+
}
3582+
driverContainer.VolumeMounts = append(driverContainer.VolumeMounts, libModulesVolMount)
3583+
3584+
libModulesVol := corev1.Volume{
3585+
Name: "lib-modules",
3586+
VolumeSource: corev1.VolumeSource{
3587+
HostPath: &corev1.HostPathVolumeSource{
3588+
Path: "/lib/modules",
3589+
Type: ptr.To(corev1.HostPathDirectory),
3590+
},
3591+
},
3592+
}
3593+
podSpec.Volumes = append(podSpec.Volumes, libModulesVol)
3594+
}
3595+
35743596
// apply proxy and env settings if this is an OpenShift cluster
35753597
if _, ok := release["OPENSHIFT_VERSION"]; ok {
35763598
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
@@ -1479,3 +1479,53 @@ func TestCertConfigPathMap(t *testing.T) {
14791479
require.Equal(t, expectedPath, path, "Incorrect path for OS %s", os)
14801480
}
14811481
}
1482+
1483+
// TestDriverSLES tests that the GPU Operator correctly handles SLES-specific configurations
1484+
func TestDriverSLES(t *testing.T) {
1485+
// Backup original parseOSRelease
1486+
originalParseOSRelease := parseOSRelease
1487+
defer func() { parseOSRelease = originalParseOSRelease }()
1488+
1489+
// Mock SLES environment
1490+
parseOSRelease = mockOSRelease("sles", "15.7")
1491+
1492+
cp := getDriverTestInput("default")
1493+
output := getDriverTestOutput("default")
1494+
1495+
ds, err := testDaemonsetCommon(t, cp, "Driver", output["numDaemonsets"].(int))
1496+
if err != nil {
1497+
t.Fatalf("error in testDaemonsetCommon(): %v", err)
1498+
}
1499+
require.NotNil(t, ds)
1500+
1501+
// Check for /lib/modules volume and mount
1502+
foundVolume := false
1503+
for _, vol := range ds.Spec.Template.Spec.Volumes {
1504+
if vol.Name == "lib-modules" {
1505+
foundVolume = true
1506+
require.NotNil(t, vol.HostPath)
1507+
require.Equal(t, "/lib/modules", vol.HostPath.Path)
1508+
}
1509+
}
1510+
require.True(t, foundVolume, "lib-modules volume not found for SLES")
1511+
1512+
foundMount := false
1513+
driverContainer := findContainerByName(ds.Spec.Template.Spec.Containers, "nvidia-driver-ctr")
1514+
require.NotNil(t, driverContainer)
1515+
1516+
for _, mount := range driverContainer.VolumeMounts {
1517+
if mount.Name == "lib-modules" {
1518+
foundMount = true
1519+
require.Equal(t, "/run/host/lib/modules", mount.MountPath)
1520+
require.True(t, mount.ReadOnly)
1521+
}
1522+
}
1523+
require.True(t, foundMount, "lib-modules volume mount not found for SLES")
1524+
1525+
// Cleanup
1526+
err = removeState(&clusterPolicyController, clusterPolicyController.idx-1)
1527+
if err != nil {
1528+
t.Fatalf("error removing state %v:", err)
1529+
}
1530+
clusterPolicyController.idx--
1531+
}

internal/state/driver_volumes.go

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

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

0 commit comments

Comments
 (0)