-
Notifications
You must be signed in to change notification settings - Fork 21
OAPE-696: Add E2E coverage reporting with Codecov integration #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PillaiManish
wants to merge
2
commits into
openshift:main
Choose a base branch
from
PillaiManish:e2e-coverage-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+217
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.25-openshift-4.22 AS builder | ||
| WORKDIR /go/src/github.com/openshift/secrets-store-csi-driver-operator | ||
| COPY . . | ||
| RUN make build-coverage | ||
|
|
||
| FROM registry.ci.openshift.org/ocp/4.22:base-rhel9 | ||
| COPY --from=builder /go/src/github.com/openshift/secrets-store-csi-driver-operator/secrets-store-csi-driver-operator /usr/bin/ | ||
| ENV GOCOVERDIR=/tmp/e2e-cover | ||
| ENTRYPOINT ["/bin/sh", "-c", "mkdir -p /tmp/e2e-cover && exec /usr/bin/secrets-store-csi-driver-operator \"$@\"", "--"] | ||
| LABEL io.k8s.display-name="OpenShift Secrets Store CSI Driver Operator" \ | ||
| io.k8s.description="The Secrets Store CSI Driver Operator installs and maintains the Secrets Store CSI Driver on a cluster." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # E2E coverage lifecycle script for CI and local use. | ||
| # | ||
| # Usage: | ||
| # hack/e2e-coverage.sh setup Prepare the operator for coverage collection | ||
| # hack/e2e-coverage.sh collect Collect, convert, and optionally upload coverage data | ||
| # | ||
| # Environment variables: | ||
| # COVERAGE_IMAGE (setup) Full pullspec of the coverage-instrumented image | ||
| # CODECOV_TOKEN (collect) Codecov upload token; skip upload if unset | ||
| # ARTIFACT_DIR (collect) Directory for CI artifacts; defaults to "." | ||
| set -euo pipefail | ||
|
|
||
| NAMESPACE="openshift-cluster-csi-drivers" | ||
| DEPLOYMENT="secrets-store-csi-driver-operator" | ||
| POD_LABEL="app=secrets-store-csi-driver-operator" | ||
| GOCOVERDIR_PATH="/tmp/e2e-cover" | ||
| CODECOV_SECRET_PATH="/var/run/secrets/codecov/CODECOV_TOKEN" | ||
|
|
||
| setup() { | ||
| echo "--- E2E Coverage Setup ---" | ||
|
|
||
| if [[ -z "${COVERAGE_IMAGE:-}" ]]; then | ||
| echo "Error: COVERAGE_IMAGE env var must be set" | ||
| exit 1 | ||
| fi | ||
| echo "Coverage image: ${COVERAGE_IMAGE}" | ||
|
|
||
| echo "Discovering CSV from deployment ownerReference..." | ||
| local csv | ||
| csv=$(oc get deployment "${DEPLOYMENT}" -n "${NAMESPACE}" \ | ||
| -o jsonpath='{.metadata.ownerReferences[?(@.kind=="ClusterServiceVersion")].name}') | ||
| if [[ -z "${csv}" ]]; then | ||
| echo "Error: no CSV found for ${DEPLOYMENT}" | ||
| exit 1 | ||
| fi | ||
| echo "Found CSV: ${csv}" | ||
|
|
||
| echo "Patching CSV with coverage image..." | ||
| oc patch csv "${csv}" -n "${NAMESPACE}" --type=json -p "[ | ||
| {\"op\": \"replace\", \"path\": \"/spec/install/spec/deployments/0/spec/template/spec/containers/0/image\", \"value\": \"${COVERAGE_IMAGE}\"} | ||
| ]" | ||
|
|
||
| local has_gocoverdir | ||
| has_gocoverdir=$(oc get csv "${csv}" -n "${NAMESPACE}" \ | ||
| -o jsonpath='{.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[?(@.name=="GOCOVERDIR")].name}' 2>/dev/null) | ||
| if [[ -z "${has_gocoverdir}" ]]; then | ||
| echo "Adding GOCOVERDIR env var to CSV..." | ||
| oc patch csv "${csv}" -n "${NAMESPACE}" --type=json -p "[ | ||
| {\"op\": \"add\", \"path\": \"/spec/install/spec/deployments/0/spec/template/spec/containers/0/env/-\", \"value\": {\"name\": \"GOCOVERDIR\", \"value\": \"${GOCOVERDIR_PATH}\"}} | ||
| ]" | ||
| else | ||
| echo "GOCOVERDIR env var already present in CSV" | ||
| fi | ||
|
|
||
| echo "Waiting for operator rollout with coverage image..." | ||
| sleep 5 | ||
| oc rollout status "deployment/${DEPLOYMENT}" -n "${NAMESPACE}" --timeout=180s | ||
|
|
||
| echo "Verifying GOCOVERDIR is set in the running pod..." | ||
| oc exec -n "${NAMESPACE}" "deploy/${DEPLOYMENT}" -- env | grep GOCOVERDIR || \ | ||
| echo "Warning: GOCOVERDIR not found in pod env (non-fatal)" | ||
|
|
||
| echo "--- Coverage setup complete ---" | ||
| } | ||
|
|
||
| collect() { | ||
| echo "--- E2E Coverage Collection ---" | ||
|
|
||
| local artifact_dir="${ARTIFACT_DIR:-.}" | ||
| local coverage_dir="${artifact_dir}/e2e-cover-data" | ||
| local coverage_profile="${artifact_dir}/coverage-e2e.out" | ||
|
|
||
| if [[ -z "${CODECOV_TOKEN:-}" ]] && [[ -f "${CODECOV_SECRET_PATH}" ]]; then | ||
| CODECOV_TOKEN=$(cat "${CODECOV_SECRET_PATH}") | ||
| export CODECOV_TOKEN | ||
| fi | ||
|
|
||
| local pod | ||
| pod=$(oc get pods -n "${NAMESPACE}" -l "${POD_LABEL}" \ | ||
| -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) | ||
| if [[ -z "${pod}" ]]; then | ||
| echo "Error: no operator pod found with label ${POD_LABEL}" | ||
| echo "Coverage collection requires the operator pod to be running." | ||
| exit 1 | ||
| fi | ||
| echo "Found operator pod: ${pod}" | ||
|
|
||
| echo "Sending SIGTERM to flush coverage data (container will restart)..." | ||
| oc exec -n "${NAMESPACE}" "${pod}" -- /bin/sh -c 'kill -TERM 1' 2>/dev/null || true | ||
|
|
||
| echo "Waiting for container to restart and become ready..." | ||
| sleep 5 | ||
| oc wait pod "${pod}" -n "${NAMESPACE}" --for=condition=Ready --timeout=120s | ||
|
|
||
| echo "Copying coverage data from the restarted container..." | ||
| mkdir -p "${coverage_dir}" | ||
| oc cp "${NAMESPACE}/${pod}:${GOCOVERDIR_PATH}/." "${coverage_dir}" | ||
|
|
||
| echo "Coverage files:" | ||
| ls -la "${coverage_dir}/" 2>/dev/null || true | ||
|
|
||
| if ls "${coverage_dir}"/covmeta.* >/dev/null 2>&1; then | ||
| echo "Converting coverage data to Go profile format..." | ||
| go tool covdata textfmt -i="${coverage_dir}" -o="${coverage_profile}" | ||
|
|
||
| echo "" | ||
| echo "=== E2E Coverage Summary ===" | ||
| go tool covdata percent -i="${coverage_dir}" | ||
| echo "=============================" | ||
| echo "" | ||
| echo "Coverage profile: ${coverage_profile} ($(wc -l < "${coverage_profile}") lines)" | ||
|
|
||
| if [[ -n "${CODECOV_TOKEN:-}" ]]; then | ||
| echo "Uploading to Codecov..." | ||
| local codecov_bin="${artifact_dir}/codecov" | ||
| curl -sS -o "${codecov_bin}" https://uploader.codecov.io/latest/linux/codecov | ||
| curl -sS -o "${codecov_bin}.SHA256SUM" https://uploader.codecov.io/latest/linux/codecov.SHA256SUM | ||
| curl -sS -o "${codecov_bin}.SHA256SUM.sig" https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig | ||
|
|
||
| if command -v gpg >/dev/null 2>&1 && command -v gpgv >/dev/null 2>&1; then | ||
| curl -sS https://keybase.io/codecovsecurity/pgp_keys.asc \ | ||
| | gpg --no-default-keyring --keyring trustedkeys.gpg --import 2>/dev/null || true | ||
| if gpgv "${codecov_bin}.SHA256SUM.sig" "${codecov_bin}.SHA256SUM" 2>/dev/null; then | ||
| echo "PGP signature verified" | ||
| else | ||
| echo "Warning: PGP signature verification failed (continuing with SHA256 check)" | ||
| fi | ||
| fi | ||
| cd "$(dirname "${codecov_bin}")" && sha256sum -c "$(basename "${codecov_bin}").SHA256SUM" && cd - >/dev/null | ||
| chmod +x "${codecov_bin}" | ||
|
|
||
| local -a codecov_args=( | ||
| --file="${coverage_profile}" | ||
| --flags=e2e | ||
| --name="E2E Coverage" | ||
| --verbose | ||
| ) | ||
|
|
||
| local job_type="${JOB_TYPE:-local}" | ||
| if [[ "${job_type}" == "presubmit" ]]; then | ||
| echo "Detected presubmit (PR #${PULL_NUMBER:-unknown})" | ||
| [[ -n "${PULL_NUMBER:-}" ]] && codecov_args+=(--pr "${PULL_NUMBER}") | ||
| [[ -n "${PULL_PULL_SHA:-}" ]] && codecov_args+=(--sha "${PULL_PULL_SHA}") | ||
| [[ -n "${PULL_BASE_REF:-}" ]] && codecov_args+=(--branch "${PULL_BASE_REF}") | ||
| [[ -n "${REPO_OWNER:-}" && -n "${REPO_NAME:-}" ]] && codecov_args+=(--slug "${REPO_OWNER}/${REPO_NAME}") | ||
| elif [[ "${job_type}" == "postsubmit" ]]; then | ||
| echo "Detected postsubmit (branch ${PULL_BASE_REF:-unknown})" | ||
| [[ -n "${PULL_BASE_SHA:-}" ]] && codecov_args+=(--sha "${PULL_BASE_SHA}") | ||
| [[ -n "${PULL_BASE_REF:-}" ]] && codecov_args+=(--branch "${PULL_BASE_REF}") | ||
| [[ -n "${REPO_OWNER:-}" && -n "${REPO_NAME:-}" ]] && codecov_args+=(--slug "${REPO_OWNER}/${REPO_NAME}") | ||
| else | ||
| echo "Local run -- no Prow context, Codecov will auto-detect from git" | ||
| fi | ||
|
|
||
| "${codecov_bin}" "${codecov_args[@]}" || echo "Warning: Codecov upload failed (non-fatal)" | ||
| rm -f "${codecov_bin}" "${codecov_bin}.SHA256SUM" "${codecov_bin}.SHA256SUM.sig" | ||
| else | ||
| echo "CODECOV_TOKEN not set -- skipping Codecov upload." | ||
| echo "Coverage profile saved as artifact: ${coverage_profile}" | ||
| fi | ||
| else | ||
| echo "Warning: No coverage data found in ${coverage_dir}" | ||
| echo "The operator may not have been built with coverage instrumentation," | ||
| echo "or the process did not exit cleanly (SIGKILL instead of SIGTERM)." | ||
| fi | ||
|
|
||
| echo "--- Coverage collection complete ---" | ||
| } | ||
|
|
||
| case "${1:-}" in | ||
| setup) | ||
| setup | ||
| ;; | ||
| collect) | ||
| collect | ||
| ;; | ||
| *) | ||
| echo "Usage: $0 {setup|collect}" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/secrets-store-csi-driver-operator
Length of output: 453
🏁 Script executed:
Repository: openshift/secrets-store-csi-driver-operator
Length of output: 1152
🏁 Script executed:
Repository: openshift/secrets-store-csi-driver-operator
Length of output: 574
🏁 Script executed:
Repository: openshift/secrets-store-csi-driver-operator
Length of output: 840
🏁 Script executed:
Repository: openshift/secrets-store-csi-driver-operator
Length of output: 589
Fix build-coverage flags syntax error—proposed fix is incorrect for FIPS mode.
The
$(GO_BUILD_FLAGS),e2ecoverageconcatenation produces invalid syntax in non-FIPS mode. WhenGO_BUILD_FLAGSis-trimpath, this expands togo build -trimpath,e2ecoverage, which is invalid Go build syntax.However, the proposed fix (
$(GO_BUILD_FLAGS) -tags e2ecoverage) breaks FIPS mode by creating duplicate-tagsflags:go build -trimpath -tags strictfipsruntime,openssl -tags e2ecoverage. Go's build command does not accept multiple-tagsflags.The correct solution requires either:
-tagsalready exists inGO_BUILD_FLAGS, or🤖 Prompt for AI Agents