|
| 1 | +# Kata Containerized Testing Tool |
| 2 | + |
| 3 | +A containerized testing framework for measuring system metrics in both Host VM and User VM (UVM) environments of Kata Confidential Containers. |
| 4 | + |
| 5 | +## Overview |
| 6 | +This tool provides a flexible framework for running tests in both standard container environments (Host VM) and Kata Confidential Containers (UVM) environments. It supports configurable test execution with expected value validation. |
| 7 | + |
| 8 | +## Building the Testing Tool |
| 9 | + |
| 10 | +### Prerequisites |
| 11 | + |
| 12 | +- Go 1.21 or higher |
| 13 | +- Docker |
| 14 | +- Access to Azure Container Registry (ACR) |
| 15 | + |
| 16 | +### Build Steps |
| 17 | + |
| 18 | +1. Clone the repository |
| 19 | + |
| 20 | +``` |
| 21 | +git clone https://github.com/kata-containers/kata-containers.git |
| 22 | +cd kata-containers/testing-tool |
| 23 | +``` |
| 24 | + |
| 25 | +2. Build the binary and the container |
| 26 | + |
| 27 | +- Using Makefile |
| 28 | +``` |
| 29 | +# Build both binary and container |
| 30 | +make all |
| 31 | +
|
| 32 | +# Or build individually |
| 33 | +make build # Just the binary |
| 34 | +make docker # Just the container |
| 35 | +``` |
| 36 | +- Alternatively, build manually using |
| 37 | + |
| 38 | +``` |
| 39 | +# Build binary |
| 40 | +go build -o kata-containerized-test-tool cmd/katatest/main.go |
| 41 | +
|
| 42 | +# Build container |
| 43 | +docker build -t kata-test-container . |
| 44 | +``` |
| 45 | + |
| 46 | +## Uploading to Azure Container Registry |
| 47 | +1. Login to your Azure Container Registry |
| 48 | + |
| 49 | +``` |
| 50 | +docker login yourregistry.azurecr.io |
| 51 | +``` |
| 52 | + |
| 53 | +2. Tag the container image |
| 54 | + |
| 55 | +``` |
| 56 | +docker tag kata-test-container yourregistry.azurecr.io/kata-test-container:v1 |
| 57 | +``` |
| 58 | + |
| 59 | +3. Push the image to ACR |
| 60 | + |
| 61 | +``` |
| 62 | +docker push yourregistry.azurecr.io/kata-test-container:v1 |
| 63 | +``` |
| 64 | +## Running Tests |
| 65 | + |
| 66 | +### Pull Container Images |
| 67 | +First, pull the container image to your test environment: |
| 68 | +``` |
| 69 | +# Pull using containerd |
| 70 | +sudo ctr images pull --user '<username>:<password>' yourregistry.azurecr.io/kata-test-container:v1 |
| 71 | +
|
| 72 | +# Or pull using crictl |
| 73 | +sudo crictl pull yourregistry.azurecr.io/kata-test-container:v1 |
| 74 | +``` |
| 75 | +### Run manually |
| 76 | + |
| 77 | +#### Host VM |
| 78 | +``` |
| 79 | +sudo ctr run \ |
| 80 | + --runtime io.containerd.runc.v2 \ |
| 81 | + -t --rm \ |
| 82 | + --env ENABLED_TESTS=cpu,memory \ |
| 83 | + --env TEST_CPU_EXPECTED_VCPU_COUNT=4 \ |
| 84 | + --env TEST_MEMORY_EXPECTED_MEMORY_MB=8192 \ |
| 85 | + yourregistry.azurecr.io/kata-test-container:v1 host-test |
| 86 | +``` |
| 87 | + |
| 88 | +#### UVM |
| 89 | +``` |
| 90 | +sudo ctr run \ |
| 91 | + --cni \ |
| 92 | + --runtime io.containerd.run.kata-cc.v2 \ |
| 93 | + --runtime-config-path /opt/confidential-containers/share/defaults/kata-containers/configuration-clh-snp.toml \ |
| 94 | + --snapshotter tardev \ |
| 95 | + -t --rm \ |
| 96 | + --env ENABLED_TESTS=cpu,memory \ |
| 97 | + --env TEST_CPU_EXPECTED_VCPU_COUNT=2 \ |
| 98 | + --env TEST_MEMORY_EXPECTED_MEMORY_MB=4096 \ |
| 99 | + yourregistry.azurecr.io/kata-test-container:v1 uvm-test |
| 100 | +``` |
| 101 | + |
| 102 | +### Run Using Pod Manifests |
| 103 | + |
| 104 | +#### Test Configuration |
| 105 | +- Selecting Tests |
| 106 | +Use the ENABLED_TESTS environment variable with a comma-separated list of test names: |
| 107 | +`ENABLED_TESTS=cpu,memory` |
| 108 | +- Setting Expected Values: |
| 109 | +Use environment variables in the format `TEST_<TESTNAME>_<PARAMETER>` |
| 110 | +``` |
| 111 | +TEST_CPU_EXPECTED_VCPU_COUNT=4 |
| 112 | +TEST_MEMORY_EXPECTED_MEMORY_MB=8192 |
| 113 | +``` |
| 114 | +You can create pod manifests with the test configurations to run the tests. |
| 115 | + |
| 116 | +For e.g. the following pod manifest runs the test for CPU and memory with relevant expected values. |
| 117 | + |
| 118 | +``` |
| 119 | +apiVersion: v1 |
| 120 | +kind: Pod |
| 121 | +metadata: |
| 122 | + name: kata-uvm-test |
| 123 | + annotations: |
| 124 | + io.kubernetes.cri.untrusted-workload: "true" |
| 125 | +spec: |
| 126 | + runtimeClassName: kata-cc |
| 127 | + containers: |
| 128 | + - name: uvm-test |
| 129 | + image: yourregistry.azurecr.io/kata-test-container:v1 |
| 130 | + imagePullPolicy: IfNotPresent |
| 131 | + env: |
| 132 | + - name: ENABLED_TESTS |
| 133 | + value: "cpu,memory" |
| 134 | + - name: TEST_CPU_EXPECTED_VCPU_COUNT |
| 135 | + value: "2" |
| 136 | + - name: TEST_MEMORY_EXPECTED_MEMORY_MB |
| 137 | + value: "4096" |
| 138 | +``` |
| 139 | + |
| 140 | +## Adding a New Test |
| 141 | + |
| 142 | +To add a new test to the framework, follow these general steps: |
| 143 | + |
| 144 | +1. Create a test file: Add a new test file in the internal/tests directory structure. The file should implement the Test interface with Name() and Run() methods. |
| 145 | +2. Register your test: Update the main.go file to register your new test with the framework. |
| 146 | +3. Document parameters: Add documentation for your test's expected parameters in the README.md file. |
| 147 | +4. Build and deploy: Rebuild the container after adding your test, then push the updated container to your container registry. |
| 148 | + |
| 149 | +Your new test will then be available and can be enabled through the configuration by including it in the ENABLED_TESTS list. |
| 150 | + |
0 commit comments