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

Function TestTransformGPUDiscoveryPlugin

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

Source from the content-addressed store, hash-verified

3920}
3921
3922func TestTransformGPUDiscoveryPlugin(t *testing.T) {
3923 node := &corev1.Node{
3924 ObjectMeta: metav1.ObjectMeta{
3925 Name: "test-node",
3926 Labels: map[string]string{
3927 nfdKernelLabelKey: "6.8.0-60-generic",
3928 commonGPULabelKey: "true",
3929 },
3930 },
3931 }
3932 mockClient := fake.NewFakeClient(node)
3933 ds := NewDaemonset().WithContainer(corev1.Container{Name: "gpu-feature-discovery"}).
3934 WithInitContainer(corev1.Container{Name: "toolkit-validation"}).
3935 WithInitContainer(corev1.Container{Name: "config-manager-init"})
3936 cpSpec := &gpuv1.ClusterPolicySpec{
3937 GPUFeatureDiscovery: gpuv1.GPUFeatureDiscoverySpec{
3938 Repository: "nvcr.io/nvidia",
3939 Image: "k8s-device-plugin",
3940 Version: "v0.18.1",
3941 },
3942 Validator: gpuv1.ValidatorSpec{
3943 Repository: "nvcr.io/nvidia/cloud-native",
3944 Image: "gpu-operator-validator",
3945 Version: "v1.0.0",
3946 ImagePullPolicy: "IfNotPresent",
3947 ImagePullSecrets: []string{"pull-secret"},
3948 Toolkit: gpuv1.ToolkitValidatorSpec{
3949 Env: []gpuv1.EnvVar{{Name: "foo", Value: "bar"}},
3950 },
3951 },
3952 }
3953 expectedDs := NewDaemonset().WithContainer(corev1.Container{
3954 Name: "gpu-feature-discovery",
3955 Image: "nvcr.io/nvidia/k8s-device-plugin:v0.18.1",
3956 ImagePullPolicy: corev1.PullIfNotPresent,
3957 Env: []corev1.EnvVar{
3958 {
3959 Name: "NVIDIA_MIG_MONITOR_DEVICES",
3960 Value: "all",
3961 },
3962 },
3963 }).WithInitContainer(corev1.Container{
3964 Name: "toolkit-validation",
3965 Image: "nvcr.io/nvidia/cloud-native/gpu-operator-validator:v1.0.0",
3966 ImagePullPolicy: corev1.PullIfNotPresent,
3967 Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}},
3968 SecurityContext: &corev1.SecurityContext{
3969 RunAsUser: rootUID,
3970 },
3971 }).WithPullSecret("pull-secret").WithRuntimeClassName("nvidia")
3972
3973 err := TransformGPUDiscoveryPlugin(ds.DaemonSet, cpSpec,
3974 ClusterPolicyController{client: mockClient, runtime: gpuv1.Containerd,
3975 operatorNamespace: "test-ns", logger: ctrl.Log.WithName("test")})
3976 require.NoError(t, err)
3977 require.EqualValues(t, expectedDs, ds)
3978}
3979

Callers

nothing calls this directly

Calls 7

NewDaemonsetFunction · 0.85
WithContainerMethod · 0.80
WithPullSecretMethod · 0.80
WithNameMethod · 0.80
WithInitContainerMethod · 0.45
WithRuntimeClassNameMethod · 0.45

Tested by

no test coverage detected