Skip to content

Conversation

@asergunov
Copy link
Contributor

@asergunov asergunov commented Nov 27, 2025

Add RVR Status Config Peers Controller

Implements #335

Summary

This PR introduces a new controller rvr_status_config_peers_controller that automatically manages peer configuration in ReplicatedVolumeReplica status. The controller ensures that each replica has up-to-date information about all other replicas (peers) in the same ReplicatedVolume, excluding itself.

Changes

New Controller Implementation

  • Controller: rvr_status_config_peers_controller
    • Watches ReplicatedVolume resources
    • Watches ReplicatedVolumeReplica resources (via owner reference)
    • Updates status.config.peers field in each ReplicatedVolumeReplica

Key Features

  1. Peer Discovery: Automatically discovers all replicas belonging to a ReplicatedVolume by:

    • Filtering replicas controlled by the ReplicatedVolume
    • Validating that replicas have required fields (NodeName, Status.Config.NodeId, Status.Config.Address)
    • Building a peer map keyed by node name
  2. Peer Management:

    • Each replica's status.config.peers contains all other replicas (excluding itself)
    • Handles edge cases:
      • Single replica scenarios (no peers)
      • Multiple replicas on the same node (only first one is kept as peer)
      • Replica deletion (automatically removes deleted replicas from peers)
    • Includes Diskless flag in peer information
  3. Optimization:

    • Only patches replicas when peer configuration actually changes
    • Uses status subresource patching for efficient updates

Testing

Comprehensive test suite using Ginkgo/Gomega covering:

  • Basic peer configuration scenarios
  • Edge cases (single replica, missing fields, invalid owner references)
  • Error handling (Get, List, Patch failures)
  • Multiple replicas scenarios
  • Replica deletion
  • Diskless replica handling
  • Idempotency (no unnecessary updates)

Dependencies

  • Updated github.com/onsi/ginkgo/v2 to v2.27.2
  • Updated github.com/onsi/gomega to v1.38.2
  • Updated various golang.org/x packages

Files Changed

  • images/controller/internal/controllers/rvr_status_config_peers/controller.go - Controller setup
  • images/controller/internal/controllers/rvr_status_config_peers/reconciler.go - Reconciliation logic
  • images/controller/internal/controllers/rvr_status_config_peers/reconciler_test.go - Test suite
  • images/controller/internal/controllers/rvr_status_config_peers/rvr_status_config_peers_suite_test.go - Test suite setup
  • images/controller/internal/controllers/registry.go - Controller registration
  • images/controller/go.mod - Dependency updates
  • images/controller/go.sum - Dependency checksums

How It Works

  1. When a ReplicatedVolume or its ReplicatedVolumeReplica changes, the controller is triggered
  2. The controller:
    • Fetches the ReplicatedVolume
    • Lists all ReplicatedVolumeReplica resources
    • Filters to only include replicas controlled by the ReplicatedVolume with required status fields
    • Builds a peer map from the filtered replicas
    • For each replica, updates its status.config.peers with all other replicas (excluding itself)
    • Only patches replicas when the peer configuration has changed

Benefits

  • Automatic Peer Discovery: Replicas automatically know about each other without manual configuration
  • Consistency: Ensures all replicas have consistent peer information
  • Resilience: Automatically handles replica additions and deletions
  • Efficiency: Only updates when necessary, reducing unnecessary API calls

Add readiness check and implement RVR status config peers controller

- Introduced `IsReady` method in `ReplicatedVolumeReplica` to determine readiness based on node name and status configuration.
- Added a new controller for managing the status of replicated volume replicas, including a handler and reconciler for processing replica readiness and peer management.

Signed-off-by: Anton Sergunov <[email protected]>
- Removed the `IsReady` method from `ReplicatedVolumeReplica` as it is no longer needed.
- Updated the controller to use a more concise naming convention for the controller and reconciler.
- Eliminated the `Handler` struct and its associated logic, streamlining the reconciliation process.
- Enhanced the peer management logic to filter out unrelated replicas and ensure only relevant peers are considered.
- Improved logging for better traceability during reconciliation.

Signed-off-by: Anton Sergunov <[email protected]>
- Updated the reconciliation process to skip adding peers that already exist on the same node, improving efficiency and preventing duplicate entries.
- Adjusted logging to indicate when a peer on the node is already found and skipped.

Signed-off-by: Anton Sergunov <[email protected]>
- Introduced the `rvr_status_config_peers` controller to manage the status of replicated volume replicas.
- Implemented a reconciler for handling the reconciliation logic.
- Added unit tests for the reconciler to ensure correct behavior.
- Updated the main registry to include the new controller.

