Skip to content

controller/workload: Clean up status reporting helpers and test infrastructure#2197

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:masterfrom
tchap:workload-controller-cleanup
May 6, 2026
Merged

controller/workload: Clean up status reporting helpers and test infrastructure#2197
openshift-merge-bot[bot] merged 1 commit into
openshift:masterfrom
tchap:workload-controller-cleanup

Conversation

@tchap
Copy link
Copy Markdown
Contributor

@tchap tchap commented May 5, 2026

This is being split from #2128

  • Replace inline error message loops with errors.Join
  • Use ptr.Deref for replicas
  • Fix areCondidtionsEqual typo
  • Remove unnecessary Template/Labels from test fixtures.

Summary by CodeRabbit

  • Refactor

    • Improved error aggregation and default replica handling in the workload controller, yielding clearer operator status messages and more reliable default scaling behavior.
  • Tests

    • Strengthened tests and simplified fixtures, fixing expectations and adding status comparison helpers to validate status updates more reliably.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 811d5ddb-17f0-4396-876f-55ee9242cda1

📥 Commits

Reviewing files that changed from the base of the PR and between aed55e5 and 1f03ec2.

📒 Files selected for processing (2)
  • pkg/operator/apiserver/controller/workload/workload.go
  • pkg/operator/apiserver/controller/workload/workload_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/operator/apiserver/controller/workload/workload_test.go

Walkthrough

Consolidates error-message construction in the workload controller via a new helper, uses k8s.io/utils/ptr to default replica counts, and updates tests (helper rename, fixture simplifications, and an expectation tweak) to match the refactored messages and behavior.

Changes

Workload status/error and replica handling

Layer / File(s) Summary
Imports
pkg/operator/apiserver/controller/workload/workload.go
Adds k8s.io/utils/ptr import.
Desired Replica Computation
pkg/operator/apiserver/controller/workload/workload.go
Replaces manual nil-checking with desiredReplicas := ptr.Deref(workload.Spec.Replicas, 1).
Core Status Logic
pkg/operator/apiserver/controller/workload/workload.go
updateOperatorStatus now aggregates precondition and sync errors using errors.Join(...).Error() instead of manual loops and falls back to a default message when no errors exist.
Error Formatting Helper
pkg/operator/apiserver/controller/workload/workload.go
Adds errMessage(errs []error) string (uses strings.Builder to join error strings with newline separators and returns a default if empty).
Tests / Fixtures
pkg/operator/apiserver/controller/workload/workload_test.go
Renames areCondidtionsEqualareConditionsEqual; removes several foo: bar pod-template labels and corresponding selectors to simplify fixtures; updates a "nasty error" expectation to remove a trailing newline; adds in-file areConditionsEqual helper that ignores LastTransitionTime.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 11 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main changes: refactoring status reporting helpers (replacing inline error loops with errors.Join) and cleaning up test infrastructure (fixing typos, simplifying fixtures).
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 The PR uses table-driven tests with static scenario names. All 12 test names are deterministic strings with no dynamic content, generated identifiers, timestamps, or values that change between runs.
Test Structure And Quality ✅ Passed The test file uses standard Go testing (TestUpdateOperatorStatus with *testing.T), not Ginkgo. Custom check targets "Ginkgo test code" exclusively, so it's not applicable to this PR.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests were added. Changes are to production code and standard Go unit tests only. MicroShift compatibility check not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR modifies unit tests (standard Go testing package, not Ginkgo). No new e2e tests added. SNO check applies only to new Ginkgo e2e tests.
Topology-Aware Scheduling Compatibility ✅ Passed No scheduling constraints added. Code cleanup only: error handling refactoring, replica default for status, test fixes.
Ote Binary Stdout Contract ✅ Passed This PR modifies a library controller package without process-level code. No stdout writes detected. Pure refactoring of error handling and test infrastructure with no impact on OTE binary output.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR does not add Ginkgo e2e tests. It modifies standard Go unit tests and production code. The custom check applies only to Ginkgo e2e tests, which are not present. Not applicable.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@openshift-ci openshift-ci Bot requested review from deads2k and p0lyn0mial May 5, 2026 09:31
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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/operator/apiserver/controller/workload/workload_test.go (1)

56-70: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Version-recorder checks are wired but effectively never exercised.

validateVersionRecorder is optional, and in the current scenario table it stays nil, so recorder assertions are skipped. Also, without at least one scenario setting operatorConfigAtHighestRevision: true, the SetVersion path remains untested.

