Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/testrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/k6.io_testruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ spec:
additionalProperties:
type: string
type: object
priorityClassName:
type: string
readinessProbe:
properties:
exec:
Expand Down Expand Up @@ -2839,6 +2841,8 @@ spec:
additionalProperties:
type: string
type: object
priorityClassName:
type: string
readinessProbe:
properties:
exec:
Expand Down Expand Up @@ -4807,6 +4811,8 @@ spec:
additionalProperties:
type: string
type: object
priorityClassName:
type: string
readinessProbe:
properties:
exec:
Expand Down
21 changes: 21 additions & 0 deletions docs/crd-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,13 @@ alive or ready to receive traffic.<br/>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>priorityClassName</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#testrunspecinitializerreadinessprobe">readinessProbe</a></b></td>
<td>object</td>
Expand Down Expand Up @@ -9483,6 +9490,13 @@ alive or ready to receive traffic.<br/>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>priorityClassName</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#testrunspecrunnerreadinessprobe">readinessProbe</a></b></td>
<td>object</td>
Expand Down Expand Up @@ -18056,6 +18070,13 @@ alive or ready to receive traffic.<br/>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>priorityClassName</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#testrunspecstarterreadinessprobe">readinessProbe</a></b></td>
<td>object</td>
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/jobs/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
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 @@ -202,6 +202,7 @@ func NewRunnerJob(k6 *v1alpha1.TestRun, index int, tokenInfo *cloud.TokenInfo) (
}},
TerminationGracePeriodSeconds: &zero,
Volumes: volumes,
PriorityClassName: k6.GetSpec().Runner.PriorityClassName,
},
},
},
Expand Down
120 changes: 120 additions & 0 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions pkg/resources/jobs/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewStarterJob(k6 *v1alpha1.TestRun, hostname []string) *batchv1.Job {
resourceRequirements,
),
},
PriorityClassName: k6.GetSpec().Starter.PriorityClassName,
},
},
},
Expand Down
Loading