|
4 | 4 | package kuberesource |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "fmt" |
7 | 8 | "testing" |
8 | 9 |
|
| 10 | + "github.com/edgelesssys/contrast/internal/platforms" |
9 | 11 | "github.com/stretchr/testify/require" |
| 12 | + corev1 "k8s.io/api/core/v1" |
| 13 | + applyappsv1 "k8s.io/client-go/applyconfigurations/apps/v1" |
10 | 14 | ) |
11 | 15 |
|
| 16 | +func TestNodeInstallerGPUToleration(t *testing.T) { |
| 17 | + for _, tc := range []struct { |
| 18 | + name string |
| 19 | + platform platforms.Platform |
| 20 | + wantTolerations int |
| 21 | + }{ |
| 22 | + { |
| 23 | + name: "GPU", |
| 24 | + platform: platforms.MetalQEMUTDXGPU, |
| 25 | + wantTolerations: 1, |
| 26 | + }, |
| 27 | + { |
| 28 | + name: "non-GPU", |
| 29 | + platform: platforms.MetalQEMUTDX, |
| 30 | + }, |
| 31 | + } { |
| 32 | + t.Run(tc.name, func(t *testing.T) { |
| 33 | + require := require.New(t) |
| 34 | + tolerations := nodeInstallerTolerations(tc.platform) |
| 35 | + require.Len(tolerations, tc.wantTolerations) |
| 36 | + if tc.wantTolerations == 0 { |
| 37 | + return |
| 38 | + } |
| 39 | + require.Equal("nvidia.com/gpu", *tolerations[0].Key) |
| 40 | + require.Equal(corev1.TolerationOpExists, *tolerations[0].Operator) |
| 41 | + require.Equal(corev1.TaintEffectNoSchedule, *tolerations[0].Effect) |
| 42 | + }) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +func TestGPUBlockDevice(t *testing.T) { |
| 47 | + for _, withBlockDevice := range []bool{false, true} { |
| 48 | + t.Run(fmt.Sprintf("withBlockDevice=%t", withBlockDevice), func(t *testing.T) { |
| 49 | + require := require.New(t) |
| 50 | + resources := GPU("gpu-tester", "nvidia.com/test", 1, withBlockDevice) |
| 51 | + require.Len(resources, 1) |
| 52 | + |
| 53 | + deployment, ok := resources[0].(*applyappsv1.DeploymentApplyConfiguration) |
| 54 | + require.True(ok) |
| 55 | + spec := deployment.Spec.Template.Spec |
| 56 | + require.Len(spec.Containers, 3) |
| 57 | + noGPUContainer := spec.Containers[2] |
| 58 | + require.Equal("no-gpu", *noGPUContainer.Name) |
| 59 | + |
| 60 | + wantBlockDevices := 0 |
| 61 | + if withBlockDevice { |
| 62 | + wantBlockDevices = 1 |
| 63 | + } |
| 64 | + require.Len(spec.Volumes, wantBlockDevices) |
| 65 | + require.Len(noGPUContainer.VolumeDevices, wantBlockDevices) |
| 66 | + }) |
| 67 | + } |
| 68 | +} |
| 69 | + |
12 | 70 | func TestNewPortForwarder(t *testing.T) { |
13 | 71 | require := require.New(t) |
14 | 72 |
|
|
0 commit comments