Repository: grafana/k6-operator
Pull request #59 (2021-08-06 22:17:30)

Removing the k6 run on the starter pod
Hi, 
  After some testing why the starter pod is always failiing on `0.0.7-rc`. I found my mistake on #56 when running the starter pod. I've replaced the original command `['scuttle', 'sh', '-c']` with `['scuttle', 'k6', '-run']`. This PR will solve this.

![1628287991](https://user-images.githubusercontent.com/11935541/128576143-490b97bc-4d4a-4394-a10f-44d94a63b172.png)


mycargus: For what it's worth, I tried this out and the .spec.scuttle.enabled="false" option works now. I didn't try it with scuttle enabled. Thanks for the quick fix, @knmsk !
vukor: Issue is reproduced to me on the next k6 test (I've built version from `v0.0.7-dev` tag):
```
apiVersion: k6.io/v1alpha1
kind: K6
metadata:
name: test
  namespace: k6-operator-system
spec:
  arguments: --vus 50 --duration 60s --verbose
  parallelism: 1
  paused: "false"
  quiet: "false"
  runner:
    nodeselector:
      group-name: XXX
    resources:
      limits:
        cpu: "7.5"
        memory: 30Gi
      requests:
        cpu: "7.5"
        memory: 30Gi
  script:
    volumeClaim:
      file: XXX
      name: XXX
  scuttle:
    enabled: "false"
  separate: false
```

creates starter job with incorrect arguments:
```
...
containers:
- command:
  - k6
  - run
  - 'curl -X PATCH -H ''Content-Type: application/json'' http://test-service-1:6565/v1/status
    -d ''{"data":{"attributes":{"paused":false},"id":"default","type":"status"}}'''
  image: radial/busyboxplus:curl
  imagePullPolicy: IfNotPresent
...
```
timothyjlaurent: LGTM!!


Patch:
diff --git a/pkg/resources/jobs/helpers.go b/pkg/resources/jobs/helpers.go
index 019d3b6..5035bf9 100644
--- a/pkg/resources/jobs/helpers.go
+++ b/pkg/resources/jobs/helpers.go
@@ -14,7 +14,7 @@ func newLabels(name string) map[string]string {
 	}
 }
 
-func newCommand(istioEnabled string) ([]string, bool) {
+func newIstioCommand(istioEnabled string, inheritedCommands []string) ([]string, bool) {
 	istio := true
 	if istioEnabled != "" {
 		istio, _ = strconv.ParseBool(istioEnabled)
@@ -24,7 +24,12 @@ func newCommand(istioEnabled string) ([]string, bool) {
 	if istio {
 		command = append(command, "scuttle")
 	}
-	return append(command, "k6", "run"), istio
+
+	for _, inheritedCommand := range inheritedCommands {
+		command = append(command, inheritedCommand)
+	}
+
+	return command, istio
 }
 
 func newIstioEnvVar(istio v1alpha1.K6Scuttle, istioEnabled bool) []corev1.EnvVar {
diff --git a/pkg/resources/jobs/runner.go b/pkg/resources/jobs/runner.go
index 319d78e..846b2e6 100644
--- a/pkg/resources/jobs/runner.go
+++ b/pkg/resources/jobs/runner.go
@@ -24,7 +24,9 @@ type Script struct {
 // NewRunnerJob creates a new k6 job from a CRD
 func NewRunnerJob(k6 *v1alpha1.K6, index int) (*batchv1.Job, error) {
 	name := fmt.Sprintf("%s-%d", k6.Name, index)
-	command, istioEnabled := newCommand(k6.Spec.Scuttle.Enabled)
+	postCommand := []string{"k6", "run"}
+
+	command, istioEnabled := newIstioCommand(k6.Spec.Scuttle.Enabled, postCommand)
 
 	quiet := true
 	if k6.Spec.Quiet != "" {
@@ -73,7 +75,7 @@ func NewRunnerJob(k6 *v1alpha1.K6, index int) (*batchv1.Job, error) {
 
 	var zero int64 = 0
 
-	image := "loadimpact/k6:latest"
+	image := "ghcr.io/grafana/operator:latest-runner"
 	if k6.Spec.Runner.Image != "" {
 		image = k6.Spec.Runner.Image
 	}
diff --git a/pkg/resources/jobs/starter.go b/pkg/resources/jobs/starter.go
index ca4aab8..651154a 100644
--- a/pkg/resources/jobs/starter.go
+++ b/pkg/resources/jobs/starter.go
@@ -19,10 +19,11 @@ func NewStarterJob(k6 *v1alpha1.K6, hostname []string) *batchv1.Job {
 		starterAnnotations = k6.Spec.Starter.Metadata.Annotations
 	}
 
-	starterImage := "radial/busyboxplus:curl"
+	starterImage := "ghcr.io/grafana/operator:latest-starter"
 	if k6.Spec.Starter.Image != "" {
 		starterImage = k6.Spec.Starter.Image
 	}
+
 	starterLabels := newLabels(k6.Name)
 	if k6.Spec.Starter.Metadata.Labels != nil {
 		for k, v := range k6.Spec.Starter.Metadata.Labels { // Order not specified
@@ -39,7 +40,7 @@ func NewStarterJob(k6 *v1alpha1.K6, hostname []string) *batchv1.Job {
 	if k6.Spec.Starter.AutomountServiceAccountToken != "" {
 		automountServiceAccountToken, _ = strconv.ParseBool(k6.Spec.Starter.AutomountServiceAccountToken)
 	}
-	command, istioEnabled := newCommand(k6.Spec.Scuttle.Enabled)
+	command, istioEnabled := newIstioCommand(k6.Spec.Scuttle.Enabled, []string{"sh", "-c"})
 	env := newIstioEnvVar(k6.Spec.Scuttle, istioEnabled)
 	return &batchv1.Job{
 		ObjectMeta: metav1.ObjectMeta{


Test patch:
diff --git a/pkg/resources/jobs/helpers_test.go b/pkg/resources/jobs/helpers_test.go
index 0cdf6c7..70def50 100644
--- a/pkg/resources/jobs/helpers_test.go
+++ b/pkg/resources/jobs/helpers_test.go
@@ -21,21 +21,21 @@ func TestNewLabels(t *testing.T) {
 	}
 }
 
-func TestNewCommandIfTrue(t *testing.T) {
+func TestNewIstioCommandIfTrue(t *testing.T) {
 	expectedOutcome := []string{"scuttle", "k6", "run"}
-	command, _ := newCommand("true")
+	command, _ := newIstioCommand("true", []string{"k6", "run"})
 
 	if diff := deep.Equal(expectedOutcome, command); diff != nil {
-		t.Errorf("newCommand returned unexpected data, diff: %s", diff)
+		t.Errorf("newIstioCommand returned unexpected data, diff: %s", diff)
 	}
 }
 
-func TestNewCommandIfFalse(t *testing.T) {
+func TestNewIstioCommandIfFalse(t *testing.T) {
 	expectedOutcome := []string{"k6", "run"}
-	command, _ := newCommand("false")
+	command, _ := newIstioCommand("false", []string{"k6", "run"})
 
 	if diff := deep.Equal(expectedOutcome, command); diff != nil {
-		t.Errorf("newCommand returned unexpected data, diff: %s", diff)
+		t.Errorf("newIstioCommand returned unexpected data, diff: %s", diff)
 	}
 }
 
diff --git a/pkg/resources/jobs/runner_test.go b/pkg/resources/jobs/runner_test.go
index db7035a..632947d 100644
--- a/pkg/resources/jobs/runner_test.go
+++ b/pkg/resources/jobs/runner_test.go
@@ -266,7 +266,7 @@ func TestNewRunnerJob(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						Image:   "loadimpact/k6:latest",
+						Image:   "ghcr.io/grafana/operator:latest-runner",
 						Name:    "k6",
 						Command: []string{"scuttle", "k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
 						Env: []corev1.EnvVar{
@@ -373,7 +373,7 @@ func TestNewRunnerJobNoisy(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						Image:   "loadimpact/k6:latest",
+						Image:   "ghcr.io/grafana/operator:latest-runner",
 						Name:    "k6",
 						Command: []string{"scuttle", "k6", "run", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
 						Env: []corev1.EnvVar{
@@ -481,7 +481,7 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						Image:   "loadimpact/k6:latest",
+						Image:   "ghcr.io/grafana/operator:latest-runner",
 						Name:    "k6",
 						Command: []string{"scuttle", "k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565"},
 						Env: []corev1.EnvVar{
@@ -589,7 +589,7 @@ func TestNewRunnerJobArguments(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						Image:   "loadimpact/k6:latest",
+						Image:   "ghcr.io/grafana/operator:latest-runner",
 						Name:    "k6",
 						Command: []string{"scuttle", "k6", "run", "--quiet", "--cool-thing", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
 						Env: []corev1.EnvVar{
@@ -698,7 +698,7 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
 					ServiceAccountName:           "test",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						Image:   "loadimpact/k6:latest",
+						Image:   "ghcr.io/grafana/operator:latest-runner",
 						Name:    "k6",
 						Command: []string{"scuttle", "k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused"},
 						Env: []corev1.EnvVar{
diff --git a/pkg/resources/jobs/starter_test.go b/pkg/resources/jobs/starter_test.go
index 75621f3..6f49287 100644
--- a/pkg/resources/jobs/starter_test.go
+++ b/pkg/resources/jobs/starter_test.go
@@ -47,7 +47,7 @@ func TestNewStarterJob(t *testing.T) {
 					NodeSelector:                 nil,
 					RestartPolicy:                corev1.RestartPolicyNever,
 					Containers: []corev1.Container{
-						containers.NewCurlContainer([]string{"testing"}, "image", []string{"scuttle", "k6", "run"}, []corev1.EnvVar{
+						containers.NewCurlContainer([]string{"testing"}, "image", []string{"scuttle", "sh", "-c"}, []corev1.EnvVar{
 							{
 								Name:  "ENVOY_ADMIN_API",
 								Value: "http://127.0.0.1:15000",