|
| 1 | +# OpenShift API Server Tests Extension |
| 2 | +======================== |
| 3 | + |
| 4 | +This repository contains the tests for the OpenShift API Server for OpenShift. |
| 5 | +These tests run against OpenShift clusters and are meant to be used in the OpenShift CI/CD pipeline. |
| 6 | +They use the framework: https://github.com/openshift-eng/openshift-tests-extension |
| 7 | + |
| 8 | +## How to Run the Tests Locally |
| 9 | + |
| 10 | +| Command | Description | |
| 11 | +|----------------------------------------------------------------------------|--------------------------------------------------------------------------| |
| 12 | +| `make tests-ext-build` | Builds the test extension binary. | |
| 13 | +| `test/extended/tests-extension/openshift-apiserver-tests-ext list` | Lists all available test cases. | |
| 14 | +| `test/extended/tests-extension/openshift-apiserver-tests-ext run-suite <suite-name>` | Runs a test suite. e.g., `openshift/openshift-apiserver/conformance/parallel` | |
| 15 | +| `test/extended/tests-extension/openshift-apiserver-tests-ext run <test-name>` | Runs one specific test. | |
| 16 | + |
| 17 | + |
| 18 | +## How to Run the Tests Locally |
| 19 | + |
| 20 | +The tests can be run locally using the `openshift-apiserver-tests-ext` binary against an OpenShift cluster. |
| 21 | +Use the environment variable `KUBECONFIG` to point to your cluster configuration file such as: |
| 22 | + |
| 23 | +```shell |
| 24 | +export KUBECONFIG=path/to/kubeconfig |
| 25 | +test/extended/tests-extension/openshift-apiserver-tests-ext run <test-name> |
| 26 | +``` |
| 27 | + |
| 28 | +### Local Test using OCP |
| 29 | + |
| 30 | +1. Use the `Cluster Bot` to create an OpenShift cluster. |
| 31 | + |
| 32 | +**Example:** |
| 33 | + |
| 34 | +```shell |
| 35 | +launch 4.20 gcp,techpreview |
| 36 | +``` |
| 37 | + |
| 38 | +2. Set the `KUBECONFIG` environment variable to point to your OpenShift cluster configuration file. |
| 39 | + |
| 40 | +**Example:** |
| 41 | + |
| 42 | +```shell |
| 43 | +mv ~/Downloads/cluster-bot-2025-08-06-082741.kubeconfig ~/.kube/cluster-bot.kubeconfig |
| 44 | +export KUBECONFIG=~/.kube/cluster-bot.kubeconfig |
| 45 | +``` |
| 46 | + |
| 47 | +3. Run the tests using the `openshift-apiserver-tests-ext` binary. |
| 48 | + |
| 49 | +**Example:** |
| 50 | +```shell |
| 51 | +test/extended/tests-extension/openshift-apiserver-tests-ext run-suite openshift/openshift-apiserver/all |
| 52 | +``` |
| 53 | + |
| 54 | +## Writing Tests |
| 55 | + |
| 56 | +You can write tests in the `test/extended/tests-extension/` directory. |
| 57 | + |
| 58 | +### Test Module Structure |
| 59 | + |
| 60 | +This test extension uses a **separate Go module** to isolate test dependencies from the production operator code: |
| 61 | + |
| 62 | +``` |
| 63 | +test/extended/tests-extension/ |
| 64 | +├── go.mod # Separate module with test dependencies |
| 65 | +├── go.sum |
| 66 | +├── cmd/openshift-apiserver-tests-ext/ |
| 67 | +│ └── main.go # Test binary entry point |
| 68 | +├── apiserver/ # Test packages |
| 69 | +│ ├── encryption.go |
| 70 | +│ └── util.go |
| 71 | +└── main.go # Additional test suites |
| 72 | +``` |
| 73 | + |
| 74 | +**Key Benefits:** |
| 75 | +- Production `go.mod` remains clean (no ginkgo, gomega, test framework dependencies) |
| 76 | +- Test dependencies are isolated in `test/extended/tests-extension/go.mod` |
| 77 | +- Prevents dependency version conflicts between operator and test framework |
| 78 | + |
| 79 | +## Development Workflow |
| 80 | + |
| 81 | +- Add or update tests in: `test/extended/tests-extension/` |
| 82 | +- When adding new test dependencies, run `go mod tidy` from within `test/extended/tests-extension/` |
| 83 | +- Run `make build` to build the operator binary and `make tests-ext-build` for the test binary |
| 84 | +- You can run the full suite or one test using the commands in the table above |
| 85 | +- Before committing your changes: |
| 86 | + - Run `make tests-ext-update` to update test metadata |
| 87 | + - Run `make verify` to check formatting, linting, and validation |
| 88 | + |
| 89 | +## How to Rename a Test |
| 90 | + |
| 91 | +1. Run `test/extended/tests-extension/openshift-apiserver-tests-ext list` to see the current test names |
| 92 | +2. Find the name of the test you want to rename |
| 93 | +3. Add a Ginkgo label with the original name, like this: |
| 94 | + |
| 95 | +```go |
| 96 | +It("should pass a renamed sanity check", |
| 97 | + Label("original-name:[sig-openshift-apiserver] My Old Test Name"), |
| 98 | + func(ctx context.Context) { |
| 99 | + Expect(len("test")).To(BeNumerically(">", 0)) |
| 100 | + }) |
| 101 | +``` |
| 102 | + |
| 103 | +4. Run `make tests-ext-update` to update the metadata |
| 104 | + |
| 105 | +**Note:** Only add the label once. Do not update it again after future renames. |
| 106 | + |
| 107 | +## How to Delete a Test |
| 108 | + |
| 109 | +1. Run `test/extended/tests-extension/openshift-apiserver-tests-ext list` to find the test name |
| 110 | +2. Add the test name to the `IgnoreObsoleteTests` block in `test/extended/tests-extension/cmd/openshift-apiserver-tests-ext/main.go`, like this: |
| 111 | + |
| 112 | +```go |
| 113 | +ext.IgnoreObsoleteTests( |
| 114 | + "[sig-openshift-apiserver] My removed test name", |
| 115 | +) |
| 116 | +``` |
| 117 | + |
| 118 | +3. Delete the test code from your suite |
| 119 | +4. Run `make tests-ext-update` to clean the metadata |
| 120 | + |
| 121 | +**WARNING**: Deleting a test may cause issues with Sippy https://sippy.dptools.openshift.org/sippy-ng/ |
| 122 | +or other tools that expected the Unique TestID tracked outside of this repository. [More info](https://github.com/openshift-eng/ci-test-mapping) |
| 123 | +Check the status of https://issues.redhat.com/browse/TRT-2208 before proceeding with test deletions. |
| 124 | + |
| 125 | +## E2E Test Configuration |
| 126 | + |
| 127 | +Tests are configured in the `openshift/release` repository, under `ci-operator/config/openshift/openshift-apiserver`. |
| 128 | + |
| 129 | +Here is a CI job example: |
| 130 | + |
| 131 | +```yaml |
| 132 | +- as: e2e-aws-techpreview-oas-ext |
| 133 | + steps: |
| 134 | + cluster_profile: aws |
| 135 | + env: |
| 136 | + FEATURE_SET: TechPreviewNoUpgrade |
| 137 | + TEST_SUITE: openshift/openshift-apiserver/all |
| 138 | + test: |
| 139 | + - ref: openshift-e2e-test |
| 140 | + workflow: openshift-e2e-aws |
| 141 | +``` |
| 142 | +
|
| 143 | +This uses the `openshift-tests` binary to run openshift-apiserver tests against a test OpenShift release. |
| 144 | + |
| 145 | +It works for pull request testing because of this: |
| 146 | + |
| 147 | +```yaml |
| 148 | +releases: |
| 149 | + latest: |
| 150 | + integration: |
| 151 | + include_built_images: true |
| 152 | +``` |
| 153 | + |
| 154 | +More info: https://docs.ci.openshift.org/docs/architecture/ci-operator/#testing-with-an-ephemeral-openshift-release |
| 155 | + |
| 156 | +## Makefile Commands |
| 157 | + |
| 158 | +| Target | Description | |
| 159 | +|--------------------------|------------------------------------------------------------------------------| |
| 160 | +| `make build` | Builds the operator binary. | |
| 161 | +| `make tests-ext-build` | Builds the test extension binary. | |
| 162 | +| `make tests-ext-update` | Updates the metadata JSON file and cleans machine-specific codeLocations. | |
| 163 | +| `make verify` | Runs formatting, vet, and linter. | |
| 164 | + |
| 165 | +**Note:** Metadata is stored in: `test/extended/tests-extension/.openshift-tests-extension/openshift_payload_openshift-apiserver.json` |
| 166 | + |
| 167 | +## FAQ |
| 168 | + |
| 169 | +### Why don't we have a Dockerfile for `openshift-apiserver-tests-ext`? |
| 170 | + |
| 171 | +We do not provide a Dockerfile for `openshift-apiserver-tests-ext` because building and shipping a |
| 172 | +standalone image for this test binary would introduce unnecessary complexity. |
| 173 | + |
| 174 | +Technically, it is possible to create a new OpenShift component just for the |
| 175 | +tests and add a corresponding test image to the payload. However, doing so requires |
| 176 | +onboarding a new component, setting up build pipelines, and maintaining image promotion |
| 177 | +and test configuration — all of which adds overhead. |
| 178 | + |
| 179 | +From the OpenShift architecture point of view: |
| 180 | + |
| 181 | +1. Tests for payload components are part of the product. Many users (such as storage vendors, or third-party CNIs) |
| 182 | +rely on these tests to validate that their solutions are compatible and conformant with OpenShift. |
| 183 | + |
| 184 | +2. Adding new images to the payload comes with significant overhead and cost. |
| 185 | +It is generally preferred to include tests in the same image as the component |
| 186 | +being tested whenever possible. |
| 187 | + |
| 188 | +### Why do we need to run `make tests-ext-update`? |
| 189 | + |
| 190 | +Running `make tests-ext-update` ensures that each test gets a unique and stable **TestID** over time. |
| 191 | + |
| 192 | +The TestID is used to identify tests across the OpenShift CI/CD pipeline and reporting tools like Sippy. |
| 193 | +It helps track test results, detect regressions, and ensures the correct tests are |
| 194 | +executed and reported. |
| 195 | + |
| 196 | +This step is important whenever you add, rename, or delete a test. |
| 197 | +More information: |
| 198 | +- https://github.com/openshift/enhancements/blob/master/enhancements/testing/openshift-tests-extension.md#test-id |
| 199 | +- https://github.com/openshift-eng/ci-test-mapping |
| 200 | + |
| 201 | +### How to get help with OTE? |
| 202 | + |
| 203 | +For help with the OpenShift Tests Extension (OTE), you can reach out on the #wg-openshift-tests-extension Slack channel. |
0 commit comments