Skip to content

Fix result CR status not updated on retry#41

Open
jameswnl wants to merge 1 commit into
openshift:mainfrom
jameswnl:fix/result-cr-update-on-retry
Open

Fix result CR status not updated on retry#41
jameswnl wants to merge 1 commit into
openshift:mainfrom
jameswnl:fix/result-cr-update-on-retry

Conversation

@jameswnl
Copy link
Copy Markdown

@jameswnl jameswnl commented Jun 3, 2026

Summary

  • When a proposal step was retried and the result CR already existed (same name from resultCRName), createIdempotent silently returned nil on AlreadyExists, leaving stale failure data in the CR
  • This caused AnalysisResult (and other result types) to show failed status/conditions even when the retry succeeded — the proposal would show Analyzed: True (Complete) but the result CR still contained the old failure reason
  • Now on AlreadyExists, the existing CR is fetched and its status is patched with the latest result data (options, actions, checks, conditions, sandbox info, failure reason)

Test plan

  • TestCreateIdempotent_AlreadyExists updated to verify status is updated (not skipped)
  • All existing tests pass: go test ./controller/proposal/... -count=1
  • End-to-end verified: proposal failed on first attempt (local operator, DNS unreachable), succeeded on retry (in-cluster operator) — result CR now reflects success

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Existing result records now update their status with the latest remediation options and properly overwrite stale failure states, clearing failure reasons when a success is applied.
  • Tests
    • Updated test to expect the revised remediation option behavior; added a new test validating overwrite of stale failure state and clearing of failure details.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7ddd1786-1d43-44a5-b2c3-5d478e0b01f3

📥 Commits

Reviewing files that changed from the base of the PR and between d4d2a37 and 6543a47.

📒 Files selected for processing (2)
  • controller/proposal/results.go
  • controller/proposal/results_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • controller/proposal/results.go
  • controller/proposal/results_test.go

📝 Walkthrough

Walkthrough

createIdempotent now, on AlreadyExists, fetches the existing Result CR, merges new .status.conditions and result-type-specific status via copyResultStatus, and applies a status patch so the stored CR reflects the newly-built status.

Changes

Status Update on Existing Result CRs

Layer / File(s) Summary
Status copy implementation
controller/proposal/results.go
copyResultStatus helper switches on concrete Result CR types to copy result-specific status fields (options, actions, verification, checks, summary, content, failure reason, sandbox). createIdempotent is refactored to load existing CRs, copy conditions from the new object, copy result-specific status via the helper, and apply a status patch instead of returning early.
Test coverage for status updates
controller/proposal/results_test.go
TestCreateIdempotent_AlreadyExists fixture and assertions are updated to expect status to be overwritten with updated remediation options. A new TestCreateIdempotent_AlreadyExists_OverwritesStaleFailure test validates that stale failure conditions and FailureReason fields are cleared and replaced with succeeded state when createIdempotent runs on an existing CR.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix result CR status not updated on retry' directly and accurately summarizes the main change: the operator now updates result CR status when a resource already exists during retry, whereas previously it did not.
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.

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

✨ 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 and usage tips.

@openshift-ci openshift-ci Bot requested review from blublinsky and harche June 3, 2026 03:35
@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 3, 2026
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 3, 2026

Hi @jameswnl. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@jameswnl jameswnl marked this pull request as draft June 3, 2026 03:42
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 3, 2026
@jameswnl jameswnl force-pushed the fix/result-cr-update-on-retry branch 2 times, most recently from 0ce6363 to d4d2a37 Compare June 3, 2026 04:00
@jameswnl jameswnl marked this pull request as ready for review June 3, 2026 13:32
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 3, 2026
@openshift-ci openshift-ci Bot requested review from onmete and xrajesh June 3, 2026 13:33
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
controller/proposal/results_test.go (1)

117-177: ⚡ Quick win

Add retry-overwrite coverage for the other result kinds.

copyResultStatus now manually maps four concrete status types, but the new regression coverage only exercises AnalysisResult. A table-driven AlreadyExists suite for ExecutionResult, VerificationResult, and EscalationResult—including sandbox replacement—would catch the same stale-status regression if any non-analysis branch drifts.

🤖 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 `@controller/proposal/results_test.go` around lines 117 - 177, The test covers
only AnalysisResult and misses regressions in the other concrete status branches
of copyResultStatus; add a table-driven variant of
TestCreateIdempotent_AlreadyExists_OverwritesStaleFailure that iterates over the
other kinds ("ExecutionResult", "VerificationResult", "EscalationResult" and
sandbox replacement cases), constructing appropriate existing and new CR objects
for each kind, calling createIdempotent with the fake client, and asserting that
stale FailureReason, Conditions and Options are correctly overwritten for each
type; reference copyResultStatus and createIdempotent to ensure each branch is
exercised and reuse the existing test's verification logic (Get + check
Status.Options, FailureReason, Conditions) inside the loop.
controller/proposal/results.go (1)

306-317: ⚡ Quick win

Use the repo error-constant pattern for the new status-update errors.

These new fmt.Errorf calls hardcode the message strings inline. Please lift them into Err... constants and wrap from those constants so the new paths match the repository’s Go error convention. As per coding guidelines, **/*.go: Define errors as constants using const ErrFoo = "…" and wrap them with fmt.Errorf("%s: %w", …) for context`.

🤖 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 `@controller/proposal/results.go` around lines 306 - 317, The inline fmt.Errorf
messages in the status-update path should follow the repo pattern: add
package-level const error strings (e.g., const ErrGetExistingStatus = "get
existing status" and const ErrUpdateExistingStatus = "update existing status")
and replace the two fmt.Errorf calls that wrap getErr and patchErr with
fmt.Errorf("%s: %w", ErrGetExistingStatus, getErr) and fmt.Errorf("%s: %w",
ErrUpdateExistingStatus, patchErr) respectively; keep the existing context
(kind, obj.GetName()) in the surrounding message if desired, but ensure the new
constants are used as the wrapped base per the repository convention (affecting
the calls around c.Get(...), existing, patched, and c.Status().Patch(...)).
🤖 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.

Nitpick comments:
In `@controller/proposal/results_test.go`:
- Around line 117-177: The test covers only AnalysisResult and misses
regressions in the other concrete status branches of copyResultStatus; add a
table-driven variant of
TestCreateIdempotent_AlreadyExists_OverwritesStaleFailure that iterates over the
other kinds ("ExecutionResult", "VerificationResult", "EscalationResult" and
sandbox replacement cases), constructing appropriate existing and new CR objects
for each kind, calling createIdempotent with the fake client, and asserting that
stale FailureReason, Conditions and Options are correctly overwritten for each
type; reference copyResultStatus and createIdempotent to ensure each branch is
exercised and reuse the existing test's verification logic (Get + check
Status.Options, FailureReason, Conditions) inside the loop.

In `@controller/proposal/results.go`:
- Around line 306-317: The inline fmt.Errorf messages in the status-update path
should follow the repo pattern: add package-level const error strings (e.g.,
const ErrGetExistingStatus = "get existing status" and const
ErrUpdateExistingStatus = "update existing status") and replace the two
fmt.Errorf calls that wrap getErr and patchErr with fmt.Errorf("%s: %w",
ErrGetExistingStatus, getErr) and fmt.Errorf("%s: %w", ErrUpdateExistingStatus,
patchErr) respectively; keep the existing context (kind, obj.GetName()) in the
surrounding message if desired, but ensure the new constants are used as the
wrapped base per the repository convention (affecting the calls around
c.Get(...), existing, patched, and c.Status().Patch(...)).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: febb71c4-c5a0-41d3-82c3-3a1d50df3288

📥 Commits

Reviewing files that changed from the base of the PR and between 8ac45f7 and d4d2a37.

📒 Files selected for processing (2)
  • controller/proposal/results.go
  • controller/proposal/results_test.go

When a proposal step is retried and the result CR name collides with an
existing one, createIdempotent previously returned nil on AlreadyExists,
leaving stale failure data in the CR. This caused the AnalysisResult to
show a failed status even when the retry succeeded.

Now on AlreadyExists, the existing CR is fetched and its status is
patched with the new result data (options, actions, checks, conditions,
sandbox info, failure reason) while preserving the original metadata
and spec.

- Use comma-ok type assertions in copyResultStatus for safety
- Add test for the core retry scenario: stale failure data overwritten
  with success data, verifying FailureReason is cleared

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jameswnl jameswnl force-pushed the fix/result-cr-update-on-retry branch from d4d2a37 to 6543a47 Compare June 3, 2026 18:53
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants