Skip to content

Commit

Permalink
localFile: fix of Volume and VolumeMount
Browse files Browse the repository at this point in the history
  • Loading branch information
yorugac committed May 25, 2022
1 parent 9db5af6 commit 6256831
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 162 deletions.
23 changes: 8 additions & 15 deletions pkg/resources/jobs/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,16 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) {
RestartPolicy: corev1.RestartPolicyNever,
Containers: []corev1.Container{
{
Image: image,
Name: "k6",
Command: command,
Env: env,
Resources: k6.Spec.Runner.Resources,
VolumeMounts: []corev1.VolumeMount{
{
Name: "k6-test-volume",
MountPath: "/test",
},
},
Ports: ports,
Image: image,
Name: "k6",
Command: command,
Env: env,
Resources: k6.Spec.Runner.Resources,
VolumeMounts: script.VolumeMount(),
Ports: ports,
},
},
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down
15 changes: 5 additions & 10 deletions pkg/resources/jobs/initializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,13 @@ func TestNewInitializerJob(t *testing.T) {
"sh", "-c",
"k6 archive /test/test.js -O ./test.js.archived.tar --out cloud && k6 inspect --execution-requirements ./test.js.archived.tar",
},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
},
},
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down
20 changes: 8 additions & 12 deletions pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,16 @@ func NewRunnerJob(k6 *v1alpha1.K6, index int, testRunId, token string) (*batchv1
NodeSelector: k6.Spec.Runner.NodeSelector,
SecurityContext: &k6.Spec.Runner.SecurityContext,
Containers: []corev1.Container{{
Image: image,
Name: "k6",
Command: command,
Env: env,
Resources: k6.Spec.Runner.Resources,
VolumeMounts: []corev1.VolumeMount{
script.VolumeMount(),
},
Ports: ports,
Image: image,
Name: "k6",
Command: command,
Env: env,
Resources: k6.Spec.Runner.Resources,
VolumeMounts: script.VolumeMount(),
Ports: ports,
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down
179 changes: 72 additions & 107 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ func TestNewScriptNoScript(t *testing.T) {
}

func TestNewVolumeSpecVolumeClaim(t *testing.T) {
expectedOutcome := corev1.Volume{
Name: "k6-test-volume",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "test",
expectedOutcome := []corev1.Volume{
corev1.Volume{
Name: "k6-test-volume",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "test",
},
},
},
}
Expand All @@ -120,12 +122,14 @@ func TestNewVolumeSpecVolumeClaim(t *testing.T) {
}

func TestNewVolumeSpecConfigMap(t *testing.T) {
expectedOutcome := corev1.Volume{
Name: "k6-test-volume",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "test",
expectedOutcome := []corev1.Volume{
corev1.Volume{
Name: "k6-test-volume",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "test",
},
},
},
},
Expand All @@ -143,7 +147,7 @@ func TestNewVolumeSpecConfigMap(t *testing.T) {
}

func TestNewVolumeSpecNoType(t *testing.T) {
expectedOutcome := corev1.Volume{}
expectedOutcome := []corev1.Volume{}

script := &types.Script{
Name: "test",
Expand Down Expand Up @@ -283,21 +287,16 @@ func TestNewRunnerJob(t *testing.T) {
ServiceAccountName: "default",
AutomountServiceAccountToken: &automountServiceAccountToken,
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down Expand Up @@ -380,21 +379,16 @@ func TestNewRunnerJobNoisy(t *testing.T) {
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down Expand Up @@ -478,21 +472,16 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down Expand Up @@ -576,21 +565,16 @@ func TestNewRunnerJobArguments(t *testing.T) {
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "--cool-thing", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "--cool-thing", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down Expand Up @@ -675,21 +659,16 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down Expand Up @@ -792,17 +771,12 @@ func TestNewRunnerJobIstio(t *testing.T) {
Value: "15",
},
},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down Expand Up @@ -900,17 +874,12 @@ func TestNewRunnerJobCloud(t *testing.T) {
Value: "token",
},
},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{{
Name: "k6-test-volume",
MountPath: "/test",
}},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down Expand Up @@ -990,20 +959,16 @@ func TestNewRunnerJobLocalFile(t *testing.T) {
AutomountServiceAccountToken: &automountServiceAccountToken,
SecurityContext: &corev1.PodSecurityContext{},
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"sh", "-c", "if [ ! -f /test/test.js ]; then echo \"LocalFile not found exiting...\"; exit 1; fi;\nk6 run --quiet /test/test.js --address=0.0.0.0:6565 --paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: []corev1.VolumeMount{
script.VolumeMount(),
},
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"sh", "-c", "if [ ! -f /test/test.js ]; then echo \"LocalFile not found exiting...\"; exit 1; fi;\nk6 run --quiet /test/test.js --address=0.0.0.0:6565 --paused"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
}},
TerminationGracePeriodSeconds: &zero,
Volumes: []corev1.Volume{
script.Volume(),
},
Volumes: script.Volume(),
},
},
},
Expand Down
Loading

0 comments on commit 6256831

Please sign in to comment.