Skip to content

Conversation

Julien-Ben
Copy link
Collaborator

@Julien-Ben Julien-Ben commented Oct 21, 2025

Summary

This PR refactors the ReplicaSet controller to use the helper pattern and separate state reading/writing, matching what we already do in the ShardedCluster and OpsManager controllers.

This is a no-op refactor: no behavior changes, just reorganizing code to prepare for multi-cluster support.

What Changed

Added ReplicaSetReconcilerHelper

  • New helper struct that holds state for a single reconcile run
  • Main reconcile logic moved from the controller to the helper
  • Helper gets created fresh for each reconcile
  • This is the pattern we used in our other reconcilers

Separated State Operations

  • readState() - reads deployment state from annotations
  • writeState() - writes deployment state back to annotations ; write vault annotations only on successful reconciliation. In the same way it is done in the sharded controller. (note that vault is not supported for multi replica set at this point)
  • initialize() - loads state during helper creation
  • This is done to clearly show where we handle data persisted on the cluster, as opposed to reading and writing in multiple places during the reconciliation. This is important for multi-cluster support

Helper's updateStatus() Override

  • Writes deployment state after every status update
  • Keeps state consistent even when we return early
  • Same pattern as ShardedCluster controller

Added ReplicaSetDeploymentState

  • Holds the state we persist between reconciles
  • Just has LastAchievedSpec for now (same as before)

Not in This PR

These will (potentially) come in follow-up PRs, in the main feature branch for multi cluster support:

  • StateStore pattern (like ShardedCluster/OpsManager use)
  • Use ConfigMap for state persistence
  • State migration logic

Proof of work

  • Existing tests pass without changes

Checklist

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you added changelog file?

@github-actions
Copy link

⚠️ (this preview might not be accurate if the PR is not rebased on current master branch)

MCK 1.6.0 Release Notes

New Features

  • MongoDBCommunity: Added support to configure custom cluster domain via newly introduced spec.clusterDomain resource field. If spec.clusterDomain is not set, environment variable CLUSTER_DOMAIN is used as cluster domain. If the environment variable CLUSTER_DOMAIN is also not set, operator falls back to cluster.local as default cluster domain.
  • Helm Chart: Introduced two new helm fields operator.podSecurityContext and operator.securityContext that can be used to configure securityContext for Operator deployment through Helm Chart.

Bug Fixes

  • Fixed parsing of the customEnvVars Helm value when values contain = characters.

@Julien-Ben Julien-Ben added the skip-changelog Use this label in Pull Request to not require new changelog entry file label Oct 21, 2025
@Julien-Ben Julien-Ben mentioned this pull request Oct 21, 2025
3 tasks
@Julien-Ben Julien-Ben changed the title Refactor replica set controller state handling, and use helper pattern CLOUDP-353180: Refactor replica set controller state handling, and use helper pattern Oct 22, 2025
@Julien-Ben Julien-Ben marked this pull request as ready for review October 22, 2025 12:48
@Julien-Ben Julien-Ben requested a review from a team as a code owner October 22, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use this label in Pull Request to not require new changelog entry file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant