Skip to content

Commit

Permalink
properly append arguments to the run command (#12)
Browse files Browse the repository at this point in the history
- adds a sample manifest with an output as argument
- fixes an issue where arguments where appended as a full string instead of a segmented array
  • Loading branch information
simskij authored Apr 27, 2021
1 parent ca1a5dd commit 949a05c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions api/v1alpha1/k6_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (

// K6Spec defines the desired state of K6
type K6Spec struct {
Script string `json:"script"`
Parallelism int32 `json:"parallelism"`
Separate bool `json:"separate,omitempty"`
// Cleanup Cleanup `json:"cleanup,omitempty"` // TODO
Arguments string `json:"arguments,omitempty"`
Script string `json:"script"`
Parallelism int32 `json:"parallelism"`
Separate bool `json:"separate,omitempty"`
Arguments string `json:"arguments,omitempty"`
// Cleanup Cleanup `json:"cleanup,omitempty"` // TODO
}

// Cleanup allows for automatic cleanup of resources pre or post execution
Expand Down
8 changes: 8 additions & 0 deletions config/samples/k6_v1alpha1_k6_with_output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: k6.io/v1alpha1
kind: K6
metadata:
name: k6-sample
spec:
parallelism: 4
script: k6-test
arguments: --out kafka=brokers=kafka-host:9092,topic=test-output,format=json
4 changes: 3 additions & 1 deletion pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)

// NewRunnerJob creates a new k6 job from a CRD
Expand All @@ -27,7 +28,8 @@ func NewRunnerJob(k *v1alpha1.K6, index int) (*batchv1.Job, error) {
}

if k.Spec.Arguments != "" {
command = append(command, k.Spec.Arguments)
args := strings.Split(k.Spec.Arguments, " ")
command = append(command, args...)
}
command = append(
command,
Expand Down

0 comments on commit 949a05c

Please sign in to comment.