Signed-off-by: Anton Sergunov <[email protected]>
- Expanded unit tests for the RVR status config peers controller, adding comprehensive checks for peer management and reconciliation scenarios.
- Introduced new Gomega matchers to validate the presence and correctness of peers in the RVR status.
- Updated the reconciler to ensure proper handling of peer updates, including filtering out duplicates and managing readiness states effectively.

Signed-off-by: Anton Sergunov <[email protected]>
…iency

- Removed redundant helper functions and streamlined test cases for better readability.
- Introduced a new `makeReady` function to simplify the setup of RVR readiness in tests.
- Enhanced test assertions to ensure accurate validation of peer management and reconciliation outcomes.

Signed-off-by: Anton Sergunov <[email protected]>
- Renamed the `whenResourcesCreated` function to `whenCreated` for clarity and improved parameter order.
- Updated test cases to utilize the new helper function, enhancing readability and consistency.
- Added support for multiple `ReplicatedVolume` instances in tests to better simulate real-world scenarios.

Signed-off-by: Anton Sergunov <[email protected]>
- Removed redundant helper functions and streamlined test cases for improved clarity and efficiency.
- Introduced a new `makeReady` function to simplify the setup of RVR readiness in tests.
- Enhanced test assertions to ensure accurate validation of peer management and reconciliation outcomes.
- Updated the reconciler to improve logging and ensure proper handling of peer updates.

Signed-off-by: Anton Sergunov <[email protected]>
…rity

- Removed the `newScheme` helper function and directly initialized the scheme in the test setup for better readability.
- Simplified test cases by consolidating assertions and enhancing the context descriptions for clarity.
- Ensured consistent use of the `expectReconcileSuccessfully` function to streamline reconciliation checks.

Signed-off-by: Anton Sergunov <[email protected]>
- Added Apache License 2.0 copyright notice to the top of the following files: controller.go, reconciler.go, reconciler_test.go, and rvr_status_config_peers_suite_test.go.
- Ensured compliance with licensing requirements for the project.

Signed-off-by: Anton Sergunov <[email protected]>
- Changed the client type in tests from `client.Client` to `client.WithWatch` to support watch functionality.
- Added interceptor functions to the client builder for enhanced testing capabilities.
- Improved test setup by integrating the new client configuration.

Signed-off-by: Anton Sergunov <[email protected]>
- Added test cases to handle non-NotFound errors during Get, List, and Patch operations for ReplicatedVolume and ReplicatedVolumeReplica.
- Introduced interceptor functions to simulate error conditions, improving the robustness of the tests.
- Ensured that the reconciler behaves correctly when encountering various error scenarios, enhancing overall test coverage.

Signed-off-by: Anton Sergunov <[email protected]>
…onsistency

- Simplified the `makeReady` function by removing the `nodeName` parameter, enhancing clarity in test setup.
- Updated test cases to reflect the new function signature, ensuring consistent usage across tests.
- Improved matcher assertions for checking RVR status and peers, streamlining the validation process.

Signed-off-by: Anton Sergunov <[email protected]>
- Updated the HaveAllPeersSet matcher to return HaveNoPeers when the expectedResources slice contains fewer than two RVRs, ensuring correct behavior in edge cases.
- Improved documentation for the matcher to clarify its functionality regarding peer checks.

Signed-off-by: Anton Sergunov <[email protected]>
…tus config peers tests

- Eliminated the Status field containing DRBDConfig from multiple instances of ReplicatedVolumeReplica in the reconciler test file, streamlining the test setup.
- This change enhances clarity and focuses on the essential aspects of the tests without unnecessary complexity.

Signed-off-by: Anton Sergunov <[email protected]>
@asergunov asergunov marked this pull request as ready for review November 28, 2025 20:04
@asergunov asergunov requested a review from astef November 28, 2025 20:05
@asergunov asergunov changed the title rvr_status_config_peers_controller initial commit Add RVR Status Config Peers Controller Nov 28, 2025
@asergunov asergunov linked an issue Nov 28, 2025 that may be closed by this pull request
Signed-off-by: Anton Sergunov <[email protected]>
…r handling

- Replaced WithTransform with gcustom.MakeMatcher in the HaveAllPeersSet and HaveAllPeersSetForAll matchers to enhance error handling and clarity.
- Streamlined the matcher logic to ensure consistent behavior when validating RVR peers.

Signed-off-by: Anton Sergunov <[email protected]>
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.

[controller] Implement rvr-status-config-peers-controller

2 participants