-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathgpu-burn.go
138 lines (122 loc) · 3.69 KB
/
gpu-burn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package gpuburn
import (
"time"
"github.com/golang/glog"
"github.com/openshift-kni/eco-goinfra/pkg/clients"
"github.com/openshift-kni/eco-goinfra/pkg/configmap"
"github.com/openshift-kni/eco-gotests/tests/hw-accel/nvidiagpu/internal/gpuparams"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var (
isFalse bool = false
isTrue bool = true
gpuBurnConfigMapData = map[string]string{
"entrypoint.sh": `#!/bin/bash
NUM_GPUS=$(nvidia-smi -L | wc -l)
if [ $NUM_GPUS -eq 0 ]; then
echo "ERROR No GPUs found"
exit 1
fi
./gpu_burn 300
if [ ! $? -eq 0 ]; then
exit 1
fi`,
}
)
// CreateGPUBurnConfigMap returns a configmap with data field populated.
func CreateGPUBurnConfigMap(apiClient *clients.Settings,
configMapName, configMapNamespace string) (*corev1.ConfigMap, error) {
configMapBuilder := configmap.NewBuilder(apiClient, configMapName, configMapNamespace)
configMapBuilderWithData := configMapBuilder.WithData(gpuBurnConfigMapData)
createdConfigMapBuilderWithData, err := configMapBuilderWithData.Create()
if err != nil {
glog.V(gpuparams.GpuLogLevel).Infof(
"error creating ConfigMap with Data named %s and for namespace %s",
createdConfigMapBuilderWithData.Object.Name, createdConfigMapBuilderWithData.Object.Namespace)
return nil, err
}
glog.V(gpuparams.GpuLogLevel).Infof(
"Created ConfigMap with Data named %s and for namespace %s",
createdConfigMapBuilderWithData.Object.Name, createdConfigMapBuilderWithData.Object.Namespace)
return createdConfigMapBuilderWithData.Object, nil
}
// CreateGPUBurnPod returns a Pod after it is Ready after a timeout periods.
func CreateGPUBurnPod(apiClient *clients.Settings, podName, podNamespace string,
gpuBurnImage string, timeout time.Duration) (*corev1.Pod, error) {
var volumeDefaultMode int32 = 0777
configMapVolumeSource := &corev1.ConfigMapVolumeSource{}
configMapVolumeSource.Name = "gpu-burn-entrypoint"
configMapVolumeSource.DefaultMode = &volumeDefaultMode
var err error = nil
return &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: podName,
Namespace: podNamespace,
Labels: map[string]string{
"app": "gpu-burn-app",
},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: &isTrue,
SeccompProfile: &corev1.SeccompProfile{Type: "RuntimeDefault"},
},
Tolerations: []corev1.Toleration{
{
Operator: corev1.TolerationOpExists,
},
{
Key: "nvidia.com/gpu",
Effect: corev1.TaintEffectNoSchedule,
Operator: corev1.TolerationOpExists,
},
},
Containers: []corev1.Container{
{
Image: gpuBurnImage,
ImagePullPolicy: corev1.PullAlways,
SecurityContext: &corev1.SecurityContext{
AllowPrivilegeEscalation: &isFalse,
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
},
},
},
Name: "gpu-burn-ctr",
Command: []string{
"/bin/entrypoint.sh",
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"nvidia.com/gpu": resource.MustParse("1"),
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "entrypoint",
MountPath: "/bin/entrypoint.sh",
ReadOnly: true,
SubPath: "entrypoint.sh",
},
},
},
},
Volumes: []corev1.Volume{
{
Name: "entrypoint",
VolumeSource: corev1.VolumeSource{
ConfigMap: configMapVolumeSource,
},
},
},
NodeSelector: map[string]string{
"nvidia.com/gpu.present": "true",
"node-role.kubernetes.io/worker": "",
},
},
}, err
}