Skip to content

Commit

Permalink
[TT-1806] add required chain.link labels (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel authored Nov 27, 2024
1 parent 2f0c331 commit 4bb98ca
Show file tree
Hide file tree
Showing 29 changed files with 594 additions and 23 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/k8s-publish-test-base-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
# we only need base image for k8s based tests
- 'lib/v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag for the base image'
required: true
type: string

jobs:
publish_test_base_image:
Expand All @@ -19,12 +24,20 @@ jobs:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- name: Strip "lib/" from github.ref_name
if: ${{ github.event_name == 'push' }}
run: |
stripped_ref_name="${GITHUB_REF//refs\/tags\/lib\//}"
# disabling as the string containing variable is double-quotted as a whole, no need to quote each variable separately
# shellcheck disable=SC2086
echo "BASE_IMAGE_TAG=${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/test-base-image:$stripped_ref_name" >> $GITHUB_ENV
- name: Export base image tag for workflow dispatch
if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
run: |
# shellcheck disable=SC2086
echo "BASE_IMAGE_TAG=${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/test-base-image:${{ github.event.inputs.tag }}" >> $GITHUB_ENV
- name: Build Base Image
uses: smartcontractkit/chainlink-github-actions/docker/build-push@d2f9642bcc24a73400568756f24b72c188ac7a9a # v2.3.31
with:
Expand Down
15 changes: 15 additions & 0 deletions book/src/k8s-test-runner/k8s-test-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The TOML config should specify the test runner configuration as follows:
```
namespace = "e2e-tests"
rbac_role_name = "" # RBAC role name for the chart
rbac_service_account_name = "" # RBAC service account name for the chart
image_registry_url = "" # URL to the ECR containing the test binary image, e.g., staging ECR URL
image_name = "k8s-test-runner"
image_tag = "" # The image tag to use, like "mercury-load-tests" (see readme above)
Expand All @@ -61,8 +62,16 @@ resources_limits_memory = "1024Mi"
WASP_LOG_LEVEL = "info"
TEST_LOG_LEVEL = "info"
MERCURY_TEST_LOG_LEVEL = "info"
[metadata.labels]
"chain.link/component" = "test-runner"
"chain.link/product" = "<your-product-name>"
"chain.link/team" = "<name–of-the-team-you're-running-the-test-for>"
"chain.link/cost-center" = "test-tooling-<testType>-test"
```

> [NOTE]
> Make sure to quote labels with "/" as otherwise parsing them will fail.
Where:

- `test_name` is the name of the test to run (must be included in the test binary).
Expand Down Expand Up @@ -113,6 +122,7 @@ Then:
cat << EOF > config.toml
namespace = "e2e-tests"
rbac_role_name = "" # RBAC role name for the chart
rbac_service_account_name = "" # RBAC service account name for the chart
image_registry_url = "${{ secrets.AWS_ACCOUNT_ID_STAGING }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
image_name = "k8s-test-runner"
image_tag = "mercury-load-test"
Expand All @@ -130,6 +140,11 @@ Then:
WASP_LOG_LEVEL = "info"
TEST_LOG_LEVEL = "info"
MERCURY_TEST_LOG_LEVEL = "info"
[metadata.labels]
"chain.link/component" = "test-runner"
"chain.link/product" = "data-streamsv0.3"
"chain.link/team" = "Data Streams"
"chain.link/cost-center" = "test-tooling-load-test"
EOF
./k8s-test-runner-linux-amd64 run -c config.toml
Expand Down
3 changes: 3 additions & 0 deletions k8s-test-runner/chart/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ metadata:
namespace: {{ $.Release.Namespace }}
labels:
sync: "{{ $.Values.sync }}"
{{- range $key, $val := $.Values.metadata.labels }}
{{- $e.key }}: "{{ $e.value }}"
{{- end }}
spec:
backoffLimit: 0
ttlSecondsAfterFinished: {{ $.Values.ttlSecondsAfterFinished }}
Expand Down
3 changes: 3 additions & 0 deletions k8s-test-runner/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ labels:
annotations: {}
env:
# TEST_LOG_LEVEL: ''
metadata:
labels:
# label: value
resources:
requests:
cpu: 1000m
Expand Down
10 changes: 9 additions & 1 deletion k8s-test-runner/cmd/internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func getChartOverrides(c config.Runner) map[string]interface{} {
}
envMap[c.TestConfigBase64EnvName] = c.TestConfigBase64

labelsMap := c.Metadata.Labels
if labelsMap == nil {
labelsMap = make(map[string]string)
}

return map[string]interface{}{
"namespace": c.Namespace,
"rbac": map[string]interface{}{
Expand All @@ -102,7 +107,10 @@ func getChartOverrides(c config.Runner) map[string]interface{} {
"imagePullPolicy": "Always",
"labels": map[string]interface{}{},
"annotations": map[string]interface{}{}, // Add specific annotations if needed
"env": envMap,
"metadata": map[string]interface{}{
"labels": labelsMap,
},
"env": envMap,
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": c.ResourcesRequestsCPU,
Expand Down
5 changes: 5 additions & 0 deletions k8s-test-runner/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type Runner struct {
DetachedMode bool `toml:"detached_mode"`
Debug bool `toml:"debug"`
Envs map[string]string `toml:"envs"`
Metadata Metadata `toml:"metadata"`
}

type Metadata struct {
Labels map[string]string `toml:"labels"`
}

// Read initializes the configuration by sequentially loading from a TOML file,
Expand Down
4 changes: 4 additions & 0 deletions lib/k8s/config/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const (
EnvVarUserDescription = "Owner of an environment"
EnvVarUserExample = "Satoshi"

EnvVarTeam = "CHAINLINK_USER_TEAM"
EnvVarTeamDescription = "Team to, which owner of the environment belongs to"
EnvVarTeamExample = "BIX, CCIP, BCM"

EnvVarCLCommitSha = "CHAINLINK_COMMIT_SHA"
EnvVarCLCommitShaDescription = "The sha of the commit that you're running tests on. Mostly used for CI"
EnvVarCLCommitShaExample = "${{ github.sha }}"
Expand Down
Loading

0 comments on commit 4bb98ca

Please sign in to comment.