Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/cluster-kube-apiserver-operator
/cluster-kube-apiserver-operator-tests-ext
/test/extended/tests-extension/bin/
/bin/
.idea/
/_output/
telepresence.log
4 changes: 2 additions & 2 deletions Dockerfile.rhel7
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY . .
ENV GO_PACKAGE github.com/openshift/cluster-kube-apiserver-operator
RUN make build --warn-undefined-variables \
&& make tests-ext-build \
&& gzip cluster-kube-apiserver-operator-tests-ext
&& gzip test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext

FROM registry.ci.openshift.org/ocp/4.21:base-rhel9
COPY --from=builder /go/src/github.com/openshift/cluster-kube-apiserver-operator/bindata/bootkube/bootstrap-manifests /usr/share/bootkube/manifests/bootstrap-manifests/
Expand All @@ -13,7 +13,7 @@ COPY --from=builder /go/src/github.com/openshift/cluster-kube-apiserver-operator
COPY --from=builder /go/src/github.com/openshift/cluster-kube-apiserver-operator/bindata/bootkube/scc-manifests /usr/share/bootkube/manifests/manifests/
COPY --from=builder /go/src/github.com/openshift/cluster-kube-apiserver-operator/vendor/github.com/openshift/api/apiserver/v1/zz_generated.crd-manifests/kube-apiserver_apirequestcounts.crd.yaml /usr/share/bootkube/manifests/manifests/
COPY --from=builder /go/src/github.com/openshift/cluster-kube-apiserver-operator/cluster-kube-apiserver-operator /usr/bin/
COPY --from=builder /go/src/github.com/openshift/cluster-kube-apiserver-operator/cluster-kube-apiserver-operator-tests-ext.gz /usr/bin/
COPY --from=builder /go/src/github.com/openshift/cluster-kube-apiserver-operator/test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext.gz /usr/bin/

COPY manifests /manifests
COPY bindata/bootkube/scc-manifests /manifests
Expand Down
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ ENCRYPTION_PROVIDERS=aescbc aesgcm
ENCRYPTION_PROVIDER?=aescbc

TESTS_EXT_BINARY := cluster-kube-apiserver-operator-tests-ext
TESTS_EXT_PACKAGE := ./cmd/cluster-kube-apiserver-operator-tests-ext
TESTS_EXT_DIR := ./test/extended/tests-extension
TESTS_EXT_PACKAGE := ./cmd

TESTS_EXT_GIT_COMMIT := $(shell git rev-parse --short HEAD)
TESTS_EXT_BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
Expand Down Expand Up @@ -101,18 +102,14 @@ test-e2e-sno-disruptive: test-unit
# -------------------------------------------------------------------
.PHONY: tests-ext-build
tests-ext-build:
GOOS=$(GOOS) GOARCH=$(GOARCH) GO_COMPLIANCE_POLICY=exempt_all CGO_ENABLED=0 \
go build -o $(TESTS_EXT_BINARY) -ldflags "$(TESTS_EXT_LDFLAGS)" $(TESTS_EXT_PACKAGE)
$(MAKE) -C test/extended/tests-extension build

