diff --git a/api/v1alpha1/testrun_types.go b/api/v1alpha1/testrun_types.go
index c8894201..d041b739 100644
--- a/api/v1alpha1/testrun_types.go
+++ b/api/v1alpha1/testrun_types.go
@@ -52,6 +52,7 @@ type Pod struct {
InitContainers []InitContainer `json:"initContainers,omitempty"`
Volumes []corev1.Volume `json:"volumes,omitempty"`
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
+ PriorityClassName string `json:"priorityClassName,omitempty"`
}
type InitContainer struct {
diff --git a/config/crd/bases/k6.io_testruns.yaml b/config/crd/bases/k6.io_testruns.yaml
index 24283c04..b352dd64 100644
--- a/config/crd/bases/k6.io_testruns.yaml
+++ b/config/crd/bases/k6.io_testruns.yaml
@@ -892,6 +892,8 @@ spec:
additionalProperties:
type: string
type: object
+ priorityClassName:
+ type: string
readinessProbe:
properties:
exec:
@@ -2839,6 +2841,8 @@ spec:
additionalProperties:
type: string
type: object
+ priorityClassName:
+ type: string
readinessProbe:
properties:
exec:
@@ -4807,6 +4811,8 @@ spec:
additionalProperties:
type: string
type: object
+ priorityClassName:
+ type: string
readinessProbe:
properties:
exec:
diff --git a/docs/crd-generated.md b/docs/crd-generated.md
index cdf63134..a2c98831 100644
--- a/docs/crd-generated.md
+++ b/docs/crd-generated.md
@@ -932,6 +932,13 @@ alive or ready to receive traffic.
false |
+
+ priorityClassName |
+ string |
+
+
+ |
+ false |
readinessProbe |
object |
@@ -9483,6 +9490,13 @@ alive or ready to receive traffic.
false |
+
+ priorityClassName |
+ string |
+
+
+ |
+ false |
readinessProbe |
object |
@@ -18056,6 +18070,13 @@ alive or ready to receive traffic.
false |
+
+ priorityClassName |
+ string |
+
+
+ |
+ false |
readinessProbe |
object |
diff --git a/pkg/resources/jobs/initializer.go b/pkg/resources/jobs/initializer.go
index 94bb0cf9..0686c990 100644
--- a/pkg/resources/jobs/initializer.go
+++ b/pkg/resources/jobs/initializer.go
@@ -128,7 +128,8 @@ func NewInitializerJob(k6 *v1alpha1.TestRun, argLine string) (*batchv1.Job, erro
SecurityContext: &k6.GetSpec().Initializer.ContainerSecurityContext,
},
},
- Volumes: volumes,
+ Volumes: volumes,
+ PriorityClassName: k6.GetSpec().Initializer.PriorityClassName,
},
},
},
diff --git a/pkg/resources/jobs/runner.go b/pkg/resources/jobs/runner.go
index 810dd84e..e7d1c714 100644
--- a/pkg/resources/jobs/runner.go
+++ b/pkg/resources/jobs/runner.go
@@ -202,6 +202,7 @@ func NewRunnerJob(k6 *v1alpha1.TestRun, index int, tokenInfo *cloud.TokenInfo) (
}},
TerminationGracePeriodSeconds: &zero,
Volumes: volumes,
+ PriorityClassName: k6.GetSpec().Runner.PriorityClassName,
},
},
},
diff --git a/pkg/resources/jobs/runner_test.go b/pkg/resources/jobs/runner_test.go
index e5d7c175..44c1500a 100644
--- a/pkg/resources/jobs/runner_test.go
+++ b/pkg/resources/jobs/runner_test.go
@@ -1747,3 +1747,123 @@ func TestNewRunnerJobPLZTestRun(t *testing.T) {
t.Errorf("NewRunnerJob returned unexpected data, diff: %s", diff)
}
}
+
+func TestNewRunnerJobPriorityClassName(t *testing.T) {
+
+ script := &types.Script{
+ Name: "test",
+ Filename: "thing.js",
+ Type: "ConfigMap",
+ }
+
+ var zero int64 = 0
+ automountServiceAccountToken := true
+
+ expectedLabels := map[string]string{
+ "app": "k6",
+ "k6_cr": "test",
+ "runner": "true",
+ "label1": "awesome",
+ }
+
+ expectedOutcome := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test-1",
+ Namespace: "test",
+ Labels: expectedLabels,
+ Annotations: map[string]string{
+ "awesomeAnnotation": "dope",
+ },
+ },
+ Spec: batchv1.JobSpec{
+ BackoffLimit: new(int32),
+ Template: corev1.PodTemplateSpec{
+ ObjectMeta: metav1.ObjectMeta{
+ Labels: expectedLabels,
+ Annotations: map[string]string{
+ "awesomeAnnotation": "dope",
+ },
+ },
+ Spec: corev1.PodSpec{
+ Hostname: "test-1",
+ RestartPolicy: corev1.RestartPolicyNever,
+ Affinity: nil,
+ NodeSelector: nil,
+ Tolerations: nil,
+ TopologySpreadConstraints: nil,
+ ServiceAccountName: "default",
+ AutomountServiceAccountToken: &automountServiceAccountToken,
+ SecurityContext: &corev1.PodSecurityContext{},
+ Containers: []corev1.Container{{
+ Image: "grafana/k6:latest",
+ ImagePullPolicy: "",
+ Name: "k6",
+ Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
+ Env: []corev1.EnvVar{},
+ Resources: corev1.ResourceRequirements{},
+ VolumeMounts: script.VolumeMount(),
+ Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
+ LivenessProbe: &corev1.Probe{
+ ProbeHandler: corev1.ProbeHandler{
+ HTTPGet: &corev1.HTTPGetAction{
+ Path: "/v1/status",
+ Port: intstr.IntOrString{IntVal: 6565},
+ Scheme: "HTTP",
+ },
+ },
+ },
+ ReadinessProbe: &corev1.Probe{
+ ProbeHandler: corev1.ProbeHandler{
+ HTTPGet: &corev1.HTTPGetAction{
+ Path: "/v1/status",
+ Port: intstr.IntOrString{IntVal: 6565},
+ Scheme: "HTTP",
+ },
+ },
+ },
+ SecurityContext: &corev1.SecurityContext{},
+ }},
+ TerminationGracePeriodSeconds: &zero,
+ Volumes: script.Volume(),
+ PriorityClassName: "high-priority",
+ },
+ },
+ },
+ }
+
+ k6 := &v1alpha1.TestRun{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test",
+ Namespace: "test",
+ },
+ Spec: v1alpha1.TestRunSpec{
+
+ Script: v1alpha1.K6Script{
+ ConfigMap: v1alpha1.K6Configmap{
+ Name: "test",
+ File: "test.js",
+ },
+ },
+ Runner: v1alpha1.Pod{
+ Metadata: v1alpha1.PodMetadata{
+ Labels: map[string]string{
+ "label1": "awesome",
+ },
+ Annotations: map[string]string{
+ "awesomeAnnotation": "dope",
+ },
+ },
+ PriorityClassName: "high-priority",
+ },
+ },
+ }
+
+ job, err := NewRunnerJob(k6, 1, cloud.NewTokenInfo("", ""))
+ if err != nil {
+ t.Errorf("NewRunnerJob errored, got: %v", err)
+ }
+
+ if diff := deep.Equal(job, expectedOutcome); diff != nil {
+ t.Errorf("NewRunnerJob returned unexpected data, diff: %s", diff)
+ }
+}
diff --git a/pkg/resources/jobs/starter.go b/pkg/resources/jobs/starter.go
index 73ed75fa..eed0960f 100644
--- a/pkg/resources/jobs/starter.go
+++ b/pkg/resources/jobs/starter.go
@@ -96,6 +96,7 @@ func NewStarterJob(k6 *v1alpha1.TestRun, hostname []string) *batchv1.Job {
resourceRequirements,
),
},
+ PriorityClassName: k6.GetSpec().Starter.PriorityClassName,
},
},
},