Skip to content

Commit 8430f36

Browse files
Shiva Kumarshivakunv
authored andcommitted
vgpu-manager: enable kernel module configuration via KernelModuleConfig
Signed-off-by: Shiva Kumar (SW-CLOUD) <shivaku@nvidia.com>
1 parent a2ca203 commit 8430f36

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

controllers/transforms_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,3 +3640,105 @@ func TestTransformGPUDiscoveryPluginOCP(t *testing.T) {
36403640
removeDigestFromDaemonSet(ds.DaemonSet)
36413641
require.EqualValues(t, expectedDs, ds)
36423642
}
3643+
3644+
func TestTransformVGPUManager(t *testing.T) {
3645+
node := &corev1.Node{
3646+
ObjectMeta: metav1.ObjectMeta{
3647+
Name: "test-node",
3648+
Labels: map[string]string{
3649+
nfdKernelLabelKey: "6.8.0-60-generic",
3650+
commonGPULabelKey: "true",
3651+
},
3652+
},
3653+
}
3654+
3655+
kernelModuleConfigMap := &corev1.ConfigMap{
3656+
ObjectMeta: metav1.ObjectMeta{
3657+
Name: "vgpu-kernel-module-config",
3658+
Namespace: "test-ns",
3659+
},
3660+
Data: map[string]string{
3661+
"nvidia.conf": "options nvidia NVreg_EnableGpuFirmware=1\n",
3662+
},
3663+
}
3664+
3665+
mockClient := fake.NewFakeClient(node, kernelModuleConfigMap)
3666+
3667+
testCases := []struct {
3668+
description string
3669+
daemonset Daemonset
3670+
cpSpec *gpuv1.ClusterPolicySpec
3671+
client client.Client
3672+
errorExpected bool
3673+
}{
3674+
{
3675+
description: "transform vgpu manager with kernel module config",
3676+
daemonset: NewDaemonset().
3677+
WithInitContainer(corev1.Container{Name: "k8s-driver-manager"}).
3678+
WithContainer(corev1.Container{Name: "nvidia-vgpu-manager-ctr"}),
3679+
cpSpec: &gpuv1.ClusterPolicySpec{
3680+
VGPUManager: gpuv1.VGPUManagerSpec{
3681+
Repository: "nvcr.io/nvidia",
3682+
Image: "vgpu-manager",
3683+
Version: "550.90.07",
3684+
ImagePullPolicy: "IfNotPresent",
3685+
DriverManager: gpuv1.DriverManagerSpec{
3686+
Repository: "nvcr.io/nvidia/cloud-native",
3687+
Image: "k8s-driver-manager",
3688+
ImagePullPolicy: "IfNotPresent",
3689+
Version: "v0.8.0",
3690+
},
3691+
KernelModuleConfig: &gpuv1.KernelModuleConfigSpec{
3692+
Name: "vgpu-kernel-module-config",
3693+
},
3694+
},
3695+
},
3696+
client: mockClient,
3697+
errorExpected: false,
3698+
},
3699+
}
3700+
3701+
for _, tc := range testCases {
3702+
t.Run(tc.description, func(t *testing.T) {
3703+
ctrl := ClusterPolicyController{
3704+
logger: ctrl.Log.WithName("test"),
3705+
client: tc.client,
3706+
operatorNamespace: "test-ns",
3707+
}
3708+
err := TransformVGPUManager(tc.daemonset.DaemonSet, tc.cpSpec, ctrl)
3709+
if tc.errorExpected {
3710+
require.Error(t, err)
3711+
return
3712+
}
3713+
require.NoError(t, err)
3714+
// Verify only the vgpu-manager container has the kernel module config
3715+
container := findContainerByName(tc.daemonset.Spec.Template.Spec.Containers, "nvidia-vgpu-manager-ctr")
3716+
require.NotNil(t, container)
3717+
require.Len(t, container.VolumeMounts, 1)
3718+
require.Equal(t, corev1.VolumeMount{
3719+
Name: "vgpu-kernel-module-config",
3720+
ReadOnly: true,
3721+
MountPath: "/drivers/nvidia.conf",
3722+
SubPath: "nvidia.conf",
3723+
}, container.VolumeMounts[0])
3724+
// Verify the ConfigMap volume is added
3725+
require.Len(t, tc.daemonset.Spec.Template.Spec.Volumes, 1)
3726+
require.Equal(t, corev1.Volume{
3727+
Name: "vgpu-kernel-module-config",
3728+
VolumeSource: corev1.VolumeSource{
3729+
ConfigMap: &corev1.ConfigMapVolumeSource{
3730+
LocalObjectReference: corev1.LocalObjectReference{
3731+
Name: "vgpu-kernel-module-config",
3732+
},
3733+
Items: []corev1.KeyToPath{
3734+
{
3735+
Key: "nvidia.conf",
3736+
Path: "nvidia.conf",
3737+
},
3738+
},
3739+
},
3740+
},
3741+
}, tc.daemonset.Spec.Template.Spec.Volumes[0])
3742+
})
3743+
}
3744+
}

0 commit comments

Comments
 (0)