Skip to content
Open
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
2 changes: 2 additions & 0 deletions api/v1alpha1/testrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Pod struct {
InitContainers []InitContainer `json:"initContainers,omitempty"`
Volumes []corev1.Volume `json:"volumes,omitempty"`
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
// +kubebuilder:default=30
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
}

type InitContainer struct {
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions config/crd/bases/k6.io_testruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,10 @@ spec:
type: object
serviceAccountName:
type: string
terminationGracePeriodSeconds:
default: 30
format: int64
type: integer
tolerations:
items:
properties:
Expand Down Expand Up @@ -3032,6 +3036,10 @@ spec:
type: object
serviceAccountName:
type: string
terminationGracePeriodSeconds:
default: 30
format: int64
type: integer
tolerations:
items:
properties:
Expand Down Expand Up @@ -5000,6 +5008,10 @@ spec:
type: object
serviceAccountName:
type: string
terminationGracePeriodSeconds:
default: 30
format: int64
type: integer
tolerations:
items:
properties:
Expand Down
21 changes: 11 additions & 10 deletions pkg/resources/jobs/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@ func NewInitializerJob(k6 *v1alpha1.TestRun, argLine string) (*batchv1.Job, erro
Annotations: annotations,
},
Spec: corev1.PodSpec{
AutomountServiceAccountToken: &automountServiceAccountToken,
ServiceAccountName: serviceAccountName,
Affinity: k6.GetSpec().Initializer.Affinity,
NodeSelector: k6.GetSpec().Initializer.NodeSelector,
Tolerations: k6.GetSpec().Initializer.Tolerations,
TopologySpreadConstraints: k6.GetSpec().Initializer.TopologySpreadConstraints,
SecurityContext: &k6.GetSpec().Initializer.SecurityContext,
RestartPolicy: corev1.RestartPolicyNever,
ImagePullSecrets: k6.GetSpec().Initializer.ImagePullSecrets,
InitContainers: getInitContainers(k6.GetSpec().Initializer, script),
AutomountServiceAccountToken: &automountServiceAccountToken,
ServiceAccountName: serviceAccountName,
Affinity: k6.GetSpec().Initializer.Affinity,
NodeSelector: k6.GetSpec().Initializer.NodeSelector,
Tolerations: k6.GetSpec().Initializer.Tolerations,
TopologySpreadConstraints: k6.GetSpec().Initializer.TopologySpreadConstraints,
SecurityContext: &k6.GetSpec().Initializer.SecurityContext,
RestartPolicy: corev1.RestartPolicyNever,
ImagePullSecrets: k6.GetSpec().Initializer.ImagePullSecrets,
InitContainers: getInitContainers(k6.GetSpec().Initializer, script),
TerminationGracePeriodSeconds: k6.GetSpec().Initializer.TerminationGracePeriodSeconds,
Containers: []corev1.Container{
{
Image: image,
Expand Down
7 changes: 2 additions & 5 deletions pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ func NewRunnerJob(k6 *v1alpha1.TestRun, index int, token string) (*batchv1.Job,

command = script.UpdateCommand(command)

var (
zero int64 = 0
zero32 int32 = 0
)
var zero32 int32 = 0

image := "ghcr.io/grafana/k6-operator:latest-runner"
if k6.GetSpec().Runner.Image != "" {
Expand Down Expand Up @@ -189,7 +186,7 @@ func NewRunnerJob(k6 *v1alpha1.TestRun, index int, token string) (*batchv1.Job,
ReadinessProbe: generateProbe(k6.GetSpec().Runner.ReadinessProbe),
SecurityContext: &k6.GetSpec().Runner.ContainerSecurityContext,
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: k6.GetSpec().Runner.TerminationGracePeriodSeconds,
Volumes: volumes,
},
},
Expand Down
44 changes: 22 additions & 22 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestNewRunnerJob(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestNewRunnerJob(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestNewRunnerJobNoisy(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestNewRunnerJobNoisy(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -527,7 +527,7 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -642,7 +642,7 @@ func TestNewRunnerJobArguments(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -709,7 +709,7 @@ func TestNewRunnerJobArguments(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -758,7 +758,7 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -825,7 +825,7 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -875,7 +875,7 @@ func TestNewRunnerJobIstio(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -955,7 +955,7 @@ func TestNewRunnerJobIstio(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -1005,7 +1005,7 @@ func TestNewRunnerJobCloud(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -1080,7 +1080,7 @@ func TestNewRunnerJobCloud(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -1131,7 +1131,7 @@ func TestNewRunnerJobLocalFile(t *testing.T) {
Type: "LocalFile",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func TestNewRunnerJobLocalFile(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -1244,7 +1244,7 @@ func TestNewRunnerJobWithInitContainer(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -1339,7 +1339,7 @@ func TestNewRunnerJobWithInitContainer(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down Expand Up @@ -1411,7 +1411,7 @@ func TestNewRunnerJobWithVolume(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -1518,7 +1518,7 @@ func TestNewRunnerJobWithVolume(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: expectedVolumes,
},
},
Expand Down Expand Up @@ -1612,7 +1612,7 @@ func TestNewRunnerJobPLZTestRun(t *testing.T) {
Type: "ConfigMap",
}

var zero int64 = 0
var zero *int64 = nil
automountServiceAccountToken := true

expectedLabels := map[string]string{
Expand Down Expand Up @@ -1688,7 +1688,7 @@ func TestNewRunnerJobPLZTestRun(t *testing.T) {
},
SecurityContext: &corev1.SecurityContext{},
}},
TerminationGracePeriodSeconds: &zero,
TerminationGracePeriodSeconds: zero,
Volumes: script.Volume(),
},
},
Expand Down
19 changes: 10 additions & 9 deletions pkg/resources/jobs/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ func NewStarterJob(k6 *v1alpha1.TestRun, hostname []string) *batchv1.Job {
Annotations: starterAnnotations,
},
Spec: corev1.PodSpec{
AutomountServiceAccountToken: &automountServiceAccountToken,
ServiceAccountName: serviceAccountName,
Affinity: k6.GetSpec().Starter.Affinity,
NodeSelector: k6.GetSpec().Starter.NodeSelector,
Tolerations: k6.GetSpec().Starter.Tolerations,
TopologySpreadConstraints: k6.GetSpec().Starter.TopologySpreadConstraints,
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: &k6.GetSpec().Starter.SecurityContext,
ImagePullSecrets: k6.GetSpec().Starter.ImagePullSecrets,
AutomountServiceAccountToken: &automountServiceAccountToken,
ServiceAccountName: serviceAccountName,
Affinity: k6.GetSpec().Starter.Affinity,
NodeSelector: k6.GetSpec().Starter.NodeSelector,
Tolerations: k6.GetSpec().Starter.Tolerations,
TopologySpreadConstraints: k6.GetSpec().Starter.TopologySpreadConstraints,
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: &k6.GetSpec().Starter.SecurityContext,
ImagePullSecrets: k6.GetSpec().Starter.ImagePullSecrets,
TerminationGracePeriodSeconds: k6.GetSpec().Runner.TerminationGracePeriodSeconds,
Containers: []corev1.Container{
containers.NewStartContainer(
hostname,
Expand Down
Loading