Add operator controller DI consistency review rules - #21
Conversation
Add a custom check and two path instruction sets that guide reviewers toward consistent dependency injection patterns in OpenShift operator controller constructors and starter.go files. The rules encode a seven-point consistency standard derived from surveying 11 operator repos (~80 controller constructors): 1. Typed informers over SharedInformerFactory 2. Narrowest client sub-interface 3. Standard Run(ctx, workers) lifecycle contract 4. Consistent parameter ordering 5. Resolved-at-construction feature gate handling (default) 6. Internal lister extraction 7. Five-phase starter.go structure All rules are warning-mode. They fire only on files matching operator patterns (pkg/operator/**/starter.go, pkg/**/controller*.go) and self-scope via instructions to skip non-operator repos.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sanchezl The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a warning-mode review check and path-scoped instructions enforcing dependency injection and startup structure conventions for operator starters and controllers. ChangesOperator DI consistency
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 16✅ Passed checks (16 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 @.coderabbit.yaml:
- Around line 521-525: Update the starter informer rule in the configuration to
explicitly allow v1helpers.KubeInformersForNamespaces, matching the exception
already permitted by the global and controller-specific rules. Apply the same
wording consistently to the corresponding duplicated rules identified in the
diff, while continuing to reject other informer factories, raw informers, and
bare listers.
- Around line 511-518: Update both path-scoped instruction blocks for “Operator
Controller DI Consistency” to require that the repository is an OpenShift
operator repository before applying the check. Preserve the existing
startup-wiring and controller-constructor path conditions, and ensure the same
repository guard is added to the additional matching block.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 98816303-6207-48aa-bb69-dbce36882403
📒 Files selected for processing (1)
.coderabbit.yaml
| - name: "Operator Controller DI Consistency" | ||
| mode: warning | ||
| instructions: | | ||
| This check applies only when a PR touches operator startup wiring | ||
| (starter.go, RunOperator) or controller constructors (New*Controller | ||
| functions) in OpenShift operator repositories. Skip this check if | ||
| the PR does not modify these files. | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Apply the non-operator repository guard to both path instructions.
The custom check is explicitly scoped to OpenShift operator repositories, but neither path-scoped block repeats that condition. Matching paths in an unrelated repository can therefore trigger these operator rules, violating the stated PR scope.
Proposed fix
- path: "**/pkg/operator/**/starter.go"
instructions: |
+ Apply only in OpenShift operator repositories. If this is not an
+ OpenShift operator repository, ignore the remainder of these instructions.
Operator starter file. Review for the five-phase structure:
...
- path: "**/pkg/**/controller*.go"
instructions: |
+ Apply only in OpenShift operator repositories. If this is not an
+ OpenShift operator repository, ignore the remainder of these instructions.
If this file contains a controller constructor (New*ControllerAlso applies to: 586-588, 620-623
🤖 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 @.coderabbit.yaml around lines 511 - 518, Update both path-scoped instruction
blocks for “Operator Controller DI Consistency” to require that the repository
is an OpenShift operator repository before applying the check. Preserve the
existing startup-wiring and controller-constructor path conditions, and ensure
the same repository guard is added to the additional matching block.
The custom check rule already allowed KubeInformersForNamespaces as an exception to the "no factory objects" rule, but the starter.go and controller path instructions did not mention it. Add the exception to both path instruction sets for consistency.
Summary
**/pkg/operator/**/starter.go(five-phase structure) and**/pkg/**/controller*.go(constructor signature conventions)Background
Surveyed 11 OpenShift operator repos (~80 controller constructors) and found wildly inconsistent dependency injection patterns: controllers in the same operator take SharedInformerFactory vs typed informers vs bare listers vs raw cache.SharedIndexInformer, return factory.Controller vs custom structs with non-standard Run signatures, receive FeatureGateAccess vs FeatureGate vs bools vs map[string]bool.
These rules encode a consistency standard to guide reviewers. All rules are warning mode (not blocking). They self-scope to operator-pattern files and skip non-operator repos.
The Seven Rules
Run(ctx, workers)signatureTest Plan
Summary by CodeRabbit
Run(ctx, workers int)signature conformance, and constructor parameter ordering.