Skip to content

Fix tls-scanner-run cleanup crash and Failed pod handling - #82522

Open
jzding wants to merge 1 commit into
openshift:mainfrom
jzding:fix-tls-scanner-owns-namespace
Open

Fix tls-scanner-run cleanup crash and Failed pod handling#82522
jzding wants to merge 1 commit into
openshift:mainfrom
jzding:fix-tls-scanner-owns-namespace

Conversation

@jzding

@jzding jzding commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Bugs

Two issues in tls-scanner-run-commands.sh:

1. OWNS_NAMESPACE: unbound variable in cleanup trap

OWNS_NAMESPACE and NAMESPACE are local variables inside run_tls_scan(). The cleanup trap references them, but when the trap fires after the function returns, locals are out of scope:

Cleaning up...
environment: line 108: OWNS_NAMESPACE: unbound variable

Fix: Use ${OWNS_NAMESPACE:-true} and ${NAMESPACE:-tls-scanner} in the cleanup function.

2. Scanner exit code 1 causes 10-minute timeout waste

When the scanner finds TLS compliance issues, it exits with code 1 and the pod phase is Failed. The script (line 255-258) catches this and calls exit 1, triggering the cleanup trap crash from bug #1. Even without the crash, the subsequent oc wait --for=Succeeded (line 261) would timeout for 10 minutes since the pod is already Failed, not Succeeded.

The scan actually completed successfully — artifacts were collected via the scan.done polling loop before this code runs:

Scan complete. Exit code: 1              ← scanner found TLS issues
/results/scan.done found — proceeding to copy artifacts
Copying artifacts...
JUnit results copied to /logs/artifacts/junit_tls_scan.xml for Spyglass

Fix: After artifacts are collected, check the pod phase. If Failed with artifacts present, log that findings were detected (not an infrastructure failure). Only fall through to oc wait for unexpected phases (e.g., pod still Running without scan.done).

Reproduction

Run tls-scanner-run against any namespace where the scanner finds TLS compliance issues (exit code 1). Observed in PTP operator periodic CI (tls-scan-periodic on release-5.0).

/cc @richardsonnick @rhmdnd @smith-xyz

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Fixes the tls-scanner-run cleanup EXIT trap in ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh so it doesn’t break under set -o nounset when the TLS scanner pod exits non-zero. The script snapshots NAMESPACE and OWNS_NAMESPACE into global _CLEANUP_* variables before registering the trap, and the trap uses those snapshots for namespace/pod deletion.
  • Improves TLS scanner post-scan handling for OpenShift CI infrastructure: when the scanner pod reports phase=Failed, the script now checks whether junit_tls_scan.xml was collected. If artifacts exist, it treats the failure as expected TLS findings (and skips describing the pod as an infrastructure failure); it only describes the pod (and fails) when artifacts are missing. For other unexpected phases, it waits up to 10 minutes for Succeeded and only fails on timeout—avoiding unnecessary oc wait --for=Succeeded timeouts for TLS finding outcomes.

@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jzding
Once this PR has been reviewed and has the lgtm label, please assign richardsonnick 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

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@jzding, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: c287e6be-8a5e-4c1a-bdb6-bd787f764640

📥 Commits

Reviewing files that changed from the base of the PR and between d70f6cb and 3603d42.

📒 Files selected for processing (1)
  • ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh

Walkthrough

The TLS scanner now snapshots cleanup variables before installing the EXIT trap and evaluates pod phases, termination codes, and JUnit artifacts before deciding whether to describe, wait, or fail.

Changes

TLS scanner execution

Layer / File(s) Summary
Cleanup trap variable snapshots
ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh
Cleanup snapshots NAMESPACE and OWNS_NAMESPACE before the EXIT trap and uses those values for namespace or pod deletion.
Post-scan pod result evaluation
ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh
Result handling reads pod phase and container termination data, preserves failed scans when JUnit artifacts exist, and waits for pending pods before timing out.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: ok-to-test

Suggested reviewers: richardsonnick, smith-xyz, rhmdnd

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (14 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: cleanup crash protection and improved handling of Failed pods.
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 Diff touches a shell script and CI/YAML config only; no Ginkgo test files or It/Describe/Context/When titles were added or modified.
Test Structure And Quality ✅ Passed PR changes only a shell script; no Ginkgo test code was added or modified, so the test-structure check is not applicable.
Microshift Test Compatibility ✅ Passed Only a shell script changed; no new Ginkgo e2e tests or MicroShift-unsupported APIs/features were added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR only changes a shell script; no new Ginkgo e2e tests or multi-node/SNO-sensitive test logic were added.
Topology-Aware Scheduling Compatibility ✅ Passed Only a shell script changed; no manifests, controllers, or topology-dependent scheduling constraints were added.
Ote Binary Stdout Contract ✅ Passed Only a shell script changed; no OTE binary process-level code or stdout contract violations were introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Only a shell script changed; no Ginkgo e2e tests were added, so IPv4/disconnected-network compatibility is not applicable.
No-Weak-Crypto ✅ Passed Only bash cleanup/status handling changed; patch adds no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret comparisons.
Container-Privileges ✅ Passed No privilege-related manifest changes were introduced; the PR only updated cleanup and pod-status handling.
No-Sensitive-Data-In-Logs ✅ Passed Added logs only report pod phase/exit code/artifact status; no passwords, tokens, PII, or hostnames are exposed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh`:
- Around line 103-110: Update run_tls_scan and cleanup so NAMESPACE and
OWNS_NAMESPACE are copied into durable snapshot variables before registering the
EXIT trap. Have cleanup use those snapshots rather than defaulting the locals
after they go out of scope, while retaining defaults only when initialization
never occurred; preserve deletion of the owned namespace versus the targeted
scanner pod based on the captured ownership state.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 05c76cc4-32ec-4e29-8371-170a1893ac6f

📥 Commits

Reviewing files that changed from the base of the PR and between 47aa395 and 08c765b.

📒 Files selected for processing (1)
  • ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh

Comment thread ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh Outdated
@jzding
jzding force-pushed the fix-tls-scanner-owns-namespace branch from 08c765b to f3e399f Compare July 28, 2026 01:59
@jzding jzding changed the title Fix OWNS_NAMESPACE unbound variable in tls-scanner-run cleanup Fix tls-scanner-run cleanup crash and Failed pod handling Jul 28, 2026
@jzding
jzding force-pushed the fix-tls-scanner-owns-namespace branch from f3e399f to ae7709d Compare July 28, 2026 02:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh`:
- Around line 264-271: Update the Failed pod branch in the scanner command flow
to return a non-zero status after logging and artifact handling. Use the numeric
pod_exit_code when it is available and non-zero; otherwise return 1, ensuring
scanner findings and crashes cannot result in successful completion.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 284641f1-dfc3-4e6f-9830-90826ad7f24f

📥 Commits

Reviewing files that changed from the base of the PR and between 08c765b and f3e399f.

📒 Files selected for processing (1)
  • ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh

@jzding
jzding force-pushed the fix-tls-scanner-owns-namespace branch 2 times, most recently from 2428419 to d70f6cb Compare July 28, 2026 16:10
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

@jzding: pj-rehearse could not automatically process this event because the request waited in queue for longer than 5 minutes. Use /pj-rehearse to trigger rehearsals manually.

1 similar comment
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

@jzding: pj-rehearse could not automatically process this event because the request waited in queue for longer than 5 minutes. Use /pj-rehearse to trigger rehearsals manually.

@jzding
jzding force-pushed the fix-tls-scanner-owns-namespace branch from d70f6cb to 7d1e850 Compare July 28, 2026 16:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh (1)

257-273: ⚠️ Potential issue | 🟠 Major

Propagate the scanner’s non-zero status.

This previous finding remains unresolved: the Failed branch only logs pod_exit_code and then falls through to the success epilogue. TLS findings and scanner crashes can therefore be reported as a successful run_tls_scan. Preserve artifact handling, then return the numeric non-zero code when valid, otherwise 1, while preserving cleanup behavior.

🤖 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 `@ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh` around
lines 257 - 273, Update the Failed branch in run_tls_scan to preserve the
existing artifact handling, then return the numeric pod_exit_code when it is a
valid non-zero value; otherwise return 1. Ensure this return occurs before the
success epilogue while retaining the existing cleanup behavior.
🤖 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 `@ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh`:
- Around line 274-280: Update the pod-wait logic in the tls scanner command flow
to poll until the pod reaches either Succeeded or Failed, rather than waiting
only for Succeeded. After polling, route a Failed phase through the existing
artifact-aware failure handling, while preserving the current success and
timeout behavior.

---

Duplicate comments:
In `@ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh`:
- Around line 257-273: Update the Failed branch in run_tls_scan to preserve the
existing artifact handling, then return the numeric pod_exit_code when it is a
valid non-zero value; otherwise return 1. Ensure this return occurs before the
success epilogue while retaining the existing cleanup behavior.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 807ae90d-6643-4cca-a4fc-48d851e8dc9e

📥 Commits

Reviewing files that changed from the base of the PR and between f3e399f and d70f6cb.

📒 Files selected for processing (1)
  • ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh

Comment thread ci-operator/step-registry/tls/scanner/run/tls-scanner-run-commands.sh Outdated
@jzding
jzding force-pushed the fix-tls-scanner-owns-namespace branch from 7d1e850 to c53a1f5 Compare July 28, 2026 16:17
Four issues in tls-scanner-run-commands.sh:

1. OWNS_NAMESPACE unbound variable: The cleanup trap references
   NAMESPACE and OWNS_NAMESPACE which are local variables inside
   run_tls_scan(). When the trap fires after the function returns,
   locals are out of scope. Fix: snapshot both locals into global
   variables (_CLEANUP_NAMESPACE, _CLEANUP_OWNS_NAMESPACE) before
   registering the trap.

2. Scanner exit code 1 treated as infrastructure failure: When the
   scanner finds TLS compliance issues, it exits with code 1 and
   the pod phase is "Failed". The script called exit 1 immediately,
   wasting the 10-minute oc-wait timeout. Replace with artifact-aware
   check: if JUnit exists, log findings; if not, describe the pod.

3. Failed pod branch did not exit non-zero: After logging, the Failed
   branch fell through silently. Add exit with the pod's exit code.

4. Fallback oc-wait only waited for Succeeded: If the pod reached
   Failed during the wait, it would timeout for 10 minutes. Replace
   oc-wait with a polling loop that terminates on either Succeeded
   or Failed, then route Failed through the same artifact-aware
   handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Jack Ding <jackding@gmail.com>
@jzding
jzding force-pushed the fix-tls-scanner-owns-namespace branch from c53a1f5 to 3603d42 Compare July 28, 2026 16:19
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

@jzding: pj-rehearse could not automatically process this event because the request waited in queue for longer than 5 minutes. Use /pj-rehearse to trigger rehearsals manually.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

[REHEARSALNOTIFIER]
@jzding: the pj-rehearse plugin accommodates running rehearsal tests for the changes in this PR. Expand 'Interacting with pj-rehearse' for usage details. The following rehearsable tests have been affected by this change:

Test name Repo Type Reason
pull-ci-openshift-oadp-operator-oadp-1.6-4.23-tls-pqc-readiness openshift/oadp-operator presubmit Registry content changed
pull-ci-openshift-oadp-operator-oadp-1.6-4.23-tls13-adherence openshift/oadp-operator presubmit Registry content changed
pull-ci-openshift-oadp-operator-oadp-1.6-4.22-tls-pqc-readiness openshift/oadp-operator presubmit Registry content changed
pull-ci-openshift-oadp-operator-oadp-1.6-4.22-tls13-adherence openshift/oadp-operator presubmit Registry content changed
pull-ci-openshift-oadp-operator-oadp-dev-4.22-tls-pqc-readiness openshift/oadp-operator presubmit Registry content changed
pull-ci-openshift-oadp-operator-oadp-dev-4.22-tls13-adherence openshift/oadp-operator presubmit Registry content changed
pull-ci-openshift-windows-machine-config-operator-master-tls-scanner openshift/windows-machine-config-operator presubmit Registry content changed
pull-ci-openshift-windows-machine-config-operator-release-5.1-tls-scanner openshift/windows-machine-config-operator presubmit Registry content changed
pull-ci-openshift-windows-machine-config-operator-release-5.0-tls-scanner openshift/windows-machine-config-operator presubmit Registry content changed
pull-ci-openshift-windows-machine-config-operator-release-4.23-tls-scanner openshift/windows-machine-config-operator presubmit Registry content changed
pull-ci-openshift-vertical-pod-autoscaler-operator-main-e2e-aws-olm openshift/vertical-pod-autoscaler-operator presubmit Registry content changed
pull-ci-openshift-insights-runtime-extractor-main-tls-scanner openshift/insights-runtime-extractor presubmit Registry content changed
pull-ci-openshift-insights-runtime-extractor-release-5.1-tls-scanner openshift/insights-runtime-extractor presubmit Registry content changed
pull-ci-openshift-insights-runtime-extractor-release-5.0-tls-scanner openshift/insights-runtime-extractor presubmit Registry content changed
pull-ci-openshift-insights-runtime-extractor-release-4.23-tls-scanner openshift/insights-runtime-extractor presubmit Registry content changed
pull-ci-openshift-insights-runtime-extractor-release-4.22-tls-scanner openshift/insights-runtime-extractor presubmit Registry content changed
pull-ci-openshift-insights-operator-master-tls-scanner openshift/insights-operator presubmit Registry content changed
pull-ci-openshift-insights-operator-release-5.1-tls-scanner openshift/insights-operator presubmit Registry content changed
pull-ci-openshift-insights-operator-release-5.0-tls-scanner openshift/insights-operator presubmit Registry content changed
pull-ci-openshift-insights-operator-release-4.23-tls-scanner openshift/insights-operator presubmit Registry content changed
pull-ci-openshift-insights-operator-release-4.22-tls-scanner openshift/insights-operator presubmit Registry content changed
pull-ci-openshift-gcp-filestore-csi-driver-operator-main-tls-scanner-gcp-filestore openshift/gcp-filestore-csi-driver-operator presubmit Registry content changed
pull-ci-openshift-gcp-filestore-csi-driver-operator-release-5.1-tls-scanner-gcp-filestore openshift/gcp-filestore-csi-driver-operator presubmit Registry content changed
pull-ci-openshift-gcp-filestore-csi-driver-operator-release-5.0-tls-scanner-gcp-filestore openshift/gcp-filestore-csi-driver-operator presubmit Registry content changed
pull-ci-openshift-gcp-filestore-csi-driver-operator-release-4.23-tls-scanner-gcp-filestore openshift/gcp-filestore-csi-driver-operator presubmit Registry content changed

A total of 75 jobs have been affected by this change. The above listing is non-exhaustive and limited to 25 jobs.

A full list of affected jobs can be found here

Interacting with pj-rehearse

Comment: /pj-rehearse to run up to 5 rehearsals
Comment: /pj-rehearse skip to opt-out of rehearsals
Comment: /pj-rehearse {test-name}, with each test separated by a space, to run one or more specific rehearsals
Comment: /pj-rehearse more to run up to 10 rehearsals
Comment: /pj-rehearse max to run up to 25 rehearsals
Comment: /pj-rehearse auto-ack to run up to 5 rehearsals, and add the rehearsals-ack label on success
Comment: /pj-rehearse list to get an up-to-date list of affected jobs
Comment: /pj-rehearse abort to abort all active rehearsals
Comment: /pj-rehearse network-access-allowed to allow rehearsals of tests that have the restrict_network_access field set to false. This must be executed by an openshift org member who is not the PR author

Once you are satisfied with the results of the rehearsals, comment: /pj-rehearse ack to unblock merge. When the rehearsals-ack label is present on your PR, merge will no longer be blocked by rehearsals.
If you would like the rehearsals-ack label removed, comment: /pj-rehearse reject to re-block merging.

@openshift-ci openshift-ci Bot added the do-not-merge/invalid-owners-file Indicates that a PR should not merge because it has an invalid OWNERS file in it. label Jul 28, 2026
@jzding

jzding commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

/verify-owners

@openshift-ci openshift-ci Bot removed the do-not-merge/invalid-owners-file Indicates that a PR should not merge because it has an invalid OWNERS file in it. label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant