Skip to content

Commit

Permalink
Removing the k6 run on the starter pod (#59)
Browse files Browse the repository at this point in the history
* Removing the k6 run on the starter pod

* Renamed the newCommand to newIstioCommand
  • Loading branch information
Kino authored Aug 17, 2021
1 parent 4ea617e commit 0766a6e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
9 changes: 7 additions & 2 deletions pkg/resources/jobs/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions pkg/resources/jobs/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/jobs/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/jobs/starter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0766a6e

Please sign in to comment.