# -------------------------------------------------------------------
# Run "update" and strip env-specific metadata
# -------------------------------------------------------------------
.PHONY: tests-ext-update
tests-ext-update: tests-ext-build
./$(TESTS_EXT_BINARY) update
for f in .openshift-tests-extension/*.json; do \
jq 'map(del(.codeLocations))' "$$f" > tmpp && mv tmpp "$$f"; \
done
tests-ext-update:
$(MAKE) -C test/extended/tests-extension build-update

# -------------------------------------------------------------------
# Run go test on ./test/extended/... with proper flags
Expand Down
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ require (
github.com/google/go-cmp v0.7.0
github.com/imdario/mergo v0.3.8
github.com/miekg/dns v1.1.61
github.com/onsi/ginkgo/v2 v2.22.0
github.com/onsi/gomega v1.36.1
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292
github.com/openshift/api v0.0.0-20251015095338-264e80a2b6e7
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235
Expand Down Expand Up @@ -57,7 +54,6 @@ require (
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac // indirect
Expand Down Expand Up @@ -133,5 +129,3 @@ require (
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)

replace github.com/onsi/ginkgo/v2 => github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20241205171354-8006f302fd12
11 changes: 5 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
Expand Down Expand Up @@ -155,10 +156,10 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFd
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw=
github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292 h1:3athg6KQ+TaNfW4BWZDlGFt1ImSZEJWgzXtPC1VPITI=
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292/go.mod h1:6gkP5f2HL0meusT0Aim8icAspcD1cG055xxBZ9yC68M=
github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM=
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/openshift/api v0.0.0-20251015095338-264e80a2b6e7 h1:Ot2fbEEPmF3WlPQkyEW/bUCV38GMugH/UmZvxpWceNc=
github.com/openshift/api v0.0.0-20251015095338-264e80a2b6e7/go.mod h1:d5uzF0YN2nQQFA0jIEWzzOZ+edmo6wzlGLvx5Fhz4uY=
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee h1:+Sp5GGnjHDhT/a/nQ1xdp43UscBMr7G5wxsYotyhzJ4=
Expand All @@ -167,8 +168,6 @@ github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235 h1:9JBeIXmnHlp
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235/go.mod h1:L49W6pfrZkfOE5iC1PqEkuLkXG4W0BX4w8b+L2Bv7fM=
github.com/openshift/library-go v0.0.0-20251015151611-6fc7a74b67c5 h1:bANtDc8SgetSK4nQehf59x3+H9FqVJCprgjs49/OTg0=
github.com/openshift/library-go v0.0.0-20251015151611-6fc7a74b67c5/go.mod h1:OlFFws1AO51uzfc48MsStGE4SFMWlMZD0+f5a/zCtKI=
github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20241205171354-8006f302fd12 h1:AKx/w1qpS8We43bsRgf8Nll3CGlDHpr/WAXvuedTNZI=
github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20241205171354-8006f302fd12/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
15 changes: 15 additions & 0 deletions test/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
reviewers:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may want to check this list again, many of those folks are not even at the company anymore. Some of them are now working for different components or other orgs within redhat.

- p0lyn0mial
- benluddy
- sanchezl
- dgrisonnet
- wangke19
- xingxingxia
approvers:
- p0lyn0mial
- benluddy
- sanchezl
- dgrisonnet
- wangke19
- xingxingxia
component: "kube-apiserver"
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "[Jira:kube-apiserver][sig-api-machinery][FeatureGate:EventTTL] Event TTL Configuration should configure and validate eventTTLMinutes=5m [Serial][Disruptive][Slow][Suite:openshift/cluster-kube-apiserver-operator/conformance/serial]",
"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:cluster-kube-apiserve-operator",
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[Jira:kube-apiserver][sig-api-machinery][FeatureGate:EventTTL] Event TTL Configuration should configure and validate eventTTLMinutes=10m [Serial][Disruptive][Slow][Suite:openshift/cluster-kube-apiserver-operator/conformance/serial]",
"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:cluster-kube-apiserve-operator",
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[Jira:kube-apiserver][sig-api-machinery][FeatureGate:EventTTL] Event TTL Configuration should configure and validate eventTTLMinutes=15m [Serial][Disruptive][Slow][Suite:openshift/cluster-kube-apiserver-operator/conformance/serial]",
"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:cluster-kube-apiserve-operator",
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[Jira:kube-apiserver][sig-api-machinery] sanity test should always pass [Suite:openshift/cluster-kube-apiserver-operator/conformance/parallel]",
"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:cluster-kube-apiserve-operator",
"lifecycle": "blocking",
"environmentSelector": {}
}
]
75 changes: 75 additions & 0 deletions test/extended/tests-extension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Get the directory where this Makefile is, so we can use it below for including
DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))

# Definitions for the extended tests
GO_PKG_NAME := github.com/openshift-eng/openshift-tests-extension

GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_TREE_STATE := $(shell if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet; then echo clean; else echo dirty; fi; else echo unknown; fi)

LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \
-X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \
-X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)'

METADATA := $(shell pwd)/.openshift-tests-extension

TOOLS_BIN_DIR := $(CURDIR)/bin
BINARY_NAME := cluster-kube-apiserver-operator-tests-ext

.PHONY: help
help: #HELP Display essential help.
@awk 'BEGIN {FS = ":[^#]*#HELP"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\n"} /^[a-zA-Z_0-9-]+:.*#HELP / { printf " \033[36m%-17s\033[0m %s\n", $$1, $$2 } ' $(MAKEFILE_LIST)

#SECTION Development
.PHONY: verify #HELP To verify the code
verify: tidy fmt vet

.PHONY: tidy #HELP Run go mod tidy.
tidy:
go mod tidy

.PHONY: fmt
fmt: #HELP Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: #HELP Run go vet against code.
go vet ./...

.PHONY: build
build: #HELP Build the extended tests binary
@mkdir -p $(TOOLS_BIN_DIR)
GO_COMPLIANCE_POLICY="exempt_all" CGO_ENABLED=0 go build -mod=mod -ldflags "$(LDFLAGS)" -o $(TOOLS_BIN_DIR)/$(BINARY_NAME) ./cmd/...

.PHONY: update-metadata
update-metadata: build #HELP Build and run 'update-metadata' to generate test metadata
$(TOOLS_BIN_DIR)/$(BINARY_NAME) update
$(MAKE) clean-metadata

.PHONY: build-update
build-update: build update-metadata #HELP Build and update metadata and sanitize output

.PHONY: clean
clean: #HELP Remove build artifacts
rm -rf $(TOOLS_BIN_DIR)

#SECTION Metadata

.PHONY: list-test-names
list-test-names: build #HELP Show current full test names
@$(TOOLS_BIN_DIR)/$(BINARY_NAME) list -o names

.PHONY: clean-metadata
clean-metadata: #HELP Remove 'codeLocations' from metadata JSON
@echo "Cleaning metadata (removing codeLocations)..."
@for f in $(METADATA)/*.json; do \
jq 'map(del(.codeLocations))' "$$f" > "$$f.tmp" && mv "$$f.tmp" "$$f"; \
done

.PHONY: verify-metadata #HELP To verify that the metadata was properly updated
verify-metadata: update-metadata
@if ! git diff --exit-code $(METADATA); then \
echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \
exit 1; \
fi
49 changes: 36 additions & 13 deletions test/extended/README.md → test/extended/tests-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ They use the framework: https://github.com/openshift-eng/openshift-tests-extensi
| Command | Description |
|--------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
| `make tests-ext-build` | Builds the test extension binary. |
| `./cluster-kube-apiserver-operator-tests-ext list` | Lists all available test cases. |
| `./cluster-kube-apiserver-operator-tests-ext run-suite <suite-name>` | Runs a test suite. e.g., `openshift/cluster-kube-apiserver-operator/conformance/parallel` |
| `./cluster-kube-apiserver-operator-tests-ext run <test-name>` | Runs one specific test. |
| `test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext list` | Lists all available test cases. |
| `test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext run-suite <suite-name>` | Runs a test suite. e.g., `openshift/cluster-kube-apiserver-operator/conformance/parallel` |
| `test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext run <test-name>` | Runs one specific test. |


## How to Run the Tests Locally
Expand All @@ -22,7 +22,7 @@ Use the environment variable `KUBECONFIG` to point to your cluster configuration

```shell
export KUBECONFIG=path/to/kubeconfig
./cluster-kube-apiserver-operator-tests-ext run <test-name>
test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext run <test-name>
```

### Local Test using OCP
Expand All @@ -48,25 +48,48 @@ export KUBECONFIG=~/.kube/cluster-bot.kubeconfig

**Example:**
```shell
./cluster-kube-apiserver-operator-tests-ext run-suite openshift/cluster-kube-apiserver-operator/all
test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext run-suite openshift/cluster-kube-apiserver-operator/all
```

## Writing Tests

You can write tests in the `test/extended/` directory.
You can write tests in the `test/extended/tests-extension/` directory.

### Test Module Structure

This test extension uses a **separate Go module** to isolate test dependencies from the production operator code:

```
test/extended/tests-extension/
├── go.mod # Separate module with test dependencies
├── go.sum
├── Makefile # Build targets for test binary
├── bin/ # Built test binaries (gitignored)
│ └── cluster-kube-apiserver-operator-tests-ext
├── cmd/cluster-kube-apiserver-operator-tests-ext/
│ └── main.go # Test binary entry point
└── tests/ # Test packages
└── *.go
```

**Key Benefits:**
- Production `go.mod` remains clean (no ginkgo, gomega, test framework dependencies)
- Test dependencies are isolated in `test/extended/tests-extension/go.mod`
- Prevents dependency version conflicts between operator and test framework

## Development Workflow

- Add or update tests in: `test/extended/`
- Run `make build` to build the operator binary and `make tests-ext-build` for the test binary.
- Add or update tests in: `test/extended/tests-extension/`
- When adding new test dependencies, run `go mod tidy` from within `test/extended/tests-extension/`
- Run `make build` to build the operator binary and `make tests-ext-build` for the test binary
- You can run the full suite or one test using the commands in the table above.
- Before committing your changes:
- Run `make tests-ext-update`
- Run `make verify` to check formatting, linting, and validation

## How to Rename a Test

1. Run `./cluster-kube-apiserver-operator-tests-ext list` to see the current test names
1. Run `test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext list` to see the current test names
2. Find the name of the test you want to rename
3. Add a Ginkgo label with the original name, like this:

Expand All @@ -84,8 +107,8 @@ It("should pass a renamed sanity check",

## How to Delete a Test

1. Run `./cluster-kube-apiserver-operator-tests-ext list` to find the test name
2. Add the test name to the `IgnoreObsoleteTests` block in `cmd/cluster-kube-apiserver-operator-tests-ext/main.go`, like this:
1. Run `test/extended/tests-extension/bin/cluster-kube-apiserver-operator-tests-ext list` to find the test name
2. Add the test name to the `IgnoreObsoleteTests` block in `test/extended/tests-extension/cmd/cluster-kube-apiserver-operator-tests-ext/main.go`, like this:

```go
ext.IgnoreObsoleteTests(
Expand Down Expand Up @@ -136,11 +159,11 @@ More info: https://docs.ci.openshift.org/docs/architecture/ci-operator/#testing-
| Target | Description |
|--------------------------|------------------------------------------------------------------------------|
| `make build` | Builds the operator binary. |
| `make tests-ext-build` | Builds the test extension binary. |
| `make tests-ext-build` | Builds the test extension binary into `test/extended/tests-extension/bin/`. |
| `make tests-ext-update` | Updates the metadata JSON file and cleans machine-specific codeLocations. |
| `make verify` | Runs formatting, vet, and linter. |

**Note:** Metadata is stored in: `.openshift-tests-extension/openshift_payload_cluster-kube-apiserver-operator.json`
**Note:** Metadata is stored in: `test/extended/tests-extension/.openshift-tests-extension/openshift_payload_cluster-kube-apiserver-operator.json`

## FAQ

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"

// The import below is necessary to ensure that the OAS operator tests are registered with the extension.
_ "github.com/openshift/cluster-kube-apiserver-operator/test/extended"
_ "github.com/openshift/cluster-kube-apiserver-operator/test/extended/tests-extension"
)

func main() {
Expand Down
Loading