MCPcopy Create free account
hub / github.com/NVIDIA/gpu-operator / TestTransformToolkitCtrForCDI

Function TestTransformToolkitCtrForCDI

controllers/transforms_test.go:3205–3261  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3203}
3204
3205func TestTransformToolkitCtrForCDI(t *testing.T) {
3206 testCases := []struct {
3207 description string
3208 ds Daemonset
3209 cpSpec *gpuv1.ClusterPolicySpec
3210 expectedDs Daemonset
3211 }{
3212 {
3213 description: "cdi enabled",
3214 ds: NewDaemonset().WithContainer(corev1.Container{Name: "main-ctr"}),
3215 cpSpec: &gpuv1.ClusterPolicySpec{
3216 CDI: gpuv1.CDIConfigSpec{
3217 Enabled: newBoolPtr(true),
3218 },
3219 },
3220 expectedDs: NewDaemonset().WithContainer(
3221 corev1.Container{
3222 Name: "main-ctr",
3223 Env: []corev1.EnvVar{
3224 {Name: CDIEnabledEnvName, Value: "true"},
3225 {Name: NvidiaRuntimeSetAsDefaultEnvName, Value: "false"},
3226 {Name: NvidiaCtrRuntimeModeEnvName, Value: "cdi"},
3227 {Name: CRIOConfigModeEnvName, Value: "config"},
3228 },
3229 }),
3230 },
3231 {
3232 description: "cdi and nri plugin enabled",
3233 ds: NewDaemonset().WithContainer(corev1.Container{Name: "main-ctr"}),
3234 cpSpec: &gpuv1.ClusterPolicySpec{
3235 CDI: gpuv1.CDIConfigSpec{
3236 Enabled: newBoolPtr(true),
3237 NRIPluginEnabled: newBoolPtr(true),
3238 },
3239 },
3240 expectedDs: NewDaemonset().WithContainer(
3241 corev1.Container{
3242 Name: "main-ctr",
3243 Env: []corev1.EnvVar{
3244 {Name: CDIEnabledEnvName, Value: "true"},
3245 {Name: NvidiaRuntimeSetAsDefaultEnvName, Value: "false"},
3246 {Name: NvidiaCtrRuntimeModeEnvName, Value: "cdi"},
3247 {Name: CRIOConfigModeEnvName, Value: "config"},
3248 {Name: CDIEnableNRIPlugin, Value: "true"},
3249 },
3250 }),
3251 },
3252 }
3253
3254 for _, tc := range testCases {
3255 t.Run(tc.description, func(t *testing.T) {
3256 mainContainer := &tc.ds.Spec.Template.Spec.Containers[0]
3257 transformToolkitCtrForCDI(mainContainer, tc.cpSpec.CDI.IsNRIPluginEnabled())
3258 require.EqualValues(t, tc.expectedDs, tc.ds)
3259 })
3260 }
3261}
3262

Callers

nothing calls this directly

Calls 6

NewDaemonsetFunction · 0.85
newBoolPtrFunction · 0.85
WithContainerMethod · 0.80
RunMethod · 0.80
IsNRIPluginEnabledMethod · 0.80

Tested by

no test coverage detected