Repository: grafana/k6-operator (go)

Issue:
Latest build requires Istio/Envoy to be installed on the cluster.
Hey!
I wanted to start using your operator, but unfortunately running any test with latest release `v0.0.7rc2` fails at connecting to Envoy.
```
2021-09-03 15:32:35 | 2021-09-03T13:32:35Z scuttle: Scuttle 1.3.5 starting up, pid 1
-- | --
  |   | 2021-09-03 15:32:35 | 2021-09-03T13:32:35Z scuttle: Logging is now enabled
  |   | 2021-09-03 15:32:35 | 2021-09-03T13:32:35Z scuttle: Blocking until Envoy starts
  |   | 2021-09-03 15:32:35 | 2021-09-03T13:32:35Z scuttle: Polling Envoy (1), error: internal_service: dial tcp 127.0.0.1:15000: connect: connection refused
  |   | 2021-09-03 15:32:35 | 2021-09-03T13:32:35Z scuttle: Polling Envoy (2), error: internal_service: dial tcp 127.0.0.1:15000: connect: connection refused
  |   | 2021-09-03 15:32:37 | 2021-09-03T13:32:37Z scuttle: Polling Envoy (3), error: internal_service: dial tcp 127.0.0.1:15000: connect: connection refused
  |   | 2021-09-03 15:32:38 | 2021-09-03T13:32:38Z scuttle: Polling Envoy (4), error: internal_service: dial tcp 127.0.0.1:15000: connect: connection refused
  |   | 2021-09-03 15:32:39 | 2021-09-03T13:32:39Z scuttle: Polling Envoy (5), error: internal_service: dial tcp 127.0.0.1:15000: connect: connection refused
  |   | 2021-09-03 15:32:42 | 2021-09-03T13:32:42Z scuttle: Polling Envoy (6), error: internal_service: dial tcp 127.0.0.1:15000: connect: connection refused

```

Running your operator with `ghcr.io/k6io/operator:v0.0.6` image fixes the issue and it can operate as expected. I am running another service mesh and I am not likely to migrate to Istio.

Thanks,
Szymon

Pull request description:
fix: change istio to disable by default in runner
resolves #70
replaces #68

