Skip to content

Commit d9bf869

Browse files
committed
add chain.link labels to new k8s test runner
1 parent 4469d3b commit d9bf869

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

book/src/k8s-test-runner/k8s-test-runner.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The TOML config should specify the test runner configuration as follows:
4545
```
4646
namespace = "e2e-tests"
4747
rbac_role_name = "" # RBAC role name for the chart
48+
rbac_service_account_name = "" # RBAC service account name for the chart
4849
image_registry_url = "" # URL to the ECR containing the test binary image, e.g., staging ECR URL
4950
image_name = "k8s-test-runner"
5051
image_tag = "" # The image tag to use, like "mercury-load-tests" (see readme above)
@@ -61,8 +62,16 @@ resources_limits_memory = "1024Mi"
6162
WASP_LOG_LEVEL = "info"
6263
TEST_LOG_LEVEL = "info"
6364
MERCURY_TEST_LOG_LEVEL = "info"
65+
[metadata.labels]
66+
"chain.link/component" = "k8s-test-runner"
67+
"chain.link/product" = "<your-product-name>"
68+
"chain.link/team" = "<name–of-the-team-you're-running-the-test-for>"
69+
"chain.link/cost-center" = "<sensible-identifier:eg: product-testType-test>"
6470
```
6571

72+
> [NOTE]
73+
> Make sure to quote labels with "/" as otherwise parsing them will fail.
74+
6675
Where:
6776

6877
- `test_name` is the name of the test to run (must be included in the test binary).
@@ -113,6 +122,7 @@ Then:
113122
cat << EOF > config.toml
114123
namespace = "e2e-tests"
115124
rbac_role_name = "" # RBAC role name for the chart
125+
rbac_service_account_name = "" # RBAC service account name for the chart
116126
image_registry_url = "${{ secrets.AWS_ACCOUNT_ID_STAGING }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
117127
image_name = "k8s-test-runner"
118128
image_tag = "mercury-load-test"
@@ -130,6 +140,11 @@ Then:
130140
WASP_LOG_LEVEL = "info"
131141
TEST_LOG_LEVEL = "info"
132142
MERCURY_TEST_LOG_LEVEL = "info"
143+
[metadata.labels]
144+
"chain.link/component" = "k8s-test-runner"
145+
"chain.link/product" = "data-streamsv0.3"
146+
"chain.link/team" = "Data Streams"
147+
"chain.link/cost-center" = "data-streamsv0.3-load-test"
133148
EOF
134149
135150
./k8s-test-runner-linux-amd64 run -c config.toml

k8s-test-runner/chart/templates/job.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ metadata:
66
namespace: {{ $.Release.Namespace }}
77
labels:
88
sync: "{{ $.Values.sync }}"
9+
{{- range $key, $val := $.Values.metadata.labels }}
10+
{{- $e.key }}: "{{ $e.value }}"
11+
{{- end }}
912
spec:
1013
backoffLimit: 0
1114
ttlSecondsAfterFinished: {{ $.Values.ttlSecondsAfterFinished }}

k8s-test-runner/chart/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ labels:
1515
annotations: {}
1616
env:
1717
# TEST_LOG_LEVEL: ''
18+
metadata:
19+
labels:
20+
# label: value
1821
resources:
1922
requests:
2023
cpu: 1000m

k8s-test-runner/cmd/internal/run.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func getChartOverrides(c config.Runner) map[string]interface{} {
8585
}
8686
envMap[c.TestConfigBase64EnvName] = c.TestConfigBase64
8787

88+
labelsMap := c.Metadata.Labels
89+
if labelsMap == nil {
90+
labelsMap = make(map[string]string)
91+
}
92+
8893
return map[string]interface{}{
8994
"namespace": c.Namespace,
9095
"rbac": map[string]interface{}{
@@ -102,7 +107,10 @@ func getChartOverrides(c config.Runner) map[string]interface{} {
102107
"imagePullPolicy": "Always",
103108
"labels": map[string]interface{}{},
104109
"annotations": map[string]interface{}{}, // Add specific annotations if needed
105-
"env": envMap,
110+
"metadata": map[string]interface{}{
111+
"labels": labelsMap,
112+
},
113+
"env": envMap,
106114
"resources": map[string]interface{}{
107115
"requests": map[string]interface{}{
108116
"cpu": c.ResourcesRequestsCPU,

k8s-test-runner/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ type Runner struct {
3434
DetachedMode bool `toml:"detached_mode"`
3535
Debug bool `toml:"debug"`
3636
Envs map[string]string `toml:"envs"`
37+
Metadata Metadata `toml:"metadata"`
38+
}
39+
40+
type Metadata struct {
41+
Labels map[string]string `toml:"labels"`
3742
}
3843

3944
// Read initializes the configuration by sequentially loading from a TOML file,

lib/k8s/environment/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (m Chart) ExportData(e *Environment) error {
5252

5353
func (m Chart) GetLabels() map[string]string {
5454
return map[string]string{
55-
"chain.link/component": "k8s-legacy-test-runner",
55+
"chain.link/component": "k8s-test-runner-legacy",
5656
}
5757
}
5858

0 commit comments

Comments
 (0)