Skip to content

Commit c13609d

Browse files
authored
feat: add use of tolerations for starter and runner (#142)
* feat: add use of tolerations for starter and runner * build: update manifests * feat: add runner tolerations to the initializer
1 parent 1f5f120 commit c13609d

File tree

7 files changed

+94
-0
lines changed

7 files changed

+94
-0
lines changed

api/v1alpha1/k6_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Pod struct {
3131
Image string `json:"image,omitempty"`
3232
Metadata PodMetadata `json:"metadata,omitempty"`
3333
NodeSelector map[string]string `json:"nodeselector,omitempty"`
34+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
3435
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
3536
ServiceAccountName string `json:"serviceAccountName,omitempty"`
3637
SecurityContext corev1.PodSecurityContext `json:"securityContext,omitempty"`

config/crd/bases/k6.io_k6s.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,46 @@ spec:
10211021
type: object
10221022
serviceAccountName:
10231023
type: string
1024+
tolerations:
1025+
items:
1026+
description: The pod this Toleration is attached to tolerates
1027+
any taint that matches the triple <key,value,effect> using
1028+
the matching operator <operator>.
1029+
properties:
1030+
effect:
1031+
description: Effect indicates the taint effect to match.
1032+
Empty means match all taint effects. When specified, allowed
1033+
values are NoSchedule, PreferNoSchedule and NoExecute.
1034+
type: string
1035+
key:
1036+
description: Key is the taint key that the toleration applies
1037+
to. Empty means match all taint keys. If the key is empty,
1038+
operator must be Exists; this combination means to match
1039+
all values and all keys.
1040+
type: string
1041+
operator:
1042+
description: Operator represents a key's relationship to
1043+
the value. Valid operators are Exists and Equal. Defaults
1044+
to Equal. Exists is equivalent to wildcard for value,
1045+
so that a pod can tolerate all taints of a particular
1046+
category.
1047+
type: string
1048+
tolerationSeconds:
1049+
description: TolerationSeconds represents the period of
1050+
time the toleration (which must be of effect NoExecute,
1051+
otherwise this field is ignored) tolerates the taint.
1052+
By default, it is not set, which means tolerate the taint
1053+
forever (do not evict). Zero and negative values will
1054+
be treated as 0 (evict immediately) by the system.
1055+
format: int64
1056+
type: integer
1057+
value:
1058+
description: Value is the taint value the toleration matches
1059+
to. If the operator is Exists, the value should be empty,
1060+
otherwise just a regular string.
1061+
type: string
1062+
type: object
1063+
type: array
10241064
type: object
10251065
script:
10261066
description: K6Script describes where the script to execute the tests
@@ -2010,6 +2050,46 @@ spec:
20102050
type: object
20112051
serviceAccountName:
20122052
type: string
2053+
tolerations:
2054+
items:
2055+
description: The pod this Toleration is attached to tolerates
2056+
any taint that matches the triple <key,value,effect> using
2057+
the matching operator <operator>.
2058+
properties:
2059+
effect:
2060+
description: Effect indicates the taint effect to match.
2061+
Empty means match all taint effects. When specified, allowed
2062+
values are NoSchedule, PreferNoSchedule and NoExecute.
2063+
type: string
2064+
key:
2065+
description: Key is the taint key that the toleration applies
2066+
to. Empty means match all taint keys. If the key is empty,
2067+
operator must be Exists; this combination means to match
2068+
all values and all keys.
2069+
type: string
2070+
operator:
2071+
description: Operator represents a key's relationship to
2072+
the value. Valid operators are Exists and Equal. Defaults
2073+
to Equal. Exists is equivalent to wildcard for value,
2074+
so that a pod can tolerate all taints of a particular
2075+
category.
2076+
type: string
2077+
tolerationSeconds:
2078+
description: TolerationSeconds represents the period of
2079+
time the toleration (which must be of effect NoExecute,
2080+
otherwise this field is ignored) tolerates the taint.
2081+
By default, it is not set, which means tolerate the taint
2082+
forever (do not evict). Zero and negative values will
2083+
be treated as 0 (evict immediately) by the system.
2084+
format: int64
2085+
type: integer
2086+
value:
2087+
description: Value is the taint value the toleration matches
2088+
to. If the operator is Exists, the value should be empty,
2089+
otherwise just a regular string.
2090+
type: string
2091+
type: object
2092+
type: array
20132093
type: object
20142094
required:
20152095
- parallelism

pkg/resources/jobs/initializer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) {
8282
ServiceAccountName: serviceAccountName,
8383
Affinity: k6.Spec.Runner.Affinity,
8484
NodeSelector: k6.Spec.Runner.NodeSelector,
85+
Tolerations: k6.Spec.Runner.Tolerations,
8586
RestartPolicy: corev1.RestartPolicyNever,
8687
Containers: []corev1.Container{
8788
{

pkg/resources/jobs/runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func NewRunnerJob(k6 *v1alpha1.K6, index int, testRunId, token string) (*batchv1
147147
RestartPolicy: corev1.RestartPolicyNever,
148148
Affinity: k6.Spec.Runner.Affinity,
149149
NodeSelector: k6.Spec.Runner.NodeSelector,
150+
Tolerations: k6.Spec.Runner.Tolerations,
150151
SecurityContext: &k6.Spec.Runner.SecurityContext,
151152
Containers: []corev1.Container{{
152153
Image: image,

pkg/resources/jobs/runner_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func TestNewRunnerJob(t *testing.T) {
284284
SecurityContext: &corev1.PodSecurityContext{},
285285
Affinity: nil,
286286
NodeSelector: nil,
287+
Tolerations: nil,
287288
ServiceAccountName: "default",
288289
AutomountServiceAccountToken: &automountServiceAccountToken,
289290
Containers: []corev1.Container{{
@@ -393,6 +394,7 @@ func TestNewRunnerJobNoisy(t *testing.T) {
393394
RestartPolicy: corev1.RestartPolicyNever,
394395
Affinity: nil,
395396
NodeSelector: nil,
397+
Tolerations: nil,
396398
ServiceAccountName: "default",
397399
AutomountServiceAccountToken: &automountServiceAccountToken,
398400
SecurityContext: &corev1.PodSecurityContext{},
@@ -486,6 +488,7 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
486488
RestartPolicy: corev1.RestartPolicyNever,
487489
Affinity: nil,
488490
NodeSelector: nil,
491+
Tolerations: nil,
489492
ServiceAccountName: "default",
490493
AutomountServiceAccountToken: &automountServiceAccountToken,
491494
SecurityContext: &corev1.PodSecurityContext{},
@@ -579,6 +582,7 @@ func TestNewRunnerJobArguments(t *testing.T) {
579582
RestartPolicy: corev1.RestartPolicyNever,
580583
Affinity: nil,
581584
NodeSelector: nil,
585+
Tolerations: nil,
582586
ServiceAccountName: "default",
583587
AutomountServiceAccountToken: &automountServiceAccountToken,
584588
SecurityContext: &corev1.PodSecurityContext{},
@@ -673,6 +677,7 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
673677
RestartPolicy: corev1.RestartPolicyNever,
674678
Affinity: nil,
675679
NodeSelector: nil,
680+
Tolerations: nil,
676681
ServiceAccountName: "test",
677682
AutomountServiceAccountToken: &automountServiceAccountToken,
678683
SecurityContext: &corev1.PodSecurityContext{},
@@ -768,6 +773,7 @@ func TestNewRunnerJobIstio(t *testing.T) {
768773
RestartPolicy: corev1.RestartPolicyNever,
769774
Affinity: nil,
770775
NodeSelector: nil,
776+
Tolerations: nil,
771777
ServiceAccountName: "default",
772778
AutomountServiceAccountToken: &automountServiceAccountToken,
773779
SecurityContext: &corev1.PodSecurityContext{},
@@ -875,6 +881,7 @@ func TestNewRunnerJobCloud(t *testing.T) {
875881
RestartPolicy: corev1.RestartPolicyNever,
876882
Affinity: nil,
877883
NodeSelector: nil,
884+
Tolerations: nil,
878885
ServiceAccountName: "default",
879886
SecurityContext: &corev1.PodSecurityContext{},
880887
AutomountServiceAccountToken: &automountServiceAccountToken,
@@ -973,6 +980,7 @@ func TestNewRunnerJobLocalFile(t *testing.T) {
973980
RestartPolicy: corev1.RestartPolicyNever,
974981
Affinity: nil,
975982
NodeSelector: nil,
983+
Tolerations: nil,
976984
ServiceAccountName: "default",
977985
AutomountServiceAccountToken: &automountServiceAccountToken,
978986
SecurityContext: &corev1.PodSecurityContext{},

pkg/resources/jobs/starter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func NewStarterJob(k6 *v1alpha1.K6, hostname []string) *batchv1.Job {
6161
ServiceAccountName: serviceAccountName,
6262
Affinity: k6.Spec.Starter.Affinity,
6363
NodeSelector: k6.Spec.Starter.NodeSelector,
64+
Tolerations: k6.Spec.Starter.Tolerations,
6465
RestartPolicy: corev1.RestartPolicyNever,
6566
SecurityContext: &k6.Spec.Starter.SecurityContext,
6667
Containers: []corev1.Container{

pkg/resources/jobs/starter_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestNewStarterJob(t *testing.T) {
4545
ServiceAccountName: "default",
4646
Affinity: nil,
4747
NodeSelector: nil,
48+
Tolerations: nil,
4849
RestartPolicy: corev1.RestartPolicyNever,
4950
SecurityContext: &corev1.PodSecurityContext{},
5051
Containers: []corev1.Container{
@@ -123,6 +124,7 @@ func TestNewStarterJobIstio(t *testing.T) {
123124
ServiceAccountName: "default",
124125
Affinity: nil,
125126
NodeSelector: nil,
127+
Tolerations: nil,
126128
RestartPolicy: corev1.RestartPolicyNever,
127129
SecurityContext: &corev1.PodSecurityContext{},
128130
Containers: []corev1.Container{

0 commit comments

Comments
 (0)