Skip to content

Commit

Permalink
plz: pass env vars to runner from GCk6
Browse files Browse the repository at this point in the history
  • Loading branch information
yorugac committed Jul 19, 2024
1 parent 94581a4 commit 535c529
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
21 changes: 18 additions & 3 deletions pkg/cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"go.k6.io/k6/cloudapi"
"go.k6.io/k6/lib/types"
"go.k6.io/k6/metrics"
corev1 "k8s.io/api/core/v1"
)

// InspectOutput is the parsed output from `k6 inspect --execution-requirements`.
Expand Down Expand Up @@ -65,15 +66,29 @@ type TestRunData struct {
}

type LZConfig struct {
RunnerImage string `json:"load_runner_image"`
InstanceCount int `json:"instance_count"`
ArchiveURL string `json:"k6_archive_temp_public_url"`
RunnerImage string `json:"load_runner_image"`
InstanceCount int `json:"instance_count"`
ArchiveURL string `json:"k6_archive_temp_public_url"`
Environment map[string]string `json:"environment"`
}

func (trd *TestRunData) TestRunID() string {
return fmt.Sprintf("%d", trd.TestRunId)
}

func (lz *LZConfig) EnvVars() []corev1.EnvVar {
ev := make([]corev1.EnvVar, len(lz.Environment))
i := 0
for k, v := range lz.Environment {
ev[i] = corev1.EnvVar{
Name: k,
Value: v,
}
i++
}
return ev
}

type TestRunStatus cloudapi.RunStatus

func (trs TestRunStatus) Aborted() bool {
Expand Down
10 changes: 6 additions & 4 deletions pkg/testrun/plz.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, trData *cloud.TestRunData, ing
volumeMount,
)

envVars := append(trData.EnvVars(), corev1.EnvVar{
Name: "K6_CLOUD_HOST",
Value: ingestUrl,
})

return &v1alpha1.TestRun{
ObjectMeta: metav1.ObjectMeta{
Name: TestName(trData.TestRunID()),
Expand All @@ -54,10 +59,7 @@ func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, trData *cloud.TestRunData, ing
InitContainers: []v1alpha1.InitContainer{
initContainer,
},
Env: []corev1.EnvVar{{
Name: "K6_CLOUD_HOST",
Value: ingestUrl,
}},
Env: envVars,
},
Starter: v1alpha1.Pod{
ServiceAccountName: plz.Spec.ServiceAccountName,
Expand Down

0 comments on commit 535c529

Please sign in to comment.