Skip to content

OAPE-698: Integration of codecov on the must-gather-operator#350

Open
praveencodes wants to merge 1 commit into
openshift:masterfrom
praveencodes:OAPE-698
Open

OAPE-698: Integration of codecov on the must-gather-operator#350
praveencodes wants to merge 1 commit into
openshift:masterfrom
praveencodes:OAPE-698

Conversation

@praveencodes

@praveencodes praveencodes commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary
This change wires end-to-end (cluster) test coverage and Codecov into the must-gather-operator workflow.

  • Dockerfile.coverage — Multi-stage image that builds the operator with Go’s -cover / -coverpkg=./... instrumentation, sets GOCOVERDIR (default /tmp/e2e-cover), and prepares a writable directory so the running pod can emit coverage data.

  • Makefile — Adds docker-build-coverage, docker-push-coverage (image tag $(COVERAGE_IMG), default $(IMG)-e2e-coverage), and e2e-coverage-collect to run the collection script; documents the typical local flow (build/push → patch CSV → e2e → collect/upload).

  • hack/e2e-coverage.sh — setup: finds the operator CSV from the deployment owner reference, patches the CSV to use COVERAGE_IMAGE, injects GOCOVERDIR, and adds an emptyDir volume mount; collect: SIGTERM to flush coverage, oc cp data off the pod, go tool covdata textfmt / percent, and optional Codecov upload (token from env or /var/run/secrets/codecov/CODECOV_TOKEN, with Prow-friendly flags when JOB_TYPE is presubmit/postsubmit).

Summary by CodeRabbit

  • Chores
    • Added infrastructure for automated E2E test coverage collection and reporting, including a containerized build with coverage instrumentation, new build and collection targets, and support for automated coverage uploads to Codecov in presubmit and postsubmit workflows.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 19, 2026
@openshift-ci-robot

openshift-ci-robot commented May 19, 2026

Copy link
Copy Markdown

@praveencodes: This pull request references OAPE-698 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the sub-task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary
This change wires end-to-end (cluster) test coverage and Codecov into the must-gather-operator workflow.

  • Dockerfile.coverage — Multi-stage image that builds the operator with Go’s -cover / -coverpkg=./... instrumentation, sets GOCOVERDIR (default /tmp/e2e-cover), and prepares a writable directory so the running pod can emit coverage data.

  • Makefile — Adds docker-build-coverage, docker-push-coverage (image tag $(COVERAGE_IMG), default $(IMG)-e2e-coverage), and e2e-coverage-collect to run the collection script; documents the typical local flow (build/push → patch CSV → e2e → collect/upload).

  • hack/e2e-coverage.sh — setup: finds the operator CSV from the deployment owner reference, patches the CSV to use COVERAGE_IMAGE, injects GOCOVERDIR, and adds an emptyDir volume mount; collect: SIGTERM to flush coverage, oc cp data off the pod, go tool covdata textfmt / percent, and optional Codecov upload (token from env or /var/run/secrets/codecov/CODECOV_TOKEN, with Prow-friendly flags when JOB_TYPE is presubmit/postsubmit).

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

Walkthrough

This PR adds end-to-end coverage instrumentation for the must-gather-operator. It introduces a multi-stage Dockerfile that compiles the binary with coverage flags, defines Make targets to orchestrate Docker image builds and coverage collection, and implements a Bash script that patches deployments with the coverage image, flushes and collects coverage data, and optionally uploads results to Codecov.

Changes

E2E Coverage Instrumentation

Layer / File(s) Summary
Coverage-instrumented Docker image
Dockerfile.coverage
Multi-stage Docker build compiles the Go binary with coverage instrumentation flags (-cover, -covermode=count, -coverpkg=./...), then constructs a runtime stage that installs OS dependencies, copies the instrumented binary, creates a non-root user, sets up /tmp/e2e-cover directory with strict permissions, sets GOCOVERDIR environment variable, and defines the container entrypoint.
Make targets for coverage orchestration
Makefile
Adds COVERAGE_IMG variable, .PHONY targets docker-build-coverage (builds coverage image via Dockerfile.coverage), docker-push-coverage (pushes the image), and e2e-coverage-collect (runs hack/e2e-coverage.sh collect with optional artifact directory).
Coverage setup and collection script
hack/e2e-coverage.sh
Bash script provides setup command to patch the operator's ClusterServiceVersion with the coverage image, inject GOCOVERDIR, add volume mounts, and wait for rollout; collect command locates the pod, sends SIGTERM to flush coverage, copies coverage data, converts coverage metadata to a text profile, and optionally downloads and invokes the Codecov uploader (with flags customized by JOB_TYPE for presubmit, postsubmit, or local runs) when CODECOV_TOKEN is available.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 10 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Microshift Test Compatibility ⚠️ Warning Four e2e tests use ImageStream API (image.openshift.io), which is unavailable on MicroShift. Tests lack required [apigroup:image.openshift.io] or [Skipped:MicroShift] protection. Add [apigroup:image.openshift.io] tag to test names in "Custom Image" Context or add tag to Context block (line 1240) to protect from MicroShift.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly references the Jira ticket (OAPE-698) and clearly describes the main change: integration of Codecov coverage collection into the must-gather-operator's E2E testing workflow.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed PR does not add or modify Ginkgo tests; it only adds coverage collection infrastructure (Dockerfile, Makefile targets, and shell script). No test names to evaluate.
Test Structure And Quality ✅ Passed This PR adds E2E coverage infrastructure (Dockerfile, Makefile targets, shell script) but does not modify any Ginkgo test code. The check applies only to test code, not infrastructure files.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR adds no new Ginkgo e2e tests. It introduces coverage infrastructure (Dockerfile, Makefile targets, utility script). SNO compatibility check not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed No topology-specific scheduling constraints. Changes add coverage collection infra with benign patches: container image, env vars, emptyDir volumes only.
Ote Binary Stdout Contract ✅ Passed PR adds E2E coverage infrastructure without modifying test code. No changes to OTE test runner, Ginkgo suite setup, or process-level stdout. Custom check is not applicable.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR adds coverage infrastructure, not new Ginkgo e2e tests. The check applies only to new Ginkgo tests, which are not added here.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci Bot requested review from Tafhim and vaidehi411 May 19, 2026 05:10
@openshift-ci

