|
1 | | -## Preparing to Run Tests on Staging |
| 1 | +# K8s Test Runner |
2 | 2 |
|
3 | | -Ensure you complete the following steps before executing tests on the staging environment: |
| 3 | +A tool to build and run arbitrary Go code in `k8s` the easy way. |
4 | 4 |
|
5 | | -1. **Connect to the VPN** |
6 | | - |
7 | | -2. **AWS Login with Staging Profile** |
8 | | - |
9 | | - Authenticate to AWS using your staging profile, specifically with the `StagingEKSAdmin` role. Execute the following command: |
10 | | - |
11 | | - ```sh |
12 | | - aws sso login --profile staging |
13 | | - ``` |
14 | | - |
15 | | -3. **Verify Authorization** |
16 | | - |
17 | | - Confirm your authorization status by listing the namespaces in the staging cluster. Run `kubectl get namespaces`. If you see a list of namespaces, this indicates successful access to the staging cluster. |
18 | | - |
19 | | -## Running Tests |
20 | | - |
21 | | -### Creating an Image with the Test Binary |
22 | | - |
23 | | -Before running tests, you must create a Docker image containing the test binary. To do this, execute the `create-test-image` command and provide the path to the test folder you wish to package. This command: |
24 | | - |
25 | | -1. Compiles test binary under `<path-to-test-folder>` |
26 | | -2. Creates a docker image with the test binary |
27 | | -3. Pushes the docker image to the image registry (e.g. Staging ECR) |
28 | | - |
29 | | -```sh |
30 | | -go run ./cmd/main.go create-test-image --image-registry-url <staging-ecr-registry-url> --image-tag "<image-tag>" "<path-to-test-folder>" |
31 | | -``` |
32 | | - |
33 | | -Where `image-tag` should be a descriptive name for your test, such as "mercury-load-tests". |
34 | | - |
35 | | -### Running the Test in Kubernetes |
36 | | - |
37 | | -If a Docker image containing the test binary is available in an image registry (such as staging ECR), use `run` command to execute the test in K8s. |
38 | | - |
39 | | -``` |
40 | | -go run ./cmd/main.go run -c "<path-to-test-runner-toml-config>" |
41 | | -``` |
42 | | - |
43 | | -The TOML config should specify the test runner configuration as follows: |
44 | | - |
45 | | -``` |
46 | | -namespace = "e2e-tests" |
47 | | -rbac_role_name = "" # RBAC role name for the chart |
48 | | -image_registry_url = "" # URL to the ECR containing the test binary image, e.g., staging ECR URL |
49 | | -image_name = "k8s-test-runner" |
50 | | -image_tag = "" # The image tag to use, like "mercury-load-tests" (see readme above) |
51 | | -job_count = "1" |
52 | | -test_name = "TestMercuryLoad/all_endpoints" |
53 | | -test_timeout = "24h" |
54 | | -test_config_base64_env_name = "LOAD_TEST_BASE64_TOML_CONTENT" |
55 | | -test_config_file_path = "/Users/lukasz/Documents/test-configs/load-staging-testnet.toml" |
56 | | -resources_requests_cpu = "1000m" |
57 | | -resources_requests_memory = "512Mi" |
58 | | -resources_limits_cpu = "2000m" |
59 | | -resources_limits_memory = "1024Mi" |
60 | | -[envs] |
61 | | -WASP_LOG_LEVEL = "info" |
62 | | -TEST_LOG_LEVEL = "info" |
63 | | -MERCURY_TEST_LOG_LEVEL = "info" |
64 | | -``` |
65 | | - |
66 | | -Where: |
67 | | - |
68 | | -- `test_name` is the name of the test to run (must be included in the test binary). |
69 | | -- `test_config_env_name` is the name of the environment variable used to provide the test configuration for the test (optional). |
70 | | -- `test_config_file_path` is the path to the configuration file for the test (optional). |
71 | | - |
72 | | -## Using K8s Test Runner on CI |
73 | | - |
74 | | -### Example |
75 | | - |
76 | | -This example demonstrates the process step by step. First, it shows how to download the Kubernetes Test Runner. Next, it details the use of the Test Runner to create a test binary specifically for the Mercury "e2e_tests/staging_prod/tests/load" test package. Finally, it describes executing the test in Kubernetes using a customized test runner configuration. |
77 | | - |
78 | | -``` |
79 | | -- name: Download K8s Test Runner |
80 | | - run: | |
81 | | - mkdir -p k8s-test-runner |
82 | | - cd k8s-test-runner |
83 | | - curl -L -o k8s-test-runner.tar.gz https://github.com/smartcontractkit/chainlink-testing-framework/releases/download/v0.2.4/test-runner.tar.gz |
84 | | - tar -xzf k8s-test-runner.tar.gz |
85 | | - chmod +x k8s-test-runner-linux-amd64 |
86 | | -``` |
87 | | - |
88 | | -Alternatively, you can place the k8s-test-runner package within your repository and unpack it: |
89 | | - |
90 | | -``` |
91 | | -- name: Unpack K8s Test Runner |
92 | | - run: | |
93 | | - cd e2e_tests |
94 | | - mkdir -p k8s-test-runner |
95 | | - tar -xzf k8s-test-runner-v0.0.1.tar.gz -C k8s-test-runner |
96 | | - chmod +x k8s-test-runner/k8s-test-runner-linux-amd64 |
97 | | -``` |
98 | | - |
99 | | -Then: |
100 | | - |
101 | | -``` |
102 | | -- name: Build K8s Test Runner Image |
103 | | - if: github.event.inputs.test-type == 'load' && github.event.inputs.rebuild-test-image == 'yes' |
104 | | - run: | |
105 | | - cd e2e_tests/k8s-test-runner |
106 | | -
|
107 | | - ./k8s-test-runner-linux-amd64 create-test-image --image-registry-url "${{ secrets.AWS_ACCOUNT_ID_STAGING }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" --image-tag "mercury-load-test" "../staging_prod/tests/load" |
108 | | -
|
109 | | -- name: Run Test in K8s |
110 | | - run: | |
111 | | - cd e2e_tests/k8s-test-runner |
112 | | -
|
113 | | - cat << EOF > config.toml |
114 | | - namespace = "e2e-tests" |
115 | | - rbac_role_name = "" # RBAC role name for the chart |
116 | | - image_registry_url = "${{ secrets.AWS_ACCOUNT_ID_STAGING }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" |
117 | | - image_name = "k8s-test-runner" |
118 | | - image_tag = "mercury-load-test" |
119 | | - job_count = "1" |
120 | | - chart_path = "./chart" |
121 | | - test_name = "TestMercuryLoad/all_endpoints" |
122 | | - test_timeout = "24h" |
123 | | - resources_requests_cpu = "1000m" |
124 | | - resources_requests_memory = "512Mi" |
125 | | - resources_limits_cpu = "2000m" |
126 | | - resources_limits_memory = "1024Mi" |
127 | | - test_config_base64_env_name = "LOAD_TEST_BASE64_TOML_CONTENT" |
128 | | - test_config_base64 = "${{ steps.conditional-env-vars.outputs.LOAD_TEST_BASE64_TOML_CONTENT }}" |
129 | | - [envs] |
130 | | - WASP_LOG_LEVEL = "info" |
131 | | - TEST_LOG_LEVEL = "info" |
132 | | - MERCURY_TEST_LOG_LEVEL = "info" |
133 | | - EOF |
134 | | -
|
135 | | - ./k8s-test-runner-linux-amd64 run -c config.toml |
136 | | -``` |
137 | | - |
138 | | -## Release |
139 | | - |
140 | | -Run `./package <version>` |
| 5 | +[](https://smartcontractkit.github.io/chainlink-testing-framework/k8s-test-runner/k8s-test-runner.html) |
0 commit comments