Skip to content

Commit 293a780

Browse files
committed
build(opensearch-operator): run the tests of the packages the patches touch
The image build ran go test on two package trees listed by hand, and go build never compiles a _test.go. A patch that reaches a directory nobody listed brings tests that are proven once, by hand, when the patch is cut, and nothing notices them failing after the next version bump. Run go test in the builder stage on the packages the patches touch. The list is read from the patches themselves, so a new patch is covered without an edit to the Dockerfile. It replaces the hand-picked go test line, keeping its -race flag: two lines testing the same packages is one too many. The hand-picked line also covered pkg/reconcilers/util, which no patch touches. controllers/ is left out. The stall-tracing patch touches it, and its suite starts an envtest control plane from etcd and kube-apiserver binaries the builder does not have, so testing it fails the build. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent bf03c84 commit 293a780

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

  • packages/system/opensearch-operator/images/opensearch-operator

‎packages/system/opensearch-operator/images/opensearch-operator/Dockerfile‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,23 @@ RUN curl -sSL https://github.com/opensearch-project/opensearch-k8s-operator/arch
7878
COPY patches /patches
7979
RUN git apply /patches/*.diff
8080

81-
WORKDIR /workspace/opensearch-operator
82-
83-
# The patches carry their own tests and nothing else in this repository runs
84-
# them: the build below compiles main.go, so a test file that had stopped
85-
# compiling, or stopped asserting, would still produce an image. These two
86-
# package trees are the ones the patches touch, and both run without a cluster.
81+
# go build never compiles a _test.go, so nothing else runs the tests of the
82+
# packages the patches touch. Each package is tested from its own directory:
83+
# that finds the module it belongs to, and an empty list runs nothing.
84+
# The list is read into a variable first: a for loop drops the exit status
85+
# of a command substitution, so a patch git cannot read would leave the list
86+
# empty and the step green.
87+
# controllers/ is left out: its suite is envtest, which execs etcd and
88+
# kube-apiserver binaries the builder does not carry.
8789
# -race is on because the timeout tests run a listener in one goroutine and
8890
# inspect what it accepted from another: an unsynchronised access there passes
8991
# the plain run, so nothing else would catch it. The builder has cgo and gcc.
90-
RUN go test -race ./opensearch-gateway/... ./pkg/reconcilers/...
92+
RUN files=$(git apply --numstat /patches/*.diff) || exit 1; \
93+
for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u | grep -vx 'opensearch-operator/controllers'); do \
94+
(cd "$dir" && go test -race .) || exit 1; \
95+
done
96+
97+
WORKDIR /workspace/opensearch-operator
9198

9299
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -a -o manager main.go
93100

0 commit comments

Comments
 (0)