openshift-ci Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: praveencodes
Once this PR has been reviewed and has the lgtm label, please assign iamkirkbater for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@praveencodes

Copy link
Copy Markdown
Contributor Author

/cc @shivprakashmuley

@openshift-ci openshift-ci Bot requested a review from shivprakashmuley May 19, 2026 05:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Dockerfile.coverage`:
- Around line 23-24: The coverage dir is owned by UID 65532 but the container
switches to USER 65534 so GOCOVERDIR writes will be blocked; update the RUN line
that creates /tmp/e2e-cover to either chown it to 65534:65534 (so the runtime
user owns it) or keep chown 65532 but change the subsequent USER to 65532;
specifically modify the mkdir/chown/chmod/USER sequence in Dockerfile.coverage
so the ownership (chown) and the USER directive refer to the same UID (or make
the directory group-writable and set the USER’s group accordingly).

In `@hack/e2e-coverage.sh`:
- Around line 109-113: The current code that downloads and verifies the Codecov
binary using variables codecov_bin and codecov_version can cause the script to
exit under set -euo pipefail; make the download/verification non-fatal by
handling errors instead of letting them propagate: perform the curl and
sha256sum steps inside a conditional or use error-catching (e.g., test the
commands' exit status) and on failure emit a warning (mentioning
codecov_bin/codecov_version) and skip chmod/verification so the script continues
to the optional upload step; ensure subsequent code still checks for the
presence/executability of codecov_bin before attempting upload.

In `@Makefile`:
- Line 42: The Makefile rule invoking the container build uses
images/ci/Dockerfile.coverage which no longer exists; update the docker build
command (the target that runs "$(CONTAINER_TOOL) build -f
images/ci/Dockerfile.coverage -t $(COVERAGE_IMG) .") to point to the new
Dockerfile.coverage location introduced in this PR (or to a Makefile variable
that references the correct path) so the docker-build-coverage target uses the
correct Dockerfile path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8c054540-8cc3-414f-9ec7-0d444071c1e9

📥 Commits

Reviewing files that changed from the base of the PR and between 59b15a1 and e4902b9.

📒 Files selected for processing (3)
  • Dockerfile.coverage
  • Makefile
  • hack/e2e-coverage.sh

Comment thread Dockerfile.coverage
Comment on lines +23 to +24
RUN mkdir -p /tmp/e2e-cover && chown 65532:65532 /tmp/e2e-cover && chmod 700 /tmp/e2e-cover
USER 65534:65534

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix coverage directory ownership mismatch (coverage writes will fail).

Line 23 grants /tmp/e2e-cover only to UID 65532, but Line 24 runs the process as UID 65534. With mode 700, the operator cannot write GOCOVERDIR output.

Suggested fix
-RUN mkdir -p /tmp/e2e-cover && chown 65532:65532 /tmp/e2e-cover && chmod 700 /tmp/e2e-cover
-USER 65534:65534
+RUN mkdir -p /tmp/e2e-cover && chown 65534:65534 /tmp/e2e-cover && chmod 700 /tmp/e2e-cover
+USER 65534:65534
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Dockerfile.coverage` around lines 23 - 24, The coverage dir is owned by UID
65532 but the container switches to USER 65534 so GOCOVERDIR writes will be
blocked; update the RUN line that creates /tmp/e2e-cover to either chown it to
65534:65534 (so the runtime user owns it) or keep chown 65532 but change the
subsequent USER to 65532; specifically modify the mkdir/chown/chmod/USER
sequence in Dockerfile.coverage so the ownership (chown) and the USER directive
refer to the same UID (or make the directory group-writable and set the USER’s
group accordingly).

