-
Notifications
You must be signed in to change notification settings - Fork 38
/
jobs.go
79 lines (74 loc) · 1.98 KB
/
jobs.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
package framework
import (
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)
func NewWorkLoad(njobs int32, memoryRequest resource.Quantity, workloadJobName string,
testLabel string, podLabel string, nodeSelectorReqs ...corev1.NodeSelectorRequirement) *batchv1.Job {
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: workloadJobName,
Namespace: MachineAPINamespace,
Labels: map[string]string{testLabel: ""},
},
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: workloadJobName,
Image: "registry.access.redhat.com/ubi8/ubi-minimal:latest",
Command: []string{
"sleep",
"86400", // 1 day
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
"memory": memoryRequest,
"cpu": resource.MustParse("500m"),
},
},
},
},
RestartPolicy: corev1.RestartPolicy("Never"),
Tolerations: []corev1.Toleration{
{
Key: "kubemark",
Operator: corev1.TolerationOpExists,
},
{
Key: ClusterAPIActuatorPkgTaint,
Effect: corev1.TaintEffectPreferNoSchedule,
},
},
},
},
BackoffLimit: ptr.To[int32](4),
Completions: ptr.To[int32](njobs),
Parallelism: ptr.To[int32](njobs),
},
}
if len(nodeSelectorReqs) > 0 {
// Create the empty node selector terms in the spec
job.Spec.Template.Spec.Affinity = &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: nodeSelectorReqs,
},
},
},
},
}
}
if podLabel != "" {
job.Spec.Template.ObjectMeta.Labels = map[string]string{
podLabel: "",
}
}
return job
}