Patch:
diff --git a/pkg/resources/jobs/helpers.go b/pkg/resources/jobs/helpers.go
index 5035bf9..3a8110a 100644
--- a/pkg/resources/jobs/helpers.go
+++ b/pkg/resources/jobs/helpers.go
@@ -15,7 +15,7 @@ func newLabels(name string) map[string]string {
 }
 
 func newIstioCommand(istioEnabled string, inheritedCommands []string) ([]string, bool) {
-	istio := true
+	istio := false
 	if istioEnabled != "" {
 		istio, _ = strconv.ParseBool(istioEnabled)
 	}


Test patch:
diff --git a/pkg/resources/jobs/runner_test.go b/pkg/resources/jobs/runner_test.go
index 632947d..2312a43 100644
--- a/pkg/resources/jobs/runner_test.go
+++ b/pkg/resources/jobs/runner_test.go
@@ -266,23 +266,10 @@ func TestNewRunnerJob(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						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{
-							{
-								Name:  "ENVOY_ADMIN_API",
-								Value: "http://127.0.0.1:15000",
-							},
-							{
-								Name:  "ISTIO_QUIT_API",
-								Value: "http://127.0.0.1:15020",
-							},
-							{
-								Name:  "WAIT_FOR_ENVOY_TIMEOUT",
-								Value: "15",
-							},
-						},
+						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",
@@ -373,23 +360,10 @@ func TestNewRunnerJobNoisy(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						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{
-							{
-								Name:  "ENVOY_ADMIN_API",
-								Value: "http://127.0.0.1:15000",
-							},
-							{
-								Name:  "ISTIO_QUIT_API",
-								Value: "http://127.0.0.1:15020",
-							},
-							{
-								Name:  "WAIT_FOR_ENVOY_TIMEOUT",
-								Value: "15",
-							},
-						},
+						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",
@@ -481,23 +455,10 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						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{
-							{
-								Name:  "ENVOY_ADMIN_API",
-								Value: "http://127.0.0.1:15000",
-							},
-							{
-								Name:  "ISTIO_QUIT_API",
-								Value: "http://127.0.0.1:15020",
-							},
-							{
-								Name:  "WAIT_FOR_ENVOY_TIMEOUT",
-								Value: "15",
-							},
-						},
+						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",
@@ -589,23 +550,10 @@ func TestNewRunnerJobArguments(t *testing.T) {
 					ServiceAccountName:           "default",
 					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
-						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{
-							{
-								Name:  "ENVOY_ADMIN_API",
-								Value: "http://127.0.0.1:15000",
-							},
-							{
-								Name:  "ISTIO_QUIT_API",
-								Value: "http://127.0.0.1:15020",
-							},
-							{
-								Name:  "WAIT_FOR_ENVOY_TIMEOUT",
-								Value: "15",
-							},
-						},
+						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",
@@ -697,6 +645,103 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
 					NodeSelector:                 nil,
 					ServiceAccountName:           "test",
 					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}},
+					}},
+					TerminationGracePeriodSeconds: &zero,
+					Volumes:                       newVolumeSpec(script),
+				},
+			},
+		},
+	}
+
+	k6 := &v1alpha1.K6{
+		ObjectMeta: metav1.ObjectMeta{
+			Name:      "test",
+			Namespace: "test",
+		},
+		Spec: v1alpha1.K6Spec{
+
+			Script: v1alpha1.K6Script{
+				ConfigMap: v1alpha1.K6Configmap{
+					Name: "test",
+					File: "test.js",
+				},
+			},
+			Runner: v1alpha1.Pod{
+				ServiceAccountName: "test",
+				Metadata: v1alpha1.PodMetadata{
+					Labels: map[string]string{
+						"label1": "awesome",
+					},
+					Annotations: map[string]string{
+						"awesomeAnnotation": "dope",
+					},
+				},
+			},
+		},
+	}
+
+	job, err := NewRunnerJob(k6, 1)
+	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)
+	}
+}
+
+func TestNewRunnerJobIstio(t *testing.T) {
+	script := &Script{
+		Name: "test",
+		File: "thing.js",
+		Type: "ConfigMap",
+	}
+
+	var zero int64 = 0
+	automountServiceAccountToken := true
+
+	expectedOutcome := &batchv1.Job{
+		ObjectMeta: metav1.ObjectMeta{
+			Name:      "test-1",
+			Namespace: "test",
+			Labels: map[string]string{
+				"app":    "k6",
+				"k6_cr":  "test",
+				"label1": "awesome",
+			},
+			Annotations: map[string]string{
+				"awesomeAnnotation": "dope",
+			},
+		},
+		Spec: batchv1.JobSpec{
+			Template: corev1.PodTemplateSpec{
+				ObjectMeta: metav1.ObjectMeta{
+					Labels: map[string]string{
+						"app":    "k6",
+						"k6_cr":  "test",
+						"label1": "awesome",
+					},
+					Annotations: map[string]string{
+						"awesomeAnnotation": "dope",
+					},
+				},
+				Spec: corev1.PodSpec{
+					Hostname:                     "test-1",
+					RestartPolicy:                corev1.RestartPolicyNever,
+					Affinity:                     nil,
+					NodeSelector:                 nil,
+					ServiceAccountName:           "default",
+					AutomountServiceAccountToken: &automountServiceAccountToken,
 					Containers: []corev1.Container{{
 						Image:   "ghcr.io/grafana/operator:latest-runner",
 						Name:    "k6",
@@ -728,14 +773,15 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
 			},
 		},
 	}
-
 	k6 := &v1alpha1.K6{
 		ObjectMeta: metav1.ObjectMeta{
 			Name:      "test",
 			Namespace: "test",
 		},
 		Spec: v1alpha1.K6Spec{
-
+			Scuttle: v1alpha1.K6Scuttle{
+				Enabled: "true",
+			},
 			Script: v1alpha1.K6Script{
 				ConfigMap: v1alpha1.K6Configmap{
 					Name: "test",
@@ -743,7 +789,6 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
 				},
 			},
 			Runner: v1alpha1.Pod{
-				ServiceAccountName: "test",
 				Metadata: v1alpha1.PodMetadata{
 					Labels: map[string]string{
 						"label1": "awesome",
diff --git a/pkg/resources/jobs/starter_test.go b/pkg/resources/jobs/starter_test.go
index 6f49287..3b8baeb 100644
--- a/pkg/resources/jobs/starter_test.go
+++ b/pkg/resources/jobs/starter_test.go
@@ -15,6 +15,83 @@ func TestNewStarterJob(t *testing.T) {
 
 	automountServiceAccountToken := true
 
+	expectedOutcome := &batchv1.Job{
+		ObjectMeta: metav1.ObjectMeta{
+			Name:      "test-starter",
+			Namespace: "test",
+			Labels: map[string]string{
+				"app":    "k6",
+				"k6_cr":  "test",
+				"label1": "awesome",
+			},
+			Annotations: map[string]string{
+				"awesomeAnnotation": "dope",
+			},
+		},
+		Spec: batchv1.JobSpec{
+			Template: corev1.PodTemplateSpec{
+				ObjectMeta: metav1.ObjectMeta{
+					Labels: map[string]string{
+						"app":    "k6",
+						"k6_cr":  "test",
+						"label1": "awesome",
+					},
+					Annotations: map[string]string{
+						"awesomeAnnotation": "dope",
+					},
+				},
+				Spec: corev1.PodSpec{
+					AutomountServiceAccountToken: &automountServiceAccountToken,
+					ServiceAccountName:           "default",
+					Affinity:                     nil,
+					NodeSelector:                 nil,
+					RestartPolicy:                corev1.RestartPolicyNever,
+					Containers: []corev1.Container{
+						containers.NewCurlContainer([]string{"testing"}, "image", []string{"sh", "-c"},
+							[]corev1.EnvVar{}),
+					},
+				},
+			},
+		},
+	}
+
+	k6 := &v1alpha1.K6{
+		ObjectMeta: metav1.ObjectMeta{
+			Name:      "test",
+			Namespace: "test",
+		},
+		Spec: v1alpha1.K6Spec{
+			Script: v1alpha1.K6Script{
+				ConfigMap: v1alpha1.K6Configmap{
+					Name: "test",
+					File: "test.js",
+				},
+			},
+			Starter: v1alpha1.Pod{
+				Metadata: v1alpha1.PodMetadata{
+					Labels: map[string]string{
+						"label1": "awesome",
+					},
+					Annotations: map[string]string{
+						"awesomeAnnotation": "dope",
+					},
+				},
+				Image: "image",
+			},
+		},
+	}
+
+	job := NewStarterJob(k6, []string{"testing"})
+	if diff := deep.Equal(job, expectedOutcome); diff != nil {
+		t.Error(diff)
+	}
+
+}
+
+func TestNewStarterJobIstio(t *testing.T) {
+
+	automountServiceAccountToken := true
+
 	expectedOutcome := &batchv1.Job{
 		ObjectMeta: metav1.ObjectMeta{
 			Name:      "test-starter",
@@ -72,6 +149,9 @@ func TestNewStarterJob(t *testing.T) {
 			Namespace: "test",
 		},
 		Spec: v1alpha1.K6Spec{
+			Scuttle: v1alpha1.K6Scuttle{
+				Enabled: "true",
+			},
 			Script: v1alpha1.K6Script{
 				ConfigMap: v1alpha1.K6Configmap{
 					Name: "test",