Suggested patch
-			if scenario.validateVersionRecorder != nil {
-				if err := scenario.validateVersionRecorder(recorder); err != nil {
-					t.Fatal(err)
-				}
-			}
+			validateVersionRecorder := scenario.validateVersionRecorder
+			if validateVersionRecorder == nil {
+				validateVersionRecorder = expectVersionNotRecorded
+			}
+			if err := validateVersionRecorder(recorder); err != nil {
+				t.Fatal(err)
+			}

And add at least one positive case, e.g. in a fully healthy rollout scenario:

+			operatorConfigAtHighestRevision: true,
+			validateVersionRecorder:         expectVersionRecorded,

Also applies to: 732-736

🤖 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 `@pkg/operator/apiserver/controller/workload/workload_test.go` around lines 56
- 70, Add a test case in TestUpdateOperatorStatus that exercises the SetVersion
path by setting operatorConfigAtHighestRevision: true and providing a non-nil
validateVersionRecorder to assert the fakeVersionRecorder observed SetVersion
calls; locate the scenario table in TestUpdateOperatorStatus and add a fully
healthy rollout scenario (healthy workload, pods, no errors) that sets
operatorConfigAtHighestRevision = true and implements validateVersionRecorder to
check the fakeVersionRecorder state (e.g., version/name/count) so the recorder
wiring is actually verified.
🤖 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 `@pkg/operator/apiserver/controller/workload/workload.go`:
- Around line 380-387: The helper function errMessage should guard against nil
entries in the errs slice to avoid panics: inside errMessage, before calling
err.Error() (iterate over errs in the existing loop), check if err == nil and
either skip that element or append a placeholder like "<nil>" instead of calling
Error(); keep the existing newline logic and strings.Builder usage so behavior
and formatting remain unchanged.

---

Outside diff comments:
In `@pkg/operator/apiserver/controller/workload/workload_test.go`:
- Around line 56-70: Add a test case in TestUpdateOperatorStatus that exercises
the SetVersion path by setting operatorConfigAtHighestRevision: true and
providing a non-nil validateVersionRecorder to assert the fakeVersionRecorder
observed SetVersion calls; locate the scenario table in TestUpdateOperatorStatus
and add a fully healthy rollout scenario (healthy workload, pods, no errors)
that sets operatorConfigAtHighestRevision = true and implements
validateVersionRecorder to check the fakeVersionRecorder state (e.g.,
version/name/count) so the recorder wiring is actually verified.
🪄 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: 50c0f1a1-5711-46e2-837a-0d39d5d1bc5f

📥 Commits

Reviewing files that changed from the base of the PR and between eae3c72 and fb38675.

📒 Files selected for processing (2)
  • pkg/operator/apiserver/controller/workload/workload.go
  • pkg/operator/apiserver/controller/workload/workload_test.go

Comment thread pkg/operator/apiserver/controller/workload/workload.go Outdated
Comment thread pkg/operator/apiserver/controller/workload/workload_test.go Outdated
Comment thread pkg/operator/apiserver/controller/workload/workload_test.go Outdated
Comment thread pkg/operator/apiserver/controller/workload/workload.go Outdated
Comment thread pkg/operator/apiserver/controller/workload/workload_test.go Outdated
@tchap tchap force-pushed the workload-controller-cleanup branch 2 times, most recently from bb83bb4 to 5b539f5 Compare May 6, 2026 08:16
Comment thread pkg/operator/apiserver/controller/workload/workload_test.go Outdated
Comment thread pkg/operator/apiserver/controller/workload/workload.go Outdated
@tchap tchap force-pushed the workload-controller-cleanup branch from 5b539f5 to fcdbbf6 Compare May 6, 2026 08:24
Comment thread pkg/operator/apiserver/controller/workload/workload_test.go Outdated
@tchap tchap force-pushed the workload-controller-cleanup branch from fcdbbf6 to aed55e5 Compare May 6, 2026 08:30
Replace inline error message loops with errors.Join, use ptr.Deref for
replicas, fix areCondidtionsEqual typo. Remove unnecessary
Template/Labels from test fixtures.
@tchap tchap force-pushed the workload-controller-cleanup branch from aed55e5 to 1f03ec2 Compare May 6, 2026 08:43
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

@tchap: all tests passed!

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.

@p0lyn0mial
Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label May 6, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: p0lyn0mial, tchap

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 6, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit b7e366d into openshift:master May 6, 2026
5 checks passed
@tchap tchap deleted the workload-controller-cleanup branch May 6, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants