Skip to content

Commit

Permalink
fix: change istio to disable by default in runner (#71)
Browse files Browse the repository at this point in the history
* fix: change istio to disable by default in runner

* chore: fix tests

Signed-off-by: Hans Knecht <[email protected]>
  • Loading branch information
knechtionscoding authored Sep 9, 2021
1 parent 0766a6e commit 6a43695
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 72 deletions.
2 changes: 1 addition & 1 deletion pkg/resources/jobs/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
187 changes: 116 additions & 71 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -728,22 +773,22 @@ 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",
File: "test.js",
},
},
Runner: v1alpha1.Pod{
ServiceAccountName: "test",
Metadata: v1alpha1.PodMetadata{
Labels: map[string]string{
"label1": "awesome",
Expand Down
80 changes: 80 additions & 0 deletions pkg/resources/jobs/starter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 6a43695

Please sign in to comment.