Skip to content

Commit 49ced7a

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 6531839 commit 49ced7a

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

controllers/object_controls.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,28 @@ func transformDriverContainer(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicy
36243624
}
36253625
}
36263626

3627+
// Mount /lib/modules for SLES/SL-Micro
3628+
if release["ID"] == "sles" || release["ID"] == "sl-micro" {
3629+
n.logger.Info("Mounting /lib/modules into the driver container", "OS", release["ID"])
3630+
libModulesVolMount := corev1.VolumeMount{
3631+
Name: "lib-modules",
3632+
MountPath: "/run/host/lib/modules",
3633+
ReadOnly: true,
3634+
}
3635+
driverContainer.VolumeMounts = append(driverContainer.VolumeMounts, libModulesVolMount)
3636+
3637+
libModulesVol := corev1.Volume{
3638+
Name: "lib-modules",
3639+
VolumeSource: corev1.VolumeSource{
3640+
HostPath: &corev1.HostPathVolumeSource{
3641+
Path: "/lib/modules",
3642+
Type: ptr.To(corev1.HostPathDirectory),
3643+
},
3644+
},
3645+
}
3646+
podSpec.Volumes = append(podSpec.Volumes, libModulesVol)
3647+
}
3648+
36273649
// apply proxy and env settings if this is an OpenShift cluster
36283650
if _, ok := release["OPENSHIFT_VERSION"]; ok {
36293651
setContainerEnv(driverContainer, "OPENSHIFT_VERSION", release["OPENSHIFT_VERSION"])

controllers/object_controls_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,4 +1921,53 @@ func TestMIGManager(t *testing.T) {
19211921
clusterPolicyController.idx--
19221922
})
19231923
}
1924+
1925+
// TestDriverSLES tests that the GPU Operator correctly handles SLES-specific configurations
1926+
func TestDriverSLES(t *testing.T) {
1927+
// Backup original parseOSRelease
1928+
originalParseOSRelease := parseOSRelease
1929+
defer func() { parseOSRelease = originalParseOSRelease }()
1930+
1931+
// Mock SLES environment
1932+
parseOSRelease = mockOSRelease("sles", "15.7")
1933+
1934+
cp := getDriverTestInput("default")
1935+
output := getDriverTestOutput("default")
1936+
1937+
ds, err := testDaemonsetCommon(t, cp, "Driver", output["numDaemonsets"].(int))
1938+
if err != nil {
1939+
t.Fatalf("error in testDaemonsetCommon(): %v", err)
1940+
}
1941+
require.NotNil(t, ds)
1942+
1943+
// Check for /lib/modules volume and mount
1944+
foundVolume := false
1945+
for _, vol := range ds.Spec.Template.Spec.Volumes {
1946+
if vol.Name == "lib-modules" {
1947+
foundVolume = true
1948+
require.NotNil(t, vol.HostPath)
1949+
require.Equal(t, "/lib/modules", vol.HostPath.Path)
1950+
}
1951+
}
1952+
require.True(t, foundVolume, "lib-modules volume not found for SLES")
1953+
1954+
foundMount := false
1955+
driverContainer := findContainerByName(ds.Spec.Template.Spec.Containers, "nvidia-driver-ctr")
1956+
require.NotNil(t, driverContainer)
1957+
1958+
for _, mount := range driverContainer.VolumeMounts {
1959+
if mount.Name == "lib-modules" {
1960+
foundMount = true
1961+
require.Equal(t, "/run/host/lib/modules", mount.MountPath)
1962+
require.True(t, mount.ReadOnly)
1963+
}
1964+
}
1965+
require.True(t, foundMount, "lib-modules volume mount not found for SLES")
1966+
1967+
// Cleanup
1968+
err = removeState(&clusterPolicyController, clusterPolicyController.idx-1)
1969+
if err != nil {
1970+
t.Fatalf("error removing state %v:", err)
1971+
}
1972+
clusterPolicyController.idx--
19241973
}

internal/state/driver_volumes.go

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

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

0 commit comments

Comments
 (0)