Skip to content

Conversation

dmartinol
Copy link
Collaborator

Fixes #2004

  • Split the monolithic Collector interface with SyncStatusCollector and APIStatusCollector to pass only the needed one to the processing methods
  • Use an Error type to transport condition and phase information to the root, instead of a generic error
  • This way, the low-level methods do not need the collectors because they raise the error that carries the desired information

This change is needed to solve #1749 for error paths: some more changes may needed to fix the e2e tests.

@dmartinol dmartinol requested a review from jhrozek September 25, 2025 16:58
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 28.32765% with 210 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.31%. Comparing base (aa8813f) to head (9c62c59).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...ator/pkg/mcpregistrystatus/mocks/mock_collector.go 0.00% 77 Missing ⚠️
...thv-operator/controllers/mcpregistry_controller.go 0.00% 65 Missing ⚠️
cmd/thv-operator/pkg/sync/manager.go 33.33% 45 Missing and 1 partial ⚠️
cmd/thv-operator/pkg/registryapi/manager.go 0.00% 17 Missing ⚠️
...thv-operator/pkg/registryapi/mocks/mock_manager.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2016      +/-   ##
==========================================
+ Coverage   48.12%   48.31%   +0.19%     
==========================================
  Files         233      238       +5     
  Lines       29229    29952     +723     
==========================================
+ Hits        14066    14472     +406     
- Misses      14131    14380     +249     
- Partials     1032     1100      +68     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dmartinol dmartinol mentioned this pull request Sep 26, 2025
jhrozek
jhrozek previously approved these changes Sep 28, 2025
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

In general I think this is a very nice refactor, one question about concurrent access inline

- Removed the `Idle` phase from `SyncPhase` and updated related logic to ensure only `Syncing`, `Complete`, and `Failed` phases are used.
- Enhanced the `ShouldSync` method to avoid syncing when the requeue timeout did not elapse.
- Avoid updating sync status at all if sync is not needed (it would cause a new reconciliation)

Signed-off-by: Daniele Martinoli <[email protected]>
@dmartinol
Copy link
Collaborator Author

@jhrozek @yrobla I reviewed the initial implementation again to:

  • remove the Idle sync state (what does it mean? 🤔 ), replaced with Completed
  • avoid syncing if there is any sync state requiring change (e.g. Failed) but before the scheduled requeue time (5m)
  • avoid updating the sync state at all if sync is not needed

The above changes prevent continuous reconciliation loops in case of failures, properly store incremental attempt counter in the sync status and respect the scheduled retries.

Hopefully, the E2E tests will confirm that everything is fine

jhrozek
jhrozek previously approved these changes Sep 30, 2025
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

awesome work @dmartinol

@JAORMX JAORMX requested a review from Copilot October 2, 2025 12:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the status collector architecture by splitting the monolithic Collector interface into domain-specific components and introducing structured error handling to improve separation of concerns and error propagation.

Key changes:

  • Replaced monolithic Collector interface with SyncStatusCollector, APIStatusCollector, and StatusManager interfaces
  • Introduced structured Error type to transport condition and phase information from low-level methods to the controller
  • Removed the Idle sync phase from the API and CRDs as it's no longer needed

Reviewed Changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/thv-operator/controllers/mcpregistry_controller.go Updated to use new status manager interfaces and handle structured errors from sync operations
cmd/thv-operator/pkg/mcpregistrystatus/types.go Refactored collector interfaces and added structured Error type
cmd/thv-operator/pkg/mcpregistrystatus/collector.go Implemented new interface structure with domain-specific collectors
cmd/thv-operator/pkg/sync/manager.go Refactored to return structured errors instead of using status collectors directly
cmd/thv-operator/pkg/registryapi/manager.go Updated to return structured errors instead of accepting status collectors
cmd/thv-operator/api/v1alpha1/mcpregistry_types.go Removed Idle sync phase from API definitions
deploy/charts/operator-crds/crds/toolhive.stacklok.dev_mcpregistries.yaml Updated CRD to remove Idle sync phase
Comments suppressed due to low confidence (1)

cmd/thv-operator/pkg/sync/manager.go:1

  • The variable name DefaultControllerRetryAfter is defined in the controller package but used here in the sync package. This creates a naming inconsistency and potential confusion. Consider using a package-local variable like DefaultSyncRequeueAfter which is already defined in this file.
package sync

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dmartinol dmartinol merged commit 43b1efb into stacklok:main Oct 3, 2025
32 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.

[Kubernetes MCPRegistry] Review the design of Collector interface
3 participants