Skip to content

Commit

Permalink
feat: add use of tolerations for starter and runner (#142)
Browse files Browse the repository at this point in the history
* feat: add use of tolerations for starter and runner

* build: update manifests

* feat: add runner tolerations to the initializer
  • Loading branch information
spoukke authored Sep 2, 2022
1 parent 1f5f120 commit c13609d
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/k6_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Pod struct {
Image string `json:"image,omitempty"`
Metadata PodMetadata `json:"metadata,omitempty"`
NodeSelector map[string]string `json:"nodeselector,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
SecurityContext corev1.PodSecurityContext `json:"securityContext,omitempty"`
Expand Down
80 changes: 80 additions & 0 deletions config/crd/bases/k6.io_k6s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,46 @@ spec:
type: object
serviceAccountName:
type: string
tolerations:
items:
description: The pod this Toleration is attached to tolerates
any taint that matches the triple <key,value,effect> using
the matching operator <operator>.
properties:
effect:
description: Effect indicates the taint effect to match.
Empty means match all taint effects. When specified, allowed
values are NoSchedule, PreferNoSchedule and NoExecute.
type: string
key:
description: Key is the taint key that the toleration applies
to. Empty means match all taint keys. If the key is empty,
operator must be Exists; this combination means to match
all values and all keys.
type: string
operator:
description: Operator represents a key's relationship to
the value. Valid operators are Exists and Equal. Defaults
to Equal. Exists is equivalent to wildcard for value,
so that a pod can tolerate all taints of a particular
category.
type: string
tolerationSeconds:
description: TolerationSeconds represents the period of
time the toleration (which must be of effect NoExecute,
otherwise this field is ignored) tolerates the taint.
By default, it is not set, which means tolerate the taint
forever (do not evict). Zero and negative values will
be treated as 0 (evict immediately) by the system.
format: int64
type: integer
value:
description: Value is the taint value the toleration matches
to. If the operator is Exists, the value should be empty,
otherwise just a regular string.
type: string
type: object
type: array
type: object
script:
description: K6Script describes where the script to execute the tests
Expand Down Expand Up @@ -2010,6 +2050,46 @@ spec:
type: object
serviceAccountName:
type: string
tolerations:
items:
description: The pod this Toleration is attached to tolerates
any taint that matches the triple <key,value,effect> using
the matching operator <operator>.
properties:
effect:
description: Effect indicates the taint effect to match.
Empty means match all taint effects. When specified, allowed
values are NoSchedule, PreferNoSchedule and NoExecute.
type: string
key:
description: Key is the taint key that the toleration applies
to. Empty means match all taint keys. If the key is empty,
operator must be Exists; this combination means to match
all values and all keys.
type: string
operator:
description: Operator represents a key's relationship to
the value. Valid operators are Exists and Equal. Defaults
to Equal. Exists is equivalent to wildcard for value,
so that a pod can tolerate all taints of a particular
category.
type: string
tolerationSeconds:
description: TolerationSeconds represents the period of
time the toleration (which must be of effect NoExecute,
otherwise this field is ignored) tolerates the taint.
By default, it is not set, which means tolerate the taint
forever (do not evict). Zero and negative values will
be treated as 0 (evict immediately) by the system.
format: int64
type: integer
value:
description: Value is the taint value the toleration matches
to. If the operator is Exists, the value should be empty,
otherwise just a regular string.
type: string
type: object
type: array
type: object
required:
- parallelism
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/jobs/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) {
ServiceAccountName: serviceAccountName,
Affinity: k6.Spec.Runner.Affinity,
NodeSelector: k6.Spec.Runner.NodeSelector,
Tolerations: k6.Spec.Runner.Tolerations,
RestartPolicy: corev1.RestartPolicyNever,
Containers: []corev1.Container{
{
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func NewRunnerJob(k6 *v1alpha1.K6, index int, testRunId, token string) (*batchv1
RestartPolicy: corev1.RestartPolicyNever,
Affinity: k6.Spec.Runner.Affinity,
NodeSelector: k6.Spec.Runner.NodeSelector,
Tolerations: k6.Spec.Runner.Tolerations,
SecurityContext: &k6.Spec.Runner.SecurityContext,
Containers: []corev1.Container{{
Image: image,
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func TestNewRunnerJob(t *testing.T) {
SecurityContext: &corev1.PodSecurityContext{},
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "default",
AutomountServiceAccountToken: &automountServiceAccountToken,
Containers: []corev1.Container{{
Expand Down Expand Up @@ -393,6 +394,7 @@ func TestNewRunnerJobNoisy(t *testing.T) {
RestartPolicy: corev1.RestartPolicyNever,
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "default",
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Expand Down Expand Up @@ -486,6 +488,7 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
RestartPolicy: corev1.RestartPolicyNever,
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "default",
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Expand Down Expand Up @@ -579,6 +582,7 @@ func TestNewRunnerJobArguments(t *testing.T) {
RestartPolicy: corev1.RestartPolicyNever,
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "default",
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Expand Down Expand Up @@ -673,6 +677,7 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
RestartPolicy: corev1.RestartPolicyNever,
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "test",
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Expand Down Expand Up @@ -768,6 +773,7 @@ func TestNewRunnerJobIstio(t *testing.T) {
RestartPolicy: corev1.RestartPolicyNever,
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "default",
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Expand Down Expand Up @@ -875,6 +881,7 @@ func TestNewRunnerJobCloud(t *testing.T) {
RestartPolicy: corev1.RestartPolicyNever,
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "default",
SecurityContext: &corev1.PodSecurityContext{},
AutomountServiceAccountToken: &automountServiceAccountToken,
Expand Down Expand Up @@ -973,6 +980,7 @@ func TestNewRunnerJobLocalFile(t *testing.T) {
RestartPolicy: corev1.RestartPolicyNever,
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
ServiceAccountName: "default",
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/jobs/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewStarterJob(k6 *v1alpha1.K6, hostname []string) *batchv1.Job {
ServiceAccountName: serviceAccountName,
Affinity: k6.Spec.Starter.Affinity,
NodeSelector: k6.Spec.Starter.NodeSelector,
Tolerations: k6.Spec.Starter.Tolerations,
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: &k6.Spec.Starter.SecurityContext,
Containers: []corev1.Container{
Expand Down
2 changes: 2 additions & 0 deletions pkg/resources/jobs/starter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestNewStarterJob(t *testing.T) {
ServiceAccountName: "default",
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: &corev1.PodSecurityContext{},
Containers: []corev1.Container{
Expand Down Expand Up @@ -123,6 +124,7 @@ func TestNewStarterJobIstio(t *testing.T) {
ServiceAccountName: "default",
Affinity: nil,
NodeSelector: nil,
Tolerations: nil,
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: &corev1.PodSecurityContext{},
Containers: []corev1.Container{
Expand Down

0 comments on commit c13609d

Please sign in to comment.