[SDCICD-1701] Add golang-osd-operator-precheck boilerplate convention#724
Conversation
New convention that generates operator pre-check tests into each
operator's `test/e2e/` directory. Validates operator readiness before
e2e tests run via a Ginkgo `BeforeSuite`:
- Auto-detects PKO (`ClusterPackage`) vs OLM (`CSV`) operator management
- Validates deployed version matches expected version from image tag
- Checks operator namespace exists and all deployments are healthy
- Polls every 5s with 10min timeout; skips version check for `latest` tag
- Uses kubernetes dynamic client to avoid API discovery rate limiting
- Scopes CSV queries to operator namespace for efficiency
- Reads `OperatorName` and `OperatorNamespace` from `config/config.go`
Files generated by the convention:
- `test/e2e/operator_precheck.go` (copied, always overwritten)
- `test/e2e/{operator}_precheck_test.go` (generated `BeforeSuite` wrapper)
Operators subscribe by adding `openshift/golang-osd-operator-precheck`
to `boilerplate/update.cfg`. Requires `openshift/golang-osd-e2e`.
## Test Strategy
Tested on cluster `2q2npckfvdh6fg2sa2d8ac6la936tbin` using osde2e
ad-hoc image execution.
### Setup
1. Cloned `rbac-permissions-operator` (OLM) and `route-monitor-operator`
(PKO) into `~/repo/osd-operators/`
2. Added `openshift/golang-osd-operator-precheck` to each operator's
`boilerplate/update.cfg`
3. Ran `BOILERPLATE_GIT_REPO=<local-boilerplate> make boilerplate-update`
to generate precheck files using the local boilerplate convention
4. Ran `GOFLAGS="-tags=osde2e" go mod tidy` to pull in dependencies
5. Built e2e images with `podman build -f test/e2e/Dockerfile` and
pushed to `quay.io/vkadapar_openshift/`
6. Tagged the same image with different version tags for mismatch
and health-only scenarios
7. Ran tests via osde2e VSCode launch configs pointing to the images
### Results
| Test | Operator | Path | Tag | Result |
|------|----------|------|-----|--------|
| OLM success | `rbac-permissions-operator` | CSV match | `v0.1.494-g951a9ca` | Passed |
| OLM mismatch | `rbac-permissions-operator` | CSV mismatch | `v999.0.0-gdeadbeef` | Passed (10min timeout, tests skipped) |
| PKO success | `route-monitor-operator` | ClusterPackage match | `3c23881` | Passed |
| PKO mismatch | `route-monitor-operator` | ClusterPackage mismatch | `v999.0.0-gdeadbeef` | Passed (10min timeout, tests skipped) |
| Health-only | `rbac-permissions-operator` | Skip version | `latest` | Passed (health checks only) |
### Issues found and fixed during testing
- **In-cluster config:** used `rest.InClusterConfig()` when `KUBECONFIG` unset
- **API rate limiting:** switched to dynamic client with explicit GVRs
- **Namespace mismatch:** read `OperatorNamespace` from `config/config.go`
### Test Images
Available at quay.io for reproducing tests via osde2e ad-hoc images:
**OLM (`rbac-permissions-operator`):**
- `quay.io/vkadapar_openshift/rbac-permissions-operator-e2e:v0.1.494-g951a9ca` (success)
- `quay.io/vkadapar_openshift/rbac-permissions-operator-e2e:v999.0.0-gdeadbeef` (mismatch)
- `quay.io/vkadapar_openshift/rbac-permissions-operator-e2e:latest` (health-only)
**PKO (`route-monitor-operator`):**
- `quay.io/vkadapar_openshift/route-monitor-operator-e2e:3c23881` (success)
- `quay.io/vkadapar_openshift/route-monitor-operator-e2e:v999.0.0-gdeadbeef` (mismatch)
Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (4)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Repository: openshift/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
|
|
||
| func versionMatches(actual, expected string) bool { | ||
| if actual == "" || expected == "" { | ||
| return false |
There was a problem hiding this comment.
The strings.Contains (and csvMatchesVersion at 230) is loose. E.g., a tag like v0.1 would match v0.10.0-gabcdef0.
There was a problem hiding this comment.
containsVersionBoundary method added to address this issue.
@clcollins can you verify this?
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: varunraokadaparthi The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
- Guard nil Spec.Replicas before deref in checkDeploymentsReady - Replace loose strings.Contains version matching with boundary-aware check - Make BeforeSuite conflict a fatal error (exit 1) instead of a warning Co-Authored-By: Claude Code <noreply@anthropic.com>
Summary
New convention that generates operator pre-check tests into each operator's
test/e2e/directory. Validates operator readiness before e2e tests run via a GinkgoBeforeSuite:ClusterPackage) vs OLM (CSV) operator managementlatesttagOperatorNameandOperatorNamespacefromconfig/config.goFiles generated by the convention
test/e2e/operator_precheck.go(copied, always overwritten)test/e2e/{operator}_precheck_test.go(generatedBeforeSuitewrapper)How to subscribe
Add
openshift/golang-osd-operator-prechecktoboilerplate/update.cfg(requiresopenshift/golang-osd-e2e), then runmake boilerplate-updateandGOFLAGS="-tags=osde2e" go mod tidy.Test Strategy
Tested on cluster
2q2npckfvdh6fg2sa2d8ac6la936tbinusing osde2e ad-hoc image execution.Setup
rbac-permissions-operator(OLM) androute-monitor-operator(PKO) into~/repo/osd-operators/openshift/golang-osd-operator-precheckto each operator'sboilerplate/update.cfgBOILERPLATE_GIT_REPO=<local-boilerplate> make boilerplate-updateto generate precheck filesGOFLAGS="-tags=osde2e" go mod tidyto pull in dependenciespodman build -f test/e2e/Dockerfileand pushed toquay.io/vkadapar_openshift/Results
rbac-permissions-operatorv0.1.494-g951a9carbac-permissions-operatorv999.0.0-gdeadbeefroute-monitor-operator3c23881route-monitor-operatorv999.0.0-gdeadbeefrbac-permissions-operatorlatestIssues found and fixed during testing
rest.InClusterConfig()whenKUBECONFIGunsetOperatorNamespacefromconfig/config.goTest Images
Available at quay.io for reproducing tests via osde2e ad-hoc images:
OLM (
rbac-permissions-operator):quay.io/vkadapar_openshift/rbac-permissions-operator-e2e:v0.1.494-g951a9ca(success)quay.io/vkadapar_openshift/rbac-permissions-operator-e2e:v999.0.0-gdeadbeef(mismatch)quay.io/vkadapar_openshift/rbac-permissions-operator-e2e:latest(health-only)PKO (
route-monitor-operator):quay.io/vkadapar_openshift/route-monitor-operator-e2e:3c23881(success)quay.io/vkadapar_openshift/route-monitor-operator-e2e:v999.0.0-gdeadbeef(mismatch)🤖 Generated with Claude Code