Skip to content

Commit 615cb5f

Browse files
committed
Create separate Go module for test extension
This commit isolates test dependencies from production code by creating a separate Go module for the test extension at test/extended/tests-extension/. Key changes: - Move test files to test/extended/tests-extension/ directory structure - Create separate go.mod for test dependencies (ginkgo, gomega, openshift-tests-extension) - Remove test dependencies from root go.mod (~XXX lines removed from vendor) - Update root Makefile to use delegation pattern for test extension targets - Update Dockerfile.rhel7 paths to reference new binary location - Update .gitignore to ignore test/extended/tests-extension/bin/ Benefits: - Smaller production images (test dependencies not included in production builds) - Faster builds (production builds don't need to vendor test dependencies) - Cleaner dependency management (test dependencies isolated) - Better CI performance (smaller images, faster pulls, less storage) Related: Similar to openshift/openshift-apiserver#571
1 parent f7a23c8 commit 615cb5f

File tree

297 files changed

+399
-199471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+399
-199471
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/cluster-kube-controller-manager-operator
2-
/cluster-kube-controller-manager-operator-tests-ext
32
.idea/
43
_output
54
telepresence.log
6-
.openshift-tests-extension/openshift_payload_*.json
5+
/test/extended/tests-extension/bin/
76

Dockerfile.rhel7

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.21 AS builder
22
WORKDIR /go/src/github.com/openshift/cluster-kube-controller-manager-operator
33
COPY . .
4-
RUN make build --warn-undefined-variables
5-
RUN make tests-ext-build --warn-undefined-variables \
6-
&& gzip cluster-kube-controller-manager-operator-tests-ext
4+
RUN make build --warn-undefined-variables \
5+
&& make tests-ext-build \
6+
&& gzip test/extended/tests-extension/bin/cluster-kube-controller-manager-operator-tests-ext
77

88
FROM registry.ci.openshift.org/ocp/4.21:base-rhel9
99
RUN mkdir -p /usr/share/bootkube/manifests/bootstrap-manifests/ /usr/share/bootkube/manifests/config/ /usr/share/bootkube/manifests/manifests/
1010
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/bindata/bootkube/bootstrap-manifests /usr/share/bootkube/manifests/bootstrap-manifests/
1111
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/bindata/bootkube/config /usr/share/bootkube/manifests/config/
1212
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/bindata/bootkube/manifests /usr/share/bootkube/manifests/manifests/
1313
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/cluster-kube-controller-manager-operator /usr/bin/
14-
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/cluster-kube-controller-manager-operator-tests-ext.gz /usr/bin/
14+
COPY --from=builder /go/src/github.com/openshift/cluster-kube-controller-manager-operator/test/extended/tests-extension/bin/cluster-kube-controller-manager-operator-tests-ext.gz /usr/bin/
1515
COPY manifests /manifests
1616
LABEL io.openshift.release.operator true

test/extended/README.md

Lines changed: 0 additions & 184 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Get the directory where this Makefile is, so we can use it below for including
2+
DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
3+
4+
# Definitions for the extended tests
5+
GO_PKG_NAME := github.com/openshift-eng/openshift-tests-extension
6+
7+
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
8+
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
9+
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)
10+
11+
LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \
12+
-X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \
13+
-X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)'
14+
15+
METADATA := $(shell pwd)/.openshift-tests-extension
16+
17+
TOOLS_BIN_DIR := $(CURDIR)/bin
18+
BINARY_NAME := cluster-kube-controller-manager-operator-tests-ext
19+
20+
.PHONY: help
21+
help: #HELP Display essential help.
22+
@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)
23+
24+
#SECTION Development
25+
.PHONY: verify #HELP To verify the code
26+
verify: tidy fmt vet
27+
28+
.PHONY: tidy #HELP To tidy the go.mod and go.sum files
29+
tidy:
30+
go mod tidy
31+
32+
.PHONY: fmt #HELP To run go fmt
33+
fmt:
34+
go fmt ./...
35+
36+
.PHONY: vet #HELP To run go vet
37+
vet:
38+
go vet ./...
39+
40+
#SECTION Build
41+
.PHONY: build
42+
build: #HELP Build the extended tests binary
43+
@mkdir -p $(TOOLS_BIN_DIR)
44+
GO_COMPLIANCE_POLICY="exempt_all" CGO_ENABLED=0 go build -mod=mod -ldflags "$(LDFLAGS)" -o $(TOOLS_BIN_DIR)/$(BINARY_NAME) ./cmd/...
45+
46+
.PHONY: update-metadata
47+
update-metadata: build #HELP Build and run 'update-metadata' to generate test metadata
48+
$(TOOLS_BIN_DIR)/$(BINARY_NAME) update --output-dir=$(METADATA)
49+
50+
.PHONY: build-update
51+
build-update: build #HELP Build and update test metadata (strips machine-specific codeLocations)
52+
$(TOOLS_BIN_DIR)/$(BINARY_NAME) update --output-dir=$(METADATA)
53+
for f in $(METADATA)/*.json; do \
54+
jq 'map(del(.codeLocations))' "$$f" > tmpp && mv tmpp "$$f"; \
55+
done
56+
57+
.PHONY: clean
58+
clean: #HELP Remove the bin directory
59+
rm -rf $(TOOLS_BIN_DIR)
60+
61+
.PHONY: run-suite
62+
run-suite: build #HELP Run a test suite (usage: make run-suite SUITE=<suite-name> [JUNIT_DIR=<dir>])
63+
@if [ -z "$(SUITE)" ]; then \
64+
echo "Error: SUITE variable is required. Usage: make run-suite SUITE=<suite-name> [JUNIT_DIR=<dir>]"; \
65+
exit 1; \
66+
fi
67+
@JUNIT_ARG=""; \
68+
if [ -n "$(JUNIT_DIR)" ]; then \
69+
mkdir -p $(JUNIT_DIR); \
70+
JUNIT_ARG="--junit-path=$(JUNIT_DIR)/junit.xml"; \
71+
fi; \
72+
$(TOOLS_BIN_DIR)/$(BINARY_NAME) run-suite $(SUITE) $$JUNIT_ARG
73+
74+
.PHONY: list-test-names
75+
list-test-names: build #HELP List all test names
76+
$(TOOLS_BIN_DIR)/$(BINARY_NAME) list
77+
78+
.PHONY: verify-metadata
79+
verify-metadata: build #HELP Verify metadata is up to date
80+
@echo "Verifying metadata is up to date..."
81+
@$(TOOLS_BIN_DIR)/$(BINARY_NAME) update --output-dir=$(METADATA) --dry-run || \
82+
(echo "Error: metadata is not up to date. Run 'make build-update' to update it."; exit 1)
83+
@echo "Metadata is up to date."

0 commit comments

Comments
 (0)