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

Function TestTransformForRuntime

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

Source from the content-addressed store, hash-verified

386}
387
388func TestTransformForRuntime(t *testing.T) {
389 testCases := []struct {
390 description string
391 runtime gpuv1.Runtime
392 input Daemonset
393 expectedOutput Daemonset
394 }{
395 {
396 description: "containerd",
397 runtime: gpuv1.Containerd,
398 input: NewDaemonset().
399 WithContainer(corev1.Container{Name: "test-ctr"}),
400 expectedOutput: NewDaemonset().
401 WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), ptr.To(corev1.HostPathDirectoryOrCreate)).
402 WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
403 WithHostPathVolume("containerd-socket", filepath.Dir(DefaultContainerdSocketFile), nil).
404 WithContainer(corev1.Container{
405 Name: "test-ctr",
406 Env: []corev1.EnvVar{
407 {Name: "RUNTIME", Value: gpuv1.Containerd.String()},
408 {Name: "CONTAINERD_RUNTIME_CLASS", Value: DefaultRuntimeClass},
409 {Name: "RUNTIME_CONFIG", Value: filepath.Join(DefaultRuntimeConfigTargetDir, filepath.Base(DefaultContainerdConfigFile))},
410 {Name: "CONTAINERD_CONFIG", Value: filepath.Join(DefaultRuntimeConfigTargetDir, filepath.Base(DefaultContainerdConfigFile))},
411 {Name: "RUNTIME_DROP_IN_CONFIG", Value: "/runtime/config-dir.d/99-nvidia.toml"},
412 {Name: "RUNTIME_DROP_IN_CONFIG_HOST_PATH", Value: "/etc/containerd/conf.d/99-nvidia.toml"},
413 {Name: "RUNTIME_SOCKET", Value: filepath.Join(DefaultRuntimeSocketTargetDir, filepath.Base(DefaultContainerdSocketFile))},
414 {Name: "CONTAINERD_SOCKET", Value: filepath.Join(DefaultRuntimeSocketTargetDir, filepath.Base(DefaultContainerdSocketFile))},
415 },
416 VolumeMounts: []corev1.VolumeMount{
417 {Name: "containerd-config", MountPath: DefaultRuntimeConfigTargetDir},
418 {Name: "containerd-drop-in-config", MountPath: "/runtime/config-dir.d/"},
419 {Name: "containerd-socket", MountPath: DefaultRuntimeSocketTargetDir},
420 },
421 }),
422 },
423 {
424 description: "containerd, file config source preferred over command source",
425 runtime: gpuv1.Containerd,
426 input: NewDaemonset().
427 WithContainer(corev1.Container{
428 Name: "test-ctr",
429 Env: []corev1.EnvVar{
430 {Name: "RUNTIME_CONFIG_SOURCE", Value: "file,command"},
431 },
432 }),
433 expectedOutput: NewDaemonset().
434 WithHostPathVolume("containerd-config", filepath.Dir(DefaultContainerdConfigFile), ptr.To(corev1.HostPathDirectoryOrCreate)).
435 WithHostPathVolume("containerd-drop-in-config", "/etc/containerd/conf.d", ptr.To(corev1.HostPathDirectoryOrCreate)).
436 WithHostPathVolume("containerd-socket", filepath.Dir(DefaultContainerdSocketFile), nil).
437 WithContainer(corev1.Container{
438 Name: "test-ctr",
439 Env: []corev1.EnvVar{
440 {Name: "RUNTIME_CONFIG_SOURCE", Value: "file,command"},
441 {Name: "RUNTIME", Value: gpuv1.Containerd.String()},
442 {Name: "CONTAINERD_RUNTIME_CLASS", Value: DefaultRuntimeClass},
443 {Name: "RUNTIME_CONFIG", Value: filepath.Join(DefaultRuntimeConfigTargetDir, filepath.Base(DefaultContainerdConfigFile))},
444 {Name: "CONTAINERD_CONFIG", Value: filepath.Join(DefaultRuntimeConfigTargetDir, filepath.Base(DefaultContainerdConfigFile))},
445 {Name: "RUNTIME_DROP_IN_CONFIG", Value: "/runtime/config-dir.d/99-nvidia.toml"},

Callers

nothing calls this directly

Calls 6

NewDaemonsetFunction · 0.85
transformForRuntimeFunction · 0.85
WithContainerMethod · 0.80
WithHostPathVolumeMethod · 0.80
StringMethod · 0.80
RunMethod · 0.80

Tested by

no test coverage detected