Comment thread hack/e2e-coverage.sh
Comment on lines +109 to +113
curl -sS -o "${codecov_bin}" "https://uploader.codecov.io/${codecov_version}/linux/codecov"
curl -sS -o "${codecov_bin}.SHA256SUM" "https://uploader.codecov.io/${codecov_version}/linux/codecov.SHA256SUM"

cd "$(dirname "${codecov_bin}")" && sha256sum -c "$(basename "${codecov_bin}").SHA256SUM" && cd - >/dev/null
chmod +x "${codecov_bin}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make Codecov download/verification non-fatal to match optional upload behavior.

With set -euo pipefail, a failure on Lines 109–113 exits the script, but upload is treated as optional later (Line 138). This can fail jobs after coverage was already collected.

Suggested fix
-            curl -sS -o "${codecov_bin}"              "https://uploader.codecov.io/${codecov_version}/linux/codecov"
-            curl -sS -o "${codecov_bin}.SHA256SUM"    "https://uploader.codecov.io/${codecov_version}/linux/codecov.SHA256SUM"
-
-            cd "$(dirname "${codecov_bin}")" && sha256sum -c "$(basename "${codecov_bin}").SHA256SUM" && cd - >/dev/null
-            chmod +x "${codecov_bin}"
+            if ! curl -sS -o "${codecov_bin}" "https://uploader.codecov.io/${codecov_version}/linux/codecov" \
+              || ! curl -sS -o "${codecov_bin}.SHA256SUM" "https://uploader.codecov.io/${codecov_version}/linux/codecov.SHA256SUM" \
+              || ! (cd "$(dirname "${codecov_bin}")" && sha256sum -c "$(basename "${codecov_bin}").SHA256SUM" >/dev/null); then
+                echo "Warning: failed to download/verify Codecov uploader (non-fatal)"
+            else
+                chmod +x "${codecov_bin}"
+                "${codecov_bin}" "${codecov_args[@]}" || echo "Warning: Codecov upload failed (non-fatal)"
+            fi
@@
-            "${codecov_bin}" "${codecov_args[@]}" || echo "Warning: Codecov upload failed (non-fatal)"
             rm -f "${codecov_bin}" "${codecov_bin}.SHA256SUM"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@hack/e2e-coverage.sh` around lines 109 - 113, The current code that downloads
and verifies the Codecov binary using variables codecov_bin and codecov_version
can cause the script to exit under set -euo pipefail; make the
download/verification non-fatal by handling errors instead of letting them
propagate: perform the curl and sha256sum steps inside a conditional or use
error-catching (e.g., test the commands' exit status) and on failure emit a
warning (mentioning codecov_bin/codecov_version) and skip chmod/verification so
the script continues to the optional upload step; ensure subsequent code still
checks for the presence/executability of codecov_bin before attempting upload.

Comment thread Makefile

.PHONY: docker-build-coverage
docker-build-coverage: ## Build coverage Docker image from images/ci/Dockerfile.coverage.
$(CONTAINER_TOOL) build -f images/ci/Dockerfile.coverage -t $(COVERAGE_IMG) .

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Align Dockerfile path with the file introduced in this PR.

Line 42 points to images/ci/Dockerfile.coverage, while this PR introduces Dockerfile.coverage. If that path is not present, docker-build-coverage breaks.

Suggested fix
-	$(CONTAINER_TOOL) build -f images/ci/Dockerfile.coverage -t $(COVERAGE_IMG) .
+	$(CONTAINER_TOOL) build -f Dockerfile.coverage -t $(COVERAGE_IMG) .
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$(CONTAINER_TOOL) build -f images/ci/Dockerfile.coverage -t $(COVERAGE_IMG) .
$(CONTAINER_TOOL) build -f Dockerfile.coverage -t $(COVERAGE_IMG) .
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` at line 42, The Makefile rule invoking the container build uses
images/ci/Dockerfile.coverage which no longer exists; update the docker build
command (the target that runs "$(CONTAINER_TOOL) build -f
images/ci/Dockerfile.coverage -t $(COVERAGE_IMG) .") to point to the new
Dockerfile.coverage location introduced in this PR (or to a Makefile variable
that references the correct path) so the docker-build-coverage target uses the
correct Dockerfile path.

@codecov-commenter

codecov-commenter commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.36%. Comparing base (59b15a1) to head (e4902b9).
⚠️ Report is 28 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #350       +/-   ##
===========================================
+ Coverage   62.89%   80.36%   +17.47%     
===========================================
  Files           8        8               
  Lines         830     1100      +270     
===========================================
+ Hits          522      884      +362     
+ Misses        302      204       -98     
- Partials        6       12        +6     

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@openshift-ci

openshift-ci Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

@praveencodes: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-operator e4902b9 link true /test e2e-gcp-operator
ci/prow/validate-boilerplate e4902b9 link false /test validate-boilerplate

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@shivprakashmuley

Copy link
Copy Markdown
Contributor

@praveencodes worth taking a look at CodeRabbit comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants