-
Notifications
You must be signed in to change notification settings - Fork 23
Add Konflux PR check for unit tests #2332
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,129 @@ | ||||||||||||||||
| # Copyright Contributors to the Open Cluster Management project | ||||||||||||||||
| # | ||||||||||||||||
| # Standalone Pipelines-as-Code PR check that runs `make test` (Go unit | ||||||||||||||||
| # tests) on every PR to main/backplane-5.1/backplane-5.2. This is a plain | ||||||||||||||||
| # PR check (not tied to Konflux Snapshot/Release gating), equivalent to | ||||||||||||||||
| # Prow's `make unit-tests` job. | ||||||||||||||||
| # | ||||||||||||||||
| # The appstudio.openshift.io/* labels are required for UI resolution | ||||||||||||||||
| # only; they don't affect the check's actual scope or gating behavior. | ||||||||||||||||
| apiVersion: tekton.dev/v1 | ||||||||||||||||
| kind: PipelineRun | ||||||||||||||||
| metadata: | ||||||||||||||||
| annotations: | ||||||||||||||||
| build.appstudio.openshift.io/repo: https://github.com/stolostron/discovery?rev={{revision}} | ||||||||||||||||
| build.appstudio.redhat.com/commit_sha: '{{revision}}' | ||||||||||||||||
| build.appstudio.redhat.com/pull_request_number: '{{pull_request_number}}' | ||||||||||||||||
| build.appstudio.redhat.com/target_branch: '{{target_branch}}' | ||||||||||||||||
| pipelinesascode.tekton.dev/cancel-in-progress: "true" | ||||||||||||||||
| pipelinesascode.tekton.dev/max-keep-runs: "3" | ||||||||||||||||
| pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && (target_branch == "main" || target_branch == "backplane-5.1" || target_branch == "backplane-5.2") | ||||||||||||||||
| creationTimestamp: null | ||||||||||||||||
| labels: | ||||||||||||||||
| appstudio.openshift.io/application: release-mce-51 | ||||||||||||||||
| appstudio.openshift.io/component: discovery-operator-mce-51 | ||||||||||||||||
| pipelines.appstudio.openshift.io/type: test | ||||||||||||||||
| name: discovery-operator-unit-tests | ||||||||||||||||
| namespace: crt-redhat-acm-tenant | ||||||||||||||||
| spec: | ||||||||||||||||
| params: | ||||||||||||||||
| - name: git-url | ||||||||||||||||
| value: '{{source_url}}' | ||||||||||||||||
| - name: revision | ||||||||||||||||
| value: '{{revision}}' | ||||||||||||||||
| timeouts: | ||||||||||||||||
| pipeline: "20m" | ||||||||||||||||
| pipelineSpec: | ||||||||||||||||
| params: | ||||||||||||||||
| - name: git-url | ||||||||||||||||
| type: string | ||||||||||||||||
| - name: revision | ||||||||||||||||
| type: string | ||||||||||||||||
| tasks: | ||||||||||||||||
| - name: unit-test | ||||||||||||||||
| params: | ||||||||||||||||
| - name: git-url | ||||||||||||||||
| value: $(params.git-url) | ||||||||||||||||
| - name: revision | ||||||||||||||||
| value: $(params.revision) | ||||||||||||||||
| taskSpec: | ||||||||||||||||
| params: | ||||||||||||||||
| - name: git-url | ||||||||||||||||
| type: string | ||||||||||||||||
| - name: revision | ||||||||||||||||
| type: string | ||||||||||||||||
| steps: | ||||||||||||||||
| - name: run-unit-tests | ||||||||||||||||
| image: registry.redhat.io/ubi9/go-toolset:1.26 | ||||||||||||||||
| workingDir: /workspace | ||||||||||||||||
| computeResources: | ||||||||||||||||
| requests: | ||||||||||||||||
| cpu: "1" | ||||||||||||||||
| memory: 2Gi | ||||||||||||||||
| limits: | ||||||||||||||||
| cpu: "2" | ||||||||||||||||
| memory: 6Gi | ||||||||||||||||
| env: | ||||||||||||||||
| - name: GIT_URL | ||||||||||||||||
| value: $(params.git-url) | ||||||||||||||||
| - name: REVISION | ||||||||||||||||
| value: $(params.revision) | ||||||||||||||||
| - name: HOME | ||||||||||||||||
| value: /tmp/home | ||||||||||||||||
| - name: GOPATH | ||||||||||||||||
| value: /tmp/go | ||||||||||||||||
| - name: GOCACHE | ||||||||||||||||
| value: /tmp/go-cache | ||||||||||||||||
| - name: GOFLAGS | ||||||||||||||||
| value: -p=2 | ||||||||||||||||
| script: | | ||||||||||||||||
| #!/bin/bash | ||||||||||||||||
| set -uo pipefail | ||||||||||||||||
| mkdir -p "${HOME}" | ||||||||||||||||
|
|
||||||||||||||||
| echo "===== Checking required tools =====" | ||||||||||||||||
| # go-toolset already ships git/make/go; just verify they exist. | ||||||||||||||||
| for tool in git make go; do | ||||||||||||||||
| if ! command -v "${tool}" >/dev/null 2>&1; then | ||||||||||||||||
| echo "Required tool '${tool}' not found in this image." | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
| done | ||||||||||||||||
| echo "git: $(git --version)" | ||||||||||||||||
| echo "make: $(make --version | head -1)" | ||||||||||||||||
| echo "go: $(go version)" | ||||||||||||||||
|
|
||||||||||||||||
| echo "===== Network reachability check =====" | ||||||||||||||||
| # Probe GOPROXY and GCS (required by make test's dependency | ||||||||||||||||
| # chain) with short timeouts so blocked egress fails fast. | ||||||||||||||||
| NETWORK_OK=true | ||||||||||||||||
| if ! timeout 8 bash -c 'exec 3<>/dev/tcp/proxy.golang.org/443' 2>/dev/null; then | ||||||||||||||||
| echo "WARNING: proxy.golang.org:443 not reachable within 8s." | ||||||||||||||||
| NETWORK_OK=false | ||||||||||||||||
| fi | ||||||||||||||||
| if ! timeout 8 bash -c 'exec 3<>/dev/tcp/storage.googleapis.com/443' 2>/dev/null; then | ||||||||||||||||
| echo "WARNING: storage.googleapis.com:443 not reachable within 8s." | ||||||||||||||||
| NETWORK_OK=false | ||||||||||||||||
| fi | ||||||||||||||||
| if [ "${NETWORK_OK}" = "true" ]; then | ||||||||||||||||
| echo "Network egress appears open." | ||||||||||||||||
| else | ||||||||||||||||
| echo "This tenant likely restricts general internet egress from Task pods." | ||||||||||||||||
| fi | ||||||||||||||||
|
Comment on lines
+110
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Fail when a required reachability probe fails.
Proposed fix else
echo "This tenant likely restricts general internet egress from Task pods."
+ exit 1
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| echo "===== Cloning ${GIT_URL}@${REVISION} =====" | ||||||||||||||||
| git clone --quiet "${GIT_URL}" src | ||||||||||||||||
| cd src | ||||||||||||||||
| git checkout --quiet "${REVISION}" | ||||||||||||||||
|
|
||||||||||||||||
| echo "===== Running unit tests: make test =====" | ||||||||||||||||
| # Timeout 10m so a stuck download fails fast, not hangs for hours. | ||||||||||||||||
| if timeout 600 make test; then | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
oc -n crt-redhat-acm-tenant run timeout-probe --rm -i --restart=Never \
--image=registry.redhat.io/ubi9/go-toolset:1.26 \
--overrides='{"spec":{"serviceAccountName":"build-pipeline-discovery-operator-mce-51"}}' \
--command -- bash -ceu '
timeout --version
set +e
timeout --kill-after=1s 1s bash -c '"'"'trap "" TERM; while :; do sleep 1; done'"'"'
status=$?
set -e
test "$status" -eq 137
'Repository: stolostron/discovery Length of output: 198 🏁 Script executed: #!/bin/bash
set -euo pipefail
file=".tekton/discovery-operator-unit-tests-pull-request.yaml"
sed -n '112,134p' "$file"
printf '\nImage and timeout references:\n'
rg -n -C 3 'ubi9/go-toolset|timeout(\s|$)|make test' .tekton Dockerfile* Containerfile* 2>/dev/null || trueRepository: stolostron/discovery Length of output: 4967 🌐 Web query:
💡 Result: The GNU coreutils timeout command with the --kill-after=DURATION option ensures that a monitored command is forcefully terminated if it fails to exit after receiving an initial signal [1][2][3]. When you specify a timeout (e.g., 600 seconds) and use --kill-after=DURATION, the behavior is as follows: 1. Initial Signal: Upon reaching the primary duration (e.g., 600 seconds), timeout sends a signal to the command [2][3]. By default, this is the TERM signal (SIGTERM), unless a different signal is specified via the -s or --signal option [1][4][3]. 2. Waiting Period: After sending the initial signal, timeout monitors the command for the duration specified by --kill-after [2][3]. This timer starts at the exact moment the initial signal is sent [2]. 3. Final Signal: If the command is still running after the --kill-after duration has elapsed, timeout sends the KILL signal (SIGKILL) [2][3]. Because the KILL signal cannot be caught or ignored by the process, this guarantees the termination of the command [4][5][3]. If the command successfully terminates on its own before the --kill-after interval, no further action is taken [2]. Regarding the exit status: - If the command times out and is terminated (either by the initial signal or the subsequent KILL signal), timeout typically exits with status 124 [1][3]. - If the command is forcefully terminated by the KILL signal, some implementations or configurations may reflect an exit status of 137 (which is 128 + 9, representing the receipt of signal 9) [4][3]. - Using the --preserve-status option will cause timeout to return the exit status of the command itself instead of the special 124 status [6][3]. A duration value of 0 for either the primary timeout or the --kill-after interval disables that specific timeout feature [2][3]. Citations:
Enforce the 10-minute test limit. GNU Proposed fix- if timeout 600 make test; then
+ if timeout --kill-after=30s 600s make test; then📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| echo "Unit tests passed." | ||||||||||||||||
| else | ||||||||||||||||
| echo "make test failed or timed out after 10m." | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
| taskRunTemplate: | ||||||||||||||||
| serviceAccountName: build-pipeline-discovery-operator-mce-51 | ||||||||||||||||
| status: {} | ||||||||||||||||
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Stop the script after clone or checkout errors.
Line 81 does not enable
-e. Ifgit checkout "${REVISION}"fails, Bash continues in the cloned default branch and can report passing tests for code that is not the PR revision. Handle failures fromgit clone,cd, andgit checkout.Proposed fix
🤖 Prompt for AI Agents