Skip to content

Conversation

@metlos
Copy link
Contributor

@metlos metlos commented Nov 11, 2025

This makes the toolchainclusterresources controller use the SSA client instead of the obsolete apply client.

Summary by CodeRabbit

  • Refactor
    • Improved resource application mechanism with enhanced label management and field-level consistency enforcement during reconciliation cycles.
    • Streamlined internal resource management pipeline for more reliable toolchain cluster resource handling.

@coderabbitai
Copy link

coderabbitai bot commented Nov 11, 2025

Walkthrough

A new generic ApplyAll function is introduced for applying slices of client objects. The SSAApplyClient.Apply method delegates to this generic function. The Reconciler struct gains a FieldManager configuration field, and the controller's reconciliation flow switches to using the new generic apply mechanism with explicit label handling.

Changes

Cohort / File(s) Summary
Controller Configuration & Reconciliation
controllers/toolchainclusterresources/toolchaincluster_resources_controller.go
Added public FieldManager field to Reconciler struct. Updated reconciliation logic to create SSA apply client using the field manager and switched from ApplyUnstructuredObjectsWithNewLabels to ApplyAll with EnsureLabels(newLabels). Added minor formatting.
Controller Tests
controllers/toolchainclusterresources/toolchaincluster_resources_controller_test.go
Updated test setup to initialize Reconciler.FieldManager to "testOwner".
SSA Client Core
pkg/client/ssa_client.go
Introduced new generic function ApplyAll[T client.Object] for iterating and applying object slices. Refactored SSAApplyClient.Apply to delegate to the new generic function.

Sequence Diagram(s)

sequenceDiagram
    participant Ctrl as Controller
    participant SSA as SSAApplyClient
    participant ApplyAll as ApplyAll Generic
    
    rect rgb(230, 245, 230)
    Note over Ctrl,ApplyAll: Old Flow
    Ctrl->>SSA: ApplyUnstructuredObjectsWithNewLabels(objs, labels)
    SSA-->>Ctrl: error
    end
    
    rect rgb(245, 230, 230)
    Note over Ctrl,ApplyAll: New Flow
    Ctrl->>SSA: ApplyAll(ctx, objects)<br/>via EnsureLabels(labels)
    SSA->>ApplyAll: ApplyAll[T](ctx, cl, objects)
    loop for each object
        ApplyAll->>SSA: ApplyObject(ctx, obj)
        SSA-->>ApplyAll: error?
    end
    ApplyAll-->>SSA: error (first or none)
    SSA-->>Ctrl: error
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Generic function logic: Verify that the ApplyAll[T] function correctly implements the iteration pattern and error handling for any client.Object type.
  • Delegation correctness: Ensure SSAApplyClient.Apply properly delegates to ApplyAll without behavioral changes.
  • Label handling transition: Review the shift from ApplyUnstructuredObjectsWithNewLabels to ApplyAll with EnsureLabels to confirm equivalent label enforcement.
  • FieldManager configuration: Verify the new FieldManager field is properly initialized and used in SSA client creation.

Poem

🐰 A generic hop through apply and slice,
Where objects dance in loops precise,
Field managers guide the way,
Refactored code saves the day!

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: migrating from the old apply client to the SSA client in the toolchainclusterresources controller, which is confirmed by the file changes and PR objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.86%. Comparing base (e8b11c5) to head (c11a719).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #499      +/-   ##
==========================================
+ Coverage   78.84%   78.86%   +0.02%     
==========================================
  Files          53       53              
  Lines        2207     2210       +3     
==========================================
+ Hits         1740     1743       +3     
  Misses        404      404              
  Partials       63       63              
Files with missing lines Coverage Δ
...resources/toolchaincluster_resources_controller.go 40.90% <100.00%> (+2.81%) ⬆️
pkg/client/ssa_client.go 88.17% <100.00%> (+0.25%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0ce87f and 51518cd.

📒 Files selected for processing (3)
  • controllers/toolchainclusterresources/toolchaincluster_resources_controller.go (3 hunks)
  • controllers/toolchainclusterresources/toolchaincluster_resources_controller_test.go (1 hunks)
  • pkg/client/ssa_client.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
controllers/toolchainclusterresources/toolchaincluster_resources_controller.go (1)
pkg/client/ssa_client.go (3)
  • NewSSAApplyClient (64-70)
  • ApplyAll (245-252)
  • EnsureLabels (116-120)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Verify Dependencies
🔇 Additional comments (2)
controllers/toolchainclusterresources/toolchaincluster_resources_controller_test.go (1)

113-114: Test field manager wired correctly

Thanks for plumbing the test owner string through prepareReconcile; this keeps the SSA client behavior exercised end-to-end.

pkg/client/ssa_client.go (1)

241-252: ApplyAll refactor keeps semantics intact

Nice extraction—ApplyAll centralizes the iteration logic without changing how ApplyObject is invoked.

Copy link
Contributor

@rsoaresd rsoaresd left a comment

Choose a reason for hiding this comment

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

🚀

@MatousJobanek
Copy link
Contributor

@sonarqubecloud
Copy link

@metlos metlos merged commit 6ed5aee into codeready-toolchain:master Nov 25, 2025
12 checks passed
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